CCreatureWindow.h 5.8 KB

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