GUIClasses.h 37 KB

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