CKingdomInterface.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * CKingdomInterface.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 "../widgets/CWindowWithArtifacts.h"
  12. #include "CWindowObject.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGObjectInstance;
  15. VCMI_LIB_NAMESPACE_END
  16. class CButton;
  17. class CAnimImage;
  18. class CToggleGroup;
  19. class CResDataBar;
  20. class CSlider;
  21. class CTownInfo;
  22. class CCreaInfo;
  23. class HeroSlots;
  24. class LRClickableAreaOpenTown;
  25. class CComponent;
  26. class CHeroArea;
  27. class MoraleLuckBox;
  28. class CListBox;
  29. class CTabbedInt;
  30. class CGStatusBar;
  31. class CGarrisonInt;
  32. class CKingdHeroList;
  33. class CKingdTownList;
  34. class IInfoBoxData;
  35. /*
  36. * Several classes to display basically any data.
  37. * Main part - class InfoBox which controls how data will be formatted\positioned
  38. * InfoBox have image and 0-2 labels
  39. * In constructor it should receive object that implements IInfoBoxData interface
  40. *
  41. * interface IInfoBoxData defines way to get data for use in InfoBox
  42. * have several implementations:
  43. * InfoBoxHeroData - to display one of fields from hero (e.g. absolute value of primary skills)
  44. * InfoBoxCustomHeroData - to display one of hero fields without hero (e.g. bonuses from objects)
  45. * InfoBoxTownData - data from town
  46. * InfoBoxCustom - user-defined data
  47. */
  48. /// Displays one of object propertries with image and optional labels
  49. class InfoBox : public CIntObject
  50. {
  51. public:
  52. enum InfoPos
  53. {
  54. POS_UP_DOWN, POS_DOWN, POS_RIGHT, POS_INSIDE, POS_CORNER, POS_NONE
  55. };
  56. enum InfoSize
  57. {
  58. SIZE_TINY, SIZE_SMALL, SIZE_MEDIUM, SIZE_BIG, SIZE_HUGE
  59. };
  60. private:
  61. InfoSize size;
  62. InfoPos infoPos;
  63. std::shared_ptr<IInfoBoxData> data;
  64. std::shared_ptr<CLabel> value;
  65. std::shared_ptr<CLabel> name;
  66. std::shared_ptr<CAnimImage> image;
  67. std::shared_ptr<CHoverableArea> hover;
  68. public:
  69. InfoBox(Point position, InfoPos Pos, InfoSize Size, std::shared_ptr<IInfoBoxData> Data);
  70. ~InfoBox();
  71. void showPopupWindow(const Point & cursorPosition) override;
  72. void clickPressed(const Point & cursorPosition) override;
  73. };
  74. class IInfoBoxData
  75. {
  76. public:
  77. enum InfoType
  78. {
  79. HERO_PRIMARY_SKILL, HERO_MANA, HERO_EXPERIENCE, HERO_SPECIAL, HERO_SECONDARY_SKILL,
  80. //TODO: Luck? Morale? Artifact?
  81. ARMY_SLOT,//TODO
  82. TOWN_GROWTH, TOWN_AVAILABLE, TOWN_BUILDING,//TODO
  83. CUSTOM
  84. };
  85. protected:
  86. InfoType type;
  87. IInfoBoxData(InfoType Type);
  88. public:
  89. //methods that generate values for displaying
  90. virtual std::string getValueText()=0;
  91. virtual std::string getNameText()=0;
  92. virtual AnimationPath getImageName(InfoBox::InfoSize size)=0;
  93. virtual std::string getHoverText()=0;
  94. virtual size_t getImageIndex()=0;
  95. //TODO: replace with something better
  96. virtual void prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp)=0;
  97. virtual ~IInfoBoxData(){};
  98. };
  99. class InfoBoxAbstractHeroData : public IInfoBoxData
  100. {
  101. protected:
  102. virtual int getSubID()=0;
  103. virtual si64 getValue()=0;
  104. public:
  105. InfoBoxAbstractHeroData(InfoType Type);
  106. std::string getValueText() override;
  107. std::string getNameText() override;
  108. AnimationPath getImageName(InfoBox::InfoSize size) override;
  109. std::string getHoverText() override;
  110. size_t getImageIndex() override;
  111. void prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp) override;
  112. };
  113. class InfoBoxHeroData : public InfoBoxAbstractHeroData
  114. {
  115. const CGHeroInstance * hero;
  116. int index;//index of data in hero (0-7 for sec. skill, 0-3 for pr. skill)
  117. int getSubID() override;
  118. si64 getValue() override;
  119. public:
  120. InfoBoxHeroData(InfoType Type, const CGHeroInstance *Hero, int Index=0);
  121. //To get a bit different texts for hero window
  122. std::string getHoverText() override;
  123. std::string getValueText() override;
  124. void prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp) override;
  125. };
  126. class InfoBoxCustomHeroData : public InfoBoxAbstractHeroData
  127. {
  128. int subID;//subID of data (0=attack...)
  129. si64 value;//actual value of data, 64-bit to fit experience and negative values
  130. int getSubID() override;
  131. si64 getValue() override;
  132. public:
  133. InfoBoxCustomHeroData(InfoType Type, int subID, si64 value);
  134. };
  135. class InfoBoxCustom : public IInfoBoxData
  136. {
  137. public:
  138. std::string valueText;
  139. std::string nameText;
  140. AnimationPath imageName;
  141. std::string hoverText;
  142. size_t imageIndex;
  143. InfoBoxCustom(std::string ValueText, std::string NameText, const AnimationPath & ImageName, size_t ImageIndex, std::string HoverText="");
  144. std::string getValueText() override;
  145. std::string getNameText() override;
  146. AnimationPath getImageName(InfoBox::InfoSize size) override;
  147. std::string getHoverText() override;
  148. size_t getImageIndex() override;
  149. void prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp) override;
  150. };
  151. //TODO!!!
  152. class InfoBoxTownData : public IInfoBoxData
  153. {
  154. const CGTownInstance * town;
  155. int index;//index of data in town
  156. int value;//actual value of data
  157. public:
  158. InfoBoxTownData(InfoType Type, const CGTownInstance * Town, int Index);
  159. InfoBoxTownData(InfoType Type, int SubID, int Value);
  160. std::string getValueText() override;
  161. std::string getNameText() override;
  162. AnimationPath getImageName(InfoBox::InfoSize size) override;
  163. std::string getHoverText() override;
  164. size_t getImageIndex() override;
  165. };
  166. /// Class which holds all parts of kingdom overview window
  167. class CKingdomInterface : public CWindowObject, public IGarrisonHolder, public CArtifactHolder
  168. {
  169. private:
  170. struct OwnedObjectInfo
  171. {
  172. int imageID;
  173. ui32 count;
  174. std::string hoverText;
  175. OwnedObjectInfo():
  176. imageID(0),
  177. count(0)
  178. {}
  179. };
  180. std::vector<OwnedObjectInfo> objects;
  181. std::shared_ptr<CListBox> dwellingsList;
  182. std::shared_ptr<CTabbedInt> tabArea;
  183. //Main buttons
  184. std::shared_ptr<CButton> btnTowns;
  185. std::shared_ptr<CButton> btnHeroes;
  186. std::shared_ptr<CButton> btnExit;
  187. //Buttons for scrolling dwellings list
  188. std::shared_ptr<CButton> dwellUp;
  189. std::shared_ptr<CButton> dwellDown;
  190. std::shared_ptr<CButton> dwellTop;
  191. std::shared_ptr<CButton> dwellBottom;
  192. std::array<std::shared_ptr<InfoBox>, 7> minesBox;
  193. std::shared_ptr<CHoverableArea> incomeArea;
  194. std::shared_ptr<CLabel> incomeAmount;
  195. std::shared_ptr<CGStatusBar> statusbar;
  196. std::shared_ptr<CResDataBar> resdatabar;
  197. void activateTab(size_t which);
  198. //Internal functions used during construction
  199. void generateButtons();
  200. void generateObjectsList(const std::vector<const CGObjectInstance * > &ownedObjects);
  201. void generateMinesList(const std::vector<const CGObjectInstance * > &ownedObjects);
  202. std::shared_ptr<CIntObject> createOwnedObject(size_t index);
  203. std::shared_ptr<CIntObject> createMainTab(size_t index);
  204. public:
  205. CKingdomInterface();
  206. void townChanged(const CGTownInstance *town);
  207. void heroRemoved();
  208. void updateGarrisons() override;
  209. void artifactRemoved(const ArtifactLocation &artLoc) override;
  210. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc, bool withRedraw) override;
  211. void artifactDisassembled(const ArtifactLocation &artLoc) override;
  212. void artifactAssembled(const ArtifactLocation &artLoc) override;
  213. };
  214. /// List item with town
  215. class CTownItem : public CIntObject, public IGarrisonHolder
  216. {
  217. std::shared_ptr<CAnimImage> background;
  218. std::shared_ptr<CAnimImage> picture;
  219. std::shared_ptr<CLabel> name;
  220. std::shared_ptr<CLabel> income;
  221. std::shared_ptr<CGarrisonInt> garr;
  222. std::shared_ptr<HeroSlots> heroes;
  223. std::shared_ptr<CTownInfo> hall;
  224. std::shared_ptr<CTownInfo> fort;
  225. std::vector<std::shared_ptr<CCreaInfo>> available;
  226. std::vector<std::shared_ptr<CCreaInfo>> growth;
  227. std::shared_ptr<LRClickableAreaOpenTown> openTown;
  228. public:
  229. const CGTownInstance * town;
  230. CTownItem(const CGTownInstance * Town);
  231. void updateGarrisons() override;
  232. void update();
  233. };
  234. /// List item with hero
  235. class CHeroItem : public CIntObject, public IGarrisonHolder
  236. {
  237. const CGHeroInstance * hero;
  238. std::vector<std::shared_ptr<CIntObject>> artTabs;
  239. std::shared_ptr<CAnimImage> portrait;
  240. std::shared_ptr<CLabel> name;
  241. std::shared_ptr<CHeroArea> heroArea;
  242. std::shared_ptr<CLabel> artsText;
  243. std::shared_ptr<CTabbedInt> artsTabs;
  244. std::shared_ptr<CToggleGroup> artButtons;
  245. std::vector<std::shared_ptr<InfoBox>> heroInfo;
  246. std::shared_ptr<MoraleLuckBox> morale;
  247. std::shared_ptr<MoraleLuckBox> luck;
  248. std::shared_ptr<CGarrisonInt> garr;
  249. void onArtChange(int tabIndex);
  250. std::shared_ptr<CIntObject> onTabSelected(size_t index);
  251. public:
  252. std::shared_ptr<CArtifactsOfHeroKingdom> heroArts;
  253. void updateGarrisons() override;
  254. CHeroItem(const CGHeroInstance * hero);
  255. };
  256. /// Tab with all hero-specific data
  257. class CKingdHeroList : public CIntObject, public IGarrisonHolder, public CWindowWithArtifacts
  258. {
  259. private:
  260. std::shared_ptr<CListBox> heroes;
  261. std::shared_ptr<CPicture> title;
  262. std::shared_ptr<CLabel> heroLabel;
  263. std::shared_ptr<CLabel> skillsLabel;
  264. std::shared_ptr<CIntObject> createHeroItem(size_t index);
  265. public:
  266. CKingdHeroList(size_t maxSize);
  267. void updateGarrisons() override;
  268. };
  269. /// Tab with all town-specific data
  270. class CKingdTownList : public CIntObject, public IGarrisonHolder
  271. {
  272. private:
  273. std::shared_ptr<CListBox> towns;
  274. std::shared_ptr<CPicture> title;
  275. std::shared_ptr<CLabel> townLabel;
  276. std::shared_ptr<CLabel> garrHeroLabel;
  277. std::shared_ptr<CLabel> visitHeroLabel;
  278. std::shared_ptr<CIntObject> createTownItem(size_t index);
  279. public:
  280. CKingdTownList(size_t maxSize);
  281. void townChanged(const CGTownInstance * town);
  282. void updateGarrisons() override;
  283. };