1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Highlight stack on queue icon hovered

This commit is contained in:
Dydzio 2023-01-22 20:03:11 +01:00
parent a19c9eccc4
commit 92754e22f0
8 changed files with 55 additions and 2 deletions

View File

@ -807,8 +807,21 @@ int32_t StackQueue::getSiegeShooterIconID()
return owner.siegeController->getSiegedTown()->town->faction->getIndex(); return owner.siegeController->getSiegedTown()->town->faction->getIndex();
} }
boost::optional<uint32_t> StackQueue::getHoveredUnitIdIfAny() const
{
for(const auto & stackBox : stackBoxes)
{
if(stackBox->hovered)
{
return stackBox->getBoundUnitID();
}
}
return boost::none;
}
StackQueue::StackBox::StackBox(StackQueue * owner): StackQueue::StackBox::StackBox(StackQueue * owner):
owner(owner) CIntObject(HOVER), owner(owner)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
background = std::make_shared<CPicture>(owner->embedded ? "StackQueueSmall" : "StackQueueLarge"); background = std::make_shared<CPicture>(owner->embedded ? "StackQueueSmall" : "StackQueueLarge");
@ -838,6 +851,7 @@ void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn)
{ {
if(unit) if(unit)
{ {
boundUnitID = unit->unitId();
background->colorize(unit->unitOwner()); background->colorize(unit->unitOwner());
icon->visible = true; icon->visible = true;
@ -872,6 +886,7 @@ void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn)
} }
else else
{ {
boundUnitID = boost::none;
background->colorize(PlayerColor::NEUTRAL); background->colorize(PlayerColor::NEUTRAL);
icon->visible = false; icon->visible = false;
icon->setFrame(0); icon->setFrame(0);
@ -881,3 +896,8 @@ void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn)
stateIcon->visible = false; stateIcon->visible = false;
} }
} }
boost::optional<uint32_t> StackQueue::StackBox::getBoundUnitID() const
{
return boundUnitID;
}

View File

@ -196,6 +196,7 @@ class StackQueue : public CIntObject
class StackBox : public CIntObject class StackBox : public CIntObject
{ {
StackQueue * owner; StackQueue * owner;
boost::optional<uint32_t> boundUnitID;
public: public:
std::shared_ptr<CPicture> background; std::shared_ptr<CPicture> background;
std::shared_ptr<CAnimImage> icon; std::shared_ptr<CAnimImage> icon;
@ -204,6 +205,7 @@ class StackQueue : public CIntObject
void setUnit(const battle::Unit * unit, size_t turn = 0); void setUnit(const battle::Unit * unit, size_t turn = 0);
StackBox(StackQueue * owner); StackBox(StackQueue * owner);
boost::optional<uint32_t> getBoundUnitID() const;
}; };
static const int QUEUE_SIZE = 10; static const int QUEUE_SIZE = 10;
@ -220,6 +222,7 @@ public:
StackQueue(bool Embedded, BattleInterface & owner); StackQueue(bool Embedded, BattleInterface & owner);
void update(); void update();
boost::optional<uint32_t> getHoveredUnitIdIfAny() const;
void show(SDL_Surface * to) override; void show(SDL_Surface * to) override;
}; };

View File

@ -897,6 +897,12 @@ std::vector<const CStack *> BattleStacksController::selectHoveredStacks()
if(owner.getAnimationCondition(EAnimationEvents::ACTION) == true) if(owner.getAnimationCondition(EAnimationEvents::ACTION) == true)
return {}; return {};
auto hoveredQueueUnitId = owner.windowObject->getQueueHoveredUnitId();
if(hoveredQueueUnitId.has_value())
{
return { owner.curInt->cb->battleGetStackByUnitId(hoveredQueueUnitId.value(), true) };
}
auto hoveredHex = owner.fieldController->getHoveredHex(); auto hoveredHex = owner.fieldController->getHoveredHex();
if (!hoveredHex.isValid()) if (!hoveredHex.isValid())

View File

@ -70,7 +70,7 @@ class BattleStacksController
/// currently active stack; nullptr - no one /// currently active stack; nullptr - no one
const CStack *activeStack; const CStack *activeStack;
/// stacks below mouse pointer (multiple stacks possible while spellcasting), used for border animation /// stacks or their battle queue images below mouse pointer (multiple stacks possible while spellcasting), used for border animation
std::vector<const CStack *> mouseHoveredStacks; std::vector<const CStack *> mouseHoveredStacks;
///when animation is playing, we should wait till the end to make the next stack active; nullptr of none ///when animation is playing, we should wait till the end to make the next stack active; nullptr of none

View File

@ -550,6 +550,11 @@ void BattleWindow::blockUI(bool on)
} }
} }
boost::optional<uint32_t> BattleWindow::getQueueHoveredUnitId()
{
return queue->getHoveredUnitIdIfAny();
}
void BattleWindow::showAll(SDL_Surface *to) void BattleWindow::showAll(SDL_Surface *to)
{ {
CIntObject::showAll(to); CIntObject::showAll(to);

View File

@ -74,6 +74,9 @@ public:
/// Refresh queue after turn order changes /// Refresh queue after turn order changes
void updateQueue(); void updateQueue();
/// Get mouse-hovered battle queue unit ID if any found
boost::optional<uint32_t> getQueueHoveredUnitId();
void activate() override; void activate() override;
void deactivate() override; void deactivate() override;
void keyPressed(const SDL_KeyboardEvent & key) override; void keyPressed(const SDL_KeyboardEvent & key) override;

View File

@ -185,6 +185,21 @@ const CStack* CBattleInfoEssentials::battleGetStackByID(int ID, bool onlyAlive)
return stacks[0]; return stacks[0];
} }
const CStack* CBattleInfoEssentials::battleGetStackByUnitId(int unitId, bool onlyAlive) const
{
RETURN_IF_NOT_BATTLE(nullptr);
auto stacks = battleGetStacksIf([=](const CStack * s)
{
return s->unitId() == unitId && (!onlyAlive || s->alive());
});
if(stacks.empty())
return nullptr;
else
return stacks[0];
}
bool CBattleInfoEssentials::battleDoWeKnowAbout(ui8 side) const bool CBattleInfoEssentials::battleDoWeKnowAbout(ui8 side) const
{ {
RETURN_IF_NOT_BATTLE(false); RETURN_IF_NOT_BATTLE(false);

View File

@ -102,6 +102,7 @@ public:
TStacks battleGetAllStacks(bool includeTurrets = false) const; TStacks battleGetAllStacks(bool includeTurrets = false) const;
const CStack * battleGetStackByID(int ID, bool onlyAlive = true) const; //returns stack info by given ID const CStack * battleGetStackByID(int ID, bool onlyAlive = true) const; //returns stack info by given ID
const CStack * battleGetStackByUnitId(int unitId, bool onlyAlive = true) const; //returns stack info by given ID
bool battleIsObstacleVisibleForSide(const CObstacleInstance & coi, BattlePerspective::BattlePerspective side) const; bool battleIsObstacleVisibleForSide(const CObstacleInstance & coi, BattlePerspective::BattlePerspective side) const;
///returns player that controls given stack; mind control included ///returns player that controls given stack; mind control included