CKingdomInterface.h 9.5 KB

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