CCastleInterface.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. #pragma once
  2. #include "CAnimation.h"
  3. #include "GUIClasses.h"
  4. class CAdventureMapButton;
  5. class CBuilding;
  6. class CCastleBuildings;
  7. class CCreaturePic;
  8. class CGStatusBar;
  9. class CGTownInstance;
  10. class CLabel;
  11. class CMinorResDataBar;
  12. class CPicture;
  13. class CResDataBar;
  14. class CSpell;
  15. class CTextBox;
  16. class CTownList;
  17. struct Structure;
  18. class CGHeroInstance;
  19. class CGarrisonInt;
  20. class CCreature;
  21. /*
  22. * CCastleInterface.h, part of VCMI engine
  23. *
  24. * Authors: listed in file AUTHORS in main folder
  25. *
  26. * License: GNU General Public License v2.0 or later
  27. * Full text of license available in license.txt file, in main folder
  28. *
  29. */
  30. /// Building "button"
  31. class CBuildingRect : public CShowableAnim
  32. {
  33. public:
  34. CCastleBuildings * parent;
  35. const CGTownInstance * town;
  36. const Structure* str;
  37. SDL_Surface* border;
  38. SDL_Surface* area;
  39. ui32 stateCounter;//For building construction - current stage in animation
  40. CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const Structure *Str); //c-tor
  41. ~CBuildingRect(); //d-tor
  42. bool operator<(const CBuildingRect & p2) const;
  43. void hover(bool on);
  44. void clickLeft(tribool down, bool previousState);
  45. void clickRight(tribool down, bool previousState);
  46. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  47. void show(SDL_Surface * to);
  48. void showAll(SDL_Surface * to);
  49. };
  50. /// Dwelling info box - right-click screen for dwellings
  51. class CDwellingInfoBox : public CWindowObject
  52. {
  53. CLabel *title;
  54. CCreaturePic *animation;
  55. CLabel *available;
  56. CLabel *costPerTroop;
  57. std::vector<CAnimImage *> resPicture;
  58. std::vector<CLabel *> resAmount;
  59. public:
  60. CDwellingInfoBox(int centerX, int centerY, const CGTownInstance *Town, int level);
  61. };
  62. class HeroSlots;
  63. /// Hero icon slot
  64. class CHeroGSlot : public CIntObject
  65. {
  66. public:
  67. HeroSlots *owner;
  68. const CGHeroInstance *hero;
  69. int upg; //0 - up garrison, 1 - down garrison
  70. CAnimImage *image;
  71. CAnimImage *selection; //selection border. NULL if not selected
  72. void setHighlight(bool on);
  73. void set(const CGHeroInstance *newHero);
  74. void hover (bool on);
  75. void clickLeft(tribool down, bool previousState);
  76. void deactivate();
  77. CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, HeroSlots * Owner); //c-tor
  78. ~CHeroGSlot(); //d-tor
  79. };
  80. /// Two hero slots that can interact with each other
  81. class HeroSlots : public CIntObject
  82. {
  83. public:
  84. bool showEmpty;
  85. const CGTownInstance * town;
  86. CGarrisonInt *garr;
  87. CHeroGSlot * garrisonedHero;
  88. CHeroGSlot * visitingHero;
  89. HeroSlots(const CGTownInstance * town, Point garrPos, Point visitPos, CGarrisonInt *Garrison, bool ShowEmpty);
  90. void splitClicked(); //for hero meeting only (splitting stacks is handled by garrison int)
  91. void update();
  92. };
  93. /// Class for town screen management (town background and structures)
  94. class CCastleBuildings : public CIntObject
  95. {
  96. CPicture *background;
  97. //List of buildings for each group
  98. std::map< int, std::vector<const Structure*> > groups;
  99. //Vector with all blittable buildings
  100. std::vector<CBuildingRect*> buildings;
  101. const CGTownInstance * town;
  102. const CGHeroInstance* getHero();//Select hero for buildings usage
  103. void checkRules();//Check animation rules (special anims for Shipyard and Mana Vortex)
  104. void enterBlacksmith(int ArtifactID);//support for blacksmith + ballista yard
  105. void enterBuilding(int building);//for buildings with simple description + pic left-click messages
  106. void enterCastleGate();
  107. void enterFountain(int building);//Rampart's fountains
  108. void enterMagesGuild();
  109. void enterTownHall();
  110. void openMagesGuild();
  111. void openTownHall();
  112. public:
  113. CBuildingRect * selectedBuilding;
  114. CCastleBuildings(const CGTownInstance* town);
  115. ~CCastleBuildings();
  116. void enterDwelling(int level);
  117. void buildingClicked(int building);
  118. void addBuilding(int building);
  119. void removeBuilding(int building);//FIXME: not tested!!!
  120. void show(SDL_Surface * to);
  121. void showAll(SDL_Surface * to);
  122. };
  123. /// Creature info window
  124. class CCreaInfo : public CIntObject
  125. {
  126. const CGTownInstance * town;
  127. const CCreature *creature;
  128. int level;
  129. bool showAvailable;
  130. CAnimImage *picture;
  131. CLabel * label;
  132. int AddToString(std::string from, std::string & to, int numb);
  133. std::string genGrowthText();
  134. public:
  135. CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool compact=false, bool showAvailable=false);
  136. void update();
  137. void hover(bool on);
  138. void clickLeft(tribool down, bool previousState);
  139. void clickRight(tribool down, bool previousState);
  140. };
  141. /// Town hall and fort icons for town screen
  142. class CTownInfo : public CIntObject
  143. {
  144. const CGTownInstance *town;
  145. const CBuilding *building;
  146. CAnimImage *picture;
  147. public:
  148. //if (townHall) hall-capital else fort - castle
  149. CTownInfo(int posX, int posY, const CGTownInstance* town, bool townHall);
  150. void hover(bool on);
  151. void clickRight(tribool down, bool previousState);
  152. };
  153. /// Class which manages the castle window
  154. class CCastleInterface : public CWindowObject, public CWindowWithGarrison
  155. {
  156. CLabel *title;
  157. CLabel *income;
  158. CAnimImage *icon;
  159. CPicture * panel;
  160. CResDataBar *resdatabar;
  161. CGStatusBar * statusbar;
  162. CTownInfo *hall, *fort;
  163. CAdventureMapButton *exit;
  164. CAdventureMapButton *split;
  165. std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
  166. public:
  167. CTownList * townlist;
  168. //TODO: remove - currently used only in dialog messages
  169. CDefEssential* bicons; //150x70 buildings imgs
  170. //TODO: move to private
  171. const CGTownInstance * town;
  172. HeroSlots *heroes;
  173. CCastleBuildings *builds;
  174. //from - previously selected castle (if any)
  175. CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr); //c-tor
  176. ~CCastleInterface();
  177. void castleTeleport(int where);
  178. void townChange();
  179. void keyPressed(const SDL_KeyboardEvent & key);
  180. void close();
  181. void addBuilding(int bid);
  182. void removeBuilding(int bid);
  183. void recreateIcons();
  184. };
  185. /// Hall window where you can build things
  186. class CHallInterface : public CWindowObject
  187. {
  188. /// Building box from town hall (building icon + subtitle)
  189. class CBuildingBox : public CIntObject
  190. {
  191. const CGTownInstance * town;
  192. const CBuilding * building;
  193. ui32 state;//Buildings::EBuildStructure enum
  194. CAnimImage * picture;
  195. CAnimImage * panel;
  196. CAnimImage * icon;
  197. CLabel * label;
  198. public:
  199. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  200. void hover(bool on);
  201. void clickLeft(tribool down, bool previousState);
  202. void clickRight(tribool down, bool previousState);
  203. };
  204. const CGTownInstance * town;
  205. std::vector< std::vector<CBuildingBox*> >boxes;
  206. CLabel *title;
  207. CGStatusBar *statusBar;
  208. CMinorResDataBar * resdatabar;
  209. CAdventureMapButton *exit;
  210. public:
  211. CHallInterface(const CGTownInstance * Town); //c-tor
  212. };
  213. /// Window where you can decide to buy a building or not
  214. class CBuildWindow: public CWindowObject
  215. {
  216. const CGTownInstance *town;
  217. const CBuilding *building;
  218. CAdventureMapButton *buy;
  219. CAdventureMapButton *cancel;
  220. std::string getTextForState(int state);
  221. void buyFunc();
  222. public:
  223. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick); //c-tor
  224. };
  225. //Small class to display
  226. class LabeledValue : public CIntObject
  227. {
  228. std::string hoverText;
  229. CLabel *name;
  230. CLabel *value;
  231. void init(std::string name, std::string descr, int min, int max);
  232. public:
  233. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  234. LabeledValue(Rect size, std::string name, std::string descr, int val);
  235. void hover(bool on);
  236. };
  237. /// The fort screen where you can afford units
  238. class CFortScreen : public CWindowObject
  239. {
  240. class RecruitArea : public CIntObject
  241. {
  242. const CGTownInstance *town;
  243. int level;
  244. std::string hoverText;
  245. CLabel * creatureName;
  246. CLabel * dwellingName;
  247. CLabel * availableCount;
  248. std::vector<LabeledValue*> values;
  249. CPicture *icons;
  250. CAnimImage * buildingPic;
  251. CCreaturePic *creatureAnim;
  252. public:
  253. RecruitArea(int posX, int posY, const CGTownInstance *town, int buildingID, int level);
  254. void creaturesChanged();
  255. void hover(bool on);
  256. void clickLeft(tribool down, bool previousState);
  257. void clickRight(tribool down, bool previousState);
  258. };
  259. CLabel *title;
  260. std::vector<RecruitArea*> recAreas;
  261. CMinorResDataBar * resdatabar;
  262. CGStatusBar *statusBar;
  263. CAdventureMapButton *exit;
  264. std::string getBgName(const CGTownInstance *town);
  265. public:
  266. CFortScreen(const CGTownInstance * town); //c-tor
  267. void creaturesChanged();
  268. };
  269. /// The mage guild screen where you can see which spells you have
  270. class CMageGuildScreen : public CWindowObject
  271. {
  272. class Scroll : public CIntObject
  273. {
  274. const CSpell *spell;
  275. CAnimImage *image;
  276. public:
  277. Scroll(Point position, const CSpell *Spell);
  278. void clickLeft(tribool down, bool previousState);
  279. void clickRight(tribool down, bool previousState);
  280. void hover(bool on);
  281. };
  282. CPicture *window;
  283. CAdventureMapButton *exit;
  284. std::vector<Scroll *> spells;
  285. CMinorResDataBar * resdatabar;
  286. CGStatusBar *statusBar;
  287. public:
  288. CMageGuildScreen(CCastleInterface * owner);
  289. };
  290. /// The blacksmith window where you can buy available in town war machine
  291. class CBlacksmithDialog : public CWindowObject
  292. {
  293. CAdventureMapButton *buy, *cancel;
  294. CPicture *animBG;
  295. CCreatureAnim * anim;
  296. CLabel * title;
  297. CLabel * costText;
  298. CLabel * costValue;
  299. CGStatusBar *statusBar;
  300. public:
  301. CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid);
  302. };