CBattleInterfaceClasses.h 6.2 KB

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