GUIClasses.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. #pragma once
  2. #include "CAnimation.h"
  3. #include "FunctionList.h"
  4. #include "../lib/ResourceSet.h"
  5. #include "../lib/GameConstants.h"
  6. #include "UIFramework/CIntObject.h"
  7. #include "UIFramework/CIntObjectClasses.h"
  8. #ifdef max
  9. #undef max
  10. #endif
  11. #ifdef min
  12. #undef min
  13. #endif
  14. /*
  15. * GUIClasses.h, part of VCMI engine
  16. *
  17. * Authors: listed in file AUTHORS in main folder
  18. *
  19. * License: GNU General Public License v2.0 or later
  20. * Full text of license available in license.txt file, in main folder
  21. *
  22. */
  23. struct ArtifactLocation;
  24. class CStackBasicDescriptor;
  25. class CBonusSystemNode;
  26. class CArtifact;
  27. class CDefEssential;
  28. class CAdventureMapButton;
  29. class CHighlightableButtonsGroup;
  30. class CDefHandler;
  31. struct HeroMoveDetails;
  32. class CDefEssential;
  33. class CGHeroInstance;
  34. class CAdvMapInt;
  35. class CCastleInterface;
  36. class CBattleInterface;
  37. class CStack;
  38. class CComponent;
  39. class CCreature;
  40. struct SDL_Surface;
  41. struct CPath;
  42. class CCreatureAnim;
  43. class CSelectableComponent;
  44. class CCreatureSet;
  45. class CGObjectInstance;
  46. class CGDwelling;
  47. class CSlider;
  48. struct UpgradeInfo;
  49. template <typename T> struct CondSh;
  50. class CInGameConsole;
  51. class CGarrisonInt;
  52. class CInGameConsole;
  53. struct Component;
  54. class CArmedInstance;
  55. class CGTownInstance;
  56. class StackState;
  57. class CPlayerInterface;
  58. class CHeroWindow;
  59. class CArtifact;
  60. class CArtifactsOfHero;
  61. class CCreatureArtifactSet;
  62. class CResDataBar;
  63. struct SPuzzleInfo;
  64. class CGGarrison;
  65. class CStackInstance;
  66. class IMarket;
  67. class CTextBox;
  68. class CArtifactInstance;
  69. class IBonusBearer;
  70. class CArtPlace;
  71. class CAnimImage;
  72. struct InfoAboutArmy;
  73. struct InfoAboutHero;
  74. struct InfoAboutTown;
  75. /// text + comp. + ok button
  76. class CInfoWindow : public CSimpleWindow
  77. { //window able to delete its components when closed
  78. bool delComps; //whether comps will be deleted
  79. public:
  80. typedef std::vector<std::pair<std::string,CFunctionList<void()> > > TButtonsInfo;
  81. typedef std::vector<CComponent*> TCompsInfo;
  82. int ID; //for identification
  83. CTextBox *text;
  84. std::vector<CAdventureMapButton *> buttons;
  85. std::vector<CComponent*> components;
  86. CSlider *slider;
  87. void setDelComps(bool DelComps);
  88. virtual void close();
  89. void show(SDL_Surface * to);
  90. void showAll(SDL_Surface * to);
  91. void sliderMoved(int to);
  92. CInfoWindow(std::string Text, int player, const TCompsInfo &comps = TCompsInfo(), const TButtonsInfo &Buttons = TButtonsInfo(), bool delComps = true); //c-tor
  93. CInfoWindow(); //c-tor
  94. ~CInfoWindow(); //d-tor
  95. static void showYesNoDialog( const std::string & text, const std::vector<CComponent*> *components, const CFunctionList<void( ) > &onYes, const CFunctionList<void()> &onNo, bool DelComps = true, int player = 1); //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  96. static CInfoWindow *create(const std::string &text, int playerID = 1, const std::vector<CComponent*> *components = NULL, bool DelComps = false);
  97. };
  98. /// component selection window
  99. class CSelWindow : public CInfoWindow
  100. { //warning - this window deletes its components by closing!
  101. public:
  102. void selectionChange(unsigned to);
  103. void madeChoice(); //looks for selected component and calls callback
  104. CSelWindow(const std::string& text, int player, int charperline ,const std::vector<CSelectableComponent*> &comps, const std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, int askID); //c-tor
  105. CSelWindow(){}; //c-tor
  106. //notification - this class inherits important destructor from CInfoWindow
  107. };
  108. /// popup displayed on R-click
  109. class CRClickPopup : public CIntObject
  110. {
  111. public:
  112. virtual void close();
  113. void clickRight(tribool down, bool previousState);
  114. CRClickPopup();
  115. virtual ~CRClickPopup(); //d-tor
  116. static CIntObject* createInfoWin(Point position, const CGObjectInstance * specific);
  117. static void createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo());
  118. static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT);
  119. };
  120. /// popup displayed on R-click
  121. class CRClickPopupInt : public CRClickPopup
  122. {
  123. public:
  124. IShowActivatable *inner;
  125. bool delInner;
  126. void show(SDL_Surface * to);
  127. void showAll(SDL_Surface * to);
  128. CRClickPopupInt(IShowActivatable *our, bool deleteInt); //c-tor
  129. virtual ~CRClickPopupInt(); //d-tor
  130. };
  131. class CInfoPopup : public CRClickPopup
  132. {
  133. public:
  134. bool free; //TODO: comment me
  135. SDL_Surface * bitmap; //popup background
  136. void close();
  137. void show(SDL_Surface * to);
  138. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  139. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor
  140. CInfoPopup(SDL_Surface * Bitmap = NULL, bool Free = false); //default c-tor
  141. void init(int x, int y);
  142. ~CInfoPopup(); //d-tor
  143. };
  144. /// popup on adventure map for town\hero objects
  145. class CInfoBoxPopup : public CWindowObject
  146. {
  147. Point toScreen(Point pos);
  148. public:
  149. CInfoBoxPopup(Point position, const CGTownInstance * town);
  150. CInfoBoxPopup(Point position, const CGHeroInstance * hero);
  151. CInfoBoxPopup(Point position, const CGGarrison * garr);
  152. };
  153. /// common popup window component
  154. class CComponent : public virtual CIntObject
  155. {
  156. size_t getIndex();
  157. std::string getFileName();
  158. std::string getDescription();
  159. std::string getSubtitle();
  160. protected:
  161. CAnimImage *image; //our image
  162. void setSurface(std::string defName, int imgPos);
  163. public:
  164. enum Etype
  165. {
  166. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck, building, hero, flag
  167. } type; //component type
  168. int subtype; //TODO: comment me
  169. int val; //TODO: comment me
  170. std::string description; //r-click
  171. std::string subtitle; //TODO: comment me
  172. void init(Etype Type, int Subtype, int Val);
  173. CComponent(Etype Type, int Subtype, int Val); //c-tor
  174. CComponent(const Component &c); //c-tor
  175. void clickRight(tribool down, bool previousState); //call-in
  176. };
  177. class CSelectableComponent : public CComponent, public CKeyShortcut
  178. {
  179. public:
  180. bool selected; //if true, this component is selected
  181. boost::function<void()> onSelect; //function called on selection change
  182. void clickLeft(tribool down, bool previousState); //call-in
  183. void init();
  184. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0); //c-tor
  185. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0); //c-tor
  186. ~CSelectableComponent(); //d-tor
  187. virtual void show(SDL_Surface * to);
  188. void select(bool on);
  189. };
  190. ////////////////////////////////////////////////////////////////////////////////
  191. /// base class for hero/town/garrison tooltips
  192. class CArmyTooltip : public CIntObject
  193. {
  194. void init(const InfoAboutArmy &army);
  195. public:
  196. CArmyTooltip(Point pos, const InfoAboutArmy &army);
  197. CArmyTooltip(Point pos, const CArmedInstance * army);
  198. };
  199. /// Class for hero tooltip. Does not have any background!
  200. /// background for infoBox: ADSTATHR
  201. /// background for tooltip: HEROQVBK
  202. class CHeroTooltip : public CArmyTooltip
  203. {
  204. void init(const InfoAboutHero &hero);
  205. public:
  206. CHeroTooltip(Point pos, const InfoAboutHero &hero);
  207. CHeroTooltip(Point pos, const CGHeroInstance * hero);
  208. };
  209. /// Class for town tooltip. Does not have any background!
  210. /// background for infoBox: ADSTATCS
  211. /// background for tooltip: TOWNQVBK
  212. class CTownTooltip : public CArmyTooltip
  213. {
  214. void init(const InfoAboutTown &town);
  215. public:
  216. CTownTooltip(Point pos, const InfoAboutTown &town);
  217. CTownTooltip(Point pos, const CGTownInstance * town);
  218. };
  219. ///////////////////////////////////////////////////////////////////////////////
  220. class CGarrisonInt;
  221. /// A single garrison slot which holds one creature of a specific amount
  222. class CGarrisonSlot : public CIntObject
  223. {
  224. public:
  225. int ID; //for identification
  226. CGarrisonInt *owner;
  227. const CStackInstance *myStack; //NULL if slot is empty
  228. const CCreature *creature;
  229. int count; //number of creatures
  230. int upg; //0 - up garrison, 1 - down garrison
  231. bool highlight;
  232. virtual void hover (bool on); //call-in
  233. const CArmedInstance * getObj();
  234. bool our();
  235. void clickRight(tribool down, bool previousState);
  236. void clickLeft(tribool down, bool previousState);
  237. void showAll(SDL_Surface * to);
  238. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CStackInstance * Creature=NULL);
  239. };
  240. /// Class which manages slots of upper and lower garrison, splitting of units
  241. class CGarrisonInt :public CIntObject
  242. {
  243. public:
  244. int interx; //space between slots
  245. Point garOffset; //offset between garrisons (not used if only one hero)
  246. CGarrisonSlot *highlighted; //chosen slot
  247. std::vector<CAdventureMapButton *> splitButtons; //may be empty if no buttons
  248. int p2, //TODO: comment me
  249. shiftPos;//1st slot of the second row, set shiftPoint for effect
  250. bool splitting, pb,
  251. smallIcons, //true - 32x32 imgs, false - 58x64
  252. removableUnits,//player can remove units from up
  253. twoRows,//slots will be placed in 2 rows
  254. owned[2];//player owns up or down army [0] upper, [1] lower
  255. // const CCreatureSet *set1; //top set of creatures
  256. // const CCreatureSet *set2; //bottom set of creatures
  257. std::vector<CGarrisonSlot*> slotsUp, slotsDown; //slots of upper and lower garrison
  258. const CArmedInstance *armedObjs[2]; //[0] is upper, [1] is down
  259. //const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  260. void setArmy(const CArmedInstance *army, bool bottomGarrison);
  261. void addSplitBtn(CAdventureMapButton * button);
  262. void createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int distance, int posY, int Upg );
  263. void activate();
  264. void createSlots();
  265. void deleteSlots();
  266. void recreateSlots();
  267. void splitClick(); //handles click on split button
  268. void splitStacks(int amountLeft, int amountRight); //TODO: comment me
  269. //x, y - position;
  270. //inx - distance between slots;
  271. //pomsur, SurOffset - UNUSED
  272. //s1, s2 - top and bottom armies;
  273. //removableUnits - you can take units from top;
  274. //smallImgs - units images size 64x58 or 32x32;
  275. //twoRows - display slots in 2 row (1st row = 4 slots, 2nd = 3 slots)
  276. CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *pomsur, const Point &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool _removableUnits = true, bool smallImgs = false, bool _twoRows=false); //c-tor
  277. ~CGarrisonInt(); //d-tor
  278. };
  279. /// draws picture with creature on background, use Animated=true to get animation
  280. class CCreaturePic : public CIntObject
  281. {
  282. private:
  283. CPicture *bg;
  284. CCreatureAnim *anim; //displayed animation
  285. public:
  286. CCreaturePic(int x, int y, const CCreature *cre, bool Big=true, bool Animated=true); //c-tor
  287. };
  288. /// Recruitment window where you can recruit creatures
  289. class CRecruitmentWindow : public CWindowObject
  290. {
  291. class CCreatureCard : public CIntObject
  292. {
  293. CRecruitmentWindow * parent;
  294. CCreaturePic *pic; //creature's animation
  295. bool selected;
  296. void clickLeft(tribool down, bool previousState);
  297. void clickRight(tribool down, bool previousState);
  298. void showAll(SDL_Surface *to);
  299. public:
  300. const CCreature * creature;
  301. si32 amount;
  302. void select(bool on);
  303. CCreatureCard(CRecruitmentWindow * window, const CCreature *crea, int totalAmount);
  304. };
  305. /// small class to display creature costs
  306. class CCostBox : public CIntObject
  307. {
  308. std::map<int, std::pair<CLabel *, CAnimImage * > > resources;
  309. public:
  310. //res - resources to show
  311. void set(TResources res);
  312. //res - visible resources
  313. CCostBox(Rect position, std::string title);
  314. void createItems(TResources res);
  315. };
  316. boost::function<void(int,int)> onRecruit; //void (int ID, int amount) <-- call to recruit creatures
  317. int level;
  318. const CArmedInstance *dst;
  319. CCreatureCard * selected;
  320. std::vector<CCreatureCard *> cards;
  321. CSlider *slider; //for selecting amount
  322. CAdventureMapButton *maxButton, *buyButton, *cancelButton;
  323. //labels for visible values
  324. CLabel * title;
  325. CLabel * availableValue;
  326. CLabel * toRecruitValue;
  327. CCostBox * costPerTroopValue;
  328. CCostBox * totalCostValue;
  329. void select(CCreatureCard * card);
  330. void buy();
  331. void sliderMoved(int to);
  332. void showAll(SDL_Surface *to);
  333. public:
  334. const CGDwelling * const dwelling;
  335. CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(int,int)> & Recruit, int y_offset = 0); //creatures - pairs<creature_ID,amount> //c-tor
  336. void availableCreaturesChanged();
  337. };
  338. /// Split window where creatures can be splitted up into two single unit stacks
  339. class CSplitWindow : public CWindowObject
  340. {
  341. boost::function<void(int, int)> callback;
  342. int leftAmount;
  343. int rightAmount;
  344. int leftMin;
  345. int rightMin;
  346. CSlider *slider;
  347. CCreaturePic *animLeft, *animRight; //creature's animation
  348. CAdventureMapButton *ok, *cancel;
  349. CTextInput *leftInput, *rightInput;
  350. void setAmountText(std::string text, bool left);
  351. void setAmount(int value, bool left);
  352. void sliderMoved(int value);
  353. void apply();
  354. public:
  355. /**
  356. * creature - displayed creature
  357. * callback(leftAmount, rightAmount) - function to call on close
  358. * leftMin, rightMin - minimal amount of creatures in each stack
  359. * leftAmount, rightAmount - amount of creatures in each stack
  360. */
  361. CSplitWindow(const CCreature * creature, boost::function<void(int, int)> callback,
  362. int leftMin, int rightMin, int leftAmount, int rightAmount);
  363. };
  364. /// Raised up level windowe where you can select one out of two skills
  365. class CLevelWindow : public CWindowObject
  366. {
  367. public:
  368. std::vector<CSelectableComponent *> comps; //skills to select
  369. boost::function<void(ui32)> cb;
  370. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  371. ~CLevelWindow(); //d-tor
  372. void selectionChanged(unsigned to);
  373. };
  374. /// Resource bar like that at the bottom of the adventure map screen
  375. class CMinorResDataBar : public CIntObject
  376. {
  377. public:
  378. SDL_Surface *bg; //background bitmap
  379. void show(SDL_Surface * to);
  380. void showAll(SDL_Surface * to);
  381. CMinorResDataBar(); //c-tor
  382. ~CMinorResDataBar(); //d-tor
  383. };
  384. /// Town portal, castle gate window
  385. class CObjectListWindow : public CWindowObject
  386. {
  387. class CItem : public CIntObject
  388. {
  389. CObjectListWindow *parent;
  390. CLabel *text;
  391. CPicture *border;
  392. public:
  393. const size_t index;
  394. CItem(CObjectListWindow *parent, size_t id, std::string text);
  395. void select(bool on);
  396. void clickLeft(tribool down, bool previousState);
  397. };
  398. boost::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
  399. CLabel * title;
  400. CLabel * descr;
  401. CListBox *list;
  402. CPicture *titleImage;//title image (castle gate\town portal picture)
  403. CAdventureMapButton *ok, *exit;
  404. std::vector< std::pair<int, std::string> > items;//all items present in list
  405. void init(CPicture * titlePic, std::string _title, std::string _descr);
  406. public:
  407. size_t selected;//index of currently selected item
  408. /// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
  409. /// Image can be NULL
  410. ///item names will be taken from map objects
  411. CObjectListWindow(const std::vector<int> &_items, CPicture * titlePic, std::string _title, std::string _descr,
  412. boost::function<void(int)> Callback);
  413. CObjectListWindow(const std::vector<std::string> &_items, CPicture * titlePic, std::string _title, std::string _descr,
  414. boost::function<void(int)> Callback);
  415. CIntObject *genItem(size_t index);
  416. void elementSelected();//call callback and close this window
  417. void changeSelection(size_t which);
  418. void keyPressed (const SDL_KeyboardEvent & key);
  419. };
  420. class CArtifactHolder
  421. {
  422. public:
  423. CArtifactHolder();
  424. virtual void artifactRemoved(const ArtifactLocation &artLoc)=0;
  425. virtual void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc)=0;
  426. virtual void artifactDisassembled(const ArtifactLocation &artLoc)=0;
  427. virtual void artifactAssembled(const ArtifactLocation &artLoc)=0;
  428. };
  429. class CWindowWithArtifacts : public CArtifactHolder
  430. {
  431. public:
  432. std::vector<CArtifactsOfHero *> artSets;
  433. void artifactRemoved(const ArtifactLocation &artLoc);
  434. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc);
  435. void artifactDisassembled(const ArtifactLocation &artLoc);
  436. void artifactAssembled(const ArtifactLocation &artLoc);
  437. };
  438. class CTradeWindow : public CWindowObject, public CWindowWithArtifacts //base for markets and altar of sacrifice
  439. {
  440. public:
  441. enum EType
  442. {
  443. RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
  444. };
  445. class CTradeableItem : public CIntObject
  446. {
  447. const CArtifactInstance *hlp; //holds ptr to artifact instance id type artifact
  448. public:
  449. EType type;
  450. int id;
  451. int serial;
  452. bool left;
  453. std::string subtitle; //empty if default
  454. const CArtifactInstance *getArtInstance() const;
  455. void setArtInstance(const CArtifactInstance *art);
  456. // const CArtifact *getArt() const;
  457. // void setArt(const CArtifact *artT) const;
  458. CFunctionList<void()> callback;
  459. bool downSelection;
  460. void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to);
  461. void clickRight(tribool down, bool previousState);
  462. void hover (bool on);
  463. void showAll(SDL_Surface * to);
  464. void clickLeft(tribool down, bool previousState);
  465. SDL_Surface *getSurface();
  466. std::string getName(int number = -1) const;
  467. CTradeableItem(EType Type, int ID, bool Left, int Serial);
  468. };
  469. const IMarket *market;
  470. const CGHeroInstance *hero;
  471. CArtifactsOfHero *arts;
  472. //all indexes: 1 = left, 0 = right
  473. std::vector<CTradeableItem*> items[2];
  474. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  475. EType itemsType[2];
  476. EMarketMode::EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  477. CAdventureMapButton *ok, *max, *deal;
  478. CSlider *slider; //for choosing amount to be exchanged
  479. bool readyToTrade;
  480. CTradeWindow(std::string bgName, const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c
  481. void showAll(SDL_Surface * to);
  482. void initSubs(bool Left);
  483. void initTypes();
  484. void initItems(bool Left);
  485. std::vector<int> *getItemsIds(bool Left); //NULL if default
  486. void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const;
  487. void removeItems(const std::set<CTradeableItem *> &toRemove);
  488. void removeItem(CTradeableItem * t);
  489. void getEmptySlots(std::set<CTradeableItem *> &toRemove);
  490. void setMode(EMarketMode::EMarketMode Mode); //mode setter
  491. void artifactSelected(CArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot
  492. virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0;
  493. virtual void selectionChanged(bool side) = 0; //true == left
  494. virtual Point selectionOffset(bool Left) const = 0;
  495. virtual std::string selectionSubtitle(bool Left) const = 0;
  496. virtual void garrisonChanged() = 0;
  497. virtual void artifactsChanged(bool left) = 0;
  498. };
  499. class CMarketplaceWindow : public CTradeWindow
  500. {
  501. bool printButtonFor(EMarketMode::EMarketMode M) const;
  502. std::string getBackgroundForMode(EMarketMode::EMarketMode mode);
  503. public:
  504. int r1, r2; //suggested amounts of traded resources
  505. bool madeTransaction; //if player made at least one transaction
  506. CTextBox *traderText;
  507. void setMax();
  508. void sliderMoved(int to);
  509. void makeDeal();
  510. void selectionChanged(bool side); //true == left
  511. CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode::EMarketMode Mode = EMarketMode::RESOURCE_RESOURCE); //c-tor
  512. ~CMarketplaceWindow(); //d-tor
  513. Point selectionOffset(bool Left) const;
  514. std::string selectionSubtitle(bool Left) const;
  515. void garrisonChanged(); //removes creatures with count 0 from the list (apparently whole stack has been sold)
  516. void artifactsChanged(bool left);
  517. void resourceChanged(int type, int val);
  518. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  519. void updateTraderText();
  520. };
  521. class CAltarWindow : public CTradeWindow
  522. {
  523. public:
  524. CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c-tor
  525. void getExpValues();
  526. ~CAltarWindow(); //d-tor
  527. std::vector<int> sacrificedUnits, //[slot_nr] -> how many creatures from that slot will be sacrificed
  528. expPerUnit;
  529. CAdventureMapButton *sacrificeAll, *sacrificeBackpack;
  530. CLabel *expToLevel, *expOnAltar;
  531. void selectionChanged(bool side); //true == left
  532. void SacrificeAll();
  533. void SacrificeBackpack();
  534. void putOnAltar(int backpackIndex);
  535. bool putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance *art);
  536. void makeDeal();
  537. void showAll(SDL_Surface * to);
  538. void blockTrade();
  539. void sliderMoved(int to);
  540. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  541. void mimicCres();
  542. Point selectionOffset(bool Left) const;
  543. std::string selectionSubtitle(bool Left) const;
  544. void garrisonChanged();
  545. void artifactsChanged(bool left);
  546. void calcTotalExp();
  547. void setExpToLevel();
  548. void updateRight(CTradeableItem *toUpdate);
  549. void artifactPicked();
  550. int firstFreeSlot();
  551. void moveFromSlotToAltar(int slotID, CTradeableItem* altarSlot, const CArtifactInstance *art);
  552. };
  553. class CSystemOptionsWindow : public CWindowObject
  554. {
  555. private:
  556. CLabel *title;
  557. CLabelGroup *leftGroup;
  558. CLabelGroup *rightGroup;
  559. CAdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet
  560. CHighlightableButtonsGroup * heroMoveSpeed;
  561. CHighlightableButtonsGroup * mapScrollSpeed;
  562. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  563. //CHighlightableButton * showPath;
  564. CHighlightableButton * showReminder;
  565. //CHighlightableButton * quickCombat;
  566. //CHighlightableButton * videoSubs;
  567. CHighlightableButton * newCreatureWin;
  568. CHighlightableButton * fullscreen;
  569. CAdventureMapButton *gameResButton;
  570. void setMusicVolume( int newVolume );
  571. void setSoundVolume( int newVolume );
  572. void setHeroMoveSpeed( int newSpeed );
  573. void setMapScrollingSpeed( int newSpeed );
  574. //functions bound to buttons
  575. void bloadf(); //load game
  576. void bsavef(); //save game
  577. void bquitf(); //quit game
  578. void breturnf(); //return to game
  579. void brestartf(); //restart game
  580. void bmainmenuf(); //return to main menu
  581. //functions for checkboxes
  582. void toggleReminder(bool on);
  583. void toggleCreatureWin(bool on);
  584. void toggleFullscreen(bool on);
  585. void selectGameRes();
  586. void setGameRes(int index);
  587. void pushSDLEvent(int type, int usercode);
  588. public:
  589. CSystemOptionsWindow(); //c-tor
  590. };
  591. class CTavernWindow : public CWindowObject
  592. {
  593. public:
  594. class HeroPortrait : public CIntObject
  595. {
  596. public:
  597. std::string hoverName;
  598. const CGHeroInstance *h;
  599. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  600. void clickLeft(tribool down, bool previousState);
  601. void clickRight(tribool down, bool previousState);
  602. void hover (bool on);
  603. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  604. private:
  605. int *_sel;
  606. const int _id;
  607. } *h1, *h2; //recruitable heroes
  608. CGStatusBar *bar; //tavern's internal status bar
  609. int selected;//0 (left) or 1 (right)
  610. int oldSelected;//0 (left) or 1 (right)
  611. CAdventureMapButton *thiefGuild, *cancel, *recruit;
  612. const CGObjectInstance *tavernObj;
  613. CTavernWindow(const CGObjectInstance *TavernObj); //c-tor
  614. ~CTavernWindow(); //d-tor
  615. void recruitb();
  616. void thievesguildb();
  617. void show(SDL_Surface * to);
  618. };
  619. class CInGameConsole : public CIntObject
  620. {
  621. private:
  622. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  623. boost::mutex texts_mx; // protects texts
  624. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  625. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  626. int defaultTimeout; //timeout for new texts (in ms)
  627. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  628. public:
  629. std::string enteredText;
  630. void show(SDL_Surface * to);
  631. void print(const std::string &txt);
  632. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  633. void startEnteringText();
  634. void endEnteringText(bool printEnteredText);
  635. void refreshEnteredText();
  636. CInGameConsole(); //c-tor
  637. };
  638. /// Can interact on left and right mouse clicks
  639. class LRClickableAreaWTextComp: public LRClickableAreaWText
  640. {
  641. public:
  642. int baseType;
  643. int bonusValue, type;
  644. virtual void clickLeft(tribool down, bool previousState);
  645. virtual void clickRight(tribool down, bool previousState);
  646. LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), int BaseType = -1);
  647. CComponent * createComponent() const;
  648. };
  649. class MoraleLuckBox : public LRClickableAreaWTextComp
  650. {
  651. CAnimImage *image;
  652. public:
  653. bool morale; //true if morale, false if luck
  654. bool small;
  655. void set(const IBonusBearer *node);
  656. MoraleLuckBox(bool Morale, const Rect &r, bool Small=false);
  657. };
  658. /// Opens hero window by left-clicking on it
  659. class CHeroArea: public CIntObject
  660. {
  661. public:
  662. const CGHeroInstance * hero;
  663. CHeroArea(int x, int y, const CGHeroInstance * _hero);
  664. void clickLeft(tribool down, bool previousState);
  665. void clickRight(tribool down, bool previousState);
  666. void hover(bool on);
  667. void showAll(SDL_Surface * to);
  668. };
  669. /// Opens town screen by left-clicking on it
  670. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  671. {
  672. public:
  673. const CGTownInstance * town;
  674. void clickLeft(tribool down, bool previousState);
  675. void clickRight(tribool down, bool previousState);
  676. LRClickableAreaOpenTown();
  677. };
  678. /// Artifacts can be placed there. Gets shown at the hero window
  679. class CArtPlace: public LRClickableAreaWTextComp
  680. {
  681. public:
  682. int slotID; //Arts::EPOS enum + backpack starting from Arts::BACKPACK_START
  683. bool picked;
  684. bool marked;
  685. bool locked;
  686. CArtifactsOfHero * ourOwner;
  687. const CArtifactInstance * ourArt;
  688. CArtPlace(const CArtifactInstance * Art); //c-tor
  689. CArtPlace(Point position, const CArtifactInstance * Art = NULL); //c-tor
  690. void clickLeft(tribool down, bool previousState);
  691. void clickRight(tribool down, bool previousState);
  692. void select ();
  693. void deselect ();
  694. void showAll(SDL_Surface * to);
  695. bool fitsHere (const CArtifactInstance * art) const; //returns true if given artifact can be placed here
  696. void setMeAsDest(bool backpackAsVoid = true);
  697. void setArtifact(const CArtifactInstance *art);
  698. };
  699. /// Contains artifacts of hero. Distincts which artifacts are worn or backpacked
  700. class CArtifactsOfHero : public CIntObject
  701. {
  702. const CGHeroInstance * curHero;
  703. std::vector<CArtPlace *> artWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
  704. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  705. int backpackPos; //number of first art visible in backpack (in hero's vector)
  706. public:
  707. struct SCommonPart
  708. {
  709. struct Artpos
  710. {
  711. int slotID;
  712. const CArtifactsOfHero *AOH;
  713. const CArtifactInstance *art;
  714. Artpos();
  715. void clear();
  716. void setTo(const CArtPlace *place, bool dontTakeBackpack);
  717. bool valid();
  718. bool operator==(const ArtifactLocation &al) const;
  719. } src, dst;
  720. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  721. void reset();
  722. } * commonInfo; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally
  723. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  724. CAdventureMapButton * leftArtRoll, * rightArtRoll;
  725. bool allowedAssembling;
  726. std::multiset<const CArtifactInstance*> artifactsOnAltar; //artifacts id that are technically present in backpack but in GUI are moved to the altar - they'll be omitted in backpack slots
  727. boost::function<void(CArtPlace*)> highlightModeCallback; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function
  728. void realizeCurrentTransaction(); //calls callback with parameters stored in commonInfo
  729. void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst);
  730. void artifactRemoved(const ArtifactLocation &al);
  731. void artifactAssembled(const ArtifactLocation &al);
  732. void artifactDisassembled(const ArtifactLocation &al);
  733. CArtPlace *getArtPlace(int slot);
  734. void setHero(const CGHeroInstance * hero);
  735. const CGHeroInstance *getHero() const;
  736. void dispose(); //free resources not needed after closing windows and reset state
  737. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  738. void safeRedraw();
  739. void markPossibleSlots(const CArtifactInstance* art);
  740. void unmarkSlots(bool withRedraw = true); //unmarks slots in all visible AOHs
  741. void unmarkLocalSlots(bool withRedraw = true); //unmarks slots in that particular AOH
  742. void setSlotData (CArtPlace* artPlace, int slotID);
  743. void updateWornSlots (bool redrawParent = true);
  744. void updateSlot(int i);
  745. void eraseSlotData (CArtPlace* artPlace, int slotID);
  746. CArtifactsOfHero(const Point& position, bool createCommonPart = false);
  747. //Alternative constructor, used if custom artifacts positioning required (Kingdom interface)
  748. CArtifactsOfHero(std::vector<CArtPlace *> ArtWorn, std::vector<CArtPlace *> Backpack,
  749. CAdventureMapButton *leftScroll, CAdventureMapButton *rightScroll, bool createCommonPart = false);
  750. ~CArtifactsOfHero(); //d-tor
  751. void updateParentWindow();
  752. friend class CArtPlace;
  753. };
  754. class CGarrisonHolder
  755. {
  756. public:
  757. CGarrisonHolder();
  758. virtual void updateGarrisons()=0;
  759. };
  760. class CWindowWithGarrison : public virtual CGarrisonHolder
  761. {
  762. public:
  763. CGarrisonInt *garr;
  764. virtual void updateGarrisons();
  765. };
  766. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  767. class CGarrisonWindow : public CWindowObject, public CWindowWithGarrison
  768. {
  769. public:
  770. CAdventureMapButton * quit;
  771. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  772. };
  773. class CExchangeWindow : public CWindowObject, public CWindowWithGarrison, public CWindowWithArtifacts
  774. {
  775. CGStatusBar * ourBar; //internal statusbar
  776. CAdventureMapButton * quit, * questlogButton[2];
  777. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  778. MoraleLuckBox *morale[2], *luck[2];
  779. LRClickableAreaWText *speciality[2];
  780. LRClickableAreaWText *experience[2];
  781. LRClickableAreaWText *spellPoints[2];
  782. CHeroArea *portrait[2];
  783. public:
  784. const CGHeroInstance* heroInst[2];
  785. CArtifactsOfHero * artifs[2];
  786. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  787. void prepareBackground(); //prepares or redraws bg
  788. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  789. ~CExchangeWindow(); //d-tor
  790. };
  791. /// Here you can buy ships
  792. class CShipyardWindow : public CWindowObject
  793. {
  794. public:
  795. CGStatusBar *bar;
  796. CPicture *bgWater;
  797. CLabel *title;
  798. CLabel *costLabel;
  799. CAnimImage *woodPic, *goldPic;
  800. CLabel *woodCost, *goldCost;
  801. CAnimImage *bgShip;
  802. CAdventureMapButton *build, *quit;
  803. CGStatusBar * statusBar;
  804. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const boost::function<void()> &onBuy);
  805. };
  806. /// Puzzle screen which gets uncovered when you visit obilisks
  807. class CPuzzleWindow : public CWindowObject
  808. {
  809. private:
  810. int3 grailPos;
  811. CAdventureMapButton * quitb;
  812. std::vector<CPicture * > piecesToRemove;
  813. ui8 currentAlpha;
  814. public:
  815. void showAll(SDL_Surface * to);
  816. void show(SDL_Surface * to);
  817. CPuzzleWindow(const int3 &grailPos, double discoveredRatio);
  818. };
  819. /// Creature transformer window
  820. class CTransformerWindow : public CWindowObject, public CGarrisonHolder
  821. {
  822. public:
  823. class CItem : public CIntObject
  824. {
  825. public:
  826. int id;//position of creature in hero army
  827. bool left;//position of the item
  828. int size; //size of creature stack
  829. CTransformerWindow * parent;
  830. CAnimImage *icon;
  831. void move();
  832. void clickLeft(tribool down, bool previousState);
  833. void update();
  834. CItem(CTransformerWindow * _parent, int _size, int _id);
  835. };
  836. const CArmedInstance *army;//object with army for transforming (hero or town)
  837. const CGHeroInstance *hero;//only if we have hero in town
  838. const CGTownInstance *town;//market, town garrison is used if hero == NULL
  839. std::vector<CItem*> items;
  840. CAdventureMapButton *all, *convert, *cancel;
  841. CGStatusBar *bar;
  842. void makeDeal();
  843. void addAll();
  844. void updateGarrisons();
  845. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); //c-tor
  846. };
  847. class CUniversityWindow : public CWindowObject
  848. {
  849. class CItem : public CAnimImage
  850. {
  851. public:
  852. int ID;//id of selected skill
  853. CUniversityWindow * parent;
  854. void showAll(SDL_Surface * to);
  855. void clickLeft(tribool down, bool previousState);
  856. void clickRight(tribool down, bool previousState);
  857. void hover(bool on);
  858. int state();//0=can't learn, 1=learned, 2=can learn
  859. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  860. };
  861. public:
  862. const CGHeroInstance *hero;
  863. const IMarket * market;
  864. CPicture * green, * yellow, * red;//colored bars near skills
  865. std::vector<CItem*> items;
  866. CAdventureMapButton *cancel;
  867. CGStatusBar *bar;
  868. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market); //c-tor
  869. };
  870. /// Confirmation window for University
  871. class CUnivConfirmWindow : public CWindowObject
  872. {
  873. public:
  874. CUniversityWindow * parent;
  875. CGStatusBar *bar;
  876. CAdventureMapButton *confirm, *cancel;
  877. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available); //c-tor
  878. void makeDeal(int skill);
  879. };
  880. /// Hill fort is the building where you can upgrade units
  881. class CHillFortWindow : public CWindowObject, public CWindowWithGarrison
  882. {
  883. public:
  884. int slotsCount;//=7;
  885. CGStatusBar * bar;
  886. CDefEssential *resources;
  887. CHeroArea *heroPic;//clickable hero image
  888. CAdventureMapButton *quit,//closes window
  889. *upgradeAll,//upgrade all creatures
  890. *upgrade[7];//upgrade single creature
  891. const CGObjectInstance * fort;
  892. const CGHeroInstance * hero;
  893. std::vector<int> currState;//current state of slot - to avoid calls to getState or updating buttons
  894. std::vector<TResources> costs;// costs [slot ID] [resource ID] = resource count for upgrade
  895. TResources totalSumm; // totalSum[resource ID] = value
  896. CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object); //c-tor
  897. void showAll (SDL_Surface *to);
  898. std::string getDefForSlot(int slot);//return def name for this slot
  899. std::string getTextForSlot(int slot);//return hover text for this slot
  900. void makeDeal(int slot);//-1 for upgrading all creatures
  901. int getState(int slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
  902. void updateGarrisons();//update buttons after garrison changes
  903. };
  904. class CThievesGuildWindow : public CWindowObject
  905. {
  906. const CGObjectInstance * owner;
  907. CGStatusBar * statusBar;
  908. CAdventureMapButton * exitb;
  909. CMinorResDataBar * resdatabar;
  910. public:
  911. CThievesGuildWindow(const CGObjectInstance * _owner);
  912. };