CKingdomInterface.h 8.2 KB

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