CKingdomInterface.h 9.8 KB

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