CCreatureWindow.h 5.6 KB

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