BattleInterfaceClasses.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * BattleInterfaceClasses.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "BattleConstants.h"
  12. #include "../gui/CIntObject.h"
  13. #include "../../lib/FunctionList.h"
  14. #include "../../lib/battle/BattleHex.h"
  15. #include "../windows/CWindowObject.h"
  16. #include "gui/InterfaceObjectConfigurable.h"
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. class CGHeroInstance;
  19. struct BattleResult;
  20. class CStack;
  21. namespace battle
  22. {
  23. class Unit;
  24. }
  25. VCMI_LIB_NAMESPACE_END
  26. class Canvas;
  27. struct SDL_Surface;
  28. class BattleInterface;
  29. class CPicture;
  30. class CFilledTexture;
  31. class CButton;
  32. class CToggleButton;
  33. class CToggleGroup;
  34. class CLabel;
  35. class CTextBox;
  36. class CAnimImage;
  37. class CPlayerInterface;
  38. class BattleRenderer;
  39. /// Class which shows the console at the bottom of the battle screen and manages the text of the console
  40. class BattleConsole : public CIntObject, public IStatusBar
  41. {
  42. private:
  43. std::shared_ptr<CPicture> background;
  44. /// List of all texts added during battle, essentially - log of entire battle
  45. std::vector< std::string > logEntries;
  46. /// Current scrolling position, to allow showing older entries via scroll buttons
  47. int scrollPosition;
  48. /// current hover text set on mouse move, takes priority over log entries
  49. std::string hoverText;
  50. /// current text entered via in-game console, takes priority over both log entries and hover text
  51. std::string consoleText;
  52. /// if true then we are currently entering console text
  53. bool enteringText;
  54. /// splits text into individual strings for battle log
  55. std::vector<std::string> splitText(const std::string &text);
  56. /// select line(s) that will be visible in UI
  57. std::vector<std::string> getVisibleText();
  58. public:
  59. BattleConsole(std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size);
  60. void showAll(SDL_Surface * to) override;
  61. void deactivate() override;
  62. bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
  63. void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions
  64. void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions
  65. // IStatusBar interface
  66. void write(const std::string & Text) override;
  67. void clearIfMatching(const std::string & Text) override;
  68. void clear() override;
  69. void setEnteringMode(bool on) override;
  70. void setEnteredText(const std::string & text) override;
  71. };
  72. /// Hero battle animation
  73. class BattleHero : public CIntObject
  74. {
  75. bool defender;
  76. CFunctionList<void()> phaseFinishedCallback;
  77. std::shared_ptr<CAnimation> animation;
  78. std::shared_ptr<CAnimation> flagAnimation;
  79. const CGHeroInstance * hero; //this animation's hero instance
  80. const BattleInterface & owner; //battle interface to which this animation is assigned
  81. EHeroAnimType phase; //stage of animation
  82. EHeroAnimType nextPhase; //stage of animation to be set after current phase is fully displayed
  83. float currentSpeed;
  84. float currentFrame; //frame of animation
  85. float flagCurrentFrame;
  86. void switchToNextPhase();
  87. void render(Canvas & canvas); //prints next frame of animation to to
  88. public:
  89. const CGHeroInstance * instance();
  90. void setPhase(EHeroAnimType newPhase); //sets phase of hero animation
  91. void collectRenderableObjects(BattleRenderer & renderer);
  92. float getFrame() const;
  93. void onPhaseFinished(const std::function<void()> &);
  94. void pause();
  95. void play();
  96. void hover(bool on) override;
  97. void clickLeft(tribool down, bool previousState) override; //call-in
  98. void clickRight(tribool down, bool previousState) override; //call-in
  99. BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
  100. };
  101. class HeroInfoWindow : public CWindowObject
  102. {
  103. private:
  104. std::vector<std::shared_ptr<CLabel>> labels;
  105. std::vector<std::shared_ptr<CAnimImage>> icons;
  106. public:
  107. HeroInfoWindow(const InfoAboutHero & hero, Point * position);
  108. };
  109. /// Class which is responsible for showing the battle result window
  110. class BattleResultWindow : public WindowBase
  111. {
  112. private:
  113. std::shared_ptr<CPicture> background;
  114. std::vector<std::shared_ptr<CLabel>> labels;
  115. std::shared_ptr<CButton> exit;
  116. std::vector<std::shared_ptr<CAnimImage>> icons;
  117. std::shared_ptr<CTextBox> description;
  118. CPlayerInterface & owner;
  119. public:
  120. BattleResultWindow(const BattleResult & br, CPlayerInterface & _owner);
  121. void bExitf(); //exit button callback
  122. void activate() override;
  123. void show(SDL_Surface * to = 0) override;
  124. };
  125. /// Class which stands for a single hex field on a battlefield
  126. class ClickableHex : public CIntObject
  127. {
  128. private:
  129. bool setAlterText; //if true, this hex has set alternative text in console and will clean it
  130. public:
  131. ui32 myNumber; //number of hex in commonly used format
  132. bool strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering)
  133. BattleInterface * myInterface; //interface that owns me
  134. //for user interactions
  135. void hover (bool on) override;
  136. void mouseMoved (const SDL_MouseMotionEvent &sEvent) override;
  137. void clickLeft(tribool down, bool previousState) override;
  138. void clickRight(tribool down, bool previousState) override;
  139. ClickableHex();
  140. };
  141. /// Shows the stack queue
  142. class StackQueue : public CIntObject
  143. {
  144. class StackBox : public CIntObject
  145. {
  146. StackQueue * owner;
  147. public:
  148. std::shared_ptr<CPicture> background;
  149. std::shared_ptr<CAnimImage> icon;
  150. std::shared_ptr<CLabel> amount;
  151. std::shared_ptr<CAnimImage> stateIcon;
  152. void setUnit(const battle::Unit * unit, size_t turn = 0);
  153. StackBox(StackQueue * owner);
  154. };
  155. static const int QUEUE_SIZE = 10;
  156. std::shared_ptr<CFilledTexture> background;
  157. std::vector<std::shared_ptr<StackBox>> stackBoxes;
  158. BattleInterface & owner;
  159. std::shared_ptr<CAnimation> icons;
  160. std::shared_ptr<CAnimation> stateIcons;
  161. int32_t getSiegeShooterIconID();
  162. public:
  163. const bool embedded;
  164. StackQueue(bool Embedded, BattleInterface & owner);
  165. void update();
  166. void show(SDL_Surface * to) override;
  167. };