GUIClasses.h 43 KB

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