CBattleInterfaceClasses.h 5.4 KB

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