CKingdomInterface.h 9.5 KB

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