CBattleInterfaceClasses.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * CBattleInterfaceClasses.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. struct SDL_Surface;
  24. class CBattleInterface;
  25. class CPicture;
  26. class CFilledTexture;
  27. class CButton;
  28. class CToggleButton;
  29. class CToggleGroup;
  30. class CLabel;
  31. class CTextBox;
  32. class CAnimImage;
  33. class CPlayerInterface;
  34. /// Class which shows the console at the bottom of the battle screen and manages the text of the console
  35. class CBattleConsole : public CIntObject, public IStatusBar
  36. {
  37. private:
  38. std::vector< std::string > texts; //a place where texts are stored
  39. int lastShown; //last shown line of text
  40. std::string ingcAlter; //alternative text set by in-game console - very important!
  41. public:
  42. CBattleConsole(const Rect & position);
  43. void showAll(SDL_Surface * to = 0) override;
  44. bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
  45. void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions
  46. void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions
  47. void clearMatching(const std::string & Text) override;
  48. void clear() override;
  49. void write(const std::string & Text) override;
  50. void lock(bool shouldLock) override;
  51. };
  52. /// Hero battle animation
  53. class CBattleHero : public CIntObject
  54. {
  55. void switchToNextPhase();
  56. public:
  57. bool flip; //false if it's attacking hero, true otherwise
  58. std::shared_ptr<CAnimation> animation;
  59. std::shared_ptr<CAnimation> flagAnimation;
  60. const CGHeroInstance * myHero; //this animation's hero instance
  61. const CBattleInterface * myOwner; //battle interface to which this animation is assigned
  62. int phase; //stage of animation
  63. int nextPhase; //stage of animation to be set after current phase is fully displayed
  64. int currentFrame, firstFrame, lastFrame; //frame of animation
  65. size_t flagAnim;
  66. ui8 animCount; //for flag animation
  67. void show(SDL_Surface * to) override; //prints next frame of animation to to
  68. void setPhase(int newPhase); //sets phase of hero animation
  69. void hover(bool on) override;
  70. void clickLeft(tribool down, bool previousState) override; //call-in
  71. void clickRight(tribool down, bool previousState) override; //call-in
  72. CBattleHero(const std::string & animationPath, bool filpG, PlayerColor player, const CGHeroInstance * hero, const CBattleInterface * owner);
  73. ~CBattleHero();
  74. };
  75. class CHeroInfoWindow : public CWindowObject
  76. {
  77. private:
  78. std::vector<std::shared_ptr<CLabel>> labels;
  79. std::vector<std::shared_ptr<CAnimImage>> icons;
  80. public:
  81. CHeroInfoWindow(const InfoAboutHero & hero, Point * position);
  82. };
  83. /// Class which manages the battle options window
  84. class CBattleOptionsWindow : public WindowBase
  85. {
  86. private:
  87. std::shared_ptr<CPicture> background;
  88. std::shared_ptr<CButton> setToDefault;
  89. std::shared_ptr<CButton> exit;
  90. std::shared_ptr<CToggleGroup> animSpeeds;
  91. std::vector<std::shared_ptr<CLabel>> labels;
  92. std::vector<std::shared_ptr<CToggleButton>> toggles;
  93. public:
  94. CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface * owner);
  95. void bDefaultf(); //default button callback
  96. void bExitf(); //exit button callback
  97. };
  98. /// Class which is responsible for showing the battle result window
  99. class CBattleResultWindow : public WindowBase
  100. {
  101. private:
  102. std::shared_ptr<CPicture> background;
  103. std::vector<std::shared_ptr<CLabel>> labels;
  104. std::shared_ptr<CButton> exit;
  105. std::vector<std::shared_ptr<CAnimImage>> icons;
  106. std::shared_ptr<CTextBox> description;
  107. CPlayerInterface & owner;
  108. public:
  109. CBattleResultWindow(const BattleResult & br, CPlayerInterface & _owner);
  110. ~CBattleResultWindow();
  111. void bExitf(); //exit button callback
  112. void activate() override;
  113. void show(SDL_Surface * to = 0) override;
  114. };
  115. /// Class which stands for a single hex field on a battlefield
  116. class CClickableHex : public CIntObject
  117. {
  118. private:
  119. bool setAlterText; //if true, this hex has set alternative text in console and will clean it
  120. public:
  121. ui32 myNumber; //number of hex in commonly used format
  122. //bool accessible; //if true, this hex is accessible for units
  123. //CStack * ourStack;
  124. bool strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering)
  125. CBattleInterface * myInterface; //interface that owns me
  126. /// returns (x, y) of left top corner of animation
  127. /// FIXME: move someplace else?
  128. /// FIXME: some usages should be replaced with creAnims->pos?
  129. static Point getXYUnitAnim(BattleHex hexNum, const CStack * creature, CBattleInterface * cbi);
  130. //for user interactions
  131. void hover (bool on) override;
  132. void mouseMoved (const SDL_MouseMotionEvent &sEvent) override;
  133. void clickLeft(tribool down, bool previousState) override;
  134. void clickRight(tribool down, bool previousState) override;
  135. CClickableHex();
  136. };
  137. /// Shows the stack queue
  138. class CStackQueue : public CIntObject
  139. {
  140. class StackBox : public CIntObject
  141. {
  142. public:
  143. std::shared_ptr<CPicture> background;
  144. std::shared_ptr<CAnimImage> icon;
  145. std::shared_ptr<CLabel> amount;
  146. std::shared_ptr<CAnimImage> stateIcon;
  147. void setUnit(const battle::Unit * unit, size_t turn = 0);
  148. StackBox(CStackQueue * owner);
  149. };
  150. static const int QUEUE_SIZE = 10;
  151. std::shared_ptr<CFilledTexture> background;
  152. std::vector<std::shared_ptr<StackBox>> stackBoxes;
  153. CBattleInterface * owner;
  154. std::shared_ptr<CAnimation> icons;
  155. std::shared_ptr<CAnimation> stateIcons;
  156. public:
  157. const bool embedded;
  158. CStackQueue(bool Embedded, CBattleInterface * _owner);
  159. ~CStackQueue();
  160. void update();
  161. };