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

CHeroArea fix

This commit is contained in:
SoundSSGood 2023-09-03 21:42:22 +03:00
parent 3675d88730
commit f1a6116088
4 changed files with 31 additions and 14 deletions

View File

@ -114,9 +114,10 @@ void LRClickableAreaWTextComp::showPopupWindow(const Point & cursorPosition)
LRClickableAreaWText::showPopupWindow(cursorPosition); //only if with-component variant not occurred
}
CHeroArea::CHeroArea(int x, int y, const CGHeroInstance * _hero)
CHeroArea::CHeroArea(int x, int y, const CGHeroInstance * hero)
: CIntObject(LCLICK | HOVER),
hero(_hero)
hero(hero),
clickFunctor(nullptr)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@ -126,13 +127,24 @@ CHeroArea::CHeroArea(int x, int y, const CGHeroInstance * _hero)
pos.h = 64;
if(hero)
{
portrait = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero->portrait);
clickFunctor = [hero]() -> void
{
LOCPLINT->openHeroWindow(hero);
};
}
}
void CHeroArea::addClickCallback(ClickFunctor callback)
{
clickFunctor = callback;
}
void CHeroArea::clickPressed(const Point & cursorPosition)
{
if(hero)
LOCPLINT->openHeroWindow(hero);
if(clickFunctor)
clickFunctor();
}
void CHeroArea::hover(bool on)

View File

@ -164,17 +164,21 @@ public:
~CMinorResDataBar();
};
/// Opens hero window by left-clicking on it
/// Performs an action by left-clicking on it. Opens hero window by default
class CHeroArea: public CIntObject
{
const CGHeroInstance * hero;
std::shared_ptr<CAnimImage> portrait;
public:
CHeroArea(int x, int y, const CGHeroInstance * _hero);
using ClickFunctor = std::function<void()>;
CHeroArea(int x, int y, const CGHeroInstance * hero);
void addClickCallback(ClickFunctor callback);
void clickPressed(const Point & cursorPosition) override;
void hover(bool on) override;
private:
const CGHeroInstance * hero;
std::shared_ptr<CAnimImage> portrait;
ClickFunctor clickFunctor;
ClickFunctor showPopupHandler;
};
/// Can interact on left and right mouse clicks

View File

@ -884,9 +884,6 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
manaValues[leftRight] = std::make_shared<CLabel>(155 + 490 * leftRight, qeLayout ? 66 : 71, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
}
portraits[0] = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), heroInst[0]->portrait, 0, 257, 13);
portraits[1] = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), heroInst[1]->portrait, 0, 485, 13);
artifs[0] = std::make_shared<CArtifactsOfHeroMain>(Point(-334, 150));
artifs[0]->setHero(heroInst[0]);
artifs[1] = std::make_shared<CArtifactsOfHeroMain>(Point(98, 150));
@ -933,7 +930,12 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
boost::algorithm::replace_first(secSkillAreas[b][g]->hoverText, "%s", CGI->skillh->getByIndex(skill)->getNameTranslated());
}
heroAreas[b] = std::make_shared<CHeroArea>(257 + 228*b, 13, hero);
heroAreas[b] = std::make_shared<CHeroArea>(257 + 228 * b, 13, hero);
heroAreas[b]->addClickCallback([this, hero]() -> void
{
if(getPickedArtifact() == nullptr)
LOCPLINT->openHeroWindow(hero);
});
specialtyAreas[b] = std::make_shared<LRClickableAreaWText>();
specialtyAreas[b]->pos = Rect(Point(pos.x + 69 + 490 * b, pos.y + (qeLayout ? 41 : 45)), Point(32, 32));

View File

@ -286,7 +286,6 @@ class CExchangeWindow : public CStatusbarWindow, public IGarrisonHolder, public
std::array<std::shared_ptr<CLabel>, 2> expValues;
std::array<std::shared_ptr<CAnimImage>, 2> manaImages;
std::array<std::shared_ptr<CLabel>, 2> manaValues;
std::array<std::shared_ptr<CAnimImage>, 2> portraits;
std::vector<std::shared_ptr<LRClickableAreaWTextComp>> primSkillAreas;
std::array<std::vector<std::shared_ptr<LRClickableAreaWTextComp>>, 2> secSkillAreas;