GUIClasses.h 36 KB

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