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