1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/battle/BattleInterfaceClasses.h

219 lines
6.3 KiB
C++
Raw Normal View History

/*
* 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
2022-12-12 23:31:18 +02:00
#include "BattleConstants.h"
#include "../gui/CIntObject.h"
#include "../../lib/FunctionList.h"
#include "../../lib/battle/BattleHex.h"
#include "../windows/CWindowObject.h"
VCMI_LIB_NAMESPACE_BEGIN
class CGHeroInstance;
struct BattleResult;
class CStack;
namespace battle
{
class Unit;
}
VCMI_LIB_NAMESPACE_END
2022-12-12 18:26:04 +02:00
class Canvas;
class BattleInterface;
class CPicture;
class CFilledTexture;
class CButton;
class CToggleButton;
class CLabel;
class CTextBox;
class CAnimImage;
class CPlayerInterface;
class BattleRenderer;
/// 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:
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;
2023-01-09 17:25:18 +02:00
/// 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();
public:
BattleConsole(std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size);
void showAll(Canvas & to) override;
void deactivate() 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;
};
/// Hero battle animation
class BattleHero : public CIntObject
{
2022-12-21 01:08:56 +02:00
bool defender;
CFunctionList<void()> phaseFinishedCallback;
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
float currentSpeed;
2022-12-12 23:31:18 +02:00
float currentFrame; //frame of animation
float flagCurrentFrame;
void switchToNextPhase();
void render(Canvas & canvas); //prints next frame of animation to to
public:
const CGHeroInstance * instance();
2022-12-12 23:31:18 +02:00
void setPhase(EHeroAnimType newPhase); //sets phase of hero animation
void collectRenderableObjects(BattleRenderer & renderer);
void tick(uint32_t msPassed) override;
2022-12-12 23:31:18 +02:00
float getFrame() const;
void onPhaseFinished(const std::function<void()> &);
void pause();
void play();
2023-01-29 17:52:19 +02:00
void heroLeftClicked();
void heroRightClicked();
2022-12-21 01:08:56 +02:00
BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
};
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 HeroInfoWindow : public CWindowObject
{
private:
std::shared_ptr<HeroInfoBasicPanel> content;
public:
HeroInfoWindow(const InfoAboutHero & hero, Point * position);
};
/// 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;
2023-04-06 17:34:07 +02:00
std::shared_ptr<CButton> repeat;
std::vector<std::shared_ptr<CAnimImage>> icons;
std::shared_ptr<CTextBox> description;
CPlayerInterface & owner;
2023-04-06 17:34:07 +02:00
void buttonPressed(int button); //internal function for button callbacks
public:
2023-04-06 17:34:07 +02:00
BattleResultWindow(const BattleResult & br, CPlayerInterface & _owner, bool allowReplay = false);
void bExitf(); //exit button callback
2023-04-06 17:34:07 +02:00
void bRepeatf(); //repeat button callback
std::function<void(int result)> resultCallback; //callback receiving which button was pressed
void activate() override;
void show(Canvas & to) override;
};
/// Shows the stack queue
class StackQueue : public CIntObject
{
class StackBox : public CIntObject
{
StackQueue * owner;
2023-04-16 19:42:56 +02:00
std::optional<uint32_t> boundUnitID;
std::shared_ptr<CPicture> background;
std::shared_ptr<CAnimImage> icon;
std::shared_ptr<CLabel> amount;
std::shared_ptr<CAnimImage> stateIcon;
2023-06-16 14:30:59 +02:00
void show(Canvas & to) override;
void showAll(Canvas & to) override;
bool isBoundUnitHighlighted() const;
public:
StackBox(StackQueue * owner);
void setUnit(const battle::Unit * unit, size_t turn = 0);
2023-04-16 19:42:56 +02:00
std::optional<uint32_t> getBoundUnitID() const;
};
static const int QUEUE_SIZE = 10;
std::shared_ptr<CFilledTexture> background;
std::vector<std::shared_ptr<StackBox>> stackBoxes;
2022-12-13 13:58:16 +02:00
BattleInterface & owner;
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
std::shared_ptr<CAnimation> icons;
std::shared_ptr<CAnimation> stateIcons;
int32_t getSiegeShooterIconID();
public:
const bool embedded;
2022-12-13 13:58:16 +02:00
StackQueue(bool Embedded, BattleInterface & owner);
void update();
2023-04-16 19:42:56 +02:00
std::optional<uint32_t> getHoveredUnitIdIfAny() const;
void show(Canvas & to) override;
};