CKingdomInterface.h 10 KB

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