Browse Source

saving states

Michael 2 years ago
parent
commit
c40c747ccf
2 changed files with 30 additions and 21 deletions
  1. 19 19
      client/lobby/OptionsTab.cpp
  2. 11 2
      client/lobby/OptionsTab.h

+ 19 - 19
client/lobby/OptionsTab.cpp

@@ -415,24 +415,29 @@ void OptionsTab::CPlayerOptionTooltipBox::genBonusWindow()
 	textBonusDescription = std::make_shared<CTextBox>(getDescription(), Rect(10, 100, pos.w - 20, 70), 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
 }
 
-OptionsTab::SelectionWindow::SelectionWindow(int color)
+OptionsTab::SelectionWindow::SelectionWindow(PlayerColor _color)
 	: CWindowObject(BORDERED)
 {
 	addUsedEvents(LCLICK | SHOW_POPUP);
 
 	OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
 
-	color = color;
+	color = _color;
 
 	pos = Rect(0, 0, (ELEMENTS_PER_LINE * 2 + 5) * 58, 700);
 
 	backgroundTexture = std::make_shared<CFilledTexture>("DIBOXBCK", pos);
 	updateShadow();
 
-	genContentTitle();
-	genContentCastles();
-	genContentHeroes();
-	genContentBonus();
+	initialFraction = SEL->getStartInfo()->playerInfos.find(color)->second.castle;
+	initialHero = SEL->getStartInfo()->playerInfos.find(color)->second.hero;
+	initialBonus = SEL->getStartInfo()->playerInfos.find(color)->second.bonus;
+	selectedFraction = initialFraction;
+	selectedHero = selectedHero;
+	selectedBonus = selectedBonus;
+	allowedFactions = SEL->getPlayerInfo(color.getNum()).allowedFactions;
+
+	redraw();
 
 	center();
 }
@@ -442,6 +447,8 @@ void OptionsTab::SelectionWindow::apply()
 	if(GH.windows().isTopWindow(this))
 	{
 		close();
+
+		CSH->setPlayerOption(LobbyChangePlayerOption::TOWN, 1, color);
 	}
 }
 
@@ -471,10 +478,8 @@ void OptionsTab::SelectionWindow::genContentCastles()
 	CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN);
 	components.push_back(std::make_shared<CAnimImage>(helper.getImageName(), helper.getImageIndex(), 0, (ELEMENTS_PER_LINE / 2) * 58 + 34, 32 / 2 + 64));
 
-
-
 	int i = 0;
-	for(auto & elem : SEL->getPlayerInfo(0).allowedFactions)
+	for(auto & elem : allowedFactions)
 	{
 		int x = i % ELEMENTS_PER_LINE + 1;
 		int y = i / ELEMENTS_PER_LINE + 2;
@@ -512,7 +517,7 @@ void OptionsTab::SelectionWindow::genContentHeroes()
 	{
 		CHero * type = VLC->heroh->objects[elem];
 
-		if(type->heroClass->faction == SEL->getStartInfo()->playerInfos.find(PlayerColor(color))->second.castle)
+		if(type->heroClass->faction == selectedFraction)
 		{
 
 			int x = (i % ELEMENTS_PER_LINE) + ELEMENTS_PER_LINE + 2;
@@ -619,22 +624,17 @@ void OptionsTab::SelectionWindow::clickReleased(const Point & cursorPosition) {
 
 	if(set.castle != -2)
 	{
-		//SEL->getStartInfo()->playerInfos.find(PlayerColor(color))->second.castle = faction;
-
-		CSH->setPlayerOption(LobbyChangePlayerOption::TOWN, 1, PlayerColor(color));
-
+		selectedFraction = set.castle;
 		redraw();
-		//CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN);
-		
 	}
 	else if(set.hero != -2)
 	{
-		//CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO);
+		selectedHero = set.hero;
 		apply();
 	}
 	else if(set.bonus != -2)
 	{
-		//CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::BONUS);
+		selectedBonus = set.bonus;
 		apply();
 	}
 }
@@ -700,7 +700,7 @@ void OptionsTab::SelectedBox::showPopupWindow(const Point & cursorPosition)
 
 void OptionsTab::SelectedBox::clickReleased(const Point & cursorPosition)
 {
-	GH.windows().createAndPushWindow<SelectionWindow>(settings.color.getNum());
+	GH.windows().createAndPushWindow<SelectionWindow>(settings.color);
 }
 
 void OptionsTab::SelectedBox::scrollBy(int distance)

+ 11 - 2
client/lobby/OptionsTab.h

@@ -99,7 +99,7 @@ public:
 	{
 		const int ELEMENTS_PER_LINE = 4;
 
-		ui8 color;
+		PlayerColor color;
 
 		std::shared_ptr<CFilledTexture> backgroundTexture;
 		std::vector<std::shared_ptr<CIntObject>> components;
@@ -107,6 +107,15 @@ public:
 		std::vector<FactionID> factions;
 		std::vector<HeroTypeID> heroes;
 
+		FactionID initialFraction;
+		HeroTypeID initialHero;
+		int initialBonus;
+		FactionID selectedFraction;
+		HeroTypeID selectedHero;
+		int selectedBonus;
+
+		std::set<FactionID> allowedFactions;
+
 		void genContentTitle();
 		void genContentCastles();
 		void genContentHeroes();
@@ -123,7 +132,7 @@ public:
 		void showPopupWindow(const Point & cursorPosition) override;
 
 	public:
-		SelectionWindow(int color);
+		SelectionWindow(PlayerColor _color);
 	};
 
 	/// Image with current town/hero/bonus