1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Merge pull request #3575 from Laserlicht/infobox_pos

fix infobox position while disabling
This commit is contained in:
Ivan Savenko 2024-01-30 17:36:30 +02:00 committed by GitHub
commit 5d8b65befd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 20 deletions

View File

@ -449,12 +449,10 @@ void HeroInfoBasicPanel::show(Canvas & to)
}
StackInfoBasicPanel::StackInfoBasicPanel(const CStack * stack, Point * position, bool initializeBackground)
StackInfoBasicPanel::StackInfoBasicPanel(const CStack * stack, bool initializeBackground)
: CIntObject(0)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
if (position != nullptr)
moveTo(*position);
if(initializeBackground)
{

View File

@ -155,7 +155,7 @@ private:
std::vector<std::shared_ptr<CMultiLineLabel>> labelsMultiline;
std::vector<std::shared_ptr<CAnimImage>> icons;
public:
StackInfoBasicPanel(const CStack * stack, Point * position, bool initializeBackground = true);
StackInfoBasicPanel(const CStack * stack, bool initializeBackground = true);
void show(Canvas & to) override;

View File

@ -139,19 +139,13 @@ void BattleWindow::createStickyHeroInfoWindows()
{
InfoAboutHero info;
info.initFromHero(owner.defendingHeroInstance, InfoAboutHero::EInfoLevel::INBATTLE);
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x + pos.w + 15, pos.y + 60)
: Point(pos.x + pos.w -79, pos.y + 195);
defenderHeroWindow = std::make_shared<HeroInfoBasicPanel>(info, &position);
defenderHeroWindow = std::make_shared<HeroInfoBasicPanel>(info, nullptr);
}
if(owner.attackingHeroInstance)
{
InfoAboutHero info;
info.initFromHero(owner.attackingHeroInstance, InfoAboutHero::EInfoLevel::INBATTLE);
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x - 93, pos.y + 60)
: Point(pos.x + 1, pos.y + 195);
attackerHeroWindow = std::make_shared<HeroInfoBasicPanel>(info, &position);
attackerHeroWindow = std::make_shared<HeroInfoBasicPanel>(info, nullptr);
}
bool showInfoWindows = settings["battle"]["stickyHeroInfoWindows"].Bool();
@ -164,6 +158,8 @@ void BattleWindow::createStickyHeroInfoWindows()
if(defenderHeroWindow)
defenderHeroWindow->disable();
}
setPositionInfoWindow();
}
void BattleWindow::createTimerInfoWindows()
@ -231,6 +227,7 @@ void BattleWindow::hideQueue()
pos.h -= queue->pos.h;
pos = center();
}
setPositionInfoWindow();
GH.windows().totalRedraw();
}
@ -244,6 +241,7 @@ void BattleWindow::showQueue()
createQueue();
updateQueue();
setPositionInfoWindow();
GH.windows().totalRedraw();
}
@ -290,6 +288,38 @@ void BattleWindow::updateQueue()
queue->update();
}
void BattleWindow::setPositionInfoWindow()
{
if(defenderHeroWindow)
{
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x + pos.w + 15, pos.y + 60)
: Point(pos.x + pos.w -79, pos.y + 195);
defenderHeroWindow->moveTo(position);
}
if(attackerHeroWindow)
{
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x - 93, pos.y + 60)
: Point(pos.x + 1, pos.y + 195);
attackerHeroWindow->moveTo(position);
}
if(defenderStackWindow)
{
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x + pos.w + 15, defenderHeroWindow ? defenderHeroWindow->pos.y + 210 : pos.y + 60)
: Point(pos.x + pos.w -79, defenderHeroWindow ? defenderHeroWindow->pos.y : pos.y + 195);
defenderStackWindow->moveTo(position);
}
if(attackerStackWindow)
{
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x - 93, attackerHeroWindow ? attackerHeroWindow->pos.y + 210 : pos.y + 60)
: Point(pos.x + 1, attackerHeroWindow ? attackerHeroWindow->pos.y : pos.y + 195);
attackerStackWindow->moveTo(position);
}
}
void BattleWindow::updateHeroInfoWindow(uint8_t side, const InfoAboutHero & hero)
{
std::shared_ptr<HeroInfoBasicPanel> panelToUpdate = side == 0 ? attackerHeroWindow : defenderHeroWindow;
@ -304,10 +334,7 @@ void BattleWindow::updateStackInfoWindow(const CStack * stack)
if(stack && stack->unitSide() == BattleSide::DEFENDER)
{
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x + pos.w + 15, defenderHeroWindow ? defenderHeroWindow->pos.y + 210 : pos.y)
: Point(pos.x + pos.w -79, defenderHeroWindow ? defenderHeroWindow->pos.y : pos.y + 135);
defenderStackWindow = std::make_shared<StackInfoBasicPanel>(stack, &position);
defenderStackWindow = std::make_shared<StackInfoBasicPanel>(stack);
defenderStackWindow->setEnabled(showInfoWindows);
}
else
@ -315,14 +342,13 @@ void BattleWindow::updateStackInfoWindow(const CStack * stack)
if(stack && stack->unitSide() == BattleSide::ATTACKER)
{
Point position = (GH.screenDimensions().x >= 1000)
? Point(pos.x - 93, attackerHeroWindow ? attackerHeroWindow->pos.y + 210 : pos.y)
: Point(pos.x + 1, attackerHeroWindow ? attackerHeroWindow->pos.y : pos.y + 135);
attackerStackWindow = std::make_shared<StackInfoBasicPanel>(stack, &position);
attackerStackWindow = std::make_shared<StackInfoBasicPanel>(stack);
attackerStackWindow->setEnabled(showInfoWindows);
}
else
attackerStackWindow = nullptr;
setPositionInfoWindow();
}
void BattleWindow::heroManaPointsChanged(const CGHeroInstance * hero)

View File

@ -102,6 +102,9 @@ public:
/// Refresh queue after turn order changes
void updateQueue();
// Set positions for hero & stack info window
void setPositionInfoWindow();
/// Refresh sticky variant of hero info window after spellcast, side same as in BattleSpellCast::side
void updateHeroInfoWindow(uint8_t side, const InfoAboutHero & hero);