GUIClasses.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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. public:
  292. static const int SPACE_BETWEEN = 18;
  293. static const int CREATURE_WIDTH = 102;
  294. static const int TOTAL_CREATURE_WIDTH = SPACE_BETWEEN + CREATURE_WIDTH;
  295. struct creinfo
  296. {
  297. SDL_Rect pos;
  298. CCreaturePic *pic; //creature's animation
  299. int ID, amount; //creature ID and available amount
  300. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  301. };
  302. std::vector<int> amounts; //how many creatures we can afford
  303. std::vector<creinfo> creatures; //recruitable creatures
  304. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  305. CSlider *slider; //for selecting amount
  306. CAdventureMapButton *max, *buy, *cancel;
  307. CGStatusBar *bar;
  308. int which; //which creature is active
  309. const CGDwelling *dwelling;
  310. int level;
  311. const CArmedInstance *dst;
  312. void Max();
  313. void Buy();
  314. void Cancel();
  315. void sliderMoved(int to);
  316. void clickLeft(tribool down, bool previousState);
  317. void clickRight(tribool down, bool previousState);
  318. void showAll(SDL_Surface * to);
  319. void initCres();
  320. 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
  321. };
  322. /// Split window where creatures can be splitted up into two single unit stacks
  323. class CSplitWindow : public CWindowObject
  324. {
  325. boost::function<void(int, int)> callback;
  326. int leftAmount;
  327. int rightAmount;
  328. int leftMin;
  329. int rightMin;
  330. CSlider *slider;
  331. CCreaturePic *animLeft, *animRight; //creature's animation
  332. CAdventureMapButton *ok, *cancel;
  333. CTextInput *leftInput, *rightInput;
  334. void setAmountText(std::string text, bool left);
  335. void setAmount(int value, bool left);
  336. void sliderMoved(int value);
  337. void apply();
  338. public:
  339. /**
  340. * creature - displayed creature
  341. * callback(leftAmount, rightAmount) - function to call on close
  342. * leftMin, rightMin - minimal amount of creatures in each stack
  343. * leftAmount, rightAmount - amount of creatures in each stack
  344. */
  345. CSplitWindow(const CCreature * creature, boost::function<void(int, int)> callback,
  346. int leftMin, int rightMin, int leftAmount, int rightAmount);
  347. };
  348. /// Raised up level windowe where you can select one out of two skills
  349. class CLevelWindow : public CWindowObject
  350. {
  351. public:
  352. std::vector<CSelectableComponent *> comps; //skills to select
  353. boost::function<void(ui32)> cb;
  354. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  355. ~CLevelWindow(); //d-tor
  356. void selectionChanged(unsigned to);
  357. };
  358. /// Resource bar like that at the bottom of the adventure map screen
  359. class CMinorResDataBar : public CIntObject
  360. {
  361. public:
  362. SDL_Surface *bg; //background bitmap
  363. void show(SDL_Surface * to);
  364. void showAll(SDL_Surface * to);
  365. CMinorResDataBar(); //c-tor
  366. ~CMinorResDataBar(); //d-tor
  367. };
  368. /// Town portal, castle gate window
  369. class CObjectListWindow : public CWindowObject
  370. {
  371. class CItem : public CIntObject
  372. {
  373. CObjectListWindow *parent;
  374. CLabel *text;
  375. CPicture *border;
  376. public:
  377. const size_t index;
  378. CItem(CObjectListWindow *parent, size_t id, std::string text);
  379. void select(bool on);
  380. void clickLeft(tribool down, bool previousState);
  381. };
  382. boost::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
  383. CLabel * title;
  384. CLabel * descr;
  385. CListBox *list;
  386. CPicture *titleImage;//title image (castle gate\town portal picture)
  387. CAdventureMapButton *ok, *exit;
  388. std::vector< std::pair<int, std::string> > items;//all items present in list
  389. void init(CPicture * titlePic, std::string _title, std::string _descr);
  390. public:
  391. size_t selected;//index of currently selected item
  392. /// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
  393. /// Image can be NULL
  394. ///item names will be taken from map objects
  395. CObjectListWindow(const std::vector<int> &_items, CPicture * titlePic, std::string _title, std::string _descr,
  396. boost::function<void(int)> Callback);
  397. CObjectListWindow(const std::vector<std::string> &_items, CPicture * titlePic, std::string _title, std::string _descr,
  398. boost::function<void(int)> Callback);
  399. CIntObject *genItem(size_t index);
  400. void elementSelected();//call callback and close this window
  401. void changeSelection(size_t which);
  402. void keyPressed (const SDL_KeyboardEvent & key);
  403. };
  404. class CArtifactHolder
  405. {
  406. public:
  407. CArtifactHolder();
  408. virtual void artifactRemoved(const ArtifactLocation &artLoc)=0;
  409. virtual void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc)=0;
  410. virtual void artifactDisassembled(const ArtifactLocation &artLoc)=0;
  411. virtual void artifactAssembled(const ArtifactLocation &artLoc)=0;
  412. };
  413. class CWindowWithArtifacts : public CArtifactHolder
  414. {
  415. public:
  416. std::vector<CArtifactsOfHero *> artSets;
  417. void artifactRemoved(const ArtifactLocation &artLoc);
  418. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc);
  419. void artifactDisassembled(const ArtifactLocation &artLoc);
  420. void artifactAssembled(const ArtifactLocation &artLoc);
  421. };
  422. class CTradeWindow : public CWindowObject, public CWindowWithArtifacts //base for markets and altar of sacrifice
  423. {
  424. public:
  425. enum EType
  426. {
  427. RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
  428. };
  429. class CTradeableItem : public CIntObject
  430. {
  431. const CArtifactInstance *hlp; //holds ptr to artifact instance id type artifact
  432. public:
  433. EType type;
  434. int id;
  435. int serial;
  436. bool left;
  437. std::string subtitle; //empty if default
  438. const CArtifactInstance *getArtInstance() const;
  439. void setArtInstance(const CArtifactInstance *art);
  440. // const CArtifact *getArt() const;
  441. // void setArt(const CArtifact *artT) const;
  442. CFunctionList<void()> callback;
  443. bool downSelection;
  444. void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to);
  445. void clickRight(tribool down, bool previousState);
  446. void hover (bool on);
  447. void showAll(SDL_Surface * to);
  448. void clickLeft(tribool down, bool previousState);
  449. SDL_Surface *getSurface();
  450. std::string getName(int number = -1) const;
  451. CTradeableItem(EType Type, int ID, bool Left, int Serial);
  452. };
  453. const IMarket *market;
  454. const CGHeroInstance *hero;
  455. CArtifactsOfHero *arts;
  456. //all indexes: 1 = left, 0 = right
  457. std::vector<CTradeableItem*> items[2];
  458. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  459. EType itemsType[2];
  460. EMarketMode::EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  461. CAdventureMapButton *ok, *max, *deal;
  462. CSlider *slider; //for choosing amount to be exchanged
  463. bool readyToTrade;
  464. CTradeWindow(std::string bgName, const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c
  465. void showAll(SDL_Surface * to);
  466. void initSubs(bool Left);
  467. void initTypes();
  468. void initItems(bool Left);
  469. std::vector<int> *getItemsIds(bool Left); //NULL if default
  470. void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const;
  471. void removeItems(const std::set<CTradeableItem *> &toRemove);
  472. void removeItem(CTradeableItem * t);
  473. void getEmptySlots(std::set<CTradeableItem *> &toRemove);
  474. void setMode(EMarketMode::EMarketMode Mode); //mode setter
  475. void artifactSelected(CArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot
  476. virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0;
  477. virtual void selectionChanged(bool side) = 0; //true == left
  478. virtual Point selectionOffset(bool Left) const = 0;
  479. virtual std::string selectionSubtitle(bool Left) const = 0;
  480. virtual void garrisonChanged() = 0;
  481. virtual void artifactsChanged(bool left) = 0;
  482. };
  483. class CMarketplaceWindow : public CTradeWindow
  484. {
  485. bool printButtonFor(EMarketMode::EMarketMode M) const;
  486. std::string getBackgroundForMode(EMarketMode::EMarketMode mode);
  487. public:
  488. int r1, r2; //suggested amounts of traded resources
  489. bool madeTransaction; //if player made at least one transaction
  490. CTextBox *traderText;
  491. void setMax();
  492. void sliderMoved(int to);
  493. void makeDeal();
  494. void selectionChanged(bool side); //true == left
  495. CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode::EMarketMode Mode = EMarketMode::RESOURCE_RESOURCE); //c-tor
  496. ~CMarketplaceWindow(); //d-tor
  497. Point selectionOffset(bool Left) const;
  498. std::string selectionSubtitle(bool Left) const;
  499. void garrisonChanged(); //removes creatures with count 0 from the list (apparently whole stack has been sold)
  500. void artifactsChanged(bool left);
  501. void resourceChanged(int type, int val);
  502. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  503. void updateTraderText();
  504. };
  505. class CAltarWindow : public CTradeWindow
  506. {
  507. public:
  508. CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c-tor
  509. void getExpValues();
  510. ~CAltarWindow(); //d-tor
  511. std::vector<int> sacrificedUnits, //[slot_nr] -> how many creatures from that slot will be sacrificed
  512. expPerUnit;
  513. CAdventureMapButton *sacrificeAll, *sacrificeBackpack;
  514. CLabel *expToLevel, *expOnAltar;
  515. void selectionChanged(bool side); //true == left
  516. void SacrificeAll();
  517. void SacrificeBackpack();
  518. void putOnAltar(int backpackIndex);
  519. bool putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance *art);
  520. void makeDeal();
  521. void showAll(SDL_Surface * to);
  522. void blockTrade();
  523. void sliderMoved(int to);
  524. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  525. void mimicCres();
  526. Point selectionOffset(bool Left) const;
  527. std::string selectionSubtitle(bool Left) const;
  528. void garrisonChanged();
  529. void artifactsChanged(bool left);
  530. void calcTotalExp();
  531. void setExpToLevel();
  532. void updateRight(CTradeableItem *toUpdate);
  533. void artifactPicked();
  534. int firstFreeSlot();
  535. void moveFromSlotToAltar(int slotID, CTradeableItem* altarSlot, const CArtifactInstance *art);
  536. };
  537. class CSystemOptionsWindow : public CWindowObject
  538. {
  539. private:
  540. CLabel *title;
  541. CLabelGroup *leftGroup;
  542. CLabelGroup *rightGroup;
  543. CAdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet
  544. CHighlightableButtonsGroup * heroMoveSpeed;
  545. CHighlightableButtonsGroup * mapScrollSpeed;
  546. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  547. //CHighlightableButton * showPath;
  548. CHighlightableButton * showReminder;
  549. //CHighlightableButton * quickCombat;
  550. //CHighlightableButton * videoSubs;
  551. CHighlightableButton * newCreatureWin;
  552. CHighlightableButton * fullscreen;
  553. CAdventureMapButton *gameResButton;
  554. void setMusicVolume( int newVolume );
  555. void setSoundVolume( int newVolume );
  556. void setHeroMoveSpeed( int newSpeed );
  557. void setMapScrollingSpeed( int newSpeed );
  558. //functions bound to buttons
  559. void bloadf(); //load game
  560. void bsavef(); //save game
  561. void bquitf(); //quit game
  562. void breturnf(); //return to game
  563. void brestartf(); //restart game
  564. void bmainmenuf(); //return to main menu
  565. //functions for checkboxes
  566. void toggleReminder(bool on);
  567. void toggleCreatureWin(bool on);
  568. void toggleFullscreen(bool on);
  569. void selectGameRes();
  570. void setGameRes(int index);
  571. void pushSDLEvent(int type, int usercode);
  572. public:
  573. CSystemOptionsWindow(); //c-tor
  574. };
  575. class CTavernWindow : public CWindowObject
  576. {
  577. public:
  578. class HeroPortrait : public CIntObject
  579. {
  580. public:
  581. std::string hoverName;
  582. const CGHeroInstance *h;
  583. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  584. void clickLeft(tribool down, bool previousState);
  585. void clickRight(tribool down, bool previousState);
  586. void hover (bool on);
  587. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  588. void show(SDL_Surface * to);
  589. private:
  590. int *_sel;
  591. const int _id;
  592. } *h1, *h2; //recruitable heroes
  593. CGStatusBar *bar; //tavern's internal status bar
  594. int selected;//0 (left) or 1 (right)
  595. int oldSelected;//0 (left) or 1 (right)
  596. CAdventureMapButton *thiefGuild, *cancel, *recruit;
  597. const CGObjectInstance *tavernObj;
  598. CTavernWindow(const CGObjectInstance *TavernObj); //c-tor
  599. ~CTavernWindow(); //d-tor
  600. void recruitb();
  601. void thievesguildb();
  602. void show(SDL_Surface * to);
  603. };
  604. class CInGameConsole : public CIntObject
  605. {
  606. private:
  607. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  608. boost::mutex texts_mx; // protects texts
  609. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  610. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  611. int defaultTimeout; //timeout for new texts (in ms)
  612. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  613. public:
  614. std::string enteredText;
  615. void show(SDL_Surface * to);
  616. void print(const std::string &txt);
  617. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  618. void startEnteringText();
  619. void endEnteringText(bool printEnteredText);
  620. void refreshEnteredText();
  621. CInGameConsole(); //c-tor
  622. };
  623. /// Can interact on left and right mouse clicks
  624. class LRClickableAreaWTextComp: public LRClickableAreaWText
  625. {
  626. public:
  627. int baseType;
  628. int bonusValue, type;
  629. virtual void clickLeft(tribool down, bool previousState);
  630. virtual void clickRight(tribool down, bool previousState);
  631. LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), int BaseType = -1);
  632. CComponent * createComponent() const;
  633. };
  634. class MoraleLuckBox : public LRClickableAreaWTextComp
  635. {
  636. CAnimImage *image;
  637. public:
  638. bool morale; //true if morale, false if luck
  639. bool small;
  640. void set(const IBonusBearer *node);
  641. MoraleLuckBox(bool Morale, const Rect &r, bool Small=false);
  642. ~MoraleLuckBox();
  643. };
  644. /// Opens hero window by left-clicking on it
  645. class CHeroArea: public CIntObject
  646. {
  647. public:
  648. const CGHeroInstance * hero;
  649. CHeroArea(int x, int y, const CGHeroInstance * _hero);
  650. void clickLeft(tribool down, bool previousState);
  651. void clickRight(tribool down, bool previousState);
  652. void hover(bool on);
  653. void showAll(SDL_Surface * to);
  654. };
  655. /// Opens town screen by left-clicking on it
  656. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  657. {
  658. public:
  659. const CGTownInstance * town;
  660. void clickLeft(tribool down, bool previousState);
  661. void clickRight(tribool down, bool previousState);
  662. LRClickableAreaOpenTown();
  663. };
  664. /// Artifacts can be placed there. Gets shown at the hero window
  665. class CArtPlace: public LRClickableAreaWTextComp
  666. {
  667. public:
  668. int slotID; //Arts::EPOS enum + backpack starting from Arts::BACKPACK_START
  669. bool picked;
  670. bool marked;
  671. bool locked;
  672. CArtifactsOfHero * ourOwner;
  673. const CArtifactInstance * ourArt;
  674. CArtPlace(const CArtifactInstance * Art); //c-tor
  675. CArtPlace(Point position, const CArtifactInstance * Art = NULL); //c-tor
  676. void clickLeft(tribool down, bool previousState);
  677. void clickRight(tribool down, bool previousState);
  678. void select ();
  679. void deselect ();
  680. void showAll(SDL_Surface * to);
  681. bool fitsHere (const CArtifactInstance * art) const; //returns true if given artifact can be placed here
  682. void setMeAsDest(bool backpackAsVoid = true);
  683. void setArtifact(const CArtifactInstance *art);
  684. ~CArtPlace(); //d-tor
  685. };
  686. /// Contains artifacts of hero. Distincts which artifacts are worn or backpacked
  687. class CArtifactsOfHero : public CIntObject
  688. {
  689. const CGHeroInstance * curHero;
  690. 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
  691. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  692. int backpackPos; //number of first art visible in backpack (in hero's vector)
  693. public:
  694. struct SCommonPart
  695. {
  696. struct Artpos
  697. {
  698. int slotID;
  699. const CArtifactsOfHero *AOH;
  700. const CArtifactInstance *art;
  701. Artpos();
  702. void clear();
  703. void setTo(const CArtPlace *place, bool dontTakeBackpack);
  704. bool valid();
  705. bool operator==(const ArtifactLocation &al) const;
  706. } src, dst;
  707. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  708. void reset();
  709. } * 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
  710. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  711. CAdventureMapButton * leftArtRoll, * rightArtRoll;
  712. bool allowedAssembling;
  713. 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
  714. boost::function<void(CArtPlace*)> highlightModeCallback; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function
  715. void realizeCurrentTransaction(); //calls callback with parameters stored in commonInfo
  716. void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst);
  717. void artifactRemoved(const ArtifactLocation &al);
  718. void artifactAssembled(const ArtifactLocation &al);
  719. void artifactDisassembled(const ArtifactLocation &al);
  720. CArtPlace *getArtPlace(int slot);
  721. void setHero(const CGHeroInstance * hero);
  722. const CGHeroInstance *getHero() const;
  723. void dispose(); //free resources not needed after closing windows and reset state
  724. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  725. void safeRedraw();
  726. void markPossibleSlots(const CArtifactInstance* art);
  727. void unmarkSlots(bool withRedraw = true); //unmarks slots in all visible AOHs
  728. void unmarkLocalSlots(bool withRedraw = true); //unmarks slots in that particular AOH
  729. void setSlotData (CArtPlace* artPlace, int slotID);
  730. void updateWornSlots (bool redrawParent = true);
  731. void updateSlot(int i);
  732. void eraseSlotData (CArtPlace* artPlace, int slotID);
  733. CArtifactsOfHero(const Point& position, bool createCommonPart = false);
  734. //Alternative constructor, used if custom artifacts positioning required (Kingdom interface)
  735. CArtifactsOfHero(std::vector<CArtPlace *> ArtWorn, std::vector<CArtPlace *> Backpack,
  736. CAdventureMapButton *leftScroll, CAdventureMapButton *rightScroll, bool createCommonPart = false);
  737. ~CArtifactsOfHero(); //d-tor
  738. void updateParentWindow();
  739. friend class CArtPlace;
  740. };
  741. class CGarrisonHolder
  742. {
  743. public:
  744. CGarrisonHolder();
  745. virtual void updateGarrisons(){}
  746. };
  747. class CWindowWithGarrison : public virtual CGarrisonHolder
  748. {
  749. public:
  750. CGarrisonInt *garr;
  751. virtual void updateGarrisons();
  752. };
  753. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  754. class CGarrisonWindow : public CWindowObject, public CWindowWithGarrison
  755. {
  756. public:
  757. CLabel *title;
  758. CAdventureMapButton *quit;
  759. void showAll(SDL_Surface * to);
  760. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  761. ~CGarrisonWindow(); //d-tor
  762. };
  763. class CExchangeWindow : public CWindowObject, public CWindowWithGarrison, public CWindowWithArtifacts
  764. {
  765. CGStatusBar * ourBar; //internal statusbar
  766. CAdventureMapButton * quit, * questlogButton[2];
  767. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  768. MoraleLuckBox *morale[2], *luck[2];
  769. LRClickableAreaWText *speciality[2];
  770. LRClickableAreaWText *experience[2];
  771. LRClickableAreaWText *spellPoints[2];
  772. CHeroArea *portrait[2];
  773. public:
  774. const CGHeroInstance* heroInst[2];
  775. CArtifactsOfHero * artifs[2];
  776. void showAll(SDL_Surface * to);
  777. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  778. void prepareBackground(); //prepares or redraws bg
  779. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  780. ~CExchangeWindow(); //d-tor
  781. };
  782. /// Here you can buy ships
  783. class CShipyardWindow : public CWindowObject
  784. {
  785. public:
  786. CGStatusBar *bar;
  787. CPicture *bgWater;
  788. CLabel *title;
  789. CLabel *costLabel;
  790. CAnimImage *woodPic, *goldPic;
  791. CLabel *woodCost, *goldCost;
  792. CAnimImage *bgShip;
  793. CAdventureMapButton *build, *quit;
  794. CGStatusBar * statusBar;
  795. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const boost::function<void()> &onBuy);
  796. };
  797. /// Puzzle screen which gets uncovered when you visit obilisks
  798. class CPuzzleWindow : public CWindowObject
  799. {
  800. private:
  801. int3 grailPos;
  802. CAdventureMapButton * quitb;
  803. std::vector<CPicture * > piecesToRemove;
  804. ui8 currentAlpha;
  805. public:
  806. void showAll(SDL_Surface * to);
  807. void show(SDL_Surface * to);
  808. CPuzzleWindow(const int3 &grailPos, double discoveredRatio);
  809. };
  810. /// Creature transformer window
  811. class CTransformerWindow : public CWindowObject
  812. {
  813. public:
  814. class CItem : public CIntObject
  815. {
  816. public:
  817. int id;//position of creature in hero army
  818. bool left;//position of the item
  819. int size; //size of creature stack
  820. CTransformerWindow * parent;
  821. CAnimImage *icon;
  822. void move();
  823. void showAll(SDL_Surface * to);
  824. void clickLeft(tribool down, bool previousState);
  825. CItem(CTransformerWindow * _parent, int _size, int _id);
  826. };
  827. const CArmedInstance *army;//object with army for transforming (hero or town)
  828. const CGHeroInstance *hero;//only if we have hero in town
  829. const CGTownInstance *town;//market, town garrison is used if hero == NULL
  830. std::vector<CItem*> items;
  831. CAdventureMapButton *all, *convert, *cancel;
  832. CGStatusBar *bar;
  833. void showAll(SDL_Surface * to);
  834. void makeDeal();
  835. void addAll();
  836. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); //c-tor
  837. };
  838. class CUniversityWindow : public CWindowObject
  839. {
  840. class CItem : public CAnimImage
  841. {
  842. public:
  843. int ID;//id of selected skill
  844. CUniversityWindow * parent;
  845. void showAll(SDL_Surface * to);
  846. void clickLeft(tribool down, bool previousState);
  847. void clickRight(tribool down, bool previousState);
  848. void hover(bool on);
  849. int state();//0=can't learn, 1=learned, 2=can learn
  850. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  851. };
  852. public:
  853. const CGHeroInstance *hero;
  854. const IMarket * market;
  855. CPicture * green, * yellow, * red;//colored bars near skills
  856. std::vector<CItem*> items;
  857. CAdventureMapButton *cancel;
  858. CGStatusBar *bar;
  859. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market); //c-tor
  860. };
  861. /// Confirmation window for University
  862. class CUnivConfirmWindow : public CWindowObject
  863. {
  864. public:
  865. CUniversityWindow * parent;
  866. CGStatusBar *bar;
  867. CAdventureMapButton *confirm, *cancel;
  868. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available); //c-tor
  869. void makeDeal(int skill);
  870. };
  871. /// Hill fort is the building where you can upgrade units
  872. class CHillFortWindow : public CWindowObject, public CWindowWithGarrison
  873. {
  874. public:
  875. int slotsCount;//=7;
  876. CGStatusBar * bar;
  877. CDefEssential *resources;
  878. CHeroArea *heroPic;//clickable hero image
  879. CAdventureMapButton *quit,//closes window
  880. *upgradeAll,//upgrade all creatures
  881. *upgrade[7];//upgrade single creature
  882. const CGObjectInstance * fort;
  883. const CGHeroInstance * hero;
  884. std::vector<int> currState;//current state of slot - to avoid calls to getState or updating buttons
  885. std::vector<TResources> costs;// costs [slot ID] [resource ID] = resource count for upgrade
  886. TResources totalSumm; // totalSum[resource ID] = value
  887. CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object); //c-tor
  888. void activate();
  889. void showAll (SDL_Surface *to);
  890. std::string getDefForSlot(int slot);//return def name for this slot
  891. std::string getTextForSlot(int slot);//return hover text for this slot
  892. void makeDeal(int slot);//-1 for upgrading all creatures
  893. int getState(int slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
  894. void updateGarrisons();//update buttons after garrison changes
  895. };
  896. class CThievesGuildWindow : public CWindowObject
  897. {
  898. const CGObjectInstance * owner;
  899. CGStatusBar * statusBar;
  900. CAdventureMapButton * exitb;
  901. CMinorResDataBar * resdatabar;
  902. public:
  903. void activate();
  904. CThievesGuildWindow(const CGObjectInstance * _owner);
  905. };