GUIClasses.h 37 KB

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