Browse Source

calculate size

Michael 2 years ago
parent
commit
b73f9d6e30
2 changed files with 33 additions and 14 deletions
  1. 31 13
      client/lobby/OptionsTab.cpp
  2. 2 1
      client/lobby/OptionsTab.h

+ 31 - 13
client/lobby/OptionsTab.cpp

@@ -424,11 +424,6 @@ OptionsTab::SelectionWindow::SelectionWindow(PlayerColor _color)
 
 
 	color = _color;
 	color = _color;
 
 
-	pos = Rect(0, 0, (ELEMENTS_PER_LINE * 2 + 5) * 58, 700);
-
-	backgroundTexture = std::make_shared<CFilledTexture>("DIBOXBCK", pos);
-	updateShadow();
-
 	initialFraction = SEL->getStartInfo()->playerInfos.find(color)->second.castle;
 	initialFraction = SEL->getStartInfo()->playerInfos.find(color)->second.castle;
 	initialHero = SEL->getStartInfo()->playerInfos.find(color)->second.hero;
 	initialHero = SEL->getStartInfo()->playerInfos.find(color)->second.hero;
 	initialBonus = SEL->getStartInfo()->playerInfos.find(color)->second.bonus;
 	initialBonus = SEL->getStartInfo()->playerInfos.find(color)->second.bonus;
@@ -436,13 +431,43 @@ OptionsTab::SelectionWindow::SelectionWindow(PlayerColor _color)
 	selectedHero = initialHero;
 	selectedHero = initialHero;
 	selectedBonus = initialBonus;
 	selectedBonus = initialBonus;
 	allowedFactions = SEL->getPlayerInfo(color.getNum()).allowedFactions;
 	allowedFactions = SEL->getPlayerInfo(color.getNum()).allowedFactions;
-	allowedHeroes = SEL->getMapInfo()->mapHeader->allowedHeroes;
+	std::vector<bool> allowedHeroesFlag = SEL->getMapInfo()->mapHeader->allowedHeroes;
+	for(int i = 0; i < allowedHeroesFlag.size(); i++)
+		if(allowedHeroesFlag[i])
+			allowedHeroes.insert(HeroTypeID(i));
+
+	pos = Rect(0, 0, (ELEMENTS_PER_LINE * 2 + 5) * 58, calcHeight());
+
+	backgroundTexture = std::make_shared<CFilledTexture>("DIBOXBCK", pos);
+	updateShadow();
 
 
 	recreate();
 	recreate();
 
 
 	center();
 	center();
 }
 }
 
 
+int OptionsTab::SelectionWindow::calcHeight()
+{
+	// size count
+	int max = 0;
+	for(auto & elemf : allowedHeroes)
+	{
+		int count = 0;
+		for(auto & elemh : allowedHeroes)
+		{
+			CHero * type = VLC->heroh->objects[elemh];
+			if(type->heroClass->faction == elemf)
+				count++;
+		}
+		max = std::max(max, count);
+	}
+	max = std::max(max, (int)allowedFactions.size());
+
+	int y = max / ELEMENTS_PER_LINE + 3;
+
+	return y * 64;
+}
+
 void OptionsTab::SelectionWindow::apply()
 void OptionsTab::SelectionWindow::apply()
 {
 {
 	if(GH.windows().isTopWindow(this))
 	if(GH.windows().isTopWindow(this))
@@ -555,13 +580,6 @@ void OptionsTab::SelectionWindow::genContentHeroes()
 	CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO);
 	CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO);
 	components.push_back(std::make_shared<CAnimImage>(helper.getImageName(), helper.getImageIndex(), 0, (ELEMENTS_PER_LINE / 2) * 58 + (ELEMENTS_PER_LINE + 1) * 58 + 34, 32 / 2 + 64));
 	components.push_back(std::make_shared<CAnimImage>(helper.getImageName(), helper.getImageIndex(), 0, (ELEMENTS_PER_LINE / 2) * 58 + (ELEMENTS_PER_LINE + 1) * 58 + 34, 32 / 2 + 64));
 
 
-	std::vector<bool> allowedHeroesFlag = allowedHeroes;
-
-	std::set<HeroTypeID> allowedHeroes;
-	for(int i = 0; i < allowedHeroesFlag.size(); i++)
-		if(allowedHeroesFlag[i])
-			allowedHeroes.insert(HeroTypeID(i));
-
 	int i = 0;
 	int i = 0;
 	for(auto & elem : allowedHeroes)
 	for(auto & elem : allowedHeroes)
 	{
 	{

+ 2 - 1
client/lobby/OptionsTab.h

@@ -115,7 +115,7 @@ public:
 		int selectedBonus;
 		int selectedBonus;
 
 
 		std::set<FactionID> allowedFactions;
 		std::set<FactionID> allowedFactions;
-		std::vector<bool> allowedHeroes;
+		std::set<HeroTypeID> allowedHeroes;
 		std::vector<bool> allowedBonus;
 		std::vector<bool> allowedBonus;
 
 
 		void genContentTitle();
 		void genContentTitle();
@@ -123,6 +123,7 @@ public:
 		void genContentHeroes();
 		void genContentHeroes();
 		void genContentBonus();
 		void genContentBonus();
 
 
+		int calcHeight();
 		void apply();
 		void apply();
 		void recreate();
 		void recreate();
 		void setSelection();
 		void setSelection();