2017-07-13 10:26:03 +02:00
|
|
|
/*
|
2022-12-11 23:16:23 +02:00
|
|
|
* BattleInterfaceClasses.h, part of VCMI engine
|
2017-07-13 10:26:03 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2011-12-22 16:05:19 +03:00
|
|
|
#pragma once
|
|
|
|
|
2022-12-12 23:31:18 +02:00
|
|
|
#include "BattleConstants.h"
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "../gui/CIntObject.h"
|
2022-12-13 18:49:35 +02:00
|
|
|
#include "../../lib/FunctionList.h"
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "../../lib/battle/BattleHex.h"
|
2016-09-27 14:13:20 +02:00
|
|
|
#include "../windows/CWindowObject.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
class CGHeroInstance;
|
2022-07-26 15:07:42 +02:00
|
|
|
struct BattleResult;
|
|
|
|
class CStack;
|
|
|
|
|
|
|
|
namespace battle
|
|
|
|
{
|
|
|
|
class Unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2022-12-12 18:26:04 +02:00
|
|
|
class Canvas;
|
2022-07-26 15:07:42 +02:00
|
|
|
struct SDL_Surface;
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleInterface;
|
2011-12-22 16:05:19 +03:00
|
|
|
class CPicture;
|
2018-04-07 13:34:11 +02:00
|
|
|
class CFilledTexture;
|
2014-08-03 14:16:19 +03:00
|
|
|
class CButton;
|
|
|
|
class CToggleButton;
|
|
|
|
class CToggleGroup;
|
2011-12-22 16:05:19 +03:00
|
|
|
class CLabel;
|
2018-04-07 13:34:11 +02:00
|
|
|
class CTextBox;
|
2012-08-28 19:28:21 +03:00
|
|
|
class CAnimImage;
|
2013-06-23 14:25:48 +03:00
|
|
|
class CPlayerInterface;
|
2022-12-21 17:02:53 +02:00
|
|
|
class BattleRenderer;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
/// Class which shows the console at the bottom of the battle screen and manages the text of the console
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleConsole : public CIntObject, public IStatusBar
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
private:
|
2022-12-21 17:02:53 +02:00
|
|
|
std::shared_ptr<CPicture> background;
|
|
|
|
|
2022-12-12 18:23:41 +02:00
|
|
|
/// List of all texts added during battle, essentially - log of entire battle
|
|
|
|
std::vector< std::string > logEntries;
|
2022-11-18 17:54:10 +02:00
|
|
|
|
2022-12-12 18:23:41 +02:00
|
|
|
/// 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;
|
2022-11-18 17:54:10 +02:00
|
|
|
public:
|
2022-12-21 17:02:53 +02:00
|
|
|
BattleConsole(std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size);
|
2022-12-19 22:06:01 +02:00
|
|
|
|
2022-12-12 18:23:41 +02:00
|
|
|
void showAll(SDL_Surface * to) override;
|
2022-12-19 22:06:01 +02:00
|
|
|
void deactivate() override;
|
2022-11-18 17:54:10 +02:00
|
|
|
|
2011-12-22 16:05:19 +03: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
|
2022-11-18 17:54:10 +02:00
|
|
|
|
2022-12-12 18:23:41 +02:00
|
|
|
// IStatusBar interface
|
|
|
|
void write(const std::string & Text) override;
|
2022-12-11 23:43:43 +02:00
|
|
|
void clearIfMatching(const std::string & Text) override;
|
2022-11-18 17:54:10 +02:00
|
|
|
void clear() override;
|
2022-12-12 18:23:41 +02:00
|
|
|
void setEnteringMode(bool on) override;
|
|
|
|
void setEnteredText(const std::string & text) override;
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Hero battle animation
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleHero : public CIntObject
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-21 01:08:56 +02:00
|
|
|
bool defender;
|
2017-09-05 15:44:27 +02:00
|
|
|
|
2022-12-13 18:49:35 +02:00
|
|
|
CFunctionList<void()> phaseFinishedCallback;
|
|
|
|
|
2017-09-05 15:44:27 +02:00
|
|
|
std::shared_ptr<CAnimation> animation;
|
|
|
|
std::shared_ptr<CAnimation> flagAnimation;
|
|
|
|
|
2022-12-21 01:08:56 +02:00
|
|
|
const CGHeroInstance * hero; //this animation's hero instance
|
2022-12-12 23:31:18 +02:00
|
|
|
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
|
2017-09-05 15:44:27 +02:00
|
|
|
|
2022-12-13 18:49:35 +02:00
|
|
|
float currentSpeed;
|
2022-12-12 23:31:18 +02:00
|
|
|
float currentFrame; //frame of animation
|
|
|
|
float flagCurrentFrame;
|
|
|
|
|
|
|
|
void switchToNextPhase();
|
|
|
|
|
2022-12-11 22:09:57 +02:00
|
|
|
void render(Canvas & canvas); //prints next frame of animation to to
|
2022-12-21 17:02:53 +02:00
|
|
|
public:
|
|
|
|
const CGHeroInstance * instance();
|
|
|
|
|
2022-12-12 23:31:18 +02:00
|
|
|
void setPhase(EHeroAnimType newPhase); //sets phase of hero animation
|
|
|
|
|
2022-12-21 17:02:53 +02:00
|
|
|
void collectRenderableObjects(BattleRenderer & renderer);
|
|
|
|
|
2022-12-12 23:31:18 +02:00
|
|
|
float getFrame() const;
|
|
|
|
void onPhaseFinished(const std::function<void()> &);
|
|
|
|
|
2022-12-13 18:49:35 +02:00
|
|
|
void pause();
|
|
|
|
void play();
|
|
|
|
|
2016-09-27 14:13:20 +02:00
|
|
|
void hover(bool on) override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void clickLeft(tribool down, bool previousState) override; //call-in
|
2016-09-27 14:13:20 +02:00
|
|
|
void clickRight(tribool down, bool previousState) override; //call-in
|
2022-12-21 01:08:56 +02:00
|
|
|
BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
2022-12-09 13:26:17 +02:00
|
|
|
class HeroInfoWindow : public CWindowObject
|
2016-09-27 14:13:20 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
private:
|
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
|
|
|
std::vector<std::shared_ptr<CAnimImage>> icons;
|
2016-09-27 14:13:20 +02:00
|
|
|
public:
|
2022-12-09 13:26:17 +02:00
|
|
|
HeroInfoWindow(const InfoAboutHero & hero, Point * position);
|
2016-09-27 14:13:20 +02:00
|
|
|
};
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
/// Class which manages the battle options window
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleOptionsWindow : public CWindowObject
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
private:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CButton> setToDefault;
|
|
|
|
std::shared_ptr<CButton> exit;
|
|
|
|
std::shared_ptr<CToggleGroup> animSpeeds;
|
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
|
|
|
std::vector<std::shared_ptr<CToggleButton>> toggles;
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleOptionsWindow(BattleInterface & owner);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
void bDefaultf(); //default button callback
|
|
|
|
void bExitf(); //exit button callback
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Class which is responsible for showing the battle result window
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleResultWindow : public WindowBase
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
private:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CPicture> background;
|
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
|
|
|
std::shared_ptr<CButton> exit;
|
|
|
|
std::vector<std::shared_ptr<CAnimImage>> icons;
|
|
|
|
std::shared_ptr<CTextBox> description;
|
|
|
|
CPlayerInterface & owner;
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2022-12-09 13:26:17 +02:00
|
|
|
BattleResultWindow(const BattleResult & br, CPlayerInterface & _owner);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
void bExitf(); //exit button callback
|
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
void activate() override;
|
|
|
|
void show(SDL_Surface * to = 0) override;
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Class which stands for a single hex field on a battlefield
|
2022-12-09 13:26:17 +02:00
|
|
|
class ClickableHex : public CIntObject
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
bool setAlterText; //if true, this hex has set alternative text in console and will clean it
|
|
|
|
public:
|
|
|
|
ui32 myNumber; //number of hex in commonly used format
|
2017-10-29 17:23:30 +02:00
|
|
|
bool strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering)
|
2022-12-09 13:26:17 +02:00
|
|
|
BattleInterface * myInterface; //interface that owns me
|
2022-11-25 00:26:14 +02:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
//for user interactions
|
2015-10-12 15:47:10 +02:00
|
|
|
void hover (bool on) override;
|
|
|
|
void mouseMoved (const SDL_MouseMotionEvent &sEvent) override;
|
|
|
|
void clickLeft(tribool down, bool previousState) override;
|
|
|
|
void clickRight(tribool down, bool previousState) override;
|
2022-12-09 13:26:17 +02:00
|
|
|
ClickableHex();
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Shows the stack queue
|
2022-12-09 13:26:17 +02:00
|
|
|
class StackQueue : public CIntObject
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
class StackBox : public CIntObject
|
|
|
|
{
|
2022-12-09 13:26:17 +02:00
|
|
|
StackQueue * owner;
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CPicture> background;
|
|
|
|
std::shared_ptr<CAnimImage> icon;
|
|
|
|
std::shared_ptr<CLabel> amount;
|
|
|
|
std::shared_ptr<CAnimImage> stateIcon;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void setUnit(const battle::Unit * unit, size_t turn = 0);
|
2022-12-09 13:26:17 +02:00
|
|
|
StackBox(StackQueue * owner);
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int QUEUE_SIZE = 10;
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CFilledTexture> background;
|
|
|
|
std::vector<std::shared_ptr<StackBox>> stackBoxes;
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleInterface & owner;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::shared_ptr<CAnimation> icons;
|
|
|
|
std::shared_ptr<CAnimation> stateIcons;
|
|
|
|
|
2022-11-29 14:59:50 +02:00
|
|
|
int32_t getSiegeShooterIconID();
|
2018-04-07 13:34:11 +02:00
|
|
|
public:
|
|
|
|
const bool embedded;
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
StackQueue(bool Embedded, BattleInterface & owner);
|
2011-12-22 16:05:19 +03:00
|
|
|
void update();
|
2014-08-03 14:16:19 +03:00
|
|
|
};
|