GUIClasses.h 37 KB

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