CKingdomInterface.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. #pragma once
  2. #include "GUIClasses.h"
  3. class CAdventureMapButton;
  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. CHoverableArea *hover;
  56. public:
  57. InfoBox(Point 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, CComponent **comp)=0;
  87. virtual ~IInfoBoxData(){};
  88. };
  89. class InfoBoxAbstractHeroData : public IInfoBoxData
  90. {
  91. protected:
  92. virtual int getSubID()=0;
  93. virtual si64 getValue()=0;
  94. public:
  95. InfoBoxAbstractHeroData(InfoType Type);
  96. std::string getValueText();
  97. std::string getNameText();
  98. std::string getImageName(InfoBox::InfoSize size);
  99. std::string getHoverText();
  100. size_t getImageIndex();
  101. bool prepareMessage(std::string &text, CComponent **comp);
  102. };
  103. class InfoBoxHeroData : public InfoBoxAbstractHeroData
  104. {
  105. const CGHeroInstance * hero;
  106. int index;//index of data in hero (0-7 for sec. skill, 0-3 for pr. skill)
  107. int getSubID();
  108. si64 getValue();
  109. public:
  110. InfoBoxHeroData(InfoType Type, const CGHeroInstance *Hero, int Index=0);
  111. //To get a bit different texts for hero window
  112. std::string getHoverText();
  113. std::string getValueText();
  114. bool prepareMessage(std::string &text, CComponent **comp);
  115. };
  116. class InfoBoxCustomHeroData : public InfoBoxAbstractHeroData
  117. {
  118. int subID;//subID of data (0=attack...)
  119. si64 value;//actual value of data, 64-bit to fit experience and negative values
  120. int getSubID();
  121. si64 getValue();
  122. public:
  123. InfoBoxCustomHeroData(InfoType Type, int subID, si64 value);
  124. };
  125. class InfoBoxCustom : public IInfoBoxData
  126. {
  127. public:
  128. std::string valueText;
  129. std::string nameText;
  130. std::string imageName;
  131. std::string hoverText;
  132. size_t imageIndex;
  133. InfoBoxCustom(std::string ValueText, std::string NameText, std::string ImageName, size_t ImageIndex, std::string HoverText="");
  134. std::string getValueText();
  135. std::string getNameText();
  136. std::string getImageName(InfoBox::InfoSize size);
  137. std::string getHoverText();
  138. size_t getImageIndex();
  139. bool prepareMessage(std::string &text, CComponent **comp);
  140. };
  141. //TODO!!!
  142. class InfoBoxTownData : public IInfoBoxData
  143. {
  144. const CGTownInstance * town;
  145. int index;//index of data in town
  146. int value;//actual value of data
  147. public:
  148. InfoBoxTownData(InfoType Type, const CGTownInstance * Town, int Index);
  149. InfoBoxTownData(InfoType Type, int SubID, int Value);
  150. std::string getValueText();
  151. std::string getNameText();
  152. std::string getImageName(InfoBox::InfoSize size);
  153. std::string getHoverText();
  154. size_t getImageIndex();
  155. };
  156. ////////////////////////////////////////////////////////////////////////////////
  157. /// Class which holds all parts of kingdom overview window
  158. class CKingdomInterface : public CWindowObject, public CGarrisonHolder, public CArtifactHolder
  159. {
  160. private:
  161. struct OwnedObjectInfo
  162. {
  163. int imageID;
  164. ui32 count;
  165. std::string hoverText;
  166. OwnedObjectInfo():
  167. imageID(0),
  168. count(0)
  169. {}
  170. };
  171. std::vector<OwnedObjectInfo> objects;
  172. CListBox * dwellingsList;
  173. CTabbedInt * tabArea;
  174. //Main buttons
  175. CAdventureMapButton *btnTowns;
  176. CAdventureMapButton *btnHeroes;
  177. CAdventureMapButton *btnExit;
  178. //Buttons for scrolling dwellings list
  179. CAdventureMapButton *dwellUp, *dwellDown;
  180. CAdventureMapButton *dwellTop, *dwellBottom;
  181. InfoBox * minesBox[7];
  182. CHoverableArea * incomeArea;
  183. CLabel * incomeAmount;
  184. CGStatusBar * statusbar;
  185. CResDataBar *resdatabar;
  186. void activateTab(size_t which);
  187. //Internal functions used during construction
  188. void generateButtons();
  189. void generateObjectsList(const std::vector<const CGObjectInstance * > &ownedObjects);
  190. void generateMinesList(const std::vector<const CGObjectInstance * > &ownedObjects);
  191. CIntObject* createOwnedObject(size_t index);
  192. CIntObject* createMainTab(size_t index);
  193. public:
  194. CKingdomInterface();
  195. void townChanged(const CGTownInstance *town);
  196. void updateGarrisons();
  197. void artifactRemoved(const ArtifactLocation &artLoc);
  198. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc);
  199. void artifactDisassembled(const ArtifactLocation &artLoc);
  200. void artifactAssembled(const ArtifactLocation &artLoc);
  201. };
  202. /// List item with town
  203. class CTownItem : public CIntObject, public CGarrisonHolder
  204. {
  205. CAnimImage *background;
  206. CAnimImage *picture;
  207. CLabel *name;
  208. CLabel *income;
  209. CGarrisonInt *garr;
  210. LRClickableAreaOpenTown *townArea;
  211. HeroSlots *heroes;
  212. CTownInfo *hall, *fort;
  213. std::vector<CCreaInfo*> available;
  214. std::vector<CCreaInfo*> growth;
  215. public:
  216. const CGTownInstance * town;
  217. CTownItem(const CGTownInstance* town);
  218. void updateGarrisons();
  219. void update();
  220. };
  221. /// List item with hero
  222. class CHeroItem : public CIntObject, public CWindowWithGarrison
  223. {
  224. const CGHeroInstance * hero;
  225. std::vector<CIntObject *> artTabs;
  226. CAnimImage *portrait;
  227. CLabel *name;
  228. CHeroArea *heroArea;
  229. CLabel *artsText;
  230. CTabbedInt *artsTabs;
  231. CHighlightableButtonsGroup *artButtons;
  232. std::vector<InfoBox*> heroInfo;
  233. MoraleLuckBox * morale, * luck;
  234. void onArtChange(int tabIndex);
  235. CIntObject * onTabSelected(size_t index);
  236. void onTabDeselected(CIntObject *object);
  237. public:
  238. CArtifactsOfHero *heroArts;
  239. CHeroItem(const CGHeroInstance* hero, CArtifactsOfHero::SCommonPart * artsCommonPart);
  240. };
  241. /// Tab with all hero-specific data
  242. class CKingdHeroList : public CIntObject, public CGarrisonHolder, public CWindowWithArtifacts
  243. {
  244. private:
  245. CArtifactsOfHero::SCommonPart artsCommonPart;
  246. std::vector<CHeroItem*> heroItems;
  247. CListBox * heroes;
  248. CPicture * title;
  249. CLabel * heroLabel;
  250. CLabel * skillsLabel;
  251. CIntObject* createHeroItem(size_t index);
  252. void destroyHeroItem(CIntObject *item);
  253. public:
  254. CKingdHeroList(size_t maxSize);
  255. void updateGarrisons();
  256. };
  257. /// Tab with all town-specific data
  258. class CKingdTownList : public CIntObject, public CGarrisonHolder
  259. {
  260. private:
  261. std::vector<CTownItem*> townItems;
  262. CListBox * towns;
  263. CPicture * title;
  264. CLabel * townLabel;
  265. CLabel * garrHeroLabel;
  266. CLabel * visitHeroLabel;
  267. CIntObject* createTownItem(size_t index);
  268. public:
  269. CKingdTownList(size_t maxSize);
  270. void townChanged(const CGTownInstance *town);
  271. void updateGarrisons();
  272. };