CBattleInterfaceClasses.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #pragma once
  2. #include "../UIFramework/CIntObject.h"
  3. struct SDL_Surface;
  4. class CDefHandler;
  5. class CGHeroInstance;
  6. class CBattleInterface;
  7. class CPicture;
  8. class CAdventureMapButton;
  9. class CHighlightableButton;
  10. class CHighlightableButtonsGroup;
  11. class CLabel;
  12. class BattleResult;
  13. class CStack;
  14. /*
  15. * CBattleInterfaceClasses.h, part of VCMI engine
  16. *
  17. * Authors: listed in file AUTHORS in main folder
  18. *
  19. * License: GNU General Public License v2.0 or later
  20. * Full text of license available in license.txt file, in main folder
  21. *
  22. */
  23. /// Class which shows the console at the bottom of the battle screen and manages the text of the console
  24. class CBattleConsole : public CIntObject
  25. {
  26. private:
  27. std::vector< std::string > texts; //a place where texts are stored
  28. int lastShown; //last shown line of text
  29. public:
  30. std::string alterTxt; //if it's not empty, this text is displayed
  31. std::string ingcAlter; //alternative text set by in-game console - very important!
  32. int whoSetAlter; //who set alter text; 0 - battle interface or none, 1 - button
  33. CBattleConsole() : lastShown(-1), alterTxt(""), whoSetAlter(0) {}
  34. ~CBattleConsole(); //d-tor
  35. void show(SDL_Surface * to = 0);
  36. bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
  37. void eraseText(ui32 pos); //erases added text at position pos
  38. void changeTextAt(const std::string &text, ui32 pos); //if we have more than pos texts, pos-th is changed to given one
  39. void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions
  40. void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions
  41. };
  42. /// Hero battle animation
  43. class CBattleHero : public CIntObject
  44. {
  45. public:
  46. bool flip; //false if it's attacking hero, true otherwise
  47. CDefHandler *dh, *flag; //animation and flag
  48. const CGHeroInstance * myHero; //this animation's hero instance
  49. const CBattleInterface * myOwner; //battle interface to which this animation is assigned
  50. int phase; //stage of animation
  51. int nextPhase; //stage of animation to be set after current phase is fully displayed
  52. int image; //frame of animation
  53. ui8 flagAnim, flagAnimCount; //for flag animation
  54. void show(SDL_Surface * to); //prints next frame of animation to to
  55. void activate();
  56. void deactivate();
  57. void setPhase(int newPhase); //sets phase of hero animation
  58. void clickLeft(tribool down, bool previousState); //call-in
  59. CBattleHero(const std::string &defName, int phaseG, int imageG, bool filpG, ui8 player, const CGHeroInstance *hero, const CBattleInterface *owner); //c-tor
  60. ~CBattleHero(); //d-tor
  61. };
  62. /// Class which manages the battle options window
  63. class CBattleOptionsWindow : public CIntObject
  64. {
  65. private:
  66. CBattleInterface * myInt;
  67. CPicture * background;
  68. CAdventureMapButton * setToDefault, * exit;
  69. CHighlightableButton * viewGrid, * movementShadow, * mouseShadow;
  70. CHighlightableButtonsGroup * animSpeeds;
  71. std::vector<CLabel*> labels;
  72. public:
  73. CBattleOptionsWindow(const SDL_Rect &position, CBattleInterface *owner); //c-tor
  74. void bDefaultf(); //default button callback
  75. void bExitf(); //exit button callback
  76. };
  77. /// Class which is responsible for showing the battle result window
  78. class CBattleResultWindow : public CIntObject
  79. {
  80. private:
  81. SDL_Surface *background;
  82. CAdventureMapButton *exit;
  83. CBattleInterface *owner;
  84. public:
  85. CBattleResultWindow(const BattleResult & br, const SDL_Rect & pos, CBattleInterface * _owner); //c-tor
  86. ~CBattleResultWindow(); //d-tor
  87. void bExitf(); //exit button callback
  88. void activate();
  89. void deactivate();
  90. void show(SDL_Surface * to = 0);
  91. };
  92. /// Class which stands for a single hex field on a battlefield
  93. class CClickableHex : public CIntObject
  94. {
  95. private:
  96. bool setAlterText; //if true, this hex has set alternative text in console and will clean it
  97. public:
  98. ui32 myNumber; //number of hex in commonly used format
  99. bool accessible; //if true, this hex is accessible for units
  100. //CStack * ourStack;
  101. bool hovered, strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering)
  102. CBattleInterface * myInterface; //interface that owns me
  103. static Point getXYUnitAnim(const int & hexNum, const bool & attacker, const CStack * creature, const CBattleInterface * cbi); //returns (x, y) of left top corner of animation
  104. //for user interactions
  105. void hover (bool on);
  106. void activate();
  107. void deactivate();
  108. void mouseMoved (const SDL_MouseMotionEvent &sEvent);
  109. void clickLeft(tribool down, bool previousState);
  110. void clickRight(tribool down, bool previousState);
  111. CClickableHex();
  112. };
  113. /// Shows the stack queue
  114. class CStackQueue : public CIntObject
  115. {
  116. class StackBox : public CIntObject
  117. {
  118. public:
  119. const CStack *my;
  120. SDL_Surface *bg;
  121. void hover (bool on);
  122. void showAll(SDL_Surface * to);
  123. void setStack(const CStack *nStack);
  124. StackBox(SDL_Surface *BG);
  125. ~StackBox();
  126. };
  127. public:
  128. static const int QUEUE_SIZE = 10;
  129. const bool embedded;
  130. std::vector<const CStack *> stacksSorted;
  131. std::vector<StackBox *> stackBoxes;
  132. SDL_Surface *box;
  133. SDL_Surface *bg;
  134. CBattleInterface * owner;
  135. void showAll(SDL_Surface * to);
  136. CStackQueue(bool Embedded, CBattleInterface * _owner);
  137. ~CStackQueue();
  138. void update();
  139. void blitBg( SDL_Surface * to );
  140. //void showAll(SDL_Surface * to);
  141. };