GUIClasses.h 38 KB

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