From 3af829e6af08422700a0f336cc1f80e6555f7f63 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 29 Mar 2023 13:03:40 +0300 Subject: [PATCH] Fix stack label position updates --- client/battle/BattleFieldController.cpp | 21 ++++++------ client/battle/BattleFieldController.h | 1 + client/battle/BattleStacksController.cpp | 41 +++++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/client/battle/BattleFieldController.cpp b/client/battle/BattleFieldController.cpp index 369fc78ac..c11d82a93 100644 --- a/client/battle/BattleFieldController.cpp +++ b/client/battle/BattleFieldController.cpp @@ -35,8 +35,6 @@ #include "../../lib/CStack.h" #include "../../lib/spells/ISpellMechanics.h" -#include - BattleFieldController::BattleFieldController(BattleInterface & owner): owner(owner) { @@ -67,10 +65,7 @@ BattleFieldController::BattleFieldController(BattleInterface & owner): backgroundWithHexes = std::make_unique(Point(background->width(), background->height())); - auto accessibility = owner.curInt->cb->getAccesibility(); - for(int i = 0; i < accessibility.size(); i++) - stackCountOutsideHexes[i] = (accessibility[i] == EAccessibility::ACCESSIBLE); - + updateAccessibleHexes(); addUsedEvents(LCLICK | RCLICK | MOVE); LOCPLINT->cingconsole->pos = this->pos; } @@ -180,11 +175,6 @@ void BattleFieldController::redrawBackgroundWithHexes() if (activeStack) occupyableHexes = owner.curInt->cb->battleGetAvailableHexes(activeStack, true, &attackableHexes); - auto accessibility = owner.curInt->cb->getAccesibility(); - - for(int i = 0; i < accessibility.size(); i++) - stackCountOutsideHexes[i] = (accessibility[i] == EAccessibility::ACCESSIBLE); - //prepare background graphic with hexes and shaded hexes backgroundWithHexes->draw(background, Point(0,0)); owner.obstacleController->showAbsoluteObstacles(*backgroundWithHexes); @@ -579,6 +569,14 @@ bool BattleFieldController::isTileAttackable(const BattleHex & number) const return false; } +void BattleFieldController::updateAccessibleHexes() +{ + auto accessibility = owner.curInt->cb->getAccesibility(); + + for(int i = 0; i < accessibility.size(); i++) + stackCountOutsideHexes[i] = (accessibility[i] == EAccessibility::ACCESSIBLE || (accessibility[i] == EAccessibility::SIDE_COLUMN)); +} + bool BattleFieldController::stackCountOutsideHex(const BattleHex & number) const { return stackCountOutsideHexes[number]; @@ -591,6 +589,7 @@ void BattleFieldController::showAll(SDL_Surface * to) void BattleFieldController::show(SDL_Surface * to) { + updateAccessibleHexes(); owner.stacksController->update(); owner.obstacleController->update(); diff --git a/client/battle/BattleFieldController.h b/client/battle/BattleFieldController.h index fdb5cd22e..60e5ad240 100644 --- a/client/battle/BattleFieldController.h +++ b/client/battle/BattleFieldController.h @@ -56,6 +56,7 @@ class BattleFieldController : public CIntObject void showBackgroundImage(Canvas & canvas); void showBackgroundImageWithHexes(Canvas & canvas); void showHighlightedHexes(Canvas & canvas); + void updateAccessibleHexes(); BattleHex::EDir selectAttackDirection(BattleHex myNumber, const Point & point); diff --git a/client/battle/BattleStacksController.cpp b/client/battle/BattleStacksController.cpp index 81b50b042..5a3229c69 100644 --- a/client/battle/BattleStacksController.cpp +++ b/client/battle/BattleStacksController.cpp @@ -296,47 +296,42 @@ std::shared_ptr BattleStacksController::getStackAmountBox(const CStack * void BattleStacksController::showStackAmountBox(Canvas & canvas, const CStack * stack) { - //blitting amount background box auto amountBG = getStackAmountBox(stack); bool doubleWide = stack->doubleWide(); + bool turnedRight = facingRight(stack); bool attacker = stack->side == BattleSide::ATTACKER; - const BattleHex stackPos = stack->getPosition(); - const BattleHex frontPos = attacker ? + + BattleHex stackPos = stack->getPosition(); + + // double-wide unit turned around - use opposite hex for stack label + if (doubleWide && turnedRight != attacker) + stackPos = stack->occupiedHex(); + + BattleHex frontPos = turnedRight ? stackPos.cloneInDirection(BattleHex::RIGHT) : stackPos.cloneInDirection(BattleHex::LEFT); - bool moveInside = frontPos.isAvailable() && !owner.fieldController->stackCountOutsideHex(frontPos); + bool moveInside = !owner.fieldController->stackCountOutsideHex(frontPos); Point boxPosition; - if (attacker) + if (moveInside) { - if (moveInside) - boxPosition = Point(181, 252); - else - boxPosition = Point(218, 252); - - if (doubleWide) - boxPosition.x += 44; + boxPosition = owner.fieldController->hexPositionLocal(stackPos).center() + Point(-15, 1); } else { - if (moveInside) - boxPosition = Point(239, 252); + if (turnedRight) + boxPosition = owner.fieldController->hexPositionLocal(frontPos).center() + Point (-22, 1); else - boxPosition = Point(202, 237); - - if (doubleWide) - boxPosition.x -= 44; + boxPosition = owner.fieldController->hexPositionLocal(frontPos).center() + Point(-8, -14); } - canvas.draw(amountBG, stackAnimation[stack->ID]->pos.topLeft() + boxPosition); + Point textPosition = amountBG->dimensions()/2 + boxPosition; - //blitting amount - Point textPos = stackAnimation[stack->ID]->pos.topLeft() + amountBG->dimensions()/2 + boxPosition; - - canvas.drawText(textPos, EFonts::FONT_TINY, Colors::WHITE, ETextAlignment::CENTER, TextOperations::formatMetric(stack->getCount(), 4)); + canvas.draw(amountBG, boxPosition); + canvas.drawText(textPosition, EFonts::FONT_TINY, Colors::WHITE, ETextAlignment::CENTER, TextOperations::formatMetric(stack->getCount(), 4)); } void BattleStacksController::showStack(Canvas & canvas, const CStack * stack)