CCreatureWindow.h 5.9 KB

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