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