GUIClasses.h 38 KB

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