CKingdomInterface.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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/CArtifactHolder.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. IInfoBoxData *data;
  60. CLabel * value;
  61. CLabel * name;
  62. CAnimImage * image;
  63. CHoverableArea *hover;
  64. public:
  65. InfoBox(Point position, InfoPos Pos, InfoSize Size, 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 bool prepareMessage(std::string &text, 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. bool prepareMessage(std::string &text, 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. bool prepareMessage(std::string &text, 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. bool prepareMessage(std::string &text, 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. ////////////////////////////////////////////////////////////////////////////////
  165. /// Class which holds all parts of kingdom overview window
  166. class CKingdomInterface : public CWindowObject, public CGarrisonHolder, public CArtifactHolder
  167. {
  168. private:
  169. struct OwnedObjectInfo
  170. {
  171. int imageID;
  172. ui32 count;
  173. std::string hoverText;
  174. OwnedObjectInfo():
  175. imageID(0),
  176. count(0)
  177. {}
  178. };
  179. std::vector<OwnedObjectInfo> objects;
  180. CListBox * dwellingsList;
  181. CTabbedInt * tabArea;
  182. //Main buttons
  183. CButton *btnTowns;
  184. CButton *btnHeroes;
  185. CButton *btnExit;
  186. //Buttons for scrolling dwellings list
  187. CButton *dwellUp, *dwellDown;
  188. CButton *dwellTop, *dwellBottom;
  189. InfoBox * minesBox[7];
  190. CHoverableArea * incomeArea;
  191. CLabel * incomeAmount;
  192. CGStatusBar * statusbar;
  193. CResDataBar *resdatabar;
  194. void activateTab(size_t which);
  195. //Internal functions used during construction
  196. void generateButtons();
  197. void generateObjectsList(const std::vector<const CGObjectInstance * > &ownedObjects);
  198. void generateMinesList(const std::vector<const CGObjectInstance * > &ownedObjects);
  199. CIntObject* createOwnedObject(size_t index);
  200. CIntObject* createMainTab(size_t index);
  201. public:
  202. CKingdomInterface();
  203. void townChanged(const CGTownInstance *town);
  204. void updateGarrisons() override;
  205. void artifactRemoved(const ArtifactLocation &artLoc) override;
  206. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc) override;
  207. void artifactDisassembled(const ArtifactLocation &artLoc) override;
  208. void artifactAssembled(const ArtifactLocation &artLoc) override;
  209. };
  210. /// List item with town
  211. class CTownItem : public CIntObject, public CGarrisonHolder
  212. {
  213. CAnimImage *background;
  214. CAnimImage *picture;
  215. CLabel *name;
  216. CLabel *income;
  217. CGarrisonInt *garr;
  218. HeroSlots *heroes;
  219. CTownInfo *hall, *fort;
  220. std::vector<CCreaInfo*> available;
  221. std::vector<CCreaInfo*> growth;
  222. public:
  223. const CGTownInstance * town;
  224. CTownItem(const CGTownInstance* town);
  225. void updateGarrisons() override;
  226. void update();
  227. };
  228. /// List item with hero
  229. class CHeroItem : public CIntObject, public CWindowWithGarrison
  230. {
  231. const CGHeroInstance * hero;
  232. std::vector<CIntObject *> artTabs;
  233. CAnimImage *portrait;
  234. CLabel *name;
  235. CHeroArea *heroArea;
  236. CLabel *artsText;
  237. CTabbedInt *artsTabs;
  238. CToggleGroup *artButtons;
  239. std::vector<InfoBox*> heroInfo;
  240. MoraleLuckBox * morale, * luck;
  241. void onArtChange(int tabIndex);
  242. CIntObject * onTabSelected(size_t index);
  243. void onTabDeselected(CIntObject *object);
  244. public:
  245. CArtifactsOfHero *heroArts;
  246. CHeroItem(const CGHeroInstance* hero);
  247. };
  248. /// Tab with all hero-specific data
  249. class CKingdHeroList : public CIntObject, public CGarrisonHolder, public CWindowWithArtifacts
  250. {
  251. private:
  252. std::vector<CHeroItem*> heroItems;
  253. CListBox * heroes;
  254. CPicture * title;
  255. CLabel * heroLabel;
  256. CLabel * skillsLabel;
  257. CIntObject* createHeroItem(size_t index);
  258. void destroyHeroItem(CIntObject *item);
  259. public:
  260. CKingdHeroList(size_t maxSize);
  261. void updateGarrisons() override;
  262. };
  263. /// Tab with all town-specific data
  264. class CKingdTownList : public CIntObject, public CGarrisonHolder
  265. {
  266. private:
  267. std::vector<CTownItem*> townItems;
  268. CListBox * towns;
  269. CPicture * title;
  270. CLabel * townLabel;
  271. CLabel * garrHeroLabel;
  272. CLabel * visitHeroLabel;
  273. CIntObject* createTownItem(size_t index);
  274. public:
  275. CKingdTownList(size_t maxSize);
  276. void townChanged(const CGTownInstance *town);
  277. void updateGarrisons() override;
  278. };