1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
/*
* 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"
#include "../../lib/texts/MetaString.h"
#include "../windows/CWindowObject.h"
VCMI_LIB_NAMESPACE_BEGIN
class CGHeroInstance;
struct BattleResult;
struct InfoAboutHero;
class CStack;
class CPlayerBattleCallback;
namespace battle
{
class Unit;
}
VCMI_LIB_NAMESPACE_END
class CAnimation;
class Canvas;
class BattleInterface;
class CPicture;
class CFilledTexture;
class CButton;
class CLabel;
class CMultiLineLabel;
class CTextBox;
class CAnimImage;
class TransparentFilledRectangle;
class CPlayerInterface;
class BattleRenderer;
class VideoWidget;
class QuickSpellPanel;
/// 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:
const BattleInterface & owner;
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
std::vector<std::string> getVisibleText() const;
public:
BattleConsole(const BattleInterface & owner, std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size);
void showAll(Canvas & to) override;
void deactivate() override;
void clickPressed(const Point & cursorPosition) override;
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;
};
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:
BattleConsoleWindow(const std::string & text);
};
/// 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);
};
class QuickSpellPanel : public CIntObject
{
private:
std::shared_ptr<CFilledTexture> background;
std::shared_ptr<TransparentFilledRectangle> rect;
std::vector<std::shared_ptr<CButton>> buttons;
std::vector<std::shared_ptr<TransparentFilledRectangle>> buttonsIsAutoGenerated;
std::vector<std::shared_ptr<TransparentFilledRectangle>> buttonsDisabled;
std::vector<std::shared_ptr<CLabel>> labels;
BattleInterface & owner;
public:
int QUICKSPELL_SLOTS = 12;
bool isEnabled; // isActive() is not working on multiple conditions, because of this we need a seperate flag
QuickSpellPanel(BattleInterface & owner);
void create();
std::vector<std::tuple<SpellID, bool>> getSpells() const;
void show(Canvas & to) override;
void inputModeChanged(InputMode modi) override;
};
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);
};
class StackInfoBasicPanel : public CIntObject
{
private:
std::shared_ptr<CPicture> background;
std::shared_ptr<CPicture> background2;
std::vector<std::shared_ptr<CLabel>> labels;
std::vector<std::shared_ptr<CMultiLineLabel>> labelsMultiline;
std::vector<std::shared_ptr<CAnimImage>> icons;
public:
StackInfoBasicPanel(const CStack * stack, bool initializeBackground = true);
void show(Canvas & to) override;
void initializeData(const CStack * stack);
void update(const CStack * updatedInfo);
};
class HeroInfoWindow : public CWindowObject
{
private:
std::shared_ptr<HeroInfoBasicPanel> content;
public:
HeroInfoWindow(const InfoAboutHero & hero, Point * position);
};
struct BattleResultResources
{
VideoPath prologueVideo;
VideoPath loopedVideo;
AudioPath musicName;
MetaString resultText;
};
/// 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;
std::shared_ptr<VideoWidget> videoPlayer;
CPlayerInterface & owner;
BattleResultResources getResources(const BattleResult & br);
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;
std::shared_ptr<CPicture> waitIcon;
std::shared_ptr<CPicture> defendIcon;
std::shared_ptr<CLabel> round;
std::shared_ptr<TransparentFilledRectangle> roundRect;
void show(Canvas & to) override;
void showAll(Canvas & to) override;
void showPopupWindow(const Point & cursorPosition) override;
bool isBoundUnitHighlighted() const;
public:
StackBox(StackQueue * owner);
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_BIG = 10;
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;
};
|