CBattleInterfaceClasses.h 5.4 KB

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