CKingdomInterface.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. #pragma once
  2. #include "../widgets/CArtifactHolder.h"
  3. #include "../widgets/CGarrisonInt.h"
  4. class CButton;
  5. class CAnimImage;
  6. class CToggleGroup;
  7. class CResDataBar;
  8. class CSlider;
  9. class CTownInfo;
  10. class CCreaInfo;
  11. class HeroSlots;
  12. class LRClickableAreaOpenTown;
  13. class CComponent;
  14. class CHeroArea;
  15. class MoraleLuckBox;
  16. class CListBox;
  17. class CTabbedInt;
  18. class CGStatusBar;
  19. /*
  20. * CKingdomInterface.h, part of VCMI engine
  21. *
  22. * Authors: listed in file AUTHORS in main folder
  23. *
  24. * License: GNU General Public License v2.0 or later
  25. * Full text of license available in license.txt file, in main folder
  26. *
  27. */
  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);
  68. void clickLeft(tribool down, bool previousState);
  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();
  105. std::string getNameText();
  106. std::string getImageName(InfoBox::InfoSize size);
  107. std::string getHoverText();
  108. size_t getImageIndex();
  109. bool prepareMessage(std::string &text, CComponent **comp);
  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();
  116. si64 getValue();
  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();
  121. std::string getValueText();
  122. bool prepareMessage(std::string &text, CComponent **comp);
  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();
  129. si64 getValue();
  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();
  143. std::string getNameText();
  144. std::string getImageName(InfoBox::InfoSize size);
  145. std::string getHoverText();
  146. size_t getImageIndex();
  147. bool prepareMessage(std::string &text, CComponent **comp);
  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();
  159. std::string getNameText();
  160. std::string getImageName(InfoBox::InfoSize size);
  161. std::string getHoverText();
  162. size_t getImageIndex();
  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();
  205. void artifactRemoved(const ArtifactLocation &artLoc);
  206. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc);
  207. void artifactDisassembled(const ArtifactLocation &artLoc);
  208. void artifactAssembled(const ArtifactLocation &artLoc);
  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. LRClickableAreaOpenTown *townArea;
  219. HeroSlots *heroes;
  220. CTownInfo *hall, *fort;
  221. std::vector<CCreaInfo*> available;
  222. std::vector<CCreaInfo*> growth;
  223. public:
  224. const CGTownInstance * town;
  225. CTownItem(const CGTownInstance* town);
  226. void updateGarrisons();
  227. void update();
  228. };
  229. /// List item with hero
  230. class CHeroItem : public CIntObject, public CWindowWithGarrison
  231. {
  232. const CGHeroInstance * hero;
  233. std::vector<CIntObject *> artTabs;
  234. CAnimImage *portrait;
  235. CLabel *name;
  236. CHeroArea *heroArea;
  237. CLabel *artsText;
  238. CTabbedInt *artsTabs;
  239. CToggleGroup *artButtons;
  240. std::vector<InfoBox*> heroInfo;
  241. MoraleLuckBox * morale, * luck;
  242. void onArtChange(int tabIndex);
  243. CIntObject * onTabSelected(size_t index);
  244. void onTabDeselected(CIntObject *object);
  245. public:
  246. CArtifactsOfHero *heroArts;
  247. CHeroItem(const CGHeroInstance* hero, CArtifactsOfHero::SCommonPart * artsCommonPart);
  248. };
  249. /// Tab with all hero-specific data
  250. class CKingdHeroList : public CIntObject, public CGarrisonHolder, public CWindowWithArtifacts
  251. {
  252. private:
  253. CArtifactsOfHero::SCommonPart artsCommonPart;
  254. std::vector<CHeroItem*> heroItems;
  255. CListBox * heroes;
  256. CPicture * title;
  257. CLabel * heroLabel;
  258. CLabel * skillsLabel;
  259. CIntObject* createHeroItem(size_t index);
  260. void destroyHeroItem(CIntObject *item);
  261. public:
  262. CKingdHeroList(size_t maxSize);
  263. void updateGarrisons();
  264. };
  265. /// Tab with all town-specific data
  266. class CKingdTownList : public CIntObject, public CGarrisonHolder
  267. {
  268. private:
  269. std::vector<CTownItem*> townItems;
  270. CListBox * towns;
  271. CPicture * title;
  272. CLabel * townLabel;
  273. CLabel * garrHeroLabel;
  274. CLabel * visitHeroLabel;
  275. CIntObject* createTownItem(size_t index);
  276. public:
  277. CKingdTownList(size_t maxSize);
  278. void townChanged(const CGTownInstance *town);
  279. void updateGarrisons();
  280. };