mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Fix stack label position updates
This commit is contained in:
@@ -35,8 +35,6 @@
|
|||||||
#include "../../lib/CStack.h"
|
#include "../../lib/CStack.h"
|
||||||
#include "../../lib/spells/ISpellMechanics.h"
|
#include "../../lib/spells/ISpellMechanics.h"
|
||||||
|
|
||||||
#include <SDL_events.h>
|
|
||||||
|
|
||||||
BattleFieldController::BattleFieldController(BattleInterface & owner):
|
BattleFieldController::BattleFieldController(BattleInterface & owner):
|
||||||
owner(owner)
|
owner(owner)
|
||||||
{
|
{
|
||||||
@@ -67,10 +65,7 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
|
|||||||
|
|
||||||
backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
|
backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
|
||||||
|
|
||||||
auto accessibility = owner.curInt->cb->getAccesibility();
|
updateAccessibleHexes();
|
||||||
for(int i = 0; i < accessibility.size(); i++)
|
|
||||||
stackCountOutsideHexes[i] = (accessibility[i] == EAccessibility::ACCESSIBLE);
|
|
||||||
|
|
||||||
addUsedEvents(LCLICK | RCLICK | MOVE);
|
addUsedEvents(LCLICK | RCLICK | MOVE);
|
||||||
LOCPLINT->cingconsole->pos = this->pos;
|
LOCPLINT->cingconsole->pos = this->pos;
|
||||||
}
|
}
|
||||||
@@ -180,11 +175,6 @@ void BattleFieldController::redrawBackgroundWithHexes()
|
|||||||
if (activeStack)
|
if (activeStack)
|
||||||
occupyableHexes = owner.curInt->cb->battleGetAvailableHexes(activeStack, true, &attackableHexes);
|
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
|
//prepare background graphic with hexes and shaded hexes
|
||||||
backgroundWithHexes->draw(background, Point(0,0));
|
backgroundWithHexes->draw(background, Point(0,0));
|
||||||
owner.obstacleController->showAbsoluteObstacles(*backgroundWithHexes);
|
owner.obstacleController->showAbsoluteObstacles(*backgroundWithHexes);
|
||||||
@@ -579,6 +569,14 @@ bool BattleFieldController::isTileAttackable(const BattleHex & number) const
|
|||||||
return false;
|
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
|
bool BattleFieldController::stackCountOutsideHex(const BattleHex & number) const
|
||||||
{
|
{
|
||||||
return stackCountOutsideHexes[number];
|
return stackCountOutsideHexes[number];
|
||||||
@@ -591,6 +589,7 @@ void BattleFieldController::showAll(SDL_Surface * to)
|
|||||||
|
|
||||||
void BattleFieldController::show(SDL_Surface * to)
|
void BattleFieldController::show(SDL_Surface * to)
|
||||||
{
|
{
|
||||||
|
updateAccessibleHexes();
|
||||||
owner.stacksController->update();
|
owner.stacksController->update();
|
||||||
owner.obstacleController->update();
|
owner.obstacleController->update();
|
||||||
|
|
||||||
|
@@ -56,6 +56,7 @@ class BattleFieldController : public CIntObject
|
|||||||
void showBackgroundImage(Canvas & canvas);
|
void showBackgroundImage(Canvas & canvas);
|
||||||
void showBackgroundImageWithHexes(Canvas & canvas);
|
void showBackgroundImageWithHexes(Canvas & canvas);
|
||||||
void showHighlightedHexes(Canvas & canvas);
|
void showHighlightedHexes(Canvas & canvas);
|
||||||
|
void updateAccessibleHexes();
|
||||||
|
|
||||||
BattleHex::EDir selectAttackDirection(BattleHex myNumber, const Point & point);
|
BattleHex::EDir selectAttackDirection(BattleHex myNumber, const Point & point);
|
||||||
|
|
||||||
|
@@ -296,47 +296,42 @@ std::shared_ptr<IImage> BattleStacksController::getStackAmountBox(const CStack *
|
|||||||
|
|
||||||
void BattleStacksController::showStackAmountBox(Canvas & canvas, const CStack * stack)
|
void BattleStacksController::showStackAmountBox(Canvas & canvas, const CStack * stack)
|
||||||
{
|
{
|
||||||
//blitting amount background box
|
|
||||||
auto amountBG = getStackAmountBox(stack);
|
auto amountBG = getStackAmountBox(stack);
|
||||||
|
|
||||||
bool doubleWide = stack->doubleWide();
|
bool doubleWide = stack->doubleWide();
|
||||||
|
bool turnedRight = facingRight(stack);
|
||||||
bool attacker = stack->side == BattleSide::ATTACKER;
|
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::RIGHT) :
|
||||||
stackPos.cloneInDirection(BattleHex::LEFT);
|
stackPos.cloneInDirection(BattleHex::LEFT);
|
||||||
|
|
||||||
bool moveInside = frontPos.isAvailable() && !owner.fieldController->stackCountOutsideHex(frontPos);
|
bool moveInside = !owner.fieldController->stackCountOutsideHex(frontPos);
|
||||||
|
|
||||||
Point boxPosition;
|
Point boxPosition;
|
||||||
|
|
||||||
if (attacker)
|
|
||||||
{
|
|
||||||
if (moveInside)
|
if (moveInside)
|
||||||
boxPosition = Point(181, 252);
|
{
|
||||||
else
|
boxPosition = owner.fieldController->hexPositionLocal(stackPos).center() + Point(-15, 1);
|
||||||
boxPosition = Point(218, 252);
|
|
||||||
|
|
||||||
if (doubleWide)
|
|
||||||
boxPosition.x += 44;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (moveInside)
|
if (turnedRight)
|
||||||
boxPosition = Point(239, 252);
|
boxPosition = owner.fieldController->hexPositionLocal(frontPos).center() + Point (-22, 1);
|
||||||
else
|
else
|
||||||
boxPosition = Point(202, 237);
|
boxPosition = owner.fieldController->hexPositionLocal(frontPos).center() + Point(-8, -14);
|
||||||
|
|
||||||
if (doubleWide)
|
|
||||||
boxPosition.x -= 44;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.draw(amountBG, stackAnimation[stack->ID]->pos.topLeft() + boxPosition);
|
Point textPosition = amountBG->dimensions()/2 + boxPosition;
|
||||||
|
|
||||||
//blitting amount
|
canvas.draw(amountBG, boxPosition);
|
||||||
Point textPos = stackAnimation[stack->ID]->pos.topLeft() + amountBG->dimensions()/2 + boxPosition;
|
canvas.drawText(textPosition, EFonts::FONT_TINY, Colors::WHITE, ETextAlignment::CENTER, TextOperations::formatMetric(stack->getCount(), 4));
|
||||||
|
|
||||||
canvas.drawText(textPos, EFonts::FONT_TINY, Colors::WHITE, ETextAlignment::CENTER, TextOperations::formatMetric(stack->getCount(), 4));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleStacksController::showStack(Canvas & canvas, const CStack * stack)
|
void BattleStacksController::showStack(Canvas & canvas, const CStack * stack)
|
||||||
|
Reference in New Issue
Block a user