GUIClasses.h 41 KB

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