GUIClasses.h 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  1. #ifndef __GUICLASSES_H__
  2. #define __GUICLASSES_H__
  3. #include "../global.h"
  4. #include "GUIBase.h"
  5. #include "FunctionList.h"
  6. #include <set>
  7. #include <list>
  8. #include <boost/thread/mutex.hpp>
  9. #include "../lib/ResourceSet.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 AdventureMapButton;
  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 SComponent;
  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 CResDataBar;
  64. struct SPuzzleInfo;
  65. class CGGarrison;
  66. class CStackInstance;
  67. class IMarket;
  68. class CTextBox;
  69. class CArtifactInstance;
  70. class IBonusBearer;
  71. class CArtPlace;
  72. class CAnimImage;
  73. extern SDL_Color tytulowy, tlo, zwykly ;
  74. /// text + comp. + ok button
  75. class CInfoWindow : public CSimpleWindow
  76. { //window able to delete its components when closed
  77. bool delComps; //whether comps will be deleted
  78. public:
  79. typedef std::vector<std::pair<std::string,CFunctionList<void()> > > TButtonsInfo;
  80. typedef std::vector<SComponent*> TCompsInfo;
  81. int ID; //for identification
  82. CTextBox *text;
  83. std::vector<AdventureMapButton *> buttons;
  84. std::vector<SComponent*> components;
  85. CSlider *slider;
  86. void setDelComps(bool DelComps);
  87. virtual void close();
  88. void show(SDL_Surface * to);
  89. void showAll(SDL_Surface * to);
  90. void sliderMoved(int to);
  91. CInfoWindow(std::string Text, int player, const TCompsInfo &comps = TCompsInfo(), const TButtonsInfo &Buttons = TButtonsInfo(), bool delComps = true); //c-tor
  92. CInfoWindow(); //c-tor
  93. ~CInfoWindow(); //d-tor
  94. static void showYesNoDialog( const std::string & text, const std::vector<SComponent*> *components, const CFunctionList<void( ) > &onYes, const CFunctionList<void()> &onNo, bool DelComps = true, int player = 1); //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  95. static CInfoWindow *create(const std::string &text, int playerID = 1, const std::vector<SComponent*> *components = NULL, bool DelComps = false);
  96. };
  97. /// component selection window
  98. class CSelWindow : public CInfoWindow
  99. { //warning - this window deletes its components by closing!
  100. public:
  101. void selectionChange(unsigned to);
  102. void madeChoice(); //looks for selected component and calls callback
  103. CSelWindow(const std::string& text, int player, int charperline ,const std::vector<CSelectableComponent*> &comps, const std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, int askID); //c-tor
  104. CSelWindow(){}; //c-tor
  105. //notification - this class inherits important destructor from CInfoWindow
  106. };
  107. /// popup displayed on R-click
  108. class CRClickPopup : public CIntObject
  109. {
  110. public:
  111. virtual void activate();
  112. virtual void deactivate();
  113. virtual void close();
  114. void clickRight(tribool down, bool previousState);
  115. CRClickPopup();
  116. virtual ~CRClickPopup(); //d-tor
  117. static void createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo());
  118. static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT);
  119. };
  120. /// popup displayed on R-click
  121. class CRClickPopupInt : public CRClickPopup
  122. {
  123. public:
  124. IShowActivable *inner;
  125. bool delInner;
  126. void show(SDL_Surface * to);
  127. void showAll(SDL_Surface * to);
  128. CRClickPopupInt(IShowActivable *our, bool deleteInt); //c-tor
  129. virtual ~CRClickPopupInt(); //d-tor
  130. };
  131. class CInfoPopup : public CRClickPopup
  132. {
  133. public:
  134. bool free; //TODO: comment me
  135. SDL_Surface * bitmap; //popup background
  136. void close();
  137. void show(SDL_Surface * to);
  138. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  139. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor
  140. CInfoPopup(SDL_Surface *Bitmap = NULL, bool Free = false); //default c-tor
  141. void init(int x, int y);
  142. ~CInfoPopup(); //d-tor
  143. };
  144. /// common popup window component
  145. class SComponent : public virtual CIntObject
  146. {
  147. public:
  148. enum Etype
  149. {
  150. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck, building, hero, flag
  151. } type; //component type
  152. int subtype; //TODO: comment me
  153. int val; //TODO: comment me
  154. std::string description; //r-click
  155. std::string subtitle; //TODO: comment me
  156. SDL_Surface *img; //our image
  157. bool free; //should surface be freed on delete
  158. SDL_Surface * setSurface(std::string defName, int imgPos);
  159. void init(Etype Type, int Subtype, int Val);
  160. SComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur=NULL, bool freeSur=false); //c-tor
  161. SComponent(const Component &c); //c-tor
  162. SComponent();; //c-tor
  163. virtual ~SComponent(); //d-tor
  164. void clickRight(tribool down, bool previousState); //call-in
  165. SDL_Surface * getImg();
  166. virtual void show(SDL_Surface * to);
  167. virtual void activate();
  168. virtual void deactivate();
  169. };
  170. class CSelectableComponent : public SComponent, public KeyShortcut
  171. {
  172. public:
  173. bool selected; //if true, this component is selected
  174. boost::function<void()> onSelect; //function called on selection change
  175. void clickLeft(tribool down, bool previousState); //call-in
  176. void init();
  177. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0); //c-tor
  178. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0); //c-tor
  179. ~CSelectableComponent(); //d-tor
  180. virtual void show(SDL_Surface * to);
  181. void activate();
  182. void deactivate();
  183. void select(bool on);
  184. };
  185. class CGarrisonInt;
  186. /// A single garrison slot which holds one creature of a specific amount
  187. class CGarrisonSlot : public CIntObject
  188. {
  189. public:
  190. int ID; //for identification
  191. CGarrisonInt *owner;
  192. const CStackInstance *myStack; //NULL if slot is empty
  193. const CCreature *creature;
  194. int count; //number of creatures
  195. int upg; //0 - up garrison, 1 - down garrison
  196. bool active; //TODO: comment me
  197. virtual void hover (bool on); //call-in
  198. const CArmedInstance * getObj();
  199. bool our();
  200. void clickRight(tribool down, bool previousState);
  201. void clickLeft(tribool down, bool previousState);
  202. void activate();
  203. void deactivate();
  204. void showAll(SDL_Surface * to);
  205. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CStackInstance * Creature=NULL);
  206. ~CGarrisonSlot(); //d-tor
  207. };
  208. /// Class which manages slots of upper and lower garrison, splitting of units
  209. class CGarrisonInt :public CIntObject
  210. {
  211. public:
  212. int interx; //space between slots
  213. Point garOffset; //offset between garrisons (not used if only one hero)
  214. CGarrisonSlot *highlighted; //chosen slot
  215. std::vector<AdventureMapButton *> splitButtons; //may be empty if no buttons
  216. int p2, //TODO: comment me
  217. shiftPos;//1st slot of the second row, set shiftPoint for effect
  218. bool splitting, pb,
  219. smallIcons, //true - 32x32 imgs, false - 58x64
  220. removableUnits,//player can remove units from up
  221. twoRows,//slots will be placed in 2 rows
  222. owned[2];//player owns up or down army [0] upper, [1] lower
  223. // const CCreatureSet *set1; //top set of creatures
  224. // const CCreatureSet *set2; //bottom set of creatures
  225. std::vector<CGarrisonSlot*> slotsUp, slotsDown; //slots of upper and lower garrison
  226. const CArmedInstance *armedObjs[2]; //[0] is upper, [1] is down
  227. //const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  228. void setArmy(const CArmedInstance *army, bool bottomGarrison);
  229. void addSplitBtn(AdventureMapButton * button);
  230. void createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int distance, int posY, int Upg );
  231. void activate();
  232. void createSlots();
  233. void deleteSlots();
  234. void recreateSlots();
  235. void splitClick(); //handles click on split button
  236. void splitStacks(int am2); //TODO: comment me
  237. //x, y - position;
  238. //inx - distance between slots;
  239. //pomsur, SurOffset - UNUSED
  240. //s1, s2 - top and bottom armies;
  241. //removableUnits - you can take units from top;
  242. //smallImgs - units images size 64x58 or 32x32;
  243. //twoRows - display slots in 2 row (1st row = 4, 2nd = 3)
  244. CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *pomsur, const Point &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool _removableUnits = true, bool smallImgs = false, bool _twoRows=false); //c-tor
  245. ~CGarrisonInt(); //d-tor
  246. };
  247. /// Status bar which is shown at the bottom of the in-game screens
  248. class CStatusBar
  249. : public CIntObject, public IStatusBar
  250. {
  251. public:
  252. SDL_Surface * bg; //background
  253. int middlex, middley; //middle of statusbar
  254. std::string current; //text currently printed
  255. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  256. ~CStatusBar(); //d-tor
  257. void print(const std::string & text); //prints text and refreshes statusbar
  258. void clear();//clears statusbar and refreshes
  259. void show(SDL_Surface * to); //shows statusbar (with current text)
  260. std::string getCurrent(); //getter for current
  261. };
  262. /// Label which shows text
  263. class CLabel
  264. : public virtual CIntObject
  265. {
  266. public:
  267. EAlignment alignment;
  268. EFonts font;
  269. SDL_Color color;
  270. std::string text;
  271. CPicture *bg;
  272. bool autoRedraw; //whether control will redraw itself on setTxt
  273. Point textOffset; //text will be blitted at pos + textOffset with appropriate alignment
  274. bool ignoreLeadingWhitespace;
  275. virtual void setTxt(const std::string &Txt);
  276. void showAll(SDL_Surface * to); //shows statusbar (with current text)
  277. CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly, const std::string &Text = "");
  278. };
  279. /// a multi-line label that tries to fit text with given available width and height; if not possible, it creates a slider for scrolling text
  280. class CTextBox
  281. : public CLabel
  282. {
  283. public:
  284. int maxW; //longest line of text in px
  285. int maxH; //total height needed to print all lines
  286. int sliderStyle;
  287. bool redrawParentOnScrolling;
  288. std::vector<std::string> lines;
  289. CSlider *slider;
  290. //CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly);
  291. CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly);
  292. void showAll(SDL_Surface * to); //shows statusbar (with current text)
  293. void setTxt(const std::string &Txt);
  294. void setBounds(int limitW, int limitH);
  295. void recalculateLines(const std::string &Txt);
  296. void sliderMoved(int to);
  297. };
  298. /// Status bar which is shown at the bottom of the in-game screens
  299. class CGStatusBar
  300. : public CLabel, public IStatusBar
  301. {
  302. void init();
  303. public:
  304. IStatusBar *oldStatusBar;
  305. //statusbar interface overloads
  306. void print(const std::string & Text); //prints text and refreshes statusbar
  307. void clear();//clears statusbar and refreshes
  308. std::string getCurrent(); //returns currently displayed text
  309. void show(SDL_Surface * to); //shows statusbar (with current text)
  310. CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly, const std::string &Text = "");
  311. CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
  312. CGStatusBar(int x, int y, std::string name, int maxw=-1);
  313. ~CGStatusBar();
  314. void calcOffset();
  315. };
  316. /// UIElement which can get input focus
  317. class CFocusable
  318. : public virtual CIntObject
  319. {
  320. public:
  321. bool focus; //only one focusable control can have focus at one moment
  322. void giveFocus(); //captures focus
  323. void moveFocus(); //moves focus to next active control (may be used for tab switching)
  324. static std::list<CFocusable*> focusables; //all existing objs
  325. static CFocusable *inputWithFocus; //who has focus now
  326. CFocusable();
  327. ~CFocusable();
  328. };
  329. /// Text input box where players can enter text
  330. class CTextInput
  331. : public CLabel, public CFocusable
  332. {
  333. public:
  334. CFunctionList<void(const std::string &)> cb;
  335. void setText(const std::string &nText, bool callCb = false);
  336. CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB);
  337. CTextInput(const Rect &Pos, SDL_Surface *srf = NULL);
  338. ~CTextInput();
  339. void showAll(SDL_Surface * to);
  340. void clickLeft(tribool down, bool previousState);
  341. void keyPressed(const SDL_KeyboardEvent & key);
  342. };
  343. /// Listbox UI Element
  344. class CList : public CIntObject
  345. {
  346. public:
  347. SDL_Surface * bg; //background bitmap
  348. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  349. SDL_Surface *empty, *selection;
  350. SDL_Rect arrupp, arrdop; //positions of arrows
  351. int posw, posh; //position width/height
  352. int selected, //id of selected position, <0 if none
  353. from;
  354. const int SIZE; //size of list
  355. tribool pressed; //true=up; false=down; indeterminate=none
  356. CList(int Size = 5); //c-tor
  357. void clickLeft(tribool down, bool previousState);
  358. void activate();
  359. void deactivate();
  360. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  361. virtual void genList()=0;
  362. virtual void select(int which)=0;
  363. virtual void draw(SDL_Surface * to)=0;
  364. virtual int size() = 0; //how many elements do we have
  365. void fixPos(); //scrolls list, so the selection will be visible
  366. };
  367. /// List of heroes which is shown at the right of the adventure map screen
  368. class CHeroList
  369. : public CList
  370. {
  371. public:
  372. CDefHandler *mobile, *mana; //mana and movement indicators
  373. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  374. CHeroList(int Size); //c-tor
  375. int getPosOfHero(const CGHeroInstance* h); //hero's position on list
  376. void genList();
  377. void select(int which); //call-in
  378. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  379. void clickLeft(tribool down, bool previousState); //call-in
  380. void clickRight(tribool down, bool previousState); //call-in
  381. void hover (bool on); //call-in
  382. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  383. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  384. void updateMove(const CGHeroInstance* which); //draws move points bar
  385. void draw(SDL_Surface * to);
  386. void show(SDL_Surface * to);
  387. void showAll(SDL_Surface * to);
  388. void init();
  389. int size(); //how many elements do we have
  390. };
  391. /// List of towns which is shown at the right of the adventure map screen
  392. class CTownList
  393. : public CList
  394. {
  395. public:
  396. boost::function<void()> fun; //function called on selection change
  397. int posporx,pospory;
  398. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  399. ~CTownList(); //d-tor
  400. void genList();
  401. void select(int which); //call-in
  402. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  403. void clickLeft(tribool down, bool previousState); //call-in
  404. void clickRight(tribool down, bool previousState); //call-in
  405. void hover (bool on); //call-in
  406. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  407. void draw(SDL_Surface * to);
  408. void show(SDL_Surface * to);
  409. void showAll(SDL_Surface * to);
  410. int size(); //how many elements do we have
  411. };
  412. /// draws picture with creature on background, use Animated=true to get animation
  413. class CCreaturePic : public CIntObject
  414. {
  415. private:
  416. CPicture *bg; //background
  417. CCreatureAnim *anim; //displayed animation
  418. public:
  419. CCreaturePic(int x, int y, const CCreature *cre, bool Big=true, bool Animated=true); //c-tor
  420. ~CCreaturePic(); //d-tor
  421. };
  422. /// Recruitment window where you can recruit creatures
  423. class CRecruitmentWindow : public CIntObject
  424. {
  425. public:
  426. static const int SPACE_BETWEEN = 18;
  427. static const int CREATURE_WIDTH = 102;
  428. static const int TOTAL_CREATURE_WIDTH = SPACE_BETWEEN + CREATURE_WIDTH;
  429. struct creinfo
  430. {
  431. SDL_Rect pos;
  432. CCreaturePic *pic; //creature's animation
  433. int ID, amount; //creature ID and available amount
  434. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  435. };
  436. std::vector<int> amounts; //how many creatures we can afford
  437. std::vector<creinfo> creatures; //recruitable creatures
  438. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  439. CSlider *slider; //for selecting amount
  440. AdventureMapButton *max, *buy, *cancel;
  441. CPicture *bitmap; //background
  442. CGStatusBar *bar;
  443. int which; //which creature is active
  444. const CGDwelling *dwelling;
  445. int level;
  446. const CArmedInstance *dst;
  447. void close();
  448. void Max();
  449. void Buy();
  450. void Cancel();
  451. void sliderMoved(int to);
  452. void clickLeft(tribool down, bool previousState);
  453. void clickRight(tribool down, bool previousState);
  454. void showAll(SDL_Surface * to);
  455. void initCres();
  456. CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(int,int)> & Recruit, int y_offset = 0); //creatures - pairs<creature_ID,amount> //c-tor
  457. ~CRecruitmentWindow(); //d-tor
  458. };
  459. /// Split window where creatures can be splitted up into two single unit stacks
  460. class CSplitWindow : public CIntObject
  461. {
  462. public:
  463. CGarrisonInt *gar;
  464. CSlider *slider;
  465. CCreaturePic *animLeft, *animRight; //creature's animation
  466. AdventureMapButton *ok, *cancel;
  467. SDL_Surface *bitmap; //background
  468. int a1, a2, c; //TODO: comment me
  469. bool which; //which creature is selected
  470. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  471. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  472. ~CSplitWindow(); //d-tor
  473. void activate();
  474. void split();
  475. void close();
  476. void deactivate();
  477. void show(SDL_Surface * to);
  478. void clickLeft(tribool down, bool previousState); //call-in
  479. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  480. void sliderMoved(int to);
  481. };
  482. /// Raised up level windowe where you can select one out of two skills
  483. class CLevelWindow : public CIntObject
  484. {
  485. public:
  486. int heroPortrait;
  487. SDL_Surface *bitmap; //background
  488. std::vector<CSelectableComponent *> comps; //skills to select
  489. AdventureMapButton *ok;
  490. boost::function<void(ui32)> cb;
  491. void close();
  492. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  493. ~CLevelWindow(); //d-tor
  494. void activate();
  495. void deactivate();
  496. void selectionChanged(unsigned to);
  497. void show(SDL_Surface * to);
  498. };
  499. /// Resource bar like that at the bottom of the adventure map screen
  500. class CMinorResDataBar : public CIntObject
  501. {
  502. public:
  503. SDL_Surface *bg; //background bitmap
  504. void show(SDL_Surface * to);
  505. void showAll(SDL_Surface * to);
  506. CMinorResDataBar(); //c-tor
  507. ~CMinorResDataBar(); //d-tor
  508. };
  509. /// Town portal, castle gate window
  510. class CObjectListWindow : public CIntObject
  511. {
  512. public:
  513. boost::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
  514. std::string title,descr;//text for title and description
  515. CPicture *bg; //background
  516. CSlider *slider;
  517. CPicture *titleImage;//title image (castle gate\town portal picture)
  518. AdventureMapButton *ok, *exit;
  519. std::vector<Rect> areas;//areas for each visible item
  520. std::vector<int> items;//id of all items present in list
  521. int selected;//currently selected item
  522. int length;//size of list (=9)
  523. bool init;//true = initialization completed
  524. /// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
  525. CObjectListWindow(const std::vector<int> &_items, CPicture * titlePic, std::string _title, std::string _descr,
  526. boost::function<void(int)> Callback, int initState=-1); //c-tor
  527. ~CObjectListWindow(); //d-tor
  528. void elementSelected();//call callback and exit
  529. void moveList(int which);//called when slider moves
  530. void clickLeft(tribool down, bool previousState); //call-in
  531. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  532. void show(SDL_Surface * to);
  533. void showAll(SDL_Surface * to);
  534. };
  535. class CArtifactHolder : public virtual CIntObject
  536. {
  537. public:
  538. CArtifactHolder();
  539. virtual void artifactRemoved(const ArtifactLocation &artLoc)=0;
  540. virtual void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc)=0;
  541. virtual void artifactDisassembled(const ArtifactLocation &artLoc)=0;
  542. virtual void artifactAssembled(const ArtifactLocation &artLoc)=0;
  543. };
  544. class CWindowWithArtifacts : public CArtifactHolder
  545. {
  546. public:
  547. std::vector<CArtifactsOfHero *> artSets;
  548. void artifactRemoved(const ArtifactLocation &artLoc);
  549. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc);
  550. void artifactDisassembled(const ArtifactLocation &artLoc);
  551. void artifactAssembled(const ArtifactLocation &artLoc);
  552. };
  553. class CTradeWindow : public CWindowWithArtifacts //base for markets and altar of sacrifice
  554. {
  555. public:
  556. enum EType
  557. {
  558. RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
  559. };
  560. class CTradeableItem : public CIntObject
  561. {
  562. const CArtifactInstance *hlp; //holds ptr to artifact instance id type artifact
  563. public:
  564. EType type;
  565. int id;
  566. int serial;
  567. bool left;
  568. std::string subtitle; //empty if default
  569. const CArtifactInstance *getArtInstance() const;
  570. void setArtInstance(const CArtifactInstance *art);
  571. // const CArtifact *getArt() const;
  572. // void setArt(const CArtifact *artT) const;
  573. CFunctionList<void()> callback;
  574. bool downSelection;
  575. void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to);
  576. void clickRight(tribool down, bool previousState);
  577. void hover (bool on);
  578. void showAll(SDL_Surface * to);
  579. void clickLeft(tribool down, bool previousState);
  580. SDL_Surface *getSurface();
  581. std::string getName(int number = -1) const;
  582. CTradeableItem(EType Type, int ID, bool Left, int Serial);
  583. };
  584. const IMarket *market;
  585. const CGHeroInstance *hero;
  586. CPicture *bg; //background
  587. CArtifactsOfHero *arts;
  588. //all indexes: 1 = left, 0 = right
  589. std::vector<CTradeableItem*> items[2];
  590. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  591. EType itemsType[2];
  592. EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  593. AdventureMapButton *ok, *max, *deal;
  594. CSlider *slider; //for choosing amount to be exchanged
  595. bool readyToTrade;
  596. CTradeWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode); //c
  597. void showAll(SDL_Surface * to);
  598. void initSubs(bool Left);
  599. void initTypes();
  600. void initItems(bool Left);
  601. std::vector<int> *getItemsIds(bool Left); //NULL if default
  602. void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const;
  603. void removeItems(const std::set<CTradeableItem *> &toRemove);
  604. void removeItem(CTradeableItem * t);
  605. void getEmptySlots(std::set<CTradeableItem *> &toRemove);
  606. void setMode(EMarketMode Mode); //mode setter
  607. void artifactSelected(CArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot
  608. virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0;
  609. virtual void selectionChanged(bool side) = 0; //true == left
  610. virtual Point selectionOffset(bool Left) const = 0;
  611. virtual std::string selectionSubtitle(bool Left) const = 0;
  612. virtual void garrisonChanged() = 0;
  613. virtual void artifactsChanged(bool left) = 0;
  614. };
  615. class CMarketplaceWindow : public CTradeWindow
  616. {
  617. bool printButtonFor(EMarketMode M) const;
  618. public:
  619. int r1, r2; //suggested amounts of traded resources
  620. bool madeTransaction; //if player made at least one transaction
  621. CTextBox *traderText;
  622. void setMax();
  623. void sliderMoved(int to);
  624. void makeDeal();
  625. void selectionChanged(bool side); //true == left
  626. CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode Mode = RESOURCE_RESOURCE); //c-tor
  627. ~CMarketplaceWindow(); //d-tor
  628. Point selectionOffset(bool Left) const;
  629. std::string selectionSubtitle(bool Left) const;
  630. void garrisonChanged(); //removes creatures with count 0 from the list (apparently whole stack has been sold)
  631. void artifactsChanged(bool left);
  632. void resourceChanged(int type, int val);
  633. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  634. void updateTraderText();
  635. };
  636. class CAltarWindow : public CTradeWindow
  637. {
  638. public:
  639. CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode); //c-tor
  640. void getExpValues();
  641. ~CAltarWindow(); //d-tor
  642. std::vector<int> sacrificedUnits, //[slot_nr] -> how many creatures from that slot will be sacrificed
  643. expPerUnit;
  644. AdventureMapButton *sacrificeAll, *sacrificeBackpack;
  645. CLabel *expToLevel, *expOnAltar;
  646. void selectionChanged(bool side); //true == left
  647. void SacrificeAll();
  648. void SacrificeBackpack();
  649. void putOnAltar(int backpackIndex);
  650. bool putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance *art);
  651. void makeDeal();
  652. void showAll(SDL_Surface * to);
  653. void blockTrade();
  654. void sliderMoved(int to);
  655. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  656. void mimicCres();
  657. Point selectionOffset(bool Left) const;
  658. std::string selectionSubtitle(bool Left) const;
  659. void garrisonChanged();
  660. void artifactsChanged(bool left);
  661. void calcTotalExp();
  662. void setExpToLevel();
  663. void updateRight(CTradeableItem *toUpdate);
  664. void artifactPicked();
  665. int firstFreeSlot();
  666. void moveFromSlotToAltar(int slotID, CTradeableItem* altarSlot, const CArtifactInstance *art);
  667. };
  668. class CSystemOptionsWindow : public CIntObject
  669. {
  670. private:
  671. SDL_Surface * background; //background of window
  672. AdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet
  673. CHighlightableButtonsGroup * heroMoveSpeed;
  674. CHighlightableButtonsGroup * mapScrollSpeed;
  675. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  676. public:
  677. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  678. ~CSystemOptionsWindow(); //d-tor
  679. //functions bound to buttons
  680. void bsavef(); //save game
  681. void bquitf(); //quit game
  682. void breturnf(); //return to game
  683. void bmainmenuf(); //return to main menu
  684. void pushSDLEvent(int type, int usercode);
  685. void activate();
  686. void deactivate();
  687. void show(SDL_Surface * to);
  688. };
  689. class CTavernWindow : public CIntObject
  690. {
  691. public:
  692. class HeroPortrait : public CIntObject
  693. {
  694. public:
  695. std::string hoverName;
  696. vstd::assigner<int,int> as;
  697. const CGHeroInstance *h;
  698. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  699. void clickLeft(tribool down, bool previousState);
  700. void clickRight(tribool down, bool previousState);
  701. void hover (bool on);
  702. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  703. void show(SDL_Surface * to);
  704. } *h1, *h2; //recruitable heroes
  705. CPicture *bg; //background
  706. CGStatusBar *bar; //tavern's internal status bar
  707. int selected;//0 (left) or 1 (right)
  708. int oldSelected;//0 (left) or 1 (right)
  709. AdventureMapButton *thiefGuild, *cancel, *recruit;
  710. const CGObjectInstance *tavernObj;
  711. CTavernWindow(const CGObjectInstance *TavernObj); //c-tor
  712. ~CTavernWindow(); //d-tor
  713. void recruitb();
  714. void close();
  715. void thievesguildb();
  716. void show(SDL_Surface * to);
  717. };
  718. class CInGameConsole : public CIntObject
  719. {
  720. private:
  721. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  722. boost::mutex texts_mx; // protects texts
  723. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  724. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  725. int defaultTimeout; //timeout for new texts (in ms)
  726. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  727. public:
  728. std::string enteredText;
  729. void activate();
  730. void deactivate();
  731. void show(SDL_Surface * to);
  732. void print(const std::string &txt);
  733. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  734. void startEnteringText();
  735. void endEnteringText(bool printEnteredText);
  736. void refreshEnteredText();
  737. CInGameConsole(); //c-tor
  738. };
  739. /// Shows a text by moving the mouse cursor over the object
  740. class HoverableArea: public virtual CIntObject
  741. {
  742. public:
  743. std::string hoverText;
  744. virtual void hover (bool on);
  745. HoverableArea();
  746. virtual ~HoverableArea();
  747. };
  748. /// Can interact on left and right mouse clicks, plus it shows a text when by hovering over it
  749. class LRClickableAreaWText: public HoverableArea
  750. {
  751. public:
  752. std::string text;
  753. LRClickableAreaWText();
  754. LRClickableAreaWText(const Rect &Pos, const std::string &HoverText = "", const std::string &ClickText = "");
  755. virtual ~LRClickableAreaWText();
  756. void init();
  757. virtual void clickLeft(tribool down, bool previousState);
  758. virtual void clickRight(tribool down, bool previousState);
  759. };
  760. /// Can interact on left and right mouse clicks
  761. class LRClickableAreaWTextComp: public LRClickableAreaWText
  762. {
  763. public:
  764. int baseType;
  765. int bonusValue, type;
  766. virtual void clickLeft(tribool down, bool previousState);
  767. virtual void clickRight(tribool down, bool previousState);
  768. LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), int BaseType = -1);
  769. SComponent * createComponent() const;
  770. };
  771. class MoraleLuckBox : public LRClickableAreaWTextComp
  772. {
  773. public:
  774. bool morale; //true if morale, false if luck
  775. bool small;
  776. void set(const IBonusBearer *node);
  777. void showAll(SDL_Surface * to);
  778. MoraleLuckBox(bool Morale, const Rect &r, bool Small=false);
  779. ~MoraleLuckBox();
  780. };
  781. /// Opens hero window by left-clicking on it
  782. class CHeroArea: public CIntObject
  783. {
  784. public:
  785. const CGHeroInstance * hero;
  786. CHeroArea(int x, int y, const CGHeroInstance * _hero);
  787. void clickLeft(tribool down, bool previousState);
  788. void clickRight(tribool down, bool previousState);
  789. void hover(bool on);
  790. void showAll(SDL_Surface * to);
  791. };
  792. /// Opens town screen by left-clicking on it
  793. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  794. {
  795. public:
  796. const CGTownInstance * town;
  797. void clickLeft(tribool down, bool previousState);
  798. void clickRight(tribool down, bool previousState);
  799. LRClickableAreaOpenTown();
  800. };
  801. /// Creature info window
  802. class CCreInfoWindow : public CIntObject
  803. {
  804. public:
  805. //bool active; //TODO: comment me
  806. int type;//0 - rclick popup; 1 - normal window
  807. CPicture *bitmap; //background
  808. std::string count; //creature count in text format
  809. boost::function<void()> dsm; //dismiss button callback
  810. CCreaturePic *anim; //related creature's animation
  811. const CCreature *c; //related creature
  812. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  813. MoraleLuckBox *luck, *morale;
  814. AdventureMapButton *dismiss, *upgrade, *ok;
  815. CCreInfoWindow(const CStackInstance &st, int Type = 0, boost::function<void()> Upg = 0, boost::function<void()> Dsm = 0, UpgradeInfo *ui = NULL); //c-tor
  816. CCreInfoWindow(const CStack &st, int Type = 0); //c-tor
  817. CCreInfoWindow(int Cid, int Type, int creatureCount); //c-tor
  818. void init(const CCreature *cre, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner, int creatureCount);
  819. void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false);
  820. ~CCreInfoWindow(); //d-tor
  821. void activate();
  822. void close();
  823. void clickRight(tribool down, bool previousState); //call-in
  824. void dismissF();
  825. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  826. void deactivate();
  827. void show(SDL_Surface * to);
  828. };
  829. /// Artifacts can be placed there. Gets shown at the hero window
  830. class CArtPlace: public LRClickableAreaWTextComp
  831. {
  832. public:
  833. int slotID; //0 head 1 shoulders 2 neck 3 right hand 4 left hand 5 torso 6 right ring 7 left ring 8 feet 9 misc. slot 1 10 misc. slot 2 11 misc. slot 3 12 misc. slot 4 13 ballista (war machine 1) 14 ammo cart (war machine 2) 15 first aid tent (war machine 3) 16 catapult 17 spell book 18 misc. slot 5 19+ backpack slots
  834. bool picked;
  835. bool marked;
  836. bool locked;
  837. CArtifactsOfHero * ourOwner;
  838. const CArtifactInstance * ourArt;
  839. CArtPlace(const CArtifactInstance * Art); //c-tor
  840. CArtPlace(Point position, const CArtifactInstance * Art = NULL); //c-tor
  841. void clickLeft(tribool down, bool previousState);
  842. void clickRight(tribool down, bool previousState);
  843. void select ();
  844. void deselect ();
  845. void activate();
  846. void deactivate();
  847. void showAll(SDL_Surface * to);
  848. bool fitsHere (const CArtifactInstance * art) const; //returns true if given artifact can be placed here
  849. void setMeAsDest(bool backpackAsVoid = true);
  850. void setArtifact(const CArtifactInstance *art);
  851. ~CArtPlace(); //d-tor
  852. };
  853. /// Contains artifacts of hero. Distincts which artifacts are worn or backpacked
  854. class CArtifactsOfHero : public CIntObject
  855. {
  856. const CGHeroInstance * curHero;
  857. 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
  858. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  859. int backpackPos; //number of first art visible in backpack (in hero's vector)
  860. public:
  861. struct SCommonPart
  862. {
  863. struct Artpos
  864. {
  865. int slotID;
  866. const CArtifactsOfHero * AOH;
  867. const CArtifactInstance *art;
  868. Artpos();
  869. void clear();
  870. void setTo(const CArtPlace *place, bool dontTakeBackpack);
  871. bool valid();
  872. bool operator==(const ArtifactLocation &al) const;
  873. } src, dst;
  874. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  875. void reset();
  876. } * 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
  877. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  878. AdventureMapButton * leftArtRoll, * rightArtRoll;
  879. bool allowedAssembling;
  880. 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
  881. boost::function<void(CArtPlace*)> highlightModeCallback; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function
  882. void realizeCurrentTransaction(); //calls callback with parameters stored in commonInfo
  883. void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst);
  884. void artifactRemoved(const ArtifactLocation &al);
  885. void artifactAssembled(const ArtifactLocation &al);
  886. void artifactDisassembled(const ArtifactLocation &al);
  887. CArtPlace *getArtPlace(int slot);
  888. void setHero(const CGHeroInstance * hero);
  889. const CGHeroInstance *getHero() const;
  890. void dispose(); //free resources not needed after closing windows and reset state
  891. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  892. void safeRedraw();
  893. void markPossibleSlots(const CArtifactInstance* art);
  894. void unmarkSlots(bool withRedraw = true); //unmarks slots in all visible AOHs
  895. void unmarkLocalSlots(bool withRedraw = true); //unmarks slots in that particular AOH
  896. void setSlotData (CArtPlace* artPlace, int slotID);
  897. void updateWornSlots (bool redrawParent = true);
  898. void updateSlot(int i);
  899. void eraseSlotData (CArtPlace* artPlace, int slotID);
  900. CArtifactsOfHero(const Point& position, bool createCommonPart = false);
  901. //Alternative constructor, used if custom artifacts positioning required (Kingdom interface)
  902. CArtifactsOfHero(std::vector<CArtPlace *> ArtWorn, std::vector<CArtPlace *> Backpack,
  903. AdventureMapButton *leftScroll, AdventureMapButton *rightScroll, bool createCommonPart = false);
  904. ~CArtifactsOfHero(); //d-tor
  905. void updateParentWindow();
  906. friend class CArtPlace;
  907. };
  908. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  909. class CGarrisonWindow : public CWindowWithGarrison
  910. {
  911. public:
  912. CPicture *bg; //background surface
  913. CLabel *title;
  914. AdventureMapButton *quit;
  915. void close();
  916. void showAll(SDL_Surface * to);
  917. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  918. ~CGarrisonWindow(); //d-tor
  919. };
  920. class CExchangeWindow : public CWindowWithGarrison, public CWindowWithArtifacts
  921. {
  922. CGStatusBar * ourBar; //internal statusbar
  923. SDL_Surface *bg; //background
  924. AdventureMapButton * quit, * questlogButton[2];
  925. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  926. MoraleLuckBox *morale[2], *luck[2];
  927. LRClickableAreaWText *speciality[2];
  928. LRClickableAreaWText *experience[2];
  929. LRClickableAreaWText *spellPoints[2];
  930. CHeroArea *portrait[2];
  931. public:
  932. const CGHeroInstance * heroInst[2];
  933. CArtifactsOfHero * artifs[2];
  934. void close();
  935. void activate();
  936. void deactivate();
  937. void show(SDL_Surface * to);
  938. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  939. void prepareBackground(); //prepares or redraws bg
  940. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  941. ~CExchangeWindow(); //d-tor
  942. };
  943. /// Here you can buy ships
  944. class CShipyardWindow : public CIntObject
  945. {
  946. public:
  947. CGStatusBar *bar;
  948. CPicture *bg; //background
  949. CPicture *bgWater;
  950. CLabel *title;
  951. CLabel *costLabel;
  952. CAnimImage *woodPic, *goldPic;
  953. CLabel *woodCost, *goldCost;
  954. CAnimImage *bgShip;
  955. AdventureMapButton *build, *quit;
  956. CGStatusBar * statusBar;
  957. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const boost::function<void()> &onBuy);
  958. };
  959. /// Puzzle screen which gets uncovered when you visit obilisks
  960. class CPuzzleWindow : public CIntObject
  961. {
  962. private:
  963. SDL_Surface * background;
  964. AdventureMapButton * quitb;
  965. CResDataBar * resdatabar;
  966. std::vector<std::pair<SDL_Surface *, const SPuzzleInfo *> > puzzlesToPullBack;
  967. ui8 animCount;
  968. public:
  969. void activate();
  970. void deactivate();
  971. void show(SDL_Surface * to);
  972. CPuzzleWindow(const int3 &grailPos, float discoveredRatio);
  973. ~CPuzzleWindow();
  974. };
  975. /// Creature transformer window
  976. class CTransformerWindow : public CIntObject
  977. {
  978. public:
  979. class CItem : public CIntObject
  980. {
  981. public:
  982. int id;//position of creature in hero army
  983. bool left;//position of the item
  984. int size; //size of creature stack
  985. CTransformerWindow * parent;
  986. void move();
  987. void showAll(SDL_Surface * to);
  988. void clickLeft(tribool down, bool previousState);
  989. CItem(CTransformerWindow * _parent, int _size, int _id);
  990. ~CItem();
  991. };
  992. const CArmedInstance *army;//object with army for transforming (hero or town)
  993. const CGHeroInstance *hero;//only if we have hero in town
  994. const CGTownInstance *town;//market, town garrison is used if hero == NULL
  995. CPicture *bg; //background
  996. std::vector<CItem*> items;
  997. AdventureMapButton *all, *convert, *cancel;
  998. CGStatusBar *bar;
  999. void showAll(SDL_Surface * to);
  1000. void makeDeal();
  1001. void addAll();
  1002. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); //c-tor
  1003. ~CTransformerWindow(); //d-tor
  1004. };
  1005. class CUniversityWindow : public CIntObject
  1006. {
  1007. class CItem : public CPicture
  1008. {
  1009. public:
  1010. int ID;//id of selected skill
  1011. CUniversityWindow * parent;
  1012. void showAll(SDL_Surface * to);
  1013. void clickLeft(tribool down, bool previousState);
  1014. void clickRight(tribool down, bool previousState);
  1015. void hover(bool on);
  1016. int state();//0=can't learn, 1=learned, 2=can learn
  1017. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  1018. };
  1019. public:
  1020. const CGHeroInstance *hero;
  1021. const IMarket * market;
  1022. CPicture * green, * yellow, * red;//colored bars near skills
  1023. CPicture *bg; //background
  1024. std::vector<CItem*> items;
  1025. AdventureMapButton *cancel;
  1026. CGStatusBar *bar;
  1027. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market); //c-tor
  1028. ~CUniversityWindow(); //d-tor
  1029. };
  1030. /// Confirmation window for University
  1031. class CUnivConfirmWindow : public CIntObject
  1032. {
  1033. public:
  1034. CUniversityWindow * parent;
  1035. CPicture * bg;
  1036. CGStatusBar *bar;
  1037. AdventureMapButton *confirm, *cancel;
  1038. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available); //c-tor
  1039. void makeDeal(int skill);
  1040. };
  1041. /// Hill fort is the building where you can upgrade units
  1042. class CHillFortWindow : public CWindowWithGarrison
  1043. {
  1044. public:
  1045. int slotsCount;//=7;
  1046. CGStatusBar * bar;
  1047. CDefEssential *resources;
  1048. CPicture *bg; //background surface
  1049. CHeroArea *heroPic;//clickable hero image
  1050. AdventureMapButton *quit,//closes window
  1051. *upgradeAll,//upgrade all creatures
  1052. *upgrade[7];//upgrade single creature
  1053. const CGObjectInstance * fort;
  1054. const CGHeroInstance * hero;
  1055. std::vector<int> currState;//current state of slot - to avoid calls to getState or updating buttons
  1056. std::vector<TResources> costs;// costs [slot ID] [resource ID] = resource count for upgrade
  1057. TResources totalSumm; // totalSum[resource ID] = value
  1058. CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object); //c-tor
  1059. ~CHillFortWindow(); //d-tor
  1060. void activate();
  1061. void showAll (SDL_Surface *to);
  1062. std::string getDefForSlot(int slot);//return def name for this slot
  1063. std::string getTextForSlot(int slot);//return hover text for this slot
  1064. void makeDeal(int slot);//-1 for upgrading all creatures
  1065. int getState(int slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
  1066. void updateGarrisons();//update buttons after garrison changes
  1067. };
  1068. class CThievesGuildWindow : public CIntObject
  1069. {
  1070. const CGObjectInstance * owner;
  1071. CGStatusBar * statusBar;
  1072. AdventureMapButton * exitb;
  1073. SDL_Surface * background;
  1074. CMinorResDataBar * resdatabar;
  1075. public:
  1076. void activate();
  1077. void show(SDL_Surface * to);
  1078. void bexitf();
  1079. CThievesGuildWindow(const CGObjectInstance * _owner);
  1080. ~CThievesGuildWindow();
  1081. };
  1082. CIntObject *createCreWindow(const CStack *s);
  1083. CIntObject *createCreWindow(int Cid, int Type, int creatureCount);
  1084. CIntObject *createCreWindow(const CStackInstance *s, int type, boost::function<void()> Upg = 0, boost::function<void()> Dsm = 0, UpgradeInfo *ui = NULL);
  1085. #endif //__GUICLASSES_H__