GUIClasses.h 42 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. std::vector<CAnimImage* > effects;
  290. CSlider *slider;
  291. //CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly);
  292. CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly);
  293. void showAll(SDL_Surface * to); //shows statusbar (with current text)
  294. void setTxt(const std::string &Txt);
  295. void setBounds(int limitW, int limitH);
  296. void recalculateLines(const std::string &Txt);
  297. void sliderMoved(int to);
  298. };
  299. /// Status bar which is shown at the bottom of the in-game screens
  300. class CGStatusBar
  301. : public CLabel, public IStatusBar
  302. {
  303. void init();
  304. public:
  305. IStatusBar *oldStatusBar;
  306. //statusbar interface overloads
  307. void print(const std::string & Text); //prints text and refreshes statusbar
  308. void clear();//clears statusbar and refreshes
  309. std::string getCurrent(); //returns currently displayed text
  310. void show(SDL_Surface * to); //shows statusbar (with current text)
  311. CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly, const std::string &Text = "");
  312. 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
  313. CGStatusBar(int x, int y, std::string name, int maxw=-1);
  314. ~CGStatusBar();
  315. void calcOffset();
  316. };
  317. /// UIElement which can get input focus
  318. class CFocusable
  319. : public virtual CIntObject
  320. {
  321. public:
  322. bool focus; //only one focusable control can have focus at one moment
  323. void giveFocus(); //captures focus
  324. void moveFocus(); //moves focus to next active control (may be used for tab switching)
  325. static std::list<CFocusable*> focusables; //all existing objs
  326. static CFocusable *inputWithFocus; //who has focus now
  327. CFocusable();
  328. ~CFocusable();
  329. };
  330. /// Text input box where players can enter text
  331. class CTextInput
  332. : public CLabel, public CFocusable
  333. {
  334. public:
  335. CFunctionList<void(const std::string &)> cb;
  336. void setText(const std::string &nText, bool callCb = false);
  337. CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB);
  338. CTextInput(const Rect &Pos, SDL_Surface *srf = NULL);
  339. ~CTextInput();
  340. void showAll(SDL_Surface * to);
  341. void clickLeft(tribool down, bool previousState);
  342. void keyPressed(const SDL_KeyboardEvent & key);
  343. };
  344. /// Listbox UI Element
  345. class CList : public CIntObject
  346. {
  347. public:
  348. SDL_Surface * bg; //background bitmap
  349. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  350. SDL_Surface *empty, *selection;
  351. SDL_Rect arrupp, arrdop; //positions of arrows
  352. int posw, posh; //position width/height
  353. int selected, //id of selected position, <0 if none
  354. from;
  355. const int SIZE; //size of list
  356. tribool pressed; //true=up; false=down; indeterminate=none
  357. CList(int Size = 5); //c-tor
  358. void clickLeft(tribool down, bool previousState);
  359. void activate();
  360. void deactivate();
  361. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  362. virtual void genList()=0;
  363. virtual void select(int which)=0;
  364. virtual void draw(SDL_Surface * to)=0;
  365. virtual int size() = 0; //how many elements do we have
  366. void fixPos(); //scrolls list, so the selection will be visible
  367. };
  368. /// List of heroes which is shown at the right of the adventure map screen
  369. class CHeroList
  370. : public CList
  371. {
  372. public:
  373. CDefHandler *mobile, *mana; //mana and movement indicators
  374. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  375. CHeroList(int Size); //c-tor
  376. int getPosOfHero(const CGHeroInstance* h); //hero's position on list
  377. void genList();
  378. void select(int which); //call-in
  379. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  380. void clickLeft(tribool down, bool previousState); //call-in
  381. void clickRight(tribool down, bool previousState); //call-in
  382. void hover (bool on); //call-in
  383. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  384. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  385. void updateMove(const CGHeroInstance* which); //draws move points bar
  386. void draw(SDL_Surface * to);
  387. void show(SDL_Surface * to);
  388. void showAll(SDL_Surface * to);
  389. void init();
  390. int size(); //how many elements do we have
  391. };
  392. /// List of towns which is shown at the right of the adventure map screen
  393. class CTownList
  394. : public CList
  395. {
  396. public:
  397. boost::function<void()> fun; //function called on selection change
  398. int posporx,pospory;
  399. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  400. ~CTownList(); //d-tor
  401. void genList();
  402. void select(int which); //call-in
  403. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  404. void clickLeft(tribool down, bool previousState); //call-in
  405. void clickRight(tribool down, bool previousState); //call-in
  406. void hover (bool on); //call-in
  407. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  408. void draw(SDL_Surface * to);
  409. void show(SDL_Surface * to);
  410. void showAll(SDL_Surface * to);
  411. int size(); //how many elements do we have
  412. };
  413. /// draws picture with creature on background, use Animated=true to get animation
  414. class CCreaturePic : public CIntObject
  415. {
  416. private:
  417. CPicture *bg; //background
  418. CCreatureAnim *anim; //displayed animation
  419. public:
  420. CCreaturePic(int x, int y, const CCreature *cre, bool Big=true, bool Animated=true); //c-tor
  421. ~CCreaturePic(); //d-tor
  422. };
  423. /// Recruitment window where you can recruit creatures
  424. class CRecruitmentWindow : public CIntObject
  425. {
  426. public:
  427. static const int SPACE_BETWEEN = 18;
  428. static const int CREATURE_WIDTH = 102;
  429. static const int TOTAL_CREATURE_WIDTH = SPACE_BETWEEN + CREATURE_WIDTH;
  430. struct creinfo
  431. {
  432. SDL_Rect pos;
  433. CCreaturePic *pic; //creature's animation
  434. int ID, amount; //creature ID and available amount
  435. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  436. };
  437. std::vector<int> amounts; //how many creatures we can afford
  438. std::vector<creinfo> creatures; //recruitable creatures
  439. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  440. CSlider *slider; //for selecting amount
  441. AdventureMapButton *max, *buy, *cancel;
  442. CPicture *bitmap; //background
  443. CGStatusBar *bar;
  444. int which; //which creature is active
  445. const CGDwelling *dwelling;
  446. int level;
  447. const CArmedInstance *dst;
  448. void close();
  449. void Max();
  450. void Buy();
  451. void Cancel();
  452. void sliderMoved(int to);
  453. void clickLeft(tribool down, bool previousState);
  454. void clickRight(tribool down, bool previousState);
  455. void showAll(SDL_Surface * to);
  456. void initCres();
  457. 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
  458. ~CRecruitmentWindow(); //d-tor
  459. };
  460. /// Split window where creatures can be splitted up into two single unit stacks
  461. class CSplitWindow : public CIntObject
  462. {
  463. public:
  464. CGarrisonInt *gar;
  465. CSlider *slider;
  466. CCreaturePic *animLeft, *animRight; //creature's animation
  467. AdventureMapButton *ok, *cancel;
  468. SDL_Surface *bitmap; //background
  469. int a1, a2, c; //TODO: comment me
  470. bool which; //which creature is selected
  471. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  472. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  473. ~CSplitWindow(); //d-tor
  474. void activate();
  475. void split();
  476. void close();
  477. void deactivate();
  478. void show(SDL_Surface * to);
  479. void clickLeft(tribool down, bool previousState); //call-in
  480. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  481. void sliderMoved(int to);
  482. };
  483. /// Raised up level windowe where you can select one out of two skills
  484. class CLevelWindow : public CIntObject
  485. {
  486. public:
  487. int heroPortrait;
  488. SDL_Surface *bitmap; //background
  489. std::vector<CSelectableComponent *> comps; //skills to select
  490. AdventureMapButton *ok;
  491. boost::function<void(ui32)> cb;
  492. void close();
  493. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  494. ~CLevelWindow(); //d-tor
  495. void activate();
  496. void deactivate();
  497. void selectionChanged(unsigned to);
  498. void show(SDL_Surface * to);
  499. };
  500. /// Resource bar like that at the bottom of the adventure map screen
  501. class CMinorResDataBar : public CIntObject
  502. {
  503. public:
  504. SDL_Surface *bg; //background bitmap
  505. void show(SDL_Surface * to);
  506. void showAll(SDL_Surface * to);
  507. CMinorResDataBar(); //c-tor
  508. ~CMinorResDataBar(); //d-tor
  509. };
  510. /// Town portal, castle gate window
  511. class CObjectListWindow : public CIntObject
  512. {
  513. public:
  514. boost::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
  515. std::string title,descr;//text for title and description
  516. CPicture *bg; //background
  517. CSlider *slider;
  518. CPicture *titleImage;//title image (castle gate\town portal picture)
  519. AdventureMapButton *ok, *exit;
  520. std::vector<Rect> areas;//areas for each visible item
  521. std::vector<int> items;//id of all items present in list
  522. int selected;//currently selected item
  523. int length;//size of list (=9)
  524. bool init;//true = initialization completed
  525. /// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
  526. CObjectListWindow(const std::vector<int> &_items, CPicture * titlePic, std::string _title, std::string _descr,
  527. boost::function<void(int)> Callback, int initState=-1); //c-tor
  528. ~CObjectListWindow(); //d-tor
  529. void elementSelected();//call callback and exit
  530. void moveList(int which);//called when slider moves
  531. void clickLeft(tribool down, bool previousState); //call-in
  532. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  533. void show(SDL_Surface * to);
  534. void showAll(SDL_Surface * to);
  535. };
  536. class CArtifactHolder : public virtual CIntObject
  537. {
  538. public:
  539. CArtifactHolder();
  540. virtual void artifactRemoved(const ArtifactLocation &artLoc)=0;
  541. virtual void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc)=0;
  542. virtual void artifactDisassembled(const ArtifactLocation &artLoc)=0;
  543. virtual void artifactAssembled(const ArtifactLocation &artLoc)=0;
  544. };
  545. class CWindowWithArtifacts : public CArtifactHolder
  546. {
  547. public:
  548. std::vector<CArtifactsOfHero *> artSets;
  549. void artifactRemoved(const ArtifactLocation &artLoc);
  550. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc);
  551. void artifactDisassembled(const ArtifactLocation &artLoc);
  552. void artifactAssembled(const ArtifactLocation &artLoc);
  553. };
  554. class CTradeWindow : public CWindowWithArtifacts //base for markets and altar of sacrifice
  555. {
  556. public:
  557. enum EType
  558. {
  559. RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
  560. };
  561. class CTradeableItem : public CIntObject
  562. {
  563. const CArtifactInstance *hlp; //holds ptr to artifact instance id type artifact
  564. public:
  565. EType type;
  566. int id;
  567. int serial;
  568. bool left;
  569. std::string subtitle; //empty if default
  570. const CArtifactInstance *getArtInstance() const;
  571. void setArtInstance(const CArtifactInstance *art);
  572. // const CArtifact *getArt() const;
  573. // void setArt(const CArtifact *artT) const;
  574. CFunctionList<void()> callback;
  575. bool downSelection;
  576. void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to);
  577. void clickRight(tribool down, bool previousState);
  578. void hover (bool on);
  579. void showAll(SDL_Surface * to);
  580. void clickLeft(tribool down, bool previousState);
  581. SDL_Surface *getSurface();
  582. std::string getName(int number = -1) const;
  583. CTradeableItem(EType Type, int ID, bool Left, int Serial);
  584. };
  585. const IMarket *market;
  586. const CGHeroInstance *hero;
  587. CPicture *bg; //background
  588. CArtifactsOfHero *arts;
  589. //all indexes: 1 = left, 0 = right
  590. std::vector<CTradeableItem*> items[2];
  591. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  592. EType itemsType[2];
  593. EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  594. AdventureMapButton *ok, *max, *deal;
  595. CSlider *slider; //for choosing amount to be exchanged
  596. bool readyToTrade;
  597. CTradeWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode); //c
  598. void showAll(SDL_Surface * to);
  599. void initSubs(bool Left);
  600. void initTypes();
  601. void initItems(bool Left);
  602. std::vector<int> *getItemsIds(bool Left); //NULL if default
  603. void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const;
  604. void removeItems(const std::set<CTradeableItem *> &toRemove);
  605. void removeItem(CTradeableItem * t);
  606. void getEmptySlots(std::set<CTradeableItem *> &toRemove);
  607. void setMode(EMarketMode Mode); //mode setter
  608. void artifactSelected(CArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot
  609. virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0;
  610. virtual void selectionChanged(bool side) = 0; //true == left
  611. virtual Point selectionOffset(bool Left) const = 0;
  612. virtual std::string selectionSubtitle(bool Left) const = 0;
  613. virtual void garrisonChanged() = 0;
  614. virtual void artifactsChanged(bool left) = 0;
  615. };
  616. class CMarketplaceWindow : public CTradeWindow
  617. {
  618. bool printButtonFor(EMarketMode M) const;
  619. public:
  620. int r1, r2; //suggested amounts of traded resources
  621. bool madeTransaction; //if player made at least one transaction
  622. CTextBox *traderText;
  623. void setMax();
  624. void sliderMoved(int to);
  625. void makeDeal();
  626. void selectionChanged(bool side); //true == left
  627. CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode Mode = RESOURCE_RESOURCE); //c-tor
  628. ~CMarketplaceWindow(); //d-tor
  629. Point selectionOffset(bool Left) const;
  630. std::string selectionSubtitle(bool Left) const;
  631. void garrisonChanged(); //removes creatures with count 0 from the list (apparently whole stack has been sold)
  632. void artifactsChanged(bool left);
  633. void resourceChanged(int type, int val);
  634. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  635. void updateTraderText();
  636. };
  637. class CAltarWindow : public CTradeWindow
  638. {
  639. public:
  640. CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode); //c-tor
  641. void getExpValues();
  642. ~CAltarWindow(); //d-tor
  643. std::vector<int> sacrificedUnits, //[slot_nr] -> how many creatures from that slot will be sacrificed
  644. expPerUnit;
  645. AdventureMapButton *sacrificeAll, *sacrificeBackpack;
  646. CLabel *expToLevel, *expOnAltar;
  647. void selectionChanged(bool side); //true == left
  648. void SacrificeAll();
  649. void SacrificeBackpack();
  650. void putOnAltar(int backpackIndex);
  651. bool putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance *art);
  652. void makeDeal();
  653. void showAll(SDL_Surface * to);
  654. void blockTrade();
  655. void sliderMoved(int to);
  656. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  657. void mimicCres();
  658. Point selectionOffset(bool Left) const;
  659. std::string selectionSubtitle(bool Left) const;
  660. void garrisonChanged();
  661. void artifactsChanged(bool left);
  662. void calcTotalExp();
  663. void setExpToLevel();
  664. void updateRight(CTradeableItem *toUpdate);
  665. void artifactPicked();
  666. int firstFreeSlot();
  667. void moveFromSlotToAltar(int slotID, CTradeableItem* altarSlot, const CArtifactInstance *art);
  668. };
  669. class CSystemOptionsWindow : public CIntObject
  670. {
  671. private:
  672. SDL_Surface * background; //background of window
  673. AdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet
  674. CHighlightableButtonsGroup * heroMoveSpeed;
  675. CHighlightableButtonsGroup * mapScrollSpeed;
  676. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  677. public:
  678. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  679. ~CSystemOptionsWindow(); //d-tor
  680. //functions bound to buttons
  681. void bsavef(); //save game
  682. void bquitf(); //quit game
  683. void breturnf(); //return to game
  684. void bmainmenuf(); //return to main menu
  685. void pushSDLEvent(int type, int usercode);
  686. void activate();
  687. void deactivate();
  688. void show(SDL_Surface * to);
  689. };
  690. class CTavernWindow : public CIntObject
  691. {
  692. public:
  693. class HeroPortrait : public CIntObject
  694. {
  695. public:
  696. std::string hoverName;
  697. vstd::assigner<int,int> as;
  698. const CGHeroInstance *h;
  699. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  700. void clickLeft(tribool down, bool previousState);
  701. void clickRight(tribool down, bool previousState);
  702. void hover (bool on);
  703. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  704. void show(SDL_Surface * to);
  705. } *h1, *h2; //recruitable heroes
  706. CPicture *bg; //background
  707. CGStatusBar *bar; //tavern's internal status bar
  708. int selected;//0 (left) or 1 (right)
  709. int oldSelected;//0 (left) or 1 (right)
  710. AdventureMapButton *thiefGuild, *cancel, *recruit;
  711. const CGObjectInstance *tavernObj;
  712. CTavernWindow(const CGObjectInstance *TavernObj); //c-tor
  713. ~CTavernWindow(); //d-tor
  714. void recruitb();
  715. void close();
  716. void thievesguildb();
  717. void show(SDL_Surface * to);
  718. };
  719. class CInGameConsole : public CIntObject
  720. {
  721. private:
  722. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  723. boost::mutex texts_mx; // protects texts
  724. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  725. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  726. int defaultTimeout; //timeout for new texts (in ms)
  727. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  728. public:
  729. std::string enteredText;
  730. void activate();
  731. void deactivate();
  732. void show(SDL_Surface * to);
  733. void print(const std::string &txt);
  734. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  735. void startEnteringText();
  736. void endEnteringText(bool printEnteredText);
  737. void refreshEnteredText();
  738. CInGameConsole(); //c-tor
  739. };
  740. /// Shows a text by moving the mouse cursor over the object
  741. class HoverableArea: public virtual CIntObject
  742. {
  743. public:
  744. std::string hoverText;
  745. virtual void hover (bool on);
  746. HoverableArea();
  747. virtual ~HoverableArea();
  748. };
  749. /// Can interact on left and right mouse clicks, plus it shows a text when by hovering over it
  750. class LRClickableAreaWText: public HoverableArea
  751. {
  752. public:
  753. std::string text;
  754. LRClickableAreaWText();
  755. LRClickableAreaWText(const Rect &Pos, const std::string &HoverText = "", const std::string &ClickText = "");
  756. virtual ~LRClickableAreaWText();
  757. void init();
  758. virtual void clickLeft(tribool down, bool previousState);
  759. virtual void clickRight(tribool down, bool previousState);
  760. };
  761. /// Can interact on left and right mouse clicks
  762. class LRClickableAreaWTextComp: public LRClickableAreaWText
  763. {
  764. public:
  765. int baseType;
  766. int bonusValue, type;
  767. virtual void clickLeft(tribool down, bool previousState);
  768. virtual void clickRight(tribool down, bool previousState);
  769. LRClickableAreaWTextComp(const Rect &Pos = Rect(0,0,0,0), int BaseType = -1);
  770. SComponent * createComponent() const;
  771. };
  772. class MoraleLuckBox : public LRClickableAreaWTextComp
  773. {
  774. public:
  775. bool morale; //true if morale, false if luck
  776. bool small;
  777. void set(const IBonusBearer *node);
  778. void showAll(SDL_Surface * to);
  779. MoraleLuckBox(bool Morale, const Rect &r, bool Small=false);
  780. ~MoraleLuckBox();
  781. };
  782. /// Opens hero window by left-clicking on it
  783. class CHeroArea: public CIntObject
  784. {
  785. public:
  786. const CGHeroInstance * hero;
  787. CHeroArea(int x, int y, const CGHeroInstance * _hero);
  788. void clickLeft(tribool down, bool previousState);
  789. void clickRight(tribool down, bool previousState);
  790. void hover(bool on);
  791. void showAll(SDL_Surface * to);
  792. };
  793. /// Opens town screen by left-clicking on it
  794. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  795. {
  796. public:
  797. const CGTownInstance * town;
  798. void clickLeft(tribool down, bool previousState);
  799. void clickRight(tribool down, bool previousState);
  800. LRClickableAreaOpenTown();
  801. };
  802. /// Creature info window
  803. class CCreInfoWindow : public CIntObject
  804. {
  805. public:
  806. CPicture *background;
  807. CLabel *creatureCount;
  808. CLabel *creatureName;
  809. CLabel *abilityText;
  810. CCreaturePic *animation;
  811. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  812. std::vector<CAnimImage * > effects;
  813. std::map<size_t, std::pair<CLabel*, CLabel* > > infoTexts;
  814. MoraleLuckBox *luck, *morale;
  815. AdventureMapButton *dismiss, *upgrade, *ok;
  816. CCreInfoWindow(const CStackInstance &st, bool LClicked, boost::function<void()> Upg = 0, boost::function<void()> Dsm = 0, UpgradeInfo *ui = NULL);
  817. CCreInfoWindow(const CStack &st, bool LClicked = 0);
  818. CCreInfoWindow(int Cid, bool LClicked, int creatureCount);
  819. ~CCreInfoWindow();
  820. void init(const CCreature *cre, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner, int creatureCount, bool LClicked);
  821. void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false);
  822. void clickRight(tribool down, bool previousState);
  823. void close();
  824. void show(SDL_Surface * to);
  825. };
  826. /// Artifacts can be placed there. Gets shown at the hero window
  827. class CArtPlace: public LRClickableAreaWTextComp
  828. {
  829. public:
  830. int slotID; //Arts::EPOS enum + backpack starting from Arts::BACKPACK_START
  831. bool picked;
  832. bool marked;
  833. bool locked;
  834. CArtifactsOfHero * ourOwner;
  835. const CArtifactInstance * ourArt;
  836. CArtPlace(const CArtifactInstance * Art); //c-tor
  837. CArtPlace(Point position, const CArtifactInstance * Art = NULL); //c-tor
  838. void clickLeft(tribool down, bool previousState);
  839. void clickRight(tribool down, bool previousState);
  840. void select ();
  841. void deselect ();
  842. void activate();
  843. void deactivate();
  844. void showAll(SDL_Surface * to);
  845. bool fitsHere (const CArtifactInstance * art) const; //returns true if given artifact can be placed here
  846. void setMeAsDest(bool backpackAsVoid = true);
  847. void setArtifact(const CArtifactInstance *art);
  848. ~CArtPlace(); //d-tor
  849. };
  850. /// Contains artifacts of hero. Distincts which artifacts are worn or backpacked
  851. class CArtifactsOfHero : public CIntObject
  852. {
  853. const CGHeroInstance * curHero;
  854. 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
  855. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  856. int backpackPos; //number of first art visible in backpack (in hero's vector)
  857. public:
  858. struct SCommonPart
  859. {
  860. struct Artpos
  861. {
  862. int slotID;
  863. const CArtifactsOfHero * AOH;
  864. const CArtifactInstance *art;
  865. Artpos();
  866. void clear();
  867. void setTo(const CArtPlace *place, bool dontTakeBackpack);
  868. bool valid();
  869. bool operator==(const ArtifactLocation &al) const;
  870. } src, dst;
  871. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  872. void reset();
  873. } * 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
  874. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  875. AdventureMapButton * leftArtRoll, * rightArtRoll;
  876. bool allowedAssembling;
  877. 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
  878. boost::function<void(CArtPlace*)> highlightModeCallback; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function
  879. void realizeCurrentTransaction(); //calls callback with parameters stored in commonInfo
  880. void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst);
  881. void artifactRemoved(const ArtifactLocation &al);
  882. void artifactAssembled(const ArtifactLocation &al);
  883. void artifactDisassembled(const ArtifactLocation &al);
  884. CArtPlace *getArtPlace(int slot);
  885. void setHero(const CGHeroInstance * hero);
  886. const CGHeroInstance *getHero() const;
  887. void dispose(); //free resources not needed after closing windows and reset state
  888. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  889. void safeRedraw();
  890. void markPossibleSlots(const CArtifactInstance* art);
  891. void unmarkSlots(bool withRedraw = true); //unmarks slots in all visible AOHs
  892. void unmarkLocalSlots(bool withRedraw = true); //unmarks slots in that particular AOH
  893. void setSlotData (CArtPlace* artPlace, int slotID);
  894. void updateWornSlots (bool redrawParent = true);
  895. void updateSlot(int i);
  896. void eraseSlotData (CArtPlace* artPlace, int slotID);
  897. CArtifactsOfHero(const Point& position, bool createCommonPart = false);
  898. //Alternative constructor, used if custom artifacts positioning required (Kingdom interface)
  899. CArtifactsOfHero(std::vector<CArtPlace *> ArtWorn, std::vector<CArtPlace *> Backpack,
  900. AdventureMapButton *leftScroll, AdventureMapButton *rightScroll, bool createCommonPart = false);
  901. ~CArtifactsOfHero(); //d-tor
  902. void updateParentWindow();
  903. friend class CArtPlace;
  904. };
  905. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  906. class CGarrisonWindow : public CWindowWithGarrison
  907. {
  908. public:
  909. CPicture *bg; //background surface
  910. CLabel *title;
  911. AdventureMapButton *quit;
  912. void close();
  913. void showAll(SDL_Surface * to);
  914. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  915. ~CGarrisonWindow(); //d-tor
  916. };
  917. class CExchangeWindow : public CWindowWithGarrison, public CWindowWithArtifacts
  918. {
  919. CGStatusBar * ourBar; //internal statusbar
  920. SDL_Surface *bg; //background
  921. AdventureMapButton * quit, * questlogButton[2];
  922. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  923. MoraleLuckBox *morale[2], *luck[2];
  924. LRClickableAreaWText *speciality[2];
  925. LRClickableAreaWText *experience[2];
  926. LRClickableAreaWText *spellPoints[2];
  927. CHeroArea *portrait[2];
  928. public:
  929. const CGHeroInstance * heroInst[2];
  930. CArtifactsOfHero * artifs[2];
  931. void close();
  932. void activate();
  933. void deactivate();
  934. void show(SDL_Surface * to);
  935. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  936. void prepareBackground(); //prepares or redraws bg
  937. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  938. ~CExchangeWindow(); //d-tor
  939. };
  940. /// Here you can buy ships
  941. class CShipyardWindow : public CIntObject
  942. {
  943. public:
  944. CGStatusBar *bar;
  945. CPicture *bg; //background
  946. CPicture *bgWater;
  947. CLabel *title;
  948. CLabel *costLabel;
  949. CAnimImage *woodPic, *goldPic;
  950. CLabel *woodCost, *goldCost;
  951. CAnimImage *bgShip;
  952. AdventureMapButton *build, *quit;
  953. CGStatusBar * statusBar;
  954. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const boost::function<void()> &onBuy);
  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__