CCastleInterface.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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 CStructure;
  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 CStructure* 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 CStructure *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. void swapArmies(); //exchange garrisoned and visiting heroes or move hero to\from garrison
  93. };
  94. /// Class for town screen management (town background and structures)
  95. class CCastleBuildings : public CIntObject
  96. {
  97. CPicture *background;
  98. //List of buildings and structures that can represent them
  99. std::map< BuildingID, std::vector<const CStructure*> > groups;
  100. // actual IntObject's visible on screen
  101. std::vector< CBuildingRect * > buildings;
  102. const CGTownInstance * town;
  103. const CGHeroInstance* getHero();//Select hero for buildings usage
  104. void enterBlacksmith(ArtifactID artifactID);//support for blacksmith + ballista yard
  105. void enterBuilding(BuildingID building);//for buildings with simple description + pic left-click messages
  106. void enterCastleGate();
  107. void enterFountain(BuildingID building);//Rampart's fountains
  108. void enterMagesGuild();
  109. void enterTownHall();
  110. void openMagesGuild();
  111. void openTownHall();
  112. void recreate();
  113. public:
  114. CBuildingRect * selectedBuilding;
  115. CCastleBuildings(const CGTownInstance* town);
  116. ~CCastleBuildings();
  117. void enterDwelling(int level);
  118. void buildingClicked(BuildingID building);
  119. void addBuilding(BuildingID building);
  120. void removeBuilding(BuildingID building);//FIXME: not tested!!!
  121. void show(SDL_Surface * to);
  122. void showAll(SDL_Surface * to);
  123. };
  124. /// Creature info window
  125. class CCreaInfo : public CIntObject
  126. {
  127. const CGTownInstance * town;
  128. const CCreature *creature;
  129. int level;
  130. bool showAvailable;
  131. CAnimImage *picture;
  132. CLabel * label;
  133. int AddToString(std::string from, std::string & to, int numb);
  134. std::string genGrowthText();
  135. public:
  136. CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool compact=false, bool showAvailable=false);
  137. void update();
  138. void hover(bool on);
  139. void clickLeft(tribool down, bool previousState);
  140. void clickRight(tribool down, bool previousState);
  141. };
  142. /// Town hall and fort icons for town screen
  143. class CTownInfo : public CIntObject
  144. {
  145. const CGTownInstance *town;
  146. const CBuilding *building;
  147. CAnimImage *picture;
  148. public:
  149. //if (townHall) hall-capital else fort - castle
  150. CTownInfo(int posX, int posY, const CGTownInstance* town, bool townHall);
  151. void hover(bool on);
  152. void clickRight(tribool down, bool previousState);
  153. };
  154. /// Class which manages the castle window
  155. class CCastleInterface : public CWindowObject, public CWindowWithGarrison
  156. {
  157. CLabel *title;
  158. CLabel *income;
  159. CAnimImage *icon;
  160. CPicture * panel;
  161. CResDataBar *resdatabar;
  162. CGStatusBar * statusbar;
  163. CTownInfo *hall, *fort;
  164. CAdventureMapButton *exit;
  165. CAdventureMapButton *split;
  166. std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
  167. public:
  168. CTownList * townlist;
  169. //TODO: remove - currently used only in dialog messages
  170. CDefEssential* bicons; //150x70 buildings imgs
  171. //TODO: move to private
  172. const CGTownInstance * town;
  173. HeroSlots *heroes;
  174. CCastleBuildings *builds;
  175. //from - previously selected castle (if any)
  176. CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr); //c-tor
  177. ~CCastleInterface();
  178. void castleTeleport(int where);
  179. void townChange();
  180. void keyPressed(const SDL_KeyboardEvent & key);
  181. void close();
  182. void addBuilding(BuildingID bid);
  183. void removeBuilding(BuildingID bid);
  184. void recreateIcons();
  185. };
  186. /// Hall window where you can build things
  187. class CHallInterface : public CWindowObject
  188. {
  189. /// Building box from town hall (building icon + subtitle)
  190. class CBuildingBox : public CIntObject
  191. {
  192. const CGTownInstance * town;
  193. const CBuilding * building;
  194. ui32 state;//Buildings::EBuildStructure enum
  195. CAnimImage * picture;
  196. CAnimImage * panel;
  197. CAnimImage * icon;
  198. CLabel * label;
  199. public:
  200. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  201. void hover(bool on);
  202. void clickLeft(tribool down, bool previousState);
  203. void clickRight(tribool down, bool previousState);
  204. };
  205. const CGTownInstance * town;
  206. std::vector< std::vector<CBuildingBox*> >boxes;
  207. CLabel *title;
  208. CGStatusBar *statusBar;
  209. CMinorResDataBar * resdatabar;
  210. CAdventureMapButton *exit;
  211. public:
  212. CHallInterface(const CGTownInstance * Town); //c-tor
  213. };
  214. /// Window where you can decide to buy a building or not
  215. class CBuildWindow: public CWindowObject
  216. {
  217. const CGTownInstance *town;
  218. const CBuilding *building;
  219. CAdventureMapButton *buy;
  220. CAdventureMapButton *cancel;
  221. std::string getTextForState(int state);
  222. void buyFunc();
  223. public:
  224. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick); //c-tor
  225. };
  226. //Small class to display
  227. class LabeledValue : public CIntObject
  228. {
  229. std::string hoverText;
  230. CLabel *name;
  231. CLabel *value;
  232. void init(std::string name, std::string descr, int min, int max);
  233. public:
  234. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  235. LabeledValue(Rect size, std::string name, std::string descr, int val);
  236. void hover(bool on);
  237. };
  238. /// The fort screen where you can afford units
  239. class CFortScreen : public CWindowObject
  240. {
  241. class RecruitArea : public CIntObject
  242. {
  243. const CGTownInstance *town;
  244. int level;
  245. std::string hoverText;
  246. CLabel * creatureName;
  247. CLabel * dwellingName;
  248. CLabel * availableCount;
  249. std::vector<LabeledValue*> values;
  250. CPicture *icons;
  251. CAnimImage * buildingPic;
  252. CCreaturePic *creatureAnim;
  253. public:
  254. RecruitArea(int posX, int posY, const CGTownInstance *town, BuildingID buildingID, int level);
  255. void creaturesChanged();
  256. void hover(bool on);
  257. void clickLeft(tribool down, bool previousState);
  258. void clickRight(tribool down, bool previousState);
  259. };
  260. CLabel *title;
  261. std::vector<RecruitArea*> recAreas;
  262. CMinorResDataBar * resdatabar;
  263. CGStatusBar *statusBar;
  264. CAdventureMapButton *exit;
  265. std::string getBgName(const CGTownInstance *town);
  266. public:
  267. CFortScreen(const CGTownInstance * town); //c-tor
  268. void creaturesChanged();
  269. };
  270. /// The mage guild screen where you can see which spells you have
  271. class CMageGuildScreen : public CWindowObject
  272. {
  273. class Scroll : public CIntObject
  274. {
  275. const CSpell *spell;
  276. CAnimImage *image;
  277. public:
  278. Scroll(Point position, const CSpell *Spell);
  279. void clickLeft(tribool down, bool previousState);
  280. void clickRight(tribool down, bool previousState);
  281. void hover(bool on);
  282. };
  283. CPicture *window;
  284. CAdventureMapButton *exit;
  285. std::vector<Scroll *> spells;
  286. CMinorResDataBar * resdatabar;
  287. CGStatusBar *statusBar;
  288. public:
  289. CMageGuildScreen(CCastleInterface * owner);
  290. };
  291. /// The blacksmith window where you can buy available in town war machine
  292. class CBlacksmithDialog : public CWindowObject
  293. {
  294. CAdventureMapButton *buy, *cancel;
  295. CPicture *animBG;
  296. CCreatureAnim * anim;
  297. CLabel * title;
  298. CLabel * costText;
  299. CLabel * costValue;
  300. CGStatusBar *statusBar;
  301. public:
  302. CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid);
  303. };