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

Merge pull request #3375 from Laserlicht/round_counter

turn indicator
This commit is contained in:
Ivan Savenko 2023-12-24 16:25:04 +02:00 committed by GitHub
commit 172e385f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View File

@ -58,6 +58,7 @@ BattleInterface::BattleInterface(const BattleID & battleID, const CCreatureSet *
, curInt(att)
, battleID(battleID)
, battleOpeningDelayActive(true)
, round(0)
{
if(spectatorInt)
{
@ -235,6 +236,7 @@ void BattleInterface::newRoundFirst()
void BattleInterface::newRound()
{
console->addText(CGI->generaltexth->allTexts[412]);
round++;
}
void BattleInterface::giveCommand(EActionType action, BattleHex tile, SpellID spell)

View File

@ -136,6 +136,7 @@ public:
const CGHeroInstance *defendingHeroInstance;
bool tacticsMode;
ui32 round;
std::unique_ptr<BattleProjectileController> projectilesController;
std::unique_ptr<BattleSiegeController> siegeController;

View File

@ -34,6 +34,7 @@
#include "../widgets/Buttons.h"
#include "../widgets/Images.h"
#include "../widgets/TextControls.h"
#include "../widgets/MiscWidgets.h"
#include "../windows/CMessage.h"
#include "../windows/CSpellWindow.h"
#include "../render/CAnimation.h"
@ -787,11 +788,16 @@ void StackQueue::update()
owner.getBattle()->battleGetTurnOrder(queueData, stackBoxes.size(), 0);
size_t boxIndex = 0;
ui32 tmpTurn = -1;
for(size_t turn = 0; turn < queueData.size() && boxIndex < stackBoxes.size(); turn++)
{
for(size_t unitIndex = 0; unitIndex < queueData[turn].size() && boxIndex < stackBoxes.size(); boxIndex++, unitIndex++)
stackBoxes[boxIndex]->setUnit(queueData[turn][unitIndex], turn);
{
ui32 currentTurn = owner.round + turn;
stackBoxes[boxIndex]->setUnit(queueData[turn][unitIndex], turn, tmpTurn != currentTurn && owner.round != 0 && (!embedded || tmpTurn != -1) ? (std::optional<ui32>)currentTurn : std::nullopt);
tmpTurn = currentTurn;
}
}
for(; boxIndex < stackBoxes.size(); boxIndex++)
@ -829,11 +835,14 @@ StackQueue::StackBox::StackBox(StackQueue * owner):
{
icon = std::make_shared<CAnimImage>(owner->icons, 0, 0, 5, 2);
amount = std::make_shared<CLabel>(pos.w/2, pos.h - 7, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
roundRect = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, 2, 48), ColorRGBA(0, 0, 0, 255), ColorRGBA(0, 255, 0, 255));
}
else
{
icon = std::make_shared<CAnimImage>(owner->icons, 0, 0, 9, 1);
amount = std::make_shared<CLabel>(pos.w/2, pos.h - 8, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE);
roundRect = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, 15, 18), ColorRGBA(0, 0, 0, 255), ColorRGBA(241, 216, 120, 255));
round = std::make_shared<CLabel>(4, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
int icon_x = pos.w - 17;
int icon_y = pos.h - 18;
@ -841,9 +850,10 @@ StackQueue::StackBox::StackBox(StackQueue * owner):
stateIcon = std::make_shared<CAnimImage>(owner->stateIcons, 0, 0, icon_x, icon_y);
stateIcon->visible = false;
}
roundRect->disable();
}
void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn)
void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn, std::optional<ui32> currentTurn)
{
if(unit)
{
@ -861,6 +871,16 @@ void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn)
icon->setFrame(owner->getSiegeShooterIconID(), 1);
amount->setText(TextOperations::formatMetric(unit->getCount(), 4));
if(currentTurn && !owner->embedded)
{
std::string tmp = std::to_string(*currentTurn);
int len = graphics->fonts[FONT_SMALL]->getStringWidth(tmp);
roundRect->pos.w = len + 6;
round->setText(tmp);
}
roundRect->setEnabled(currentTurn.has_value());
if(!owner->embedded)
round->setEnabled(currentTurn.has_value());
if(stateIcon)
{

View File

@ -39,6 +39,7 @@ class CToggleButton;
class CLabel;
class CTextBox;
class CAnimImage;
class TransparentFilledRectangle;
class CPlayerInterface;
class BattleRenderer;
@ -206,6 +207,8 @@ class StackQueue : public CIntObject
std::shared_ptr<CAnimImage> icon;
std::shared_ptr<CLabel> amount;
std::shared_ptr<CAnimImage> stateIcon;
std::shared_ptr<CLabel> round;
std::shared_ptr<TransparentFilledRectangle> roundRect;
void show(Canvas & to) override;
void showAll(Canvas & to) override;
@ -213,9 +216,8 @@ class StackQueue : public CIntObject
bool isBoundUnitHighlighted() const;
public:
StackBox(StackQueue * owner);
void setUnit(const battle::Unit * unit, size_t turn = 0);
void setUnit(const battle::Unit * unit, size_t turn = 0, std::optional<ui32> currentTurn = std::nullopt);
std::optional<uint32_t> getBoundUnitID() const;
};
static const int QUEUE_SIZE = 10;