GUIClasses.h 42 KB

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