2023-10-19 16:19:09 +02:00
|
|
|
/*
|
|
|
|
* BattleInterfaceClasses.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BattleConstants.h"
|
|
|
|
#include "../gui/CIntObject.h"
|
|
|
|
#include "../../lib/FunctionList.h"
|
|
|
|
#include "../../lib/battle/BattleHex.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../../lib/texts/MetaString.h"
|
2023-10-19 16:19:09 +02:00
|
|
|
#include "../windows/CWindowObject.h"
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class CGHeroInstance;
|
|
|
|
struct BattleResult;
|
|
|
|
struct InfoAboutHero;
|
|
|
|
class CStack;
|
2024-05-20 00:28:08 +02:00
|
|
|
class CPlayerBattleCallback;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
namespace battle
|
|
|
|
{
|
|
|
|
class Unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
class CAnimation;
|
|
|
|
class Canvas;
|
|
|
|
class BattleInterface;
|
|
|
|
class CPicture;
|
|
|
|
class CFilledTexture;
|
|
|
|
class CButton;
|
|
|
|
class CLabel;
|
2023-12-23 15:51:26 +02:00
|
|
|
class CMultiLineLabel;
|
2023-10-19 16:19:09 +02:00
|
|
|
class CTextBox;
|
|
|
|
class CAnimImage;
|
2023-12-23 20:57:19 +02:00
|
|
|
class TransparentFilledRectangle;
|
2023-10-19 16:19:09 +02:00
|
|
|
class CPlayerInterface;
|
|
|
|
class BattleRenderer;
|
2024-05-02 21:14:50 +02:00
|
|
|
class VideoWidget;
|
2024-05-19 21:29:23 +02:00
|
|
|
class QuickSpellPanel;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
/// Class which shows the console at the bottom of the battle screen and manages the text of the console
|
|
|
|
class BattleConsole : public CIntObject, public IStatusBar
|
|
|
|
{
|
|
|
|
private:
|
2024-05-14 02:50:57 +02:00
|
|
|
const BattleInterface & owner;
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
std::shared_ptr<CPicture> background;
|
|
|
|
|
|
|
|
/// List of all texts added during battle, essentially - log of entire battle
|
|
|
|
std::vector< std::string > logEntries;
|
|
|
|
|
|
|
|
/// Current scrolling position, to allow showing older entries via scroll buttons
|
|
|
|
int scrollPosition;
|
|
|
|
|
|
|
|
/// current hover text set on mouse move, takes priority over log entries
|
|
|
|
std::string hoverText;
|
|
|
|
|
|
|
|
/// current text entered via in-game console, takes priority over both log entries and hover text
|
|
|
|
std::string consoleText;
|
|
|
|
|
|
|
|
/// if true then we are currently entering console text
|
|
|
|
bool enteringText;
|
|
|
|
|
|
|
|
/// splits text into individual strings for battle log
|
|
|
|
std::vector<std::string> splitText(const std::string &text);
|
|
|
|
|
|
|
|
/// select line(s) that will be visible in UI
|
2024-06-01 13:48:30 +02:00
|
|
|
std::vector<std::string> getVisibleText() const;
|
2023-10-19 16:19:09 +02:00
|
|
|
public:
|
2024-05-14 02:50:57 +02:00
|
|
|
BattleConsole(const BattleInterface & owner, std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size);
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
void showAll(Canvas & to) override;
|
|
|
|
void deactivate() override;
|
|
|
|
|
2024-05-14 02:50:57 +02:00
|
|
|
void clickPressed(const Point & cursorPosition) override;
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
|
|
|
|
void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions
|
|
|
|
void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions
|
|
|
|
|
|
|
|
// IStatusBar interface
|
|
|
|
void write(const std::string & Text) override;
|
|
|
|
void clearIfMatching(const std::string & Text) override;
|
|
|
|
void clear() override;
|
|
|
|
void setEnteringMode(bool on) override;
|
|
|
|
void setEnteredText(const std::string & text) override;
|
|
|
|
};
|
|
|
|
|
2024-05-14 02:50:57 +02:00
|
|
|
class BattleConsoleWindow : public CWindowObject
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<CFilledTexture> backgroundTexture;
|
|
|
|
std::shared_ptr<CButton> buttonOk;
|
|
|
|
std::shared_ptr<TransparentFilledRectangle> textBoxBackgroundBorder;
|
|
|
|
std::shared_ptr<CTextBox> textBox;
|
|
|
|
public:
|
2024-05-14 12:44:08 +02:00
|
|
|
BattleConsoleWindow(const std::string & text);
|
2024-05-14 02:50:57 +02:00
|
|
|
};
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
/// Hero battle animation
|
|
|
|
class BattleHero : public CIntObject
|
|
|
|
{
|
|
|
|
bool defender;
|
|
|
|
|
|
|
|
CFunctionList<void()> phaseFinishedCallback;
|
|
|
|
|
|
|
|
std::shared_ptr<CAnimation> animation;
|
|
|
|
std::shared_ptr<CAnimation> flagAnimation;
|
|
|
|
|
|
|
|
const CGHeroInstance * hero; //this animation's hero instance
|
|
|
|
const BattleInterface & owner; //battle interface to which this animation is assigned
|
|
|
|
|
|
|
|
EHeroAnimType phase; //stage of animation
|
|
|
|
EHeroAnimType nextPhase; //stage of animation to be set after current phase is fully displayed
|
|
|
|
|
|
|
|
float currentSpeed;
|
|
|
|
float currentFrame; //frame of animation
|
|
|
|
float flagCurrentFrame;
|
|
|
|
|
|
|
|
void switchToNextPhase();
|
|
|
|
|
|
|
|
void render(Canvas & canvas); //prints next frame of animation to to
|
|
|
|
public:
|
|
|
|
const CGHeroInstance * instance();
|
|
|
|
|
|
|
|
void setPhase(EHeroAnimType newPhase); //sets phase of hero animation
|
|
|
|
|
|
|
|
void collectRenderableObjects(BattleRenderer & renderer);
|
|
|
|
void tick(uint32_t msPassed) override;
|
|
|
|
|
|
|
|
float getFrame() const;
|
|
|
|
void onPhaseFinished(const std::function<void()> &);
|
|
|
|
|
|
|
|
void pause();
|
|
|
|
void play();
|
|
|
|
|
|
|
|
void heroLeftClicked();
|
|
|
|
void heroRightClicked();
|
|
|
|
|
|
|
|
BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
|
|
|
|
};
|
|
|
|
|
2024-07-16 23:36:23 +02:00
|
|
|
class QuickSpellPanel : public CIntObject
|
2024-05-19 03:27:28 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<CFilledTexture> background;
|
|
|
|
std::shared_ptr<TransparentFilledRectangle> rect;
|
|
|
|
std::vector<std::shared_ptr<CButton>> buttons;
|
2024-07-26 20:11:14 +02:00
|
|
|
std::vector<std::shared_ptr<TransparentFilledRectangle>> buttonsIsAutoGenerated;
|
2024-05-19 03:27:28 +02:00
|
|
|
std::vector<std::shared_ptr<TransparentFilledRectangle>> buttonsDisabled;
|
2024-05-19 20:45:55 +02:00
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
|
|
|
|
2024-05-19 23:12:48 +02:00
|
|
|
BattleInterface & owner;
|
2024-05-19 03:27:28 +02:00
|
|
|
public:
|
2024-07-26 20:11:14 +02:00
|
|
|
int QUICKSPELL_SLOTS = 12;
|
|
|
|
|
2024-07-17 13:48:00 +02:00
|
|
|
bool isEnabled; // isActive() is not working on multiple conditions, because of this we need a seperate flag
|
|
|
|
|
2024-07-16 22:47:40 +02:00
|
|
|
QuickSpellPanel(BattleInterface & owner);
|
2024-05-19 03:27:28 +02:00
|
|
|
|
2024-05-19 21:29:23 +02:00
|
|
|
void create();
|
|
|
|
|
2024-08-12 20:26:30 +02:00
|
|
|
std::vector<std::tuple<SpellID, bool>> getSpells() const;
|
2024-07-26 20:11:14 +02:00
|
|
|
|
2024-05-19 03:27:28 +02:00
|
|
|
void show(Canvas & to) override;
|
2024-07-19 11:41:00 +02:00
|
|
|
void inputModeChanged(InputMode modi) override;
|
2024-05-19 03:27:28 +02:00
|
|
|
};
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
class HeroInfoBasicPanel : public CIntObject //extracted from InfoWindow to fit better as non-popup embed element
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<CPicture> background;
|
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
|
|
|
std::vector<std::shared_ptr<CAnimImage>> icons;
|
|
|
|
public:
|
|
|
|
HeroInfoBasicPanel(const InfoAboutHero & hero, Point * position, bool initializeBackground = true);
|
|
|
|
|
|
|
|
void show(Canvas & to) override;
|
|
|
|
|
|
|
|
void initializeData(const InfoAboutHero & hero);
|
|
|
|
void update(const InfoAboutHero & updatedInfo);
|
|
|
|
};
|
|
|
|
|
2023-12-22 23:26:35 +02:00
|
|
|
class StackInfoBasicPanel : public CIntObject
|
2023-12-22 22:26:40 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<CPicture> background;
|
2023-12-23 04:32:42 +02:00
|
|
|
std::shared_ptr<CPicture> background2;
|
2023-12-22 22:26:40 +02:00
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
2023-12-23 15:51:26 +02:00
|
|
|
std::vector<std::shared_ptr<CMultiLineLabel>> labelsMultiline;
|
2023-12-22 22:26:40 +02:00
|
|
|
std::vector<std::shared_ptr<CAnimImage>> icons;
|
|
|
|
public:
|
2024-01-29 22:11:18 +02:00
|
|
|
StackInfoBasicPanel(const CStack * stack, bool initializeBackground = true);
|
2023-12-22 22:26:40 +02:00
|
|
|
|
|
|
|
void show(Canvas & to) override;
|
|
|
|
|
2023-12-22 23:26:35 +02:00
|
|
|
void initializeData(const CStack * stack);
|
|
|
|
void update(const CStack * updatedInfo);
|
2023-12-22 22:26:40 +02:00
|
|
|
};
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
class HeroInfoWindow : public CWindowObject
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<HeroInfoBasicPanel> content;
|
|
|
|
public:
|
|
|
|
HeroInfoWindow(const InfoAboutHero & hero, Point * position);
|
|
|
|
};
|
|
|
|
|
2024-05-02 21:14:50 +02:00
|
|
|
struct BattleResultResources
|
|
|
|
{
|
|
|
|
VideoPath prologueVideo;
|
|
|
|
VideoPath loopedVideo;
|
|
|
|
AudioPath musicName;
|
|
|
|
MetaString resultText;
|
|
|
|
};
|
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
/// Class which is responsible for showing the battle result window
|
|
|
|
class BattleResultWindow : public WindowBase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::shared_ptr<CPicture> background;
|
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
|
|
|
std::shared_ptr<CButton> exit;
|
|
|
|
std::shared_ptr<CButton> repeat;
|
|
|
|
std::vector<std::shared_ptr<CAnimImage>> icons;
|
|
|
|
std::shared_ptr<CTextBox> description;
|
2024-05-02 21:14:50 +02:00
|
|
|
std::shared_ptr<VideoWidget> videoPlayer;
|
2023-10-19 16:19:09 +02:00
|
|
|
CPlayerInterface & owner;
|
|
|
|
|
2024-05-02 21:14:50 +02:00
|
|
|
BattleResultResources getResources(const BattleResult & br);
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
void buttonPressed(int button); //internal function for button callbacks
|
|
|
|
public:
|
|
|
|
BattleResultWindow(const BattleResult & br, CPlayerInterface & _owner, bool allowReplay = false);
|
|
|
|
|
|
|
|
void bExitf(); //exit button callback
|
|
|
|
void bRepeatf(); //repeat button callback
|
|
|
|
std::function<void(int result)> resultCallback; //callback receiving which button was pressed
|
|
|
|
|
|
|
|
void activate() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Shows the stack queue
|
|
|
|
class StackQueue : public CIntObject
|
|
|
|
{
|
|
|
|
class StackBox : public CIntObject
|
|
|
|
{
|
|
|
|
StackQueue * owner;
|
|
|
|
std::optional<uint32_t> boundUnitID;
|
|
|
|
|
|
|
|
std::shared_ptr<CPicture> background;
|
|
|
|
std::shared_ptr<CAnimImage> icon;
|
|
|
|
std::shared_ptr<CLabel> amount;
|
2024-11-22 18:46:48 +02:00
|
|
|
std::shared_ptr<CPicture> waitIcon;
|
|
|
|
std::shared_ptr<CPicture> defendIcon;
|
2023-12-23 20:57:19 +02:00
|
|
|
std::shared_ptr<CLabel> round;
|
|
|
|
std::shared_ptr<TransparentFilledRectangle> roundRect;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
void show(Canvas & to) override;
|
|
|
|
void showAll(Canvas & to) override;
|
2024-01-07 17:38:37 +02:00
|
|
|
void showPopupWindow(const Point & cursorPosition) override;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
bool isBoundUnitHighlighted() const;
|
|
|
|
public:
|
|
|
|
StackBox(StackQueue * owner);
|
2023-12-23 20:57:19 +02:00
|
|
|
void setUnit(const battle::Unit * unit, size_t turn = 0, std::optional<ui32> currentTurn = std::nullopt);
|
2023-10-19 16:19:09 +02:00
|
|
|
std::optional<uint32_t> getBoundUnitID() const;
|
|
|
|
};
|
|
|
|
|
2024-02-01 21:38:38 +02:00
|
|
|
static const int QUEUE_SIZE_BIG = 10;
|
2023-10-19 16:19:09 +02:00
|
|
|
std::shared_ptr<CFilledTexture> background;
|
|
|
|
std::vector<std::shared_ptr<StackBox>> stackBoxes;
|
|
|
|
BattleInterface & owner;
|
|
|
|
|
|
|
|
int32_t getSiegeShooterIconID();
|
|
|
|
public:
|
|
|
|
const bool embedded;
|
|
|
|
|
|
|
|
StackQueue(bool Embedded, BattleInterface & owner);
|
|
|
|
void update();
|
|
|
|
std::optional<uint32_t> getHoveredUnitIdIfAny() const;
|
|
|
|
|
|
|
|
void show(Canvas & to) override;
|
|
|
|
};
|