CCastleInterface.h 12 KB

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