BattleInterfaceClasses.h 6.3 KB

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