1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

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

This commit is contained in:
Raphnalor 2018-03-17 07:23:22 +03:00 committed by ArseniyShestakov
parent 1e9a3e0fe4
commit 0f00dbf8cf
7 changed files with 34 additions and 8 deletions

View File

@ -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);
}

View File

@ -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
{

View File

@ -52,6 +52,23 @@ void CButton::update()
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)
{
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));
}

View File

@ -47,6 +47,7 @@ private:
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<boost::optional<SDL_Color>, 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<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
void addCallback(std::function<void()> callback);

View File

@ -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);
}
}

View File

@ -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]);

View File

@ -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);
}