BattleInterfaceClasses.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. class Canvas;
  19. namespace battle
  20. {
  21. class Unit;
  22. }
  23. VCMI_LIB_NAMESPACE_END
  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. std::vector< std::string > texts; //a place where texts are stored
  40. int lastShown; //last shown line of text
  41. std::string ingcAlter; //alternative text set by in-game console - very important!
  42. public:
  43. BattleConsole(const Rect & position);
  44. void showAll(SDL_Surface * to = 0) override;
  45. bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
  46. void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions
  47. void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions
  48. void clearMatching(const std::string & Text) override;
  49. void clear() override;
  50. void write(const std::string & Text) override;
  51. void lock(bool shouldLock) override;
  52. };
  53. /// Hero battle animation
  54. class BattleHero : 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 BattleInterface * 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 render(Canvas & canvas); //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. BattleHero(const std::string & animationPath, bool filpG, PlayerColor player, const CGHeroInstance * hero, const BattleInterface * owner);
  74. };
  75. class HeroInfoWindow : public CWindowObject
  76. {
  77. private:
  78. std::vector<std::shared_ptr<CLabel>> labels;
  79. std::vector<std::shared_ptr<CAnimImage>> icons;
  80. public:
  81. HeroInfoWindow(const InfoAboutHero & hero, Point * position);
  82. };
  83. /// Class which manages the battle options window
  84. class BattleOptionsWindow : public CWindowObject
  85. {
  86. private:
  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. BattleOptionsWindow(BattleInterface * 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 BattleResultWindow : public WindowBase
  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. BattleResultWindow(const BattleResult & br, CPlayerInterface & _owner);
  109. void bExitf(); //exit button callback
  110. void activate() override;
  111. void show(SDL_Surface * to = 0) override;
  112. };
  113. /// Class which stands for a single hex field on a battlefield
  114. class ClickableHex : public CIntObject
  115. {
  116. private:
  117. bool setAlterText; //if true, this hex has set alternative text in console and will clean it
  118. public:
  119. ui32 myNumber; //number of hex in commonly used format
  120. //bool accessible; //if true, this hex is accessible for units
  121. //CStack * ourStack;
  122. bool strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering)
  123. BattleInterface * myInterface; //interface that owns me
  124. //for user interactions
  125. void hover (bool on) override;
  126. void mouseMoved (const SDL_MouseMotionEvent &sEvent) override;
  127. void clickLeft(tribool down, bool previousState) override;
  128. void clickRight(tribool down, bool previousState) override;
  129. ClickableHex();
  130. };
  131. /// Shows the stack queue
  132. class StackQueue : public CIntObject
  133. {
  134. class StackBox : public CIntObject
  135. {
  136. StackQueue * owner;
  137. public:
  138. std::shared_ptr<CPicture> background;
  139. std::shared_ptr<CAnimImage> icon;
  140. std::shared_ptr<CLabel> amount;
  141. std::shared_ptr<CAnimImage> stateIcon;
  142. void setUnit(const battle::Unit * unit, size_t turn = 0);
  143. StackBox(StackQueue * owner);
  144. };
  145. static const int QUEUE_SIZE = 10;
  146. std::shared_ptr<CFilledTexture> background;
  147. std::vector<std::shared_ptr<StackBox>> stackBoxes;
  148. BattleInterface * owner;
  149. std::shared_ptr<CAnimation> icons;
  150. std::shared_ptr<CAnimation> stateIcons;
  151. int32_t getSiegeShooterIconID();
  152. public:
  153. const bool embedded;
  154. StackQueue(bool Embedded, BattleInterface * _owner);
  155. void update();
  156. };