CCastleInterface.h 9.8 KB

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