1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Unified naming of method to recolor UI element to current player scheme

This commit is contained in:
Ivan Savenko 2024-06-05 15:50:50 +00:00
parent 9f31ec5326
commit 920a39844b
20 changed files with 43 additions and 45 deletions

View File

@ -399,7 +399,7 @@ void AdventureMapInterface::onCurrentPlayerChanged(PlayerColor playerID)
return;
currentPlayerID = playerID;
widget->setPlayer(playerID);
widget->setPlayerColor(playerID);
}
void AdventureMapInterface::onPlayerTurnStarted(PlayerColor playerID)
@ -914,7 +914,7 @@ void AdventureMapInterface::onScreenResize()
widget = std::make_shared<AdventureMapWidget>(shortcuts);
widget->getMapView()->onViewMapActivated();
widget->setPlayer(currentPlayerID);
widget->setPlayerColor(currentPlayerID);
widget->updateActiveState();
widget->getMinimap()->update();
widget->getInfoBar()->showSelection();

View File

@ -335,7 +335,7 @@ std::shared_ptr<CInfoBar> AdventureMapWidget::getInfoBar()
return infoBar;
}
void AdventureMapWidget::setPlayer(const PlayerColor & player)
void AdventureMapWidget::setPlayerColor(const PlayerColor & player)
{
setPlayerChildren(this, player);
}
@ -354,16 +354,16 @@ void AdventureMapWidget::setPlayerChildren(CIntObject * widget, const PlayerColo
button->setPlayerColor(player);
if(resDataBar)
resDataBar->colorize(player);
resDataBar->setPlayerColor(player);
if(icon)
icon->setPlayer(player);
icon->setPlayerColor(player);
if(container)
setPlayerChildren(container, player);
if (texture)
texture->playerColored(player);
texture->setPlayerColor(player);
}
redraw();
@ -378,7 +378,7 @@ CAdventureMapIcon::CAdventureMapIcon(const Point & position, const AnimationPath
image = std::make_shared<CAnimImage>(animation, index);
}
void CAdventureMapIcon::setPlayer(const PlayerColor & player)
void CAdventureMapIcon::setPlayerColor(const PlayerColor & player)
{
image->setFrame(index + player.getNum() * iconsPerPlayer);
}

View File

@ -56,7 +56,6 @@ class AdventureMapWidget : public InterfaceObjectConfigurable
std::shared_ptr<CIntObject> buildStatusBar(const JsonNode & input);
std::shared_ptr<CIntObject> buildTexturePlayerColored(const JsonNode &);
void setPlayerChildren(CIntObject * widget, const PlayerColor & player);
void updateActiveStateChildden(CIntObject * widget);
public:
@ -68,7 +67,7 @@ public:
std::shared_ptr<MapView> getMapView();
std::shared_ptr<CInfoBar> getInfoBar();
void setPlayer(const PlayerColor & player);
void setPlayerColor(const PlayerColor & player);
void onMapViewMoved(const Rect & visibleArea, int mapLevel);
void updateActiveState();
@ -98,5 +97,5 @@ class CAdventureMapIcon : public CIntObject
public:
CAdventureMapIcon(const Point & position, const AnimationPath & image, size_t index, size_t iconsPerPlayer);
void setPlayer(const PlayerColor & player);
void setPlayerColor(const PlayerColor & player);
};

View File

@ -31,7 +31,7 @@ CResDataBar::CResDataBar(const ImagePath & imageName, const Point & position)
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
background = std::make_shared<CPicture>(imageName, 0, 0);
background->colorize(LOCPLINT->playerID);
background->setPlayerColor(LOCPLINT->playerID);
pos.w = background->pos.w;
pos.h = background->pos.h;
@ -84,7 +84,7 @@ void CResDataBar::showAll(Canvas & to)
to.drawText(pos.topLeft() + *datePosition, FONT_SMALL, Colors::WHITE, ETextAlignment::TOPLEFT, buildDateString());
}
void CResDataBar::colorize(PlayerColor player)
void CResDataBar::setPlayerColor(PlayerColor player)
{
background->colorize(player);
background->setPlayerColor(player);
}

