CKingdomInterface.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. #pragma once
  2. #include "../global.h"
  3. #include <list>
  4. #include "GUIBase.h"
  5. #include "GUIClasses.h"
  6. class AdventureMapButton;
  7. class CAnimImage;
  8. class CHighlightableButtonsGroup;
  9. class CResDataBar;
  10. class CSlider;
  11. class CTownInfo;
  12. class CCreaInfo;
  13. class HeroSlots;
  14. /*
  15. * CKingdomInterface.h, part of VCMI engine
  16. *
  17. * Authors: listed in file AUTHORS in main folder
  18. *
  19. * License: GNU General Public License v2.0 or later
  20. * Full text of license available in license.txt file, in main folder
  21. *
  22. */
  23. class CKingdHeroList;
  24. class CKingdTownList;
  25. class IInfoBoxData;
  26. /*
  27. * Several classes to display basically any data.
  28. * Main part - class InfoBox which controls how data will be formatted\positioned
  29. * InfoBox have image and 0-2 labels
  30. * In constructor it should receive object that implements IInfoBoxData interface
  31. *
  32. * interface IInfoBoxData defines way to get data for use in InfoBox
  33. * have several implementations:
  34. * InfoBoxHeroData - to display one of fields from hero (e.g. absolute value of primary skills)
  35. * InfoBoxCustomHeroData - to display one of hero fields without hero (e.g. bonuses from objects)
  36. * InfoBoxTownData - data from town
  37. * InfoBoxCustom - user-defined data
  38. */
  39. /// Displays one of object propertries with image and optional labels
  40. class InfoBox : public CIntObject
  41. {
  42. public:
  43. enum InfoPos
  44. {
  45. POS_UP_DOWN, POS_DOWN, POS_RIGHT, POS_INSIDE, POS_CORNER, POS_NONE
  46. };
  47. enum InfoSize
  48. {
  49. SIZE_TINY, SIZE_SMALL, SIZE_MEDIUM, SIZE_BIG, SIZE_HUGE
  50. };
  51. private:
  52. InfoSize size;
  53. InfoPos infoPos;
  54. IInfoBoxData *data;
  55. CLabel * value;
  56. CLabel * name;
  57. CAnimImage * image;
  58. HoverableArea *hover;
  59. public:
  60. InfoBox(Point position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data);
  61. ~InfoBox();
  62. void clickRight(tribool down, bool previousState);
  63. void clickLeft(tribool down, bool previousState);
  64. //Update object if data may have changed
  65. //void update();
  66. };
  67. class IInfoBoxData
  68. {
  69. public:
  70. enum InfoType
  71. {
  72. HERO_PRIMARY_SKILL, HERO_MANA, HERO_EXPERIENCE, HERO_SPECIAL, HERO_SECONDARY_SKILL,
  73. //TODO: Luck? Morale? Artifact?
  74. ARMY_SLOT,//TODO
  75. TOWN_GROWTH, TOWN_AVAILABLE, TOWN_BUILDING,//TODO
  76. CUSTOM
  77. };
  78. protected:
  79. InfoType type;
  80. IInfoBoxData(InfoType Type);
  81. public:
  82. //methods that generate values for displaying
  83. virtual std::string getValueText()=0;
  84. virtual std::string getNameText()=0;
  85. virtual std::string getImageName(InfoBox::InfoSize size)=0;
  86. virtual std::string getHoverText()=0;
  87. virtual size_t getImageIndex()=0;
  88. //TODO: replace with something better
  89. virtual bool prepareMessage(std::string &text, SComponent **comp)=0;
  90. };
  91. class InfoBoxAbstractHeroData : public IInfoBoxData
  92. {
  93. protected:
  94. virtual int getSubID()=0;
  95. virtual si64 getValue()=0;
  96. public:
  97. InfoBoxAbstractHeroData(InfoType Type);
  98. std::string getValueText();
  99. std::string getNameText();
  100. std::string getImageName(InfoBox::InfoSize size);
  101. std::string getHoverText();
  102. size_t getImageIndex();
  103. bool prepareMessage(std::string &text, SComponent **comp);
  104. };
  105. class InfoBoxHeroData : public InfoBoxAbstractHeroData
  106. {
  107. const CGHeroInstance * hero;
  108. int index;//index of data in hero (0-7 for sec. skill, 0-3 for pr. skill)
  109. int getSubID();
  110. si64 getValue();
  111. public:
  112. InfoBoxHeroData(InfoType Type, const CGHeroInstance *Hero, int Index=0);
  113. //To get a bit different texts for hero window
  114. std::string getHoverText();
  115. std::string getValueText();
  116. bool prepareMessage(std::string &text, SComponent **comp);
  117. };
  118. class InfoBoxCustomHeroData : public InfoBoxAbstractHeroData
  119. {
  120. int subID;//subID of data (0=attack...)
  121. si64 value;//actual value of data, 64-bit to fit experience and negative values
  122. int getSubID();
  123. si64 getValue();
  124. public:
  125. InfoBoxCustomHeroData(InfoType Type, int subID, si64 value);
  126. };
  127. class InfoBoxCustom : public IInfoBoxData
  128. {
  129. public:
  130. std::string valueText;
  131. std::string nameText;
  132. std::string imageName;
  133. std::string hoverText;
  134. size_t imageIndex;
  135. InfoBoxCustom(std::string ValueText, std::string NameText, std::string ImageName, size_t ImageIndex, std::string HoverText="");
  136. std::string getValueText();
  137. std::string getNameText();
  138. std::string getImageName(InfoBox::InfoSize size);
  139. std::string getHoverText();
  140. size_t getImageIndex();
  141. bool prepareMessage(std::string &text, SComponent **comp);
  142. };
  143. //TODO!!!
  144. class InfoBoxTownData : public IInfoBoxData
  145. {
  146. const CGTownInstance * town;
  147. int index;//index of data in town
  148. int value;//actual value of data
  149. public:
  150. InfoBoxTownData(InfoType Type, const CGTownInstance * Town, int Index);
  151. InfoBoxTownData(InfoType Type, int SubID, int Value);
  152. std::string getValueText();
  153. std::string getNameText();
  154. std::string getImageName(InfoBox::InfoSize size);
  155. std::string getHoverText();
  156. size_t getImageIndex();
  157. };
  158. ////////////////////////////////////////////////////////////////////////////////
  159. /// Interface used in CTabbedInt and CListBox
  160. class IGuiObjectListManager
  161. {
  162. public:
  163. //Create object for specified position, may return NULL if no object is needed at this position
  164. //NOTE: position may be greater then size (empty rows in ListBox)
  165. virtual CIntObject * getObject(size_t position)=0;
  166. //Called when object needs to be removed
  167. virtual void removeObject(CIntObject * object)
  168. {
  169. delete object;
  170. };
  171. virtual ~IGuiObjectListManager(){};
  172. };
  173. /// Used as base for Tabs and List classes
  174. class CObjectList : public CIntObject
  175. {
  176. IGuiObjectListManager *manager;
  177. protected:
  178. //Internal methods for safe creation of items (Children capturing and activation/deactivation if needed)
  179. void deleteItem(CIntObject* item);
  180. CIntObject* createItem(size_t index);
  181. public:
  182. CObjectList(IGuiObjectListManager *Manager);
  183. ~CObjectList();
  184. };
  185. /// Window element with multiple tabs
  186. class CTabbedInt : public CObjectList
  187. {
  188. private:
  189. CIntObject * activeTab;
  190. size_t activeID;
  191. public:
  192. //Manager - object which implements this interface, will be destroyed by TabbedInt
  193. //Pos - position of object, all tabs will be moved here
  194. //ActiveID - ID of initially active tab
  195. CTabbedInt(IGuiObjectListManager *Manager, Point position=Point(), size_t ActiveID=0);
  196. void setActive(size_t which);
  197. //recreate active tab
  198. void reset();
  199. //return currently active item
  200. CIntObject * getItem();
  201. };
  202. /// List of IntObjects with optional slider
  203. class CListBox : public CObjectList
  204. {
  205. private:
  206. std::list< CIntObject* > items;
  207. size_t first;
  208. size_t totalSize;
  209. Point itemOffset;
  210. CSlider * slider;
  211. void updatePositions();
  212. public:
  213. //Manager - object which implements this interface, will be destroyed by ListBox
  214. //Pos - position of first item
  215. //ItemOffset - distance between items in the list
  216. //VisibleSize - maximal number of displayable at once items
  217. //TotalSize
  218. //Slider - slider style, bit field: 1 = present(disabled), 2=horisontal(vertical), 4=blue(brown)
  219. //SliderPos - position of slider, if present
  220. CListBox(IGuiObjectListManager *Manager, Point Pos, Point ItemOffset, size_t VisibleSize,
  221. size_t TotalSize, size_t InitialPos=0, int Slider=0, Rect SliderPos=Rect() );
  222. //recreate all visible items
  223. void reset();
  224. //return currently active items
  225. std::list< CIntObject * > getItems();
  226. //scroll list
  227. void moveToPos(size_t which);
  228. void moveToNext();
  229. void moveToPrev();
  230. };
  231. ////////////////////////////////////////////////////////////////////////////////
  232. /// Class which holds all parts of kingdom overview window
  233. class CKingdomInterface : public CGarrisonHolder, public CArtifactHolder
  234. {
  235. private:
  236. CListBox * dwellingsList;
  237. CTabbedInt * tabArea;
  238. CPicture * background;
  239. //Main buttons
  240. AdventureMapButton *btnTowns;
  241. AdventureMapButton *btnHeroes;
  242. AdventureMapButton *btnExit;
  243. //Buttons for scrolling dwellings list
  244. AdventureMapButton *dwellUp, *dwellDown;
  245. AdventureMapButton *dwellTop, *dwellBottom;
  246. InfoBox * minesBox[7];
  247. HoverableArea * incomeArea;
  248. CLabel * incomeAmount;
  249. CGStatusBar * statusbar;
  250. CResDataBar *resdatabar;
  251. void activateTab(size_t which);
  252. //Internal functions used during construction
  253. void generateButtons();
  254. void generateObjectsList(const std::vector<const CGObjectInstance * > &ownedObjects);
  255. void generateMinesList(const std::vector<const CGObjectInstance * > &ownedObjects);
  256. public:
  257. CKingdomInterface();
  258. void townChanged(const CGTownInstance *town);
  259. void updateGarrisons();
  260. void artifactRemoved(const ArtifactLocation &artLoc);
  261. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc);
  262. void artifactDisassembled(const ArtifactLocation &artLoc);
  263. void artifactAssembled(const ArtifactLocation &artLoc);
  264. };
  265. /// List item with town
  266. class CTownItem : public CGarrisonHolder
  267. {
  268. CAnimImage *background;
  269. CAnimImage *picture;
  270. CLabel *name;
  271. CLabel *income;
  272. CGarrisonInt *garr;
  273. LRClickableAreaOpenTown *townArea;
  274. HeroSlots *heroes;
  275. CTownInfo *hall, *fort;
  276. std::vector<CCreaInfo*> available;
  277. std::vector<CCreaInfo*> growth;
  278. public:
  279. const CGTownInstance * town;
  280. CTownItem(const CGTownInstance* town);
  281. void updateGarrisons();
  282. void update();
  283. };
  284. /// List item with hero
  285. class CHeroItem : public CWindowWithGarrison
  286. {
  287. const CGHeroInstance * hero;
  288. CAnimImage *background;
  289. CAnimImage *portrait;
  290. CLabel *name;
  291. CHeroArea *heroArea;
  292. CLabel *artsText;
  293. CTabbedInt *artsTabs;
  294. CHighlightableButtonsGroup *artButtons;
  295. std::vector<InfoBox*> heroInfo;
  296. MoraleLuckBox * morale, * luck;
  297. void onArtChange(int tabIndex);
  298. public:
  299. CArtifactsOfHero *heroArts;
  300. CHeroItem(const CGHeroInstance* hero, CArtifactsOfHero::SCommonPart * artsCommonPart);
  301. };
  302. /// Tab with all hero-specific data
  303. class CKingdHeroList : public CGarrisonHolder, public CWindowWithArtifacts
  304. {
  305. private:
  306. std::vector<CHeroItem*> heroItems;
  307. CListBox * heroes;
  308. CPicture * title;
  309. CLabel * heroLabel;
  310. CLabel * skillsLabel;
  311. public:
  312. CKingdHeroList(size_t maxSize);
  313. void updateGarrisons();
  314. };
  315. /// Tab with all town-specific data
  316. class CKingdTownList : public CGarrisonHolder
  317. {
  318. private:
  319. std::vector<CTownItem*> townItems;
  320. CListBox * towns;
  321. CPicture * title;
  322. CLabel * townLabel;
  323. CLabel * garrHeroLabel;
  324. CLabel * visitHeroLabel;
  325. public:
  326. CKingdTownList(size_t maxSize);
  327. void townChanged(const CGTownInstance *town);
  328. void updateGarrisons();
  329. };