CCastleInterface.h 12 KB

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