CCastleInterface.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. #pragma once
  2. #include "CAnimation.h"
  3. #include "GUIClasses.h"
  4. class AdventureMapButton;
  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 CIntObject
  53. {
  54. CPicture *background;
  55. CLabel *title;
  56. CCreaturePic *animation;
  57. CLabel *available;
  58. CLabel *costPerTroop;
  59. std::vector<CPicture *> resPicture;
  60. std::vector<CLabel *> resAmount;
  61. public:
  62. CDwellingInfoBox(int centerX, int centerY, const CGTownInstance *Town, int level);
  63. void clickRight(tribool down, bool previousState);
  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. bool highlight; //indicates id the slot is highlighted
  74. void setHighlight(bool on);
  75. void hover (bool on);
  76. void clickLeft(tribool down, bool previousState);
  77. void deactivate();
  78. void showAll(SDL_Surface * to);
  79. CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, HeroSlots * Owner); //c-tor
  80. ~CHeroGSlot(); //d-tor
  81. };
  82. /// Two hero slots that can interact with each other
  83. class HeroSlots : public CIntObject
  84. {
  85. public:
  86. bool showEmpty;
  87. const CGTownInstance * town;
  88. CGarrisonInt *garr;
  89. CHeroGSlot * garrisonedHero;
  90. CHeroGSlot * visitingHero;
  91. HeroSlots(const CGTownInstance * town, SPoint garrPos, SPoint visitPos, CGarrisonInt *Garrison, bool ShowEmpty);
  92. void splitClicked(); //for hero meeting only (splitting stacks is handled by garrison int)
  93. void update();
  94. };
  95. /// Class for town screen management (town background and structures)
  96. class CCastleBuildings : public CIntObject
  97. {
  98. CPicture *background;
  99. //List of buildings for each group
  100. std::map< int, std::vector<const Structure*> > groups;
  101. //Vector with all blittable buildings
  102. std::vector<CBuildingRect*> buildings;
  103. const CGTownInstance * town;
  104. const CGHeroInstance* getHero();//Select hero for buildings usage
  105. void checkRules();//Check animation rules (special anims for Shipyard and Mana Vortex)
  106. void enterBlacksmith(int ArtifactID);//support for blacksmith + ballista yard
  107. void enterBuilding(int building);//for buildings with simple description + pic left-click messages
  108. void enterCastleGate();
  109. void enterFountain(int building);//Rampart's fountains
  110. void enterMagesGuild();
  111. void enterTownHall();
  112. void openMagesGuild();
  113. void openTownHall();
  114. public:
  115. CBuildingRect * selectedBuilding;
  116. CCastleBuildings(const CGTownInstance* town);
  117. ~CCastleBuildings();
  118. void enterDwelling(int level);
  119. void buildingClicked(int building);
  120. void addBuilding(int building);
  121. void removeBuilding(int building);//FIXME: not tested!!!
  122. void show(SDL_Surface *to);
  123. void showAll(SDL_Surface *to);
  124. };
  125. /// Creature info window
  126. class CCreaInfo : public CIntObject
  127. {
  128. const CGTownInstance * town;
  129. const CCreature *creature;
  130. int level;
  131. bool showAvailable;
  132. CAnimImage *picture;
  133. CLabel * label;
  134. int AddToString(std::string from, std::string & to, int numb);
  135. std::string genGrowthText();
  136. public:
  137. CCreaInfo(SPoint position, const CGTownInstance *Town, int Level, bool compact=false, bool showAvailable=false);
  138. void update();
  139. void hover(bool on);
  140. void clickLeft(tribool down, bool previousState);
  141. void clickRight(tribool down, bool previousState);
  142. };
  143. /// Town hall and fort icons for town screen
  144. class CTownInfo : public CIntObject
  145. {
  146. const CGTownInstance *town;
  147. const CBuilding *building;
  148. CAnimImage *picture;
  149. public:
  150. //if (townHall) hall-capital else fort - castle
  151. CTownInfo(int posX, int posY, const CGTownInstance* town, bool townHall);
  152. void hover(bool on);
  153. void clickRight(tribool down, bool previousState);
  154. };
  155. /// Class which manages the castle window
  156. class CCastleInterface : public CWindowWithGarrison
  157. {
  158. CLabel *title;
  159. CLabel *income;
  160. CAnimImage *icon;
  161. CPicture * panel;
  162. CResDataBar *resdatabar;
  163. CGStatusBar * statusbar;
  164. CTownInfo *hall, *fort;
  165. CTownList * townlist;
  166. AdventureMapButton *exit;
  167. AdventureMapButton *split;
  168. std::vector<CCreaInfo*> creainfo;//small icons of creatures (bottom-left corner);
  169. public:
  170. //TODO: remove - currently used only in dialog messages
  171. CDefEssential* bicons; //150x70 buildings imgs
  172. //TODO: move to private
  173. const CGTownInstance * town;
  174. HeroSlots *heroes;
  175. CCastleBuildings *builds;
  176. CCastleInterface(const CGTownInstance * Town, int listPos = 1); //c-tor
  177. ~CCastleInterface();
  178. void castleTeleport(int where);
  179. void townChange();
  180. void keyPressed(const SDL_KeyboardEvent & key);
  181. void showAll(SDL_Surface *to);
  182. void close();
  183. void addBuilding(int bid);
  184. void removeBuilding(int bid);
  185. void recreateIcons();
  186. };
  187. /// Hall window where you can build things
  188. class CHallInterface : public CIntObject
  189. {
  190. /// Building box from town hall (building icon + subtitle)
  191. class CBuildingBox : public CIntObject
  192. {
  193. const CGTownInstance * town;
  194. const CBuilding * building;
  195. ui32 state;//Buildings::EBuildStructure enum
  196. CAnimImage * picture;
  197. CAnimImage * panel;
  198. CAnimImage * icon;
  199. CLabel * label;
  200. public:
  201. CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building);
  202. void hover(bool on);
  203. void clickLeft(tribool down, bool previousState);
  204. void clickRight(tribool down, bool previousState);
  205. };
  206. const CGTownInstance * town;
  207. std::vector< std::vector<CBuildingBox*> >boxes;
  208. CPicture *background;
  209. CLabel *title;
  210. CGStatusBar *statusBar;
  211. CMinorResDataBar * resdatabar;
  212. AdventureMapButton *exit;
  213. public:
  214. CHallInterface(const CGTownInstance * Town); //c-tor
  215. void close();
  216. };
  217. /// Window where you can decide to buy a building or not
  218. class CBuildWindow: public CIntObject
  219. {
  220. const CGTownInstance *town;
  221. const CBuilding *building;
  222. int state; //state - same as CHallInterface::CBuildingBox::state
  223. bool mode; // 0 - normal (with buttons), 1 - r-click popup
  224. CPicture *background;
  225. CAnimImage *buildingPic;
  226. AdventureMapButton *buy;
  227. AdventureMapButton *cancel;
  228. CLabel * title;
  229. CTextBox * buildingDescr;
  230. CTextBox * buildingState;
  231. CGStatusBar *statusBar;
  232. std::vector<CPicture *> resPicture;
  233. std::vector<CLabel *> resAmount;
  234. std::string getTextForState(int state);
  235. void buyFunc();
  236. void close();
  237. public:
  238. void clickRight(tribool down, bool previousState);
  239. CBuildWindow(const CGTownInstance *Town, const CBuilding * building, int State, bool Mode); //c-tor
  240. ~CBuildWindow(); //d-tor
  241. };
  242. //Small class to display
  243. class LabeledValue : public CIntObject
  244. {
  245. std::string hoverText;
  246. CLabel *name;
  247. CLabel *value;
  248. void init(std::string name, std::string descr, int min, int max);
  249. public:
  250. LabeledValue(SRect size, std::string name, std::string descr, int min, int max);
  251. LabeledValue(SRect size, std::string name, std::string descr, int val);
  252. void hover(bool on);
  253. };
  254. /// The fort screen where you can afford units
  255. class CFortScreen : public CIntObject
  256. {
  257. class RecruitArea : public CIntObject
  258. {
  259. const CGTownInstance *town;
  260. int level;
  261. std::string hoverText;
  262. CLabel * creatureName;
  263. CLabel * dwellingName;
  264. CLabel * availableCount;
  265. std::vector<LabeledValue*> values;
  266. CPicture *icons;
  267. CAnimImage * buildingPic;
  268. CCreaturePic *creatureAnim;
  269. public:
  270. RecruitArea(int posX, int posY, const CGTownInstance *town, int buildingID, int level);
  271. void creaturesChanged();
  272. void hover(bool on);
  273. void clickLeft(tribool down, bool previousState);
  274. void clickRight(tribool down, bool previousState);
  275. };
  276. CPicture *background;
  277. CLabel *title;
  278. std::vector<RecruitArea*> recAreas;
  279. CMinorResDataBar * resdatabar;
  280. CGStatusBar *statusBar;
  281. AdventureMapButton *exit;
  282. public:
  283. CFortScreen(const CGTownInstance * town); //c-tor
  284. void creaturesChanged();
  285. void close();
  286. };
  287. /// The mage guild screen where you can see which spells you have
  288. class CMageGuildScreen : public CIntObject
  289. {
  290. class Scroll : public CIntObject
  291. {
  292. const CSpell *spell;
  293. CAnimImage *image;
  294. public:
  295. Scroll(SPoint position, const CSpell *Spell);
  296. void clickLeft(tribool down, bool previousState);
  297. void clickRight(tribool down, bool previousState);
  298. void hover(bool on);
  299. };
  300. CPicture *background;
  301. CPicture *window;
  302. AdventureMapButton *exit;
  303. std::vector<Scroll *> spells;
  304. CMinorResDataBar * resdatabar;
  305. CGStatusBar *statusBar;
  306. void close();
  307. public:
  308. CMageGuildScreen(CCastleInterface * owner);
  309. };
  310. /// The blacksmith window where you can buy available in town war machine
  311. class CBlacksmithDialog : public CIntObject
  312. {
  313. AdventureMapButton *buy, *cancel;
  314. CPicture *background;
  315. CPicture *animBG;
  316. CCreatureAnim * anim;
  317. CPicture * gold;
  318. CLabel * title;
  319. CLabel * costText;
  320. CLabel * costValue;
  321. CGStatusBar *statusBar;
  322. void close();
  323. public:
  324. CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid);
  325. };