CCastleInterface.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. CTownList * townlist;
  164. CAdventureMapButton *exit;
  165. CAdventureMapButton *split;
  166. std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
  167. public:
  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. CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from = nullptr); //c-tor
  175. ~CCastleInterface();
  176. void castleTeleport(int where);
  177. void townChange();
  178. void keyPressed(const SDL_KeyboardEvent & key);
  179. void close();
  180. void addBuilding(int bid);
  181. void removeBuilding(int bid);
  182. void recreateIcons();
  183. };
  184. /// Hall window where you can build things
  185. class CHallInterface : public CWindowObject
  186. {
  187. /// Building box from town hall (building icon + subtitle)
  188. class CBuildingBox : public CIntObject
  189. {
  190. const CGTownInstance * town;
  191. const CBuilding * building;
  192. ui32 state;//Buildings::EBuildStructure enum
  193. CAnimImage * picture;
  194. CAnimImage * panel;
  195. CAnimImage * icon;
  196. CLabel * label;
  197. public:
  198. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  199. void hover(bool on);
  200. void clickLeft(tribool down, bool previousState);
  201. void clickRight(tribool down, bool previousState);
  202. };
  203. const CGTownInstance * town;
  204. std::vector< std::vector<CBuildingBox*> >boxes;
  205. CLabel *title;
  206. CGStatusBar *statusBar;
  207. CMinorResDataBar * resdatabar;
  208. CAdventureMapButton *exit;
  209. public:
  210. CHallInterface(const CGTownInstance * Town); //c-tor
  211. };
  212. /// Window where you can decide to buy a building or not
  213. class CBuildWindow: public CWindowObject
  214. {
  215. const CGTownInstance *town;
  216. const CBuilding *building;
  217. int state; //state - same as CHallInterface::CBuildingBox::state
  218. CAnimImage *buildingPic;
  219. CAdventureMapButton *buy;
  220. CAdventureMapButton *cancel;
  221. CLabel * title;
  222. CTextBox * buildingDescr;
  223. CTextBox * buildingState;
  224. CGStatusBar *statusBar;
  225. std::vector<CAnimImage *> resPicture;
  226. std::vector<CLabel *> resAmount;
  227. std::string getTextForState(int state);
  228. void buyFunc();
  229. public:
  230. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick); //c-tor
  231. };
  232. //Small class to display
  233. class LabeledValue : public CIntObject
  234. {
  235. std::string hoverText;
  236. CLabel *name;
  237. CLabel *value;
  238. void init(std::string name, std::string descr, int min, int max);
  239. public:
  240. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  241. LabeledValue(Rect size, std::string name, std::string descr, int val);
  242. void hover(bool on);
  243. };
  244. /// The fort screen where you can afford units
  245. class CFortScreen : public CWindowObject
  246. {
  247. class RecruitArea : public CIntObject
  248. {
  249. const CGTownInstance *town;
  250. int level;
  251. std::string hoverText;
  252. CLabel * creatureName;
  253. CLabel * dwellingName;
  254. CLabel * availableCount;
  255. std::vector<LabeledValue*> values;
  256. CPicture *icons;
  257. CAnimImage * buildingPic;
  258. CCreaturePic *creatureAnim;
  259. public:
  260. RecruitArea(int posX, int posY, const CGTownInstance *town, int buildingID, int level);
  261. void creaturesChanged();
  262. void hover(bool on);
  263. void clickLeft(tribool down, bool previousState);
  264. void clickRight(tribool down, bool previousState);
  265. };
  266. CLabel *title;
  267. std::vector<RecruitArea*> recAreas;
  268. CMinorResDataBar * resdatabar;
  269. CGStatusBar *statusBar;
  270. CAdventureMapButton *exit;
  271. std::string getBgName(const CGTownInstance *town);
  272. public:
  273. CFortScreen(const CGTownInstance * town); //c-tor
  274. void creaturesChanged();
  275. };
  276. /// The mage guild screen where you can see which spells you have
  277. class CMageGuildScreen : public CWindowObject
  278. {
  279. class Scroll : public CIntObject
  280. {
  281. const CSpell *spell;
  282. CAnimImage *image;
  283. public:
  284. Scroll(Point position, const CSpell *Spell);
  285. void clickLeft(tribool down, bool previousState);
  286. void clickRight(tribool down, bool previousState);
  287. void hover(bool on);
  288. };
  289. CPicture *window;
  290. CAdventureMapButton *exit;
  291. std::vector<Scroll *> spells;
  292. CMinorResDataBar * resdatabar;
  293. CGStatusBar *statusBar;
  294. public:
  295. CMageGuildScreen(CCastleInterface * owner);
  296. };
  297. /// The blacksmith window where you can buy available in town war machine
  298. class CBlacksmithDialog : public CWindowObject
  299. {
  300. CAdventureMapButton *buy, *cancel;
  301. CPicture *animBG;
  302. CCreatureAnim * anim;
  303. CLabel * title;
  304. CLabel * costText;
  305. CLabel * costValue;
  306. CGStatusBar *statusBar;
  307. public:
  308. CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid);
  309. };