View File

@ -34,7 +34,7 @@ public:
void setDatePosition(const Point & position);
void setResourcePosition(const GameResID & resource, const Point & position);
void colorize(PlayerColor player);
void setPlayerColor(PlayerColor player);
void showAll(Canvas & to) override;
};

View File

@ -506,7 +506,7 @@ HeroInfoBasicPanel::HeroInfoBasicPanel(const InfoAboutHero & hero, Point * posit
{
background = std::make_shared<CPicture>(ImagePath::builtin("CHRPOP"));
background->getSurface()->setBlitMode(EImageBlitMode::OPAQUE);
background->colorize(hero.owner);
background->setPlayerColor(hero.owner);
}
initializeData(hero);
@ -574,10 +574,10 @@ StackInfoBasicPanel::StackInfoBasicPanel(const CStack * stack, bool initializeBa
background = std::make_shared<CPicture>(ImagePath::builtin("CCRPOP"));
background->pos.y += 37;
background->getSurface()->setBlitMode(EImageBlitMode::OPAQUE);
background->colorize(stack->getOwner());
background->setPlayerColor(stack->getOwner());
background2 = std::make_shared<CPicture>(ImagePath::builtin("CHRPOP"));
background2->getSurface()->setBlitMode(EImageBlitMode::OPAQUE);
background2->colorize(stack->getOwner());
background2->setPlayerColor(stack->getOwner());
}
initializeData(stack);
@ -681,7 +681,7 @@ HeroInfoWindow::HeroInfoWindow(const InfoAboutHero & hero, Point * position)
if (position != nullptr)
moveTo(*position);
background->colorize(hero.owner); //maybe add this functionality to base class?
background->setPlayerColor(hero.owner); //maybe add this functionality to base class?
content = std::make_shared<HeroInfoBasicPanel>(hero, nullptr, false);
}
@ -692,7 +692,7 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
background = std::make_shared<CPicture>(ImagePath::builtin("CPRESULT"));
background->colorize(owner.playerID);
background->setPlayerColor(owner.playerID);
pos = center(background->pos);
exit = std::make_shared<CButton>(Point(384, 505), AnimationPath::builtin("iok6432.def"), std::make_pair("", ""), [&](){ bExitf();}, EShortcut::GLOBAL_ACCEPT);
@ -1037,7 +1037,7 @@ void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn, std::
if(unit)
{
boundUnitID = unit->unitId();
background->colorize(unit->unitOwner());
background->setPlayerColor(unit->unitOwner());
icon->visible = true;
// temporary code for mod compatibility:
@ -1083,7 +1083,7 @@ void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn, std::
else
{
boundUnitID = std::nullopt;
background->colorize(PlayerColor::NEUTRAL);
background->setPlayerColor(PlayerColor::NEUTRAL);
icon->visible = false;
icon->setFrame(0);
amount->setText("");

View File

@ -79,7 +79,7 @@ GlobalLobbyInviteWindow::GlobalLobbyInviteWindow()
pos.h = 420;
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
filledBackground->playerColored(PlayerColor(1));
filledBackground->setPlayerColor(PlayerColor(1));
labelTitle = std::make_shared<CLabel>(
pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.invite.header").toString()
);

View File

@ -70,7 +70,7 @@ GlobalLobbyLoginWindow::GlobalLobbyLoginWindow()
else
toggleMode->setSelected(1);
filledBackground->playerColored(PlayerColor(1));
filledBackground->setPlayerColor(PlayerColor(1));
inputUsername->setCallback([this](const std::string & text)
{
this->buttonLogin->block(text.empty());

View File

@ -188,7 +188,7 @@ GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const s
modListTitle = std::make_shared<CLabel>( 182, 59, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.preview.mods").toString());
buttonJoin->block(!errorMessage.empty());
filledBackground->playerColored(PlayerColor(1));
filledBackground->setPlayerColor(PlayerColor(1));
center();
}

View File

@ -78,7 +78,7 @@ GlobalLobbyServerSetup::GlobalLobbyServerSetup()
buttonCreate = std::make_shared<CButton>(Point(10, 300), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this](){ onCreate(); }, EShortcut::GLOBAL_ACCEPT);
buttonClose = std::make_shared<CButton>(Point(210, 300), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this](){ onClose(); }, EShortcut::GLOBAL_CANCEL);
filledBackground->playerColored(PlayerColor(1));
filledBackground->setPlayerColor(PlayerColor(1));
updateDescription();
center();

View File

@ -333,7 +333,7 @@ std::shared_ptr<CPicture> InterfaceObjectConfigurable::buildPicture(const JsonNo
auto pic = std::make_shared<CPicture>(image, position.x, position.y);
if ( config["playerColored"].Bool() && LOCPLINT)
pic->colorize(LOCPLINT->playerID);
pic->setPlayerColor(LOCPLINT->playerID);
return pic;
}
@ -571,7 +571,7 @@ std::shared_ptr<CFilledTexture> InterfaceObjectConfigurable::buildTexture(const
if(playerColor.isValidPlayer())
{
auto result = std::make_shared<FilledTexturePlayerColored>(image, rect);
result->playerColored(playerColor);
result->setPlayerColor(playerColor);
return result;
}
return std::make_shared<CFilledTexture>(image, rect);

View File

@ -401,7 +401,7 @@ PvPBox::PvPBox(const Rect & rect)
setRedrawParent(true);
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, rect.w, rect.h));
backgroundTexture->playerColored(PlayerColor(1));
backgroundTexture->setPlayerColor(PlayerColor(1));
backgroundBorder = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, rect.w, rect.h), ColorRGBA(0, 0, 0, 64), ColorRGBA(96, 96, 96, 255), 1);
townSelector = std::make_shared<TownSelector>(Point(5, 3));

