GUIClasses.h 38 KB

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