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

Fix stack label position updates

This commit is contained in:
Ivan Savenko 2023-03-29 13:03:40 +03:00
parent 0c023347dd
commit 3af829e6af
3 changed files with 29 additions and 34 deletions

View File

@ -35,8 +35,6 @@
#include "../../lib/CStack.h"
#include "../../lib/spells/ISpellMechanics.h"
#include <SDL_events.h>
BattleFieldController::BattleFieldController(BattleInterface & owner):
owner(owner)
{
@ -67,10 +65,7 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
backgroundWithHexes = std::make_unique<Canvas>(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();

View File

@ -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);

View File

@ -296,47 +296,42 @@ std::shared_ptr<IImage> 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)