BattleInterfaceClasses.h 5.9 KB

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