CCreatureWindow.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. public:
  63. ActiveSpellsSection(CStackWindow * owner, int yOffset);
  64. };
  65. class BonusLineSection : public CWindowSection
  66. {
  67. std::array<std::shared_ptr<CPicture>, 2> icon;
  68. std::array<std::shared_ptr<CLabel>, 2> name;
  69. std::array<std::shared_ptr<CMultiLineLabel>, 2> description;
  70. public:
  71. BonusLineSection(CStackWindow * owner, size_t lineIndex);
  72. };
  73. class BonusesSection : public CWindowSection
  74. {
  75. std::shared_ptr<CListBox> lines;
  76. public:
  77. BonusesSection(CStackWindow * owner, int yOffset, std::optional<size_t> preferredSize = std::optional<size_t>());
  78. };
  79. class ButtonsSection : public CWindowSection
  80. {
  81. std::shared_ptr<CButton> dismiss;
  82. std::array<std::shared_ptr<CButton>, 3> upgrade;// no more than 3 buttons - space limit
  83. std::shared_ptr<CButton> exit;
  84. public:
  85. ButtonsSection(CStackWindow * owner, int yOffset);
  86. };
  87. class CommanderMainSection : public CWindowSection
  88. {
  89. std::vector<std::shared_ptr<CCommanderSkillIcon>> skillIcons;
  90. std::vector<std::shared_ptr<CCommanderArtPlace>> artifacts;
  91. std::shared_ptr<CPicture> abilitiesBackground;
  92. std::shared_ptr<CListBox> abilities;
  93. std::shared_ptr<CButton> leftBtn;
  94. std::shared_ptr<CButton> rightBtn;
  95. public:
  96. CommanderMainSection(CStackWindow * owner, int yOffset);
  97. };
  98. class MainSection : public CWindowSection
  99. {
  100. enum class EStat : size_t
  101. {
  102. ATTACK,
  103. DEFENCE,
  104. SHOTS,
  105. DAMAGE,
  106. HEALTH,
  107. HEALTH_LEFT,
  108. SPEED,
  109. MANA,
  110. AFTER_LAST
  111. };
  112. std::shared_ptr<CCreaturePic> animation;
  113. std::shared_ptr<CLabel> name;
  114. std::shared_ptr<CPicture> icons;
  115. std::shared_ptr<MoraleLuckBox> morale;
  116. std::shared_ptr<MoraleLuckBox> luck;
  117. std::vector<std::shared_ptr<CLabel>> stats;
  118. std::shared_ptr<CAnimImage> expRankIcon;
  119. std::shared_ptr<LRClickableAreaWText> expArea;
  120. std::shared_ptr<CLabel> expLabel;
  121. void addStatLabel(EStat index, int64_t value1, int64_t value2);
  122. void addStatLabel(EStat index, int64_t value);
  123. static ImagePath getBackgroundName(bool showExp, bool showArt);
  124. std::array<std::string, 8> statNames;
  125. std::array<std::string, 8> statFormats;
  126. public:
  127. MainSection(CStackWindow * owner, int yOffset, bool showExp, bool showArt);
  128. };
  129. std::shared_ptr<CAnimImage> stackArtifactIcon;
  130. std::shared_ptr<LRClickableAreaWTextComp> stackArtifactHelp;
  131. std::shared_ptr<CButton> stackArtifactButton;
  132. std::shared_ptr<UnitView> info;
  133. std::vector<BonusInfo> activeBonuses;
  134. size_t activeTab;
  135. std::shared_ptr<CTabbedInt> commanderTab;
  136. std::map<size_t, std::shared_ptr<CButton>> switchButtons;
  137. std::shared_ptr<CWindowSection> mainSection;
  138. std::shared_ptr<CWindowSection> activeSpellsSection;
  139. std::shared_ptr<CWindowSection> commanderMainSection;
  140. std::shared_ptr<CWindowSection> commanderBonusesSection;
  141. std::shared_ptr<CWindowSection> bonusesSection;
  142. std::shared_ptr<CWindowSection> buttonsSection;
  143. std::shared_ptr<CCommanderSkillIcon> selectedIcon;
  144. si32 selectedSkill;
  145. void setSelection(si32 newSkill, std::shared_ptr<CCommanderSkillIcon> newIcon);
  146. std::shared_ptr<CIntObject> switchTab(size_t index);
  147. void removeStackArtifact(ArtifactPosition pos);
  148. void initSections();
  149. void initBonusesList();
  150. void init();
  151. std::string generateStackExpDescription();
  152. public:
  153. // for battles
  154. CStackWindow(const CStack * stack, bool popup);
  155. // for non-existing stacks, e.g. recruit screen
  156. CStackWindow(const CCreature * creature, bool popup);
  157. // for normal stacks in armies
  158. CStackWindow(const CStackInstance * stack, bool popup);
  159. CStackWindow(const CStackInstance * stack, std::function<void()> dismiss, const UpgradeInfo & info, std::function<void(CreatureID)> callback);
  160. // for commanders & commander level-up dialog
  161. CStackWindow(const CCommanderInstance * commander, bool popup);
  162. CStackWindow(const CCommanderInstance * commander, std::vector<ui32> &skills, std::function<void(ui32)> callback);
  163. ~CStackWindow();
  164. };