View File

@ -518,9 +518,8 @@ void OptionsTab::SelectionWindow::recreate(int sliderPos)
int sliderWidth = ((amountLines > MAX_LINES) ? 16 : 0);
pos = Rect(pos.x, pos.y, x + sliderWidth, y);
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w - sliderWidth, pos.h));
backgroundTexture->playerColored(PlayerColor(1));
backgroundTexture->setPlayerColor(PlayerColor(1));
updateShadow();
if(type == SelType::TOWN)

View File

@ -99,7 +99,7 @@ void ButtonBase::setImage(const AnimationPath & defName, bool playerColoredButto
pos = image->pos;
if (playerColoredButton)
image->playerColored(LOCPLINT->playerID);
image->setPlayerColor(LOCPLINT->playerID);
}
const JsonNode & ButtonBase::getCurrentConfig() const
@ -134,7 +134,7 @@ void ButtonBase::setConfigurable(const JsonPath & jsonName, bool playerColoredBu
pos = configurable->pos;
if (playerColoredButton)
image->playerColored(LOCPLINT->playerID);
image->setPlayerColor(LOCPLINT->playerID);
}
void CButton::addHoverText(EButtonState state, const std::string & text)
@ -364,7 +364,7 @@ CButton::CButton(Point position, const AnimationPath &defName, const std::pair<s
void ButtonBase::setPlayerColor(PlayerColor player)
{
if (image && image->isPlayerColored())
image->playerColored(player);
image->setPlayerColor(player);
}
void CButton::showAll(Canvas & to)

View File

@ -106,7 +106,7 @@ void CPicture::scaleTo(Point size)
pos.h = bg->height();
}
void CPicture::colorize(PlayerColor player)
void CPicture::setPlayerColor(PlayerColor player)
{
bg->playerColored(player);
}
@ -145,7 +145,7 @@ FilledTexturePlayerColored::FilledTexturePlayerColored(const ImagePath & imageNa
{
}
void FilledTexturePlayerColored::playerColored(PlayerColor player)
void FilledTexturePlayerColored::setPlayerColor(PlayerColor player)
{
// Color transform to make color of brown DIBOX.PCX texture match color of specified player
std::array<ColorFilter, PlayerColor::PLAYER_LIMIT_I> filters = {
@ -301,7 +301,7 @@ void CAnimImage::setFrame(size_t Frame, size_t Group)
logGlobal->error("Error: accessing unavailable frame %d:%d in CAnimation!", Group, Frame);
}
void CAnimImage::playerColored(PlayerColor currPlayer)
void CAnimImage::setPlayerColor(PlayerColor currPlayer)
{
player = currPlayer;
anim->getImage(frame, group)->playerColored(*player);

View File

@ -54,7 +54,7 @@ public:
/// 0=transparent, 255=opaque
void setAlpha(uint8_t value);
void scaleTo(Point size);
void colorize(PlayerColor player);
void setPlayerColor(PlayerColor player);
void show(Canvas & to) override;
void showAll(Canvas & to) override;
@ -79,7 +79,7 @@ class FilledTexturePlayerColored : public CFilledTexture
public:
FilledTexturePlayerColored(const ImagePath & imageName, Rect position);
void playerColored(PlayerColor player);
void setPlayerColor(PlayerColor player);
};
/// Class for displaying one image from animation
@ -114,7 +114,7 @@ public:
void setFrame(size_t Frame, size_t Group=0);
/// makes image player-colored to specific player
void playerColored(PlayerColor player);
void setPlayerColor(PlayerColor player);
/// returns true if image has player-colored effect applied
bool isPlayerColored() const;

View File

@ -248,7 +248,7 @@ CMinorResDataBar::CMinorResDataBar()
pos.y = 575;
background = std::make_shared<CPicture>(ImagePath::builtin("KRESBAR.bmp"));
background->colorize(LOCPLINT->playerID);
background->setPlayerColor(LOCPLINT->playerID);
pos.w = background->pos.w;
pos.h = background->pos.h;

View File

@ -272,7 +272,7 @@ CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstanc
: CWindowObject(RCLICK_POPUP, ImagePath::builtin("CRTOINFO"), Point(centerX, centerY))
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
background->colorize(Town->tempOwner);
background->setPlayerColor(Town->tempOwner);
const CCreature * creature = Town->creatures.at(level).second.back().toCreature();
@ -1245,7 +1245,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
builds = std::make_shared<CCastleBuildings>(town);
panel = std::make_shared<CPicture>(ImagePath::builtin("TOWNSCRN"), 0, builds->pos.h);
panel->colorize(LOCPLINT->playerID);
panel->setPlayerColor(LOCPLINT->playerID);
pos.w = panel->pos.w;
pos.h = builds->pos.h + panel->pos.h;
center();

View File

@ -692,7 +692,7 @@ CKingdHeroList::CKingdHeroList(size_t maxSize, const CreateHeroItemFunctor & onC
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
title = std::make_shared<CPicture>(ImagePath::builtin("OVTITLE"),16,0);
title->colorize(LOCPLINT->playerID);
title->setPlayerColor(LOCPLINT->playerID);
heroLabel = std::make_shared<CLabel>(150, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[0]);
skillsLabel = std::make_shared<CLabel>(500, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[1]);
@ -736,7 +736,7 @@ CKingdTownList::CKingdTownList(size_t maxSize)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
title = std::make_shared<CPicture>(ImagePath::builtin("OVTITLE"), 16, 0);
title->colorize(LOCPLINT->playerID);
title->setPlayerColor(LOCPLINT->playerID);
townLabel = std::make_shared<CLabel>(146, 10,FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[3]);
garrHeroLabel = std::make_shared<CLabel>(375, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[4]);
visitHeroLabel = std::make_shared<CLabel>(608, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[5]);

View File

@ -93,7 +93,7 @@ std::shared_ptr<CPicture> CWindowObject::createBg(const ImagePath & imageName, b
auto image = std::make_shared<CPicture>(imageName);
image->getSurface()->setBlitMode(EImageBlitMode::OPAQUE);
if(playerColored)
image->colorize(LOCPLINT->playerID);
image->setPlayerColor(LOCPLINT->playerID);
return image;
}