CCastleInterface.h 12 KB

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