CBattleInterfaceClasses.h 5.9 KB

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