CCreatureWindow.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * CCreatureWindow.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 "../../lib/bonuses/Bonus.h"
  12. #include "../../lib/filesystem/ResourcePath.h"
  13. #include "../widgets/MiscWidgets.h"
  14. #include "CWindowObject.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. class CCommanderInstance;
  17. class CStackInstance;
  18. class CStack;
  19. struct UpgradeInfo;
  20. VCMI_LIB_NAMESPACE_END
  21. class UnitView;
  22. class CTabbedInt;
  23. class CButton;
  24. class CMultiLineLabel;
  25. class CListBox;
  26. class CArtPlace;
  27. class CCommanderArtPlace;
  28. class LRClickableArea;
  29. class GraphicalPrimitiveCanvas;
  30. class CCommanderSkillIcon : public LRClickableAreaWText //TODO: maybe bring commander skill button initialization logic inside?
  31. {
  32. std::shared_ptr<CIntObject> object; // passive object that will be used to determine clickable area
  33. bool isMasterAbility; // refers to WoG abilities obtainable via combining master skills (for example attack + speed unlocks shoot)
  34. bool isSelected; // used only for programmatically created border around selected "master abilities"
  35. public:
  36. CCommanderSkillIcon(std::shared_ptr<CIntObject> object_, bool isMasterAbility_, std::function<void()> callback);
  37. std::function<void()> callback;
  38. void clickPressed(const Point & cursorPosition) override;
  39. void setObject(std::shared_ptr<CIntObject> object);
  40. void deselect(); //TODO: consider using observer pattern instead?
  41. bool getIsMasterAbility();
  42. void show(Canvas &to) override;
  43. };
  44. class CStackWindow : public CWindowObject
  45. {
  46. struct BonusInfo
  47. {
  48. std::string name;
  49. std::string description;
  50. ImagePath imagePath;
  51. BonusSource bonusSource;
  52. };
  53. class CWindowSection : public CIntObject
  54. {
  55. private:
  56. std::shared_ptr<CPicture> background;
  57. protected:
  58. CStackWindow * parent;
  59. public:
  60. CWindowSection(CStackWindow * parent, const ImagePath & backgroundPath, int yOffset);
  61. };
  62. class ActiveSpellsSection : public CWindowSection
  63. {
  64. std::vector<std::shared_ptr<CAnimImage>> spellIcons;
  65. std::vector<std::shared_ptr<LRClickableAreaWText>> clickableAreas;
  66. std::vector<std::shared_ptr<CLabel>> labels;
  67. public:
  68. ActiveSpellsSection(CStackWindow * owner, int yOffset);
  69. };
  70. class BonusLineSection : public CWindowSection
  71. {
  72. std::array<std::shared_ptr<CPicture>, 2> icon;
  73. std::array<std::shared_ptr<CLabel>, 2> name;
  74. std::array<std::shared_ptr<CMultiLineLabel>, 2> description;
  75. std::array<std::shared_ptr<GraphicalPrimitiveCanvas>, 2> frame;
  76. std::array<std::vector<std::shared_ptr<CLabel>>, 2> bonusSource;
  77. public:
  78. BonusLineSection(CStackWindow * owner, size_t lineIndex, bool noScroll);
  79. };
  80. class BonusesSection : public CWindowSection
  81. {
  82. std::shared_ptr<CListBox> lines;
  83. public:
  84. BonusesSection(CStackWindow * owner, int yOffset, std::optional<size_t> preferredSize = std::optional<size_t>());
  85. };
  86. class ButtonsSection : public CWindowSection
  87. {
  88. std::shared_ptr<CButton> dismiss;
  89. std::array<std::shared_ptr<CButton>, 3> upgrade;// no more than 3 buttons - space limit
  90. std::shared_ptr<CButton> exit;
  91. public:
  92. ButtonsSection(CStackWindow * owner, int yOffset);
  93. };
  94. class CommanderMainSection : public CWindowSection
  95. {
  96. std::vector<std::shared_ptr<CCommanderSkillIcon>> skillIcons;
  97. std::vector<std::shared_ptr<CCommanderArtPlace>> artifacts;
  98. std::shared_ptr<CPicture> abilitiesBackground;
  99. std::shared_ptr<CListBox> abilities;
  100. std::shared_ptr<CButton> leftBtn;
  101. std::shared_ptr<CButton> rightBtn;
  102. public:
  103. CommanderMainSection(CStackWindow * owner, int yOffset);
  104. };
  105. class MainSection : public CWindowSection
  106. {
  107. enum class EStat : size_t
  108. {
  109. ATTACK,
  110. DEFENCE,
  111. SHOTS,
  112. DAMAGE,
  113. HEALTH,
  114. HEALTH_LEFT,
  115. SPEED,
  116. MANA,
  117. AFTER_LAST
  118. };
  119. std::shared_ptr<CCreaturePic> animation;
  120. std::shared_ptr<LRClickableArea> animationArea;
  121. std::shared_ptr<CLabel> name;
  122. std::shared_ptr<CPicture> icons;
  123. std::shared_ptr<MoraleLuckBox> morale;
  124. std::shared_ptr<MoraleLuckBox> luck;
  125. std::vector<std::shared_ptr<CLabel>> stats;
  126. std::shared_ptr<CAnimImage> expRankIcon;
  127. std::shared_ptr<LRClickableAreaWText> expArea;
  128. std::shared_ptr<CLabel> expLabel;
  129. void addStatLabel(EStat index, int64_t value1, int64_t value2);
  130. void addStatLabel(EStat index, int64_t value);
  131. static ImagePath getBackgroundName(bool showExp, bool showArt);
  132. std::array<std::string, 8> statNames;
  133. std::array<std::string, 8> statFormats;
  134. public:
  135. MainSection(CStackWindow * owner, int yOffset, bool showExp, bool showArt);
  136. };
  137. std::shared_ptr<CArtPlace> stackArtifact;
  138. std::shared_ptr<CButton> stackArtifactButton;
  139. std::shared_ptr<UnitView> info;
  140. std::vector<BonusInfo> activeBonuses;
  141. size_t activeTab;
  142. std::shared_ptr<CTabbedInt> commanderTab;
  143. std::map<size_t, std::shared_ptr<CButton>> switchButtons;
  144. std::shared_ptr<CWindowSection> mainSection;
  145. std::shared_ptr<CWindowSection> activeSpellsSection;
  146. std::shared_ptr<CWindowSection> commanderMainSection;
  147. std::shared_ptr<CWindowSection> commanderBonusesSection;
  148. std::shared_ptr<CWindowSection> bonusesSection;
  149. std::shared_ptr<CWindowSection> buttonsSection;
  150. std::shared_ptr<CCommanderSkillIcon> selectedIcon;
  151. si32 selectedSkill;
  152. void setSelection(si32 newSkill, std::shared_ptr<CCommanderSkillIcon> newIcon);
  153. std::shared_ptr<CIntObject> switchTab(size_t index);
  154. void removeStackArtifact(ArtifactPosition pos);
  155. void initSections();
  156. void initBonusesList();
  157. void init();
  158. std::string generateStackExpDescription();
  159. std::string getCommanderSkillDescription(int skillIndex, int skillLevel);
  160. public:
  161. // for battles
  162. CStackWindow(const CStack * stack, bool popup);
  163. // for non-existing stacks, e.g. recruit screen
  164. CStackWindow(const CCreature * creature, bool popup);
  165. // for normal stacks in armies
  166. CStackWindow(const CStackInstance * stack, bool popup);
  167. CStackWindow(const CStackInstance * stack, std::function<void()> dismiss, const UpgradeInfo & info, std::function<void(CreatureID)> callback);
  168. // for commanders & commander level-up dialog
  169. CStackWindow(const CCommanderInstance * commander, bool popup);
  170. CStackWindow(const CCommanderInstance * commander, std::vector<ui32> &skills, std::function<void(ui32)> callback);
  171. ~CStackWindow();
  172. };