CCastleInterface.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 CStatusBar;
  16. class CTextBox;
  17. class CTownList;
  18. struct Structure;
  19. class CGHeroInstance;
  20. class CGarrisonInt;
  21. class CCreature;
  22. /*
  23. * CCastleInterface.h, part of VCMI engine
  24. *
  25. * Authors: listed in file AUTHORS in main folder
  26. *
  27. * License: GNU General Public License v2.0 or later
  28. * Full text of license available in license.txt file, in main folder
  29. *
  30. */
  31. /// Building "button"
  32. class CBuildingRect : public CShowableAnim
  33. {
  34. public:
  35. CCastleBuildings * parent;
  36. const CGTownInstance * town;
  37. const Structure* str;
  38. SDL_Surface* border;
  39. SDL_Surface* area;
  40. ui32 stateCounter;//For building construction - current stage in animation
  41. CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const Structure *Str); //c-tor
  42. ~CBuildingRect(); //d-tor
  43. bool operator<(const CBuildingRect & p2) const;
  44. void hover(bool on);
  45. void clickLeft(tribool down, bool previousState);
  46. void clickRight(tribool down, bool previousState);
  47. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  48. void show(SDL_Surface * to);
  49. void showAll(SDL_Surface * to);
  50. };
  51. /// Dwelling info box - right-click screen for dwellings
  52. class CDwellingInfoBox : public CWindowObject
  53. {
  54. CLabel *title;
  55. CCreaturePic *animation;
  56. CLabel *available;
  57. CLabel *costPerTroop;
  58. std::vector<CAnimImage *> resPicture;
  59. std::vector<CLabel *> resAmount;
  60. public:
  61. CDwellingInfoBox(int centerX, int centerY, const CGTownInstance *Town, int level);
  62. };
  63. class HeroSlots;
  64. /// Hero icon slot
  65. class CHeroGSlot : public CIntObject
  66. {
  67. public:
  68. HeroSlots *owner;
  69. const CGHeroInstance *hero;
  70. int upg; //0 - up garrison, 1 - down garrison
  71. CAnimImage *image;
  72. CAnimImage *selection; //selection border. NULL if not selected
  73. void setHighlight(bool on);
  74. void set(const CGHeroInstance *newHero);
  75. void hover (bool on);
  76. void clickLeft(tribool down, bool previousState);
  77. void deactivate();
  78. CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, HeroSlots * Owner); //c-tor
  79. ~CHeroGSlot(); //d-tor
  80. };
  81. /// Two hero slots that can interact with each other
  82. class HeroSlots : public CIntObject
  83. {
  84. public:
  85. bool showEmpty;
  86. const CGTownInstance * town;
  87. CGarrisonInt *garr;
  88. CHeroGSlot * garrisonedHero;
  89. CHeroGSlot * visitingHero;
  90. HeroSlots(const CGTownInstance * town, Point garrPos, Point visitPos, CGarrisonInt *Garrison, bool ShowEmpty);
  91. void splitClicked(); //for hero meeting only (splitting stacks is handled by garrison int)
  92. void update();
  93. };
  94. /// Class for town screen management (town background and structures)
  95. class CCastleBuildings : public CIntObject
  96. {
  97. CPicture *background;
  98. //List of buildings for each group
  99. std::map< int, std::vector<const Structure*> > groups;
  100. //Vector with all blittable buildings
  101. std::vector<CBuildingRect*> buildings;
  102. const CGTownInstance * town;
  103. const CGHeroInstance* getHero();//Select hero for buildings usage
  104. void checkRules();//Check animation rules (special anims for Shipyard and Mana Vortex)
  105. void enterBlacksmith(int ArtifactID);//support for blacksmith + ballista yard
  106. void enterBuilding(int building);//for buildings with simple description + pic left-click messages
  107. void enterCastleGate();
  108. void enterFountain(int building);//Rampart's fountains
  109. void enterMagesGuild();
  110. void enterTownHall();
  111. void openMagesGuild();
  112. void openTownHall();
  113. public:
  114. CBuildingRect * selectedBuilding;
  115. CCastleBuildings(const CGTownInstance* town);
  116. ~CCastleBuildings();
  117. void enterDwelling(int level);
  118. void buildingClicked(int building);
  119. void addBuilding(int building);
  120. void removeBuilding(int 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. CTownList * townlist;
  165. CAdventureMapButton *exit;
  166. CAdventureMapButton *split;
  167. std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
  168. public:
  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. 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. int state; //state - same as CHallInterface::CBuildingBox::state
  219. CAnimImage *buildingPic;
  220. CAdventureMapButton *buy;
  221. CAdventureMapButton *cancel;
  222. CLabel * title;
  223. CTextBox * buildingDescr;
  224. CTextBox * buildingState;
  225. CGStatusBar *statusBar;
  226. std::vector<CAnimImage *> resPicture;
  227. std::vector<CLabel *> resAmount;
  228. std::string getTextForState(int state);
  229. void buyFunc();
  230. public:
  231. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool rightClick); //c-tor
  232. };
  233. //Small class to display
  234. class LabeledValue : public CIntObject
  235. {
  236. std::string hoverText;
  237. CLabel *name;
  238. CLabel *value;
  239. void init(std::string name, std::string descr, int min, int max);
  240. public:
  241. LabeledValue(Rect size, std::string name, std::string descr, int min, int max);
  242. LabeledValue(Rect size, std::string name, std::string descr, int val);
  243. void hover(bool on);
  244. };
  245. /// The fort screen where you can afford units
  246. class CFortScreen : public CWindowObject
  247. {
  248. class RecruitArea : public CIntObject
  249. {
  250. const CGTownInstance *town;
  251. int level;
  252. std::string hoverText;
  253. CLabel * creatureName;
  254. CLabel * dwellingName;
  255. CLabel * availableCount;
  256. std::vector<LabeledValue*> values;
  257. CPicture *icons;
  258. CAnimImage * buildingPic;
  259. CCreaturePic *creatureAnim;
  260. public:
  261. RecruitArea(int posX, int posY, const CGTownInstance *town, int buildingID, int level);
  262. void creaturesChanged();
  263. void hover(bool on);
  264. void clickLeft(tribool down, bool previousState);
  265. void clickRight(tribool down, bool previousState);
  266. };
  267. CLabel *title;
  268. std::vector<RecruitArea*> recAreas;
  269. CMinorResDataBar * resdatabar;
  270. CGStatusBar *statusBar;
  271. CAdventureMapButton *exit;
  272. std::string getBgName(const CGTownInstance *town);
  273. public:
  274. CFortScreen(const CGTownInstance * town); //c-tor
  275. void creaturesChanged();
  276. };
  277. /// The mage guild screen where you can see which spells you have
  278. class CMageGuildScreen : public CWindowObject
  279. {
  280. class Scroll : public CIntObject
  281. {
  282. const CSpell *spell;
  283. CAnimImage *image;
  284. public:
  285. Scroll(Point position, const CSpell *Spell);
  286. void clickLeft(tribool down, bool previousState);
  287. void clickRight(tribool down, bool previousState);
  288. void hover(bool on);
  289. };
  290. CPicture *window;
  291. CAdventureMapButton *exit;
  292. std::vector<Scroll *> spells;
  293. CMinorResDataBar * resdatabar;
  294. CGStatusBar *statusBar;
  295. public:
  296. CMageGuildScreen(CCastleInterface * owner);
  297. };
  298. /// The blacksmith window where you can buy available in town war machine
  299. class CBlacksmithDialog : public CWindowObject
  300. {
  301. CAdventureMapButton *buy, *cancel;
  302. CPicture *animBG;
  303. CCreatureAnim * anim;
  304. CLabel * title;
  305. CLabel * costText;
  306. CLabel * costValue;
  307. CGStatusBar *statusBar;
  308. public:
  309. CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid);
  310. };