CCastleInterface.h 12 KB

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