GUIClasses.h 43 KB

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