From 0f00dbf8cf9f24c97f0620d996cb2746d0ec8607 Mon Sep 17 00:00:00 2001 From: Raphnalor <37222713+Raphnalor@users.noreply.github.com> Date: Sat, 17 Mar 2018 07:23:22 +0300 Subject: [PATCH] Fix highlighting of a selected bonus for campaign. (#432) --- client/CPreGame.cpp | 2 +- client/battle/CBattleInterfaceClasses.cpp | 2 +- client/widgets/Buttons.cpp | 18 ++++++++++++++++++ client/widgets/Buttons.h | 12 ++++++++++-- client/windows/CCastleInterface.cpp | 4 ++-- client/windows/GUIClasses.cpp | 2 +- client/windows/InfoWindows.cpp | 2 +- 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index c2509148c..7d3e1f4cf 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -3712,7 +3712,7 @@ void CBonusSelection::updateBonusSelection() anim->setCustom(picName, 0); bonusButton->setImage(anim); const SDL_Color brightYellow = { 242, 226, 110, 0 }; - bonusButton->borderColor = boost::make_optional(brightYellow); + bonusButton->setBorderColor({}, {}, {}, brightYellow); bonuses->addToggle(i, bonusButton); } diff --git a/client/battle/CBattleInterfaceClasses.cpp b/client/battle/CBattleInterfaceClasses.cpp index 3425b6d1b..86632c253 100644 --- a/client/battle/CBattleInterfaceClasses.cpp +++ b/client/battle/CBattleInterfaceClasses.cpp @@ -347,7 +347,7 @@ CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect bg->colorize(owner.playerID); 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 { diff --git a/client/widgets/Buttons.cpp b/client/widgets/Buttons.cpp index ed93a75ee..1c32f2761 100644 --- a/client/widgets/Buttons.cpp +++ b/client/widgets/Buttons.cpp @@ -52,6 +52,23 @@ void CButton::update() redraw(); } +void CButton::setBorderColor(boost::optional borderColor) +{ + setBorderColor(borderColor, borderColor, borderColor, borderColor); +} + +void CButton::setBorderColor(boost::optional normalBorderColor, + boost::optional pressedBorderColor, + boost::optional blockedBorderColor, + boost::optional highlightedBorderColor) +{ + stateToBorderColor[NORMAL] = normalBorderColor; + stateToBorderColor[PRESSED] = pressedBorderColor; + stateToBorderColor[BLOCKED] = blockedBorderColor; + stateToBorderColor[HIGHLIGHTED] = highlightedBorderColor; + update(); +} + void CButton::addCallback(std::function callback) { this->callback += callback; @@ -273,6 +290,7 @@ void CButton::showAll(SDL_Surface * to) { CIntObject::showAll(to); + auto borderColor = stateToBorderColor[getState()]; 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)); } diff --git a/client/widgets/Buttons.h b/client/widgets/Buttons.h index 7334a3c48..e390fdb00 100644 --- a/client/widgets/Buttons.h +++ b/client/widgets/Buttons.h @@ -47,6 +47,7 @@ private: std::array stateToIndex; // mapping of button state to index of frame in animation std::array hoverTexts; //texts for statusbar, if empty - first entry will be used + std::array, 4> stateToBorderColor; // mapping of button state to border color std::string helpBox; //for right-click help CAnimImage * image; //image for this button @@ -65,8 +66,15 @@ public: hoverable,//if true, button will be highlighted when hovered (e.g. main menu) soundDisabled; - // if set, button will have 1-px border around it with this color - boost::optional 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 normalBorderColor, + boost::optional pressedBorderColor, + boost::optional blockedBorderColor, + boost::optional highlightedBorderColor); + + // sets the same border color for all button states. + void setBorderColor(boost::optional borderColor); /// adds one more callback to on-click actions void addCallback(std::function callback); diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 67d4ee30e..77851a3b5 100644 --- a/client/windows/CCastleInterface.cpp +++ b/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()); 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); 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); } } diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index cf6d3a47c..b0af3ad91 100644 --- a/client/windows/GUIClasses.cpp +++ b/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->assignedKeys.insert(SDLK_ESCAPE); - quitb->borderColor = boost::make_optional(Colors::METALLIC_GOLD); + quitb->setBorderColor(Colors::METALLIC_GOLD); new CPicture("PUZZLOGO", 607, 3); new CLabel(700, 95, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[463]); diff --git a/client/windows/InfoWindows.cpp b/client/windows/InfoWindows.cpp index 81e28edfd..48af4c4f7 100644 --- a/client/windows/InfoWindows.cpp +++ b/client/windows/InfoWindows.cpp @@ -126,7 +126,7 @@ CInfoWindow::CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo for(auto & Button : Buttons) { 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 buttons.push_back(button); }