Ver Fonte

Fix highlighting of a selected bonus for campaign. (#432)

Raphnalor há 7 anos atrás
pai
commit
0f00dbf8cf

+ 1 - 1
client/CPreGame.cpp

@@ -3712,7 +3712,7 @@ void CBonusSelection::updateBonusSelection()
 		anim->setCustom(picName, 0);
 		anim->setCustom(picName, 0);
 		bonusButton->setImage(anim);
 		bonusButton->setImage(anim);
 		const SDL_Color brightYellow = { 242, 226, 110, 0 };
 		const SDL_Color brightYellow = { 242, 226, 110, 0 };
-		bonusButton->borderColor = boost::make_optional(brightYellow);
+		bonusButton->setBorderColor({}, {}, {}, brightYellow);
 		bonuses->addToggle(i, bonusButton);
 		bonuses->addToggle(i, bonusButton);
 	}
 	}
 
 

+ 1 - 1
client/battle/CBattleInterfaceClasses.cpp

@@ -347,7 +347,7 @@ CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect
 	bg->colorize(owner.playerID);
 	bg->colorize(owner.playerID);
 
 
 	exit = new CButton (Point(384, 505), "iok6432.def", std::make_pair("", ""), [&](){ bExitf();}, SDLK_RETURN);
 	exit = new CButton (Point(384, 505), "iok6432.def", std::make_pair("", ""), [&](){ bExitf();}, SDLK_RETURN);
-	exit->borderColor = boost::make_optional(Colors::METALLIC_GOLD);
+	exit->setBorderColor(Colors::METALLIC_GOLD);
 
 
 	if(br.winner==0) //attacker won
 	if(br.winner==0) //attacker won
 	{
 	{

+ 18 - 0
client/widgets/Buttons.cpp

@@ -52,6 +52,23 @@ void CButton::update()
 		redraw();
 		redraw();
 }
 }
 
 
+void CButton::setBorderColor(boost::optional<SDL_Color> borderColor)
+{
+	setBorderColor(borderColor, borderColor, borderColor, borderColor);
+}
+
+void CButton::setBorderColor(boost::optional<SDL_Color> normalBorderColor,
+                             boost::optional<SDL_Color> pressedBorderColor,
+                             boost::optional<SDL_Color> blockedBorderColor,
+                             boost::optional<SDL_Color> highlightedBorderColor)
+{
+	stateToBorderColor[NORMAL] = normalBorderColor;
+	stateToBorderColor[PRESSED] = pressedBorderColor;
+	stateToBorderColor[BLOCKED] = blockedBorderColor;
+	stateToBorderColor[HIGHLIGHTED] = highlightedBorderColor;
+	update();
+}
+
 void CButton::addCallback(std::function<void()> callback)
 void CButton::addCallback(std::function<void()> callback)
 {
 {
 	this->callback += callback;
 	this->callback += callback;
@@ -273,6 +290,7 @@ void CButton::showAll(SDL_Surface * to)
 {
 {
 	CIntObject::showAll(to);
 	CIntObject::showAll(to);
 
 
+	auto borderColor = stateToBorderColor[getState()];
 	if (borderColor && borderColor->a == 0)
 	if (borderColor && borderColor->a == 0)
 		CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor->r, borderColor->g, borderColor->b));
 		CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor->r, borderColor->g, borderColor->b));
 }
 }

+ 10 - 2
client/widgets/Buttons.h

@@ -47,6 +47,7 @@ private:
 
 
 	std::array<int, 4> stateToIndex; // mapping of button state to index of frame in animation
 	std::array<int, 4> stateToIndex; // mapping of button state to index of frame in animation
 	std::array<std::string, 4> hoverTexts; //texts for statusbar, if empty - first entry will be used
 	std::array<std::string, 4> hoverTexts; //texts for statusbar, if empty - first entry will be used
+	std::array<boost::optional<SDL_Color>, 4> stateToBorderColor; // mapping of button state to border color
 	std::string helpBox; //for right-click help
 	std::string helpBox; //for right-click help
 
 
 	CAnimImage * image; //image for this button
 	CAnimImage * image; //image for this button
@@ -65,8 +66,15 @@ public:
 		hoverable,//if true, button will be highlighted when hovered (e.g. main menu)
 		hoverable,//if true, button will be highlighted when hovered (e.g. main menu)
 		soundDisabled;
 		soundDisabled;
 
 
-	// if set, button will have 1-px border around it with this color
-	boost::optional<SDL_Color> borderColor;
+	// sets border color for each button state;
+	// if it's set, the button will have 1-px border around it with this color
+	void setBorderColor(boost::optional<SDL_Color> normalBorderColor,
+	                    boost::optional<SDL_Color> pressedBorderColor,
+	                    boost::optional<SDL_Color> blockedBorderColor,
+	                    boost::optional<SDL_Color> highlightedBorderColor);
+
+	// sets the same border color for all button states.
+	void setBorderColor(boost::optional<SDL_Color> borderColor);
 
 
 	/// adds one more callback to on-click actions
 	/// adds one more callback to on-click actions
 	void addCallback(std::function<void()> callback);
 	void addCallback(std::function<void()> callback);

+ 2 - 2
client/windows/CCastleInterface.cpp

@@ -1451,11 +1451,11 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin
 		std::string tooltipNo  = boost::str(boost::format(CGI->generaltexth->allTexts[596]) % building->Name());
 		std::string tooltipNo  = boost::str(boost::format(CGI->generaltexth->allTexts[596]) % building->Name());
 
 
 		CButton * buy = new CButton(Point(45, 446), "IBUY30", CButton::tooltip(tooltipYes), [&](){ buyFunc(); }, SDLK_RETURN);
 		CButton * buy = new CButton(Point(45, 446), "IBUY30", CButton::tooltip(tooltipYes), [&](){ buyFunc(); }, SDLK_RETURN);
-		buy->borderColor = boost::make_optional(Colors::METALLIC_GOLD);
+		buy->setBorderColor(Colors::METALLIC_GOLD);
 		buy->block(state!=7 || LOCPLINT->playerID != town->tempOwner);
 		buy->block(state!=7 || LOCPLINT->playerID != town->tempOwner);
 
 
 		CButton * cancel = new CButton(Point(290, 445), "ICANCEL", CButton::tooltip(tooltipNo), [&](){ close();}, SDLK_ESCAPE);
 		CButton * cancel = new CButton(Point(290, 445), "ICANCEL", CButton::tooltip(tooltipNo), [&](){ close();}, SDLK_ESCAPE);
-		cancel->borderColor = boost::make_optional(Colors::METALLIC_GOLD);
+		cancel->setBorderColor(Colors::METALLIC_GOLD);
 	}
 	}
 }
 }
 
 

+ 1 - 1
client/windows/GUIClasses.cpp

@@ -1005,7 +1005,7 @@ CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio):
 
 
 	quitb = new CButton(Point(670, 538), "IOK6432.DEF", CButton::tooltip(CGI->generaltexth->allTexts[599]), std::bind(&CPuzzleWindow::close, this), SDLK_RETURN);
 	quitb = new CButton(Point(670, 538), "IOK6432.DEF", CButton::tooltip(CGI->generaltexth->allTexts[599]), std::bind(&CPuzzleWindow::close, this), SDLK_RETURN);
 	quitb->assignedKeys.insert(SDLK_ESCAPE);
 	quitb->assignedKeys.insert(SDLK_ESCAPE);
-	quitb->borderColor = boost::make_optional(Colors::METALLIC_GOLD);
+	quitb->setBorderColor(Colors::METALLIC_GOLD);
 
 
 	new CPicture("PUZZLOGO", 607, 3);
 	new CPicture("PUZZLOGO", 607, 3);
 	new CLabel(700, 95, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[463]);
 	new CLabel(700, 95, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[463]);

+ 1 - 1
client/windows/InfoWindows.cpp

@@ -126,7 +126,7 @@ CInfoWindow::CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo
 	for(auto & Button : Buttons)
 	for(auto & Button : Buttons)
 	{
 	{
 		CButton *button = new CButton(Point(0,0), Button.first, CButton::tooltip(), std::bind(&CInfoWindow::close,this));
 		CButton *button = new CButton(Point(0,0), Button.first, CButton::tooltip(), std::bind(&CInfoWindow::close,this));
-		button->borderColor = boost::make_optional(Colors::METALLIC_GOLD);
+		button->setBorderColor(Colors::METALLIC_GOLD);
 		button->addCallback(Button.second); //each button will close the window apart from call-defined actions
 		button->addCallback(Button.second); //each button will close the window apart from call-defined actions
 		buttons.push_back(button);
 		buttons.push_back(button);
 	}
 	}