GUIClasses.h 37 KB

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