GUIClasses.h 39 KB

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