CCastleInterface.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /*
  2. * CCastleInterface.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 "../widgets/CGarrisonInt.h"
  12. #include "../widgets/Images.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CBuilding;
  15. class CGTownInstance;
  16. class CSpell;
  17. struct CStructure;
  18. class CGHeroInstance;
  19. class CCreature;
  20. VCMI_LIB_NAMESPACE_END
  21. class CButton;
  22. class CCastleBuildings;
  23. class CCreaturePic;
  24. class CGStatusBar;
  25. class CLabel;
  26. class CMinorResDataBar;
  27. class CPicture;
  28. class CResDataBar;
  29. class CTextBox;
  30. class CTownList;
  31. class CGarrisonInt;
  32. class CComponent;
  33. class CComponentBox;
  34. /// Building "button"
  35. class CBuildingRect : public CShowableAnim
  36. {
  37. std::string getSubtitle();
  38. public:
  39. enum EBuildingCreationAnimationPhases : uint32_t
  40. {
  41. BUILDING_APPEAR_TIMEPOINT = 500, //500 msec building appears: 0->100% transparency
  42. BUILDING_WHITE_BORDER_TIMEPOINT = 900, //400 msec border glows from white to yellow
  43. BUILDING_YELLOW_BORDER_TIMEPOINT = 1100, //200 msec border glows from yellow to normal (dark orange)
  44. BUILD_ANIMATION_FINISHED_TIMEPOINT = 2100, // 1000msec once border is back to yellow nothing happens (this stage is basically removed by HD Mod)
  45. BUILDING_FRAME_TIME = 150 // confirmed H3 timing: 150 ms for each building animation frame
  46. };
  47. /// returns building associated with this structure
  48. const CBuilding * getBuilding();
  49. CCastleBuildings * parent;
  50. const CGTownInstance * town;
  51. const CStructure* str;
  52. std::shared_ptr<IImage> border;
  53. std::shared_ptr<IImage> area;
  54. ui32 stateTimeCounter;//For building construction - current stage in animation
  55. CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str);
  56. bool operator<(const CBuildingRect & p2) const;
  57. void hover(bool on) override;
  58. void clickLeft(tribool down, bool previousState) override;
  59. void showPopupWindow() override;
  60. void mouseMoved (const Point & cursorPosition) override;
  61. void tick(uint32_t msPassed) override;
  62. void show(Canvas & to) override;
  63. void showAll(Canvas & to) override;
  64. };
  65. /// Dwelling info box - right-click screen for dwellings
  66. class CDwellingInfoBox : public CWindowObject
  67. {
  68. std::shared_ptr<CLabel> title;
  69. std::shared_ptr<CCreaturePic> animation;
  70. std::shared_ptr<CLabel> available;
  71. std::shared_ptr<CLabel> costPerTroop;
  72. std::vector<std::shared_ptr<CAnimImage>> resPicture;
  73. std::vector<std::shared_ptr<CLabel>> resAmount;
  74. public:
  75. CDwellingInfoBox(int centerX, int centerY, const CGTownInstance * Town, int level);
  76. ~CDwellingInfoBox();
  77. };
  78. class HeroSlots;
  79. /// Hero icon slot
  80. class CHeroGSlot : public CIntObject
  81. {
  82. std::shared_ptr<CAnimImage> portrait;
  83. std::shared_ptr<CAnimImage> flag;
  84. std::shared_ptr<CAnimImage> selection; //selection border. nullptr if not selected
  85. HeroSlots * owner;
  86. const CGHeroInstance * hero;
  87. int upg; //0 - up garrison, 1 - down garrison
  88. public:
  89. CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, HeroSlots * Owner);
  90. ~CHeroGSlot();
  91. bool isSelected() const;
  92. void setHighlight(bool on);
  93. void set(const CGHeroInstance * newHero);
  94. void hover (bool on) override;
  95. void clickLeft(tribool down, bool previousState) override;
  96. void showPopupWindow() override;
  97. void deactivate() override;
  98. };
  99. /// Two hero slots that can interact with each other
  100. class HeroSlots : public CIntObject
  101. {
  102. public:
  103. bool showEmpty;
  104. const CGTownInstance * town;
  105. std::shared_ptr<CGarrisonInt> garr;
  106. std::shared_ptr<CHeroGSlot> garrisonedHero;
  107. std::shared_ptr<CHeroGSlot> visitingHero;
  108. HeroSlots(const CGTownInstance * town, Point garrPos, Point visitPos, std::shared_ptr<CGarrisonInt> Garrison, bool ShowEmpty);
  109. ~HeroSlots();
  110. void splitClicked(); //for hero meeting only (splitting stacks is handled by garrison int)
  111. void update();
  112. void swapArmies(); //exchange garrisoned and visiting heroes or move hero to\from garrison
  113. };
  114. /// Class for town screen management (town background and structures)
  115. class CCastleBuildings : public CIntObject
  116. {
  117. std::shared_ptr<CPicture> background;
  118. //List of buildings and structures that can represent them
  119. std::map<BuildingID, std::vector<const CStructure *> > groups;
  120. // actual IntObject's visible on screen
  121. std::vector<std::shared_ptr<CBuildingRect>> buildings;
  122. const CGTownInstance * town;
  123. const CGHeroInstance* getHero();//Select hero for buildings usage
  124. void enterBlacksmith(ArtifactID artifactID);//support for blacksmith + ballista yard
  125. void enterBuilding(BuildingID building);//for buildings with simple description + pic left-click messages
  126. void enterCastleGate();
  127. void enterFountain(const BuildingID & building, BuildingSubID::EBuildingSubID subID, BuildingID::EBuildingID upgrades);//Rampart's fountains
  128. void enterMagesGuild();
  129. void enterTownHall();
  130. void openMagesGuild();
  131. void openTownHall();
  132. void recreate();
  133. public:
  134. CBuildingRect * selectedBuilding;
  135. CCastleBuildings(const CGTownInstance * town);
  136. ~CCastleBuildings();
  137. void enterDwelling(int level);
  138. void enterToTheQuickRecruitmentWindow();
  139. void buildingClicked(BuildingID building, BuildingSubID::EBuildingSubID subID = BuildingSubID::NONE, BuildingID::EBuildingID upgrades = BuildingID::NONE);
  140. void addBuilding(BuildingID building);
  141. void removeBuilding(BuildingID building);//FIXME: not tested!!!
  142. };
  143. /// Creature info window
  144. class CCreaInfo : public CIntObject
  145. {
  146. const CGTownInstance * town;
  147. const CCreature * creature;
  148. int level;
  149. bool showAvailable;
  150. std::shared_ptr<CAnimImage> picture;
  151. std::shared_ptr<CLabel> label;
  152. std::string genGrowthText();
  153. public:
  154. CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact=false, bool _showAvailable=false);
  155. void update();
  156. void hover(bool on) override;
  157. void clickLeft(tribool down, bool previousState) override;
  158. void showPopupWindow() override;
  159. bool getShowAvailable();
  160. };
  161. /// Town hall and fort icons for town screen
  162. class CTownInfo : public CIntObject
  163. {
  164. const CGTownInstance * town;
  165. const CBuilding * building;
  166. public:
  167. std::shared_ptr<CAnimImage> picture;
  168. //if (townHall) hall-capital else fort - castle
  169. CTownInfo(int posX, int posY, const CGTownInstance * town, bool townHall);
  170. void hover(bool on) override;
  171. void showPopupWindow() override;
  172. };
  173. /// Class which manages the castle window
  174. class CCastleInterface : public CStatusbarWindow, public CGarrisonHolder
  175. {
  176. std::shared_ptr<CLabel> title;
  177. std::shared_ptr<CLabel> income;
  178. std::shared_ptr<CAnimImage> icon;
  179. std::shared_ptr<CPicture> panel;
  180. std::shared_ptr<CResDataBar> resdatabar;
  181. std::shared_ptr<CTownInfo> hall;
  182. std::shared_ptr<CTownInfo> fort;
  183. std::shared_ptr<CButton> exit;
  184. std::shared_ptr<CButton> split;
  185. std::shared_ptr<CButton> fastArmyPurchase;
  186. std::vector<std::shared_ptr<CCreaInfo>> creainfo;//small icons of creatures (bottom-left corner);
  187. public:
  188. std::shared_ptr<CTownList> townlist;
  189. //TODO: move to private
  190. const CGTownInstance * town;
  191. std::shared_ptr<HeroSlots> heroes;
  192. std::shared_ptr<CCastleBuildings> builds;
  193. std::shared_ptr<CGarrisonInt> garr;
  194. //from - previously selected castle (if any)
  195. CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr);
  196. ~CCastleInterface();
  197. virtual void updateGarrisons() override;
  198. void castleTeleport(int where);
  199. void townChange();
  200. void keyPressed(EShortcut key) override;
  201. void close();
  202. void addBuilding(BuildingID bid);
  203. void removeBuilding(BuildingID bid);
  204. void recreateIcons();
  205. void creaturesChangedEventHandler();
  206. };
  207. /// Hall window where you can build things
  208. class CHallInterface : public CStatusbarWindow
  209. {
  210. class CBuildingBox : public CIntObject
  211. {
  212. const CGTownInstance * town;
  213. const CBuilding * building;
  214. ui32 state;//Buildings::EBuildStructure enum
  215. std::shared_ptr<CAnimImage> header;
  216. std::shared_ptr<CAnimImage> icon;
  217. std::shared_ptr<CAnimImage> mark;
  218. std::shared_ptr<CLabel> name;
  219. public:
  220. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  221. void hover(bool on) override;
  222. void clickLeft(tribool down, bool previousState) override;
  223. void showPopupWindow() override;
  224. };
  225. const CGTownInstance * town;
  226. std::vector<std::vector<std::shared_ptr<CBuildingBox>>> boxes;
  227. std::shared_ptr<CLabel> title;
  228. std::shared_ptr<CMinorResDataBar> resdatabar;
  229. std::shared_ptr<CButton> exit;
  230. public:
  231. CHallInterface(const CGTownInstance * Town);
  232. };
  233. /// Window where you can decide to buy a building or not
  234. class CBuildWindow: public CStatusbarWindow
  235. {
  236. const CGTownInstance * town;
  237. const CBuilding * building;
  238. std::shared_ptr<CAnimImage> icon;
  239. std::shared_ptr<CLabel> name;
  240. std::shared_ptr<CTextBox> description;
  241. std::shared_ptr<CTextBox> stateText;
  242. std::shared_ptr<CComponentBox> cost;
  243. std::shared_ptr<CButton> buy;
  244. std::shared_ptr<CButton> cancel;
  245. std::string getTextForState(int state);
  246. void buyFunc();
  247. public:
  248. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick);
  249. };
  250. //Small class to display
  251. class LabeledValue : public CIntObject
  252. {
  253. std::string hoverText;
  254. std::shared_ptr<CLabel> name;
  255. std::shared_ptr<CLabel> value;
  256. void init(std::string name, std::string descr, int min, int max);
  257. public:
  258. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  259. LabeledValue(Rect size, std::string name, std::string descr, int val);
  260. void hover(bool on) override;
  261. };
  262. /// The fort screen where you can afford units
  263. class CFortScreen : public CStatusbarWindow
  264. {
  265. class RecruitArea : public CIntObject
  266. {
  267. const CGTownInstance * town;
  268. int level;
  269. std::string hoverText;
  270. std::shared_ptr<CLabel> availableCount;
  271. std::vector<std::shared_ptr<LabeledValue>> values;
  272. std::shared_ptr<CPicture> icons;
  273. std::shared_ptr<CAnimImage> buildingIcon;
  274. std::shared_ptr<CLabel> buildingName;
  275. const CCreature * getMyCreature();
  276. const CBuilding * getMyBuilding();
  277. public:
  278. RecruitArea(int posX, int posY, const CGTownInstance *town, int level);
  279. void creaturesChangedEventHandler();
  280. void hover(bool on) override;
  281. void clickLeft(tribool down, bool previousState) override;
  282. };
  283. std::shared_ptr<CLabel> title;
  284. std::vector<std::shared_ptr<RecruitArea>> recAreas;
  285. std::shared_ptr<CMinorResDataBar> resdatabar;
  286. std::shared_ptr<CButton> exit;
  287. std::string getBgName(const CGTownInstance * town);
  288. public:
  289. CFortScreen(const CGTownInstance * town);
  290. void creaturesChangedEventHandler();
  291. };
  292. /// The mage guild screen where you can see which spells you have
  293. class CMageGuildScreen : public CStatusbarWindow
  294. {
  295. class Scroll : public CIntObject
  296. {
  297. const CSpell * spell;
  298. std::shared_ptr<CAnimImage> image;
  299. public:
  300. Scroll(Point position, const CSpell *Spell);
  301. void clickLeft(tribool down, bool previousState) override;
  302. void showPopupWindow() override;
  303. void hover(bool on) override;
  304. };
  305. std::shared_ptr<CPicture> window;
  306. std::shared_ptr<CButton> exit;
  307. std::vector<std::shared_ptr<Scroll>> spells;
  308. std::vector<std::shared_ptr<CAnimImage>> emptyScrolls;
  309. std::shared_ptr<CMinorResDataBar> resdatabar;
  310. public:
  311. CMageGuildScreen(CCastleInterface * owner,std::string image);
  312. };
  313. /// The blacksmith window where you can buy available in town war machine
  314. class CBlacksmithDialog : public CStatusbarWindow
  315. {
  316. std::shared_ptr<CButton> buy;
  317. std::shared_ptr<CButton> cancel;
  318. std::shared_ptr<CPicture> animBG;
  319. std::shared_ptr<CCreatureAnim> anim;
  320. std::shared_ptr<CLabel> title;
  321. std::shared_ptr<CAnimImage> costIcon;
  322. std::shared_ptr<CLabel> costText;
  323. std::shared_ptr<CLabel> costValue;
  324. public:
  325. CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid);
  326. };