BattleInterfaceClasses.h 6.2 KB

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