CPreGame.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #ifndef CPREGAME_H
  2. #define CPREGAME_H
  3. #include "global.h"
  4. #include <set>
  5. #include "SDL.h"
  6. #include "StartInfo.h"
  7. #include "hch/CPreGameTextHandler.h"
  8. #include "CMessage.h"
  9. #include "map.h"
  10. #include "hch/CMusicHandler.h"
  11. #include <boost/function.hpp>
  12. #include <boost/bind.hpp>
  13. class CPreGame;
  14. class CDefHandler;
  15. extern CPreGame * CPG;
  16. typedef void(CPreGame::*ttt)();
  17. class CGroup;
  18. class CPoinGroup ;
  19. class IntSelBut;
  20. struct HighButton
  21. {
  22. int ID;
  23. int type;
  24. SDL_Rect pos;
  25. CDefHandler* imgs;
  26. int state;
  27. HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1);
  28. HighButton();
  29. bool selectable, selected;
  30. bool highlightable, highlighted;
  31. virtual void show();
  32. virtual void press(bool down=true);
  33. virtual void hover(bool on=true)=0;
  34. virtual void select(bool on=true)=0;
  35. };
  36. struct Button: public HighButton
  37. {
  38. CGroup *ourGroup;
  39. Button( SDL_Rect Pos, boost::function<void()> Fun,CDefHandler* Imgs, bool Sel=false, CGroup* gr=NULL, int id=-1);
  40. Button();
  41. boost::function<void()> fun;
  42. virtual void hover(bool on=true);
  43. virtual void select(bool on=true);
  44. };
  45. struct SetrButton: public Button
  46. {
  47. int key, * poin;
  48. virtual void press(bool down=true);
  49. SetrButton();
  50. };
  51. class Slider
  52. {
  53. public:
  54. bool vertical; // false means horizontal
  55. SDL_Rect pos; // position
  56. Button up, down, //or left/right
  57. slider;
  58. int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once
  59. int whereAreWe; // first displayed thing
  60. bool moving;
  61. boost::function<void(int)> fun;
  62. void clickDown(int x, int y, bool bzgl=true);
  63. void clickUp(int x, int y, bool bzgl=true);
  64. void mMove(int x, int y, bool bzgl=true);
  65. void moveUp();
  66. void moveDown();
  67. void deactivate();
  68. void activate();
  69. Slider(int x, int y, int h, int amnt, int cap, bool ver);
  70. void updateSlid();
  71. void handleIt(SDL_Event sev);
  72. };
  73. struct IntBut: public Button
  74. {
  75. public:
  76. int key;
  77. int * what;
  78. IntBut();
  79. void set();
  80. };
  81. class CGroup
  82. {
  83. public:
  84. Button * selected;
  85. int type; // 1=sinsel
  86. CGroup():selected(NULL),type(0){};
  87. };
  88. class CPoinGroup :public CGroup
  89. {
  90. public:
  91. int * gdzie; //where (po polsku, bo by by³o s³owo kluczowe :/)
  92. void setYour(IntSelBut * your);
  93. };
  94. struct IntSelBut: public Button
  95. {
  96. public:
  97. CPoinGroup * ourPoinGroup;
  98. int key;
  99. IntSelBut(){};
  100. IntSelBut( SDL_Rect Pos, boost::function<void()> Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1);
  101. void select(bool on=true);
  102. };
  103. class PreGameTab
  104. {
  105. public:
  106. bool showed;
  107. virtual void init()=0;
  108. virtual void show()=0;
  109. virtual void hide()=0;
  110. PreGameTab();
  111. };
  112. class RanSel : public PreGameTab
  113. {
  114. Button horcpl[9], horcte[9], conpl[9], conte[8], water[4], monster[4], //last is random
  115. size[4], twoLevel, showRand;
  116. CGroup *Ghorcpl, *Ghorcte, *Gconpl, *Gconte, *Gwater, *Gmonster, *Gsize;
  117. };
  118. class Options : public PreGameTab
  119. {
  120. bool inited;
  121. struct OptionSwitch:public HighButton
  122. {
  123. void hover(bool on=true){};
  124. void select(bool on=true){};
  125. OptionSwitch( SDL_Rect Pos, CDefHandler* Imgs, bool Left, int Which)
  126. :HighButton(Pos,Imgs,false,7),left(Left),which(Which)
  127. {selectable=false;highlightable=false;}
  128. void press(bool down=true);
  129. bool left;
  130. int playerID;
  131. int serialID;
  132. int which; //-1=castle;0=hero;1=bonus
  133. };
  134. struct PlayerFlag:public HighButton
  135. {
  136. int color;
  137. PlayerFlag(SDL_Rect Pos, CDefHandler* Imgs, int Color)
  138. :HighButton(Pos,Imgs,false,7),color(Color)
  139. {selectable=false;highlightable=true;}
  140. void hover(bool on=true);
  141. void press(bool down=true);
  142. void select(bool on=true){};
  143. };
  144. struct PlayerOptions
  145. {
  146. PlayerOptions(int serial, int player);
  147. Ecolor color;
  148. PlayerFlag flag;
  149. //SDL_Surface * bg;
  150. OptionSwitch Cleft, Cright, Hleft, Hright, Bleft, Bright;
  151. int nr;
  152. };
  153. public:
  154. std::set<int> usedHeroes;
  155. Slider * turnLength;
  156. SDL_Surface * bg,
  157. * rHero, * rCastle, * nHero, * nCastle;
  158. std::vector<SDL_Surface*> bgs;
  159. std::vector<CDefHandler*> flags;
  160. CDefHandler //* castles, * heroes, * bonus,
  161. * left, * right,
  162. * bonuses;
  163. std::vector<PlayerOptions*> poptions;
  164. void show();
  165. void hide();
  166. void init();
  167. void showIcon (int what, int nr, bool abs); //what: -1=castle, 0=hero, 1=bonus, 2=all; abs=true -> nr is absolute
  168. bool canUseThisHero(int ID);
  169. int nextAllowedHero(int min, int max, int incl, int dir); //incl 0 - wlacznie; incl 1 - wylacznie; min-max - zakres szukania
  170. Options(){inited=showed=false;};
  171. ~Options();
  172. };
  173. class MapSel : public PreGameTab
  174. {
  175. public:
  176. ESortBy sortBy;
  177. SDL_Surface * bg;
  178. int selected; //selected map
  179. CDefHandler * Dtypes, * Dvic;
  180. CDefHandler *Dsizes, * Dloss,
  181. * sFlags;
  182. std::vector<Mapa*> scenList;
  183. std::vector<SDL_Surface*> scenImgs;
  184. //int current;
  185. std::vector<CMapInfo> ourMaps;
  186. IntBut small, medium, large, xlarge, all;
  187. SetrButton nrplayer, mapsize, type, name, viccon, loscon;
  188. Slider *slid, *descslid;
  189. int sizeFilter;
  190. int whichWL(int nr);
  191. int countWL();
  192. void show();
  193. void hide();
  194. void init();
  195. std::string gdiff(std::string ss);
  196. void printMaps(int from,int to=18, int at=0, bool abs=false);
  197. void select(int which, bool updateMapsList=true, bool forceSettingsUpdate=false);
  198. void moveByOne(bool up);
  199. void printSelectedInfo();
  200. void printFlags();
  201. void processMaps(std::vector<std::string> &pliczkiTemp, int &index);
  202. MapSel();
  203. ~MapSel();
  204. };
  205. class ScenSel
  206. {
  207. public:
  208. bool listShowed;
  209. //RanSel ransel;
  210. MapSel mapsel;
  211. SDL_Surface * background, *scenInf, *scenList, *randMap, *options ;
  212. Button bScens, bOptions, bRandom, bBegin, bBack;
  213. IntSelBut bEasy, bNormal, bHard, bExpert, bImpossible;
  214. Button * pressed;
  215. CPoinGroup * difficulty;
  216. std::vector<Mapa> maps;
  217. int selectedDiff;
  218. void initRanSel();
  219. void showRanSel();
  220. void hideRanSel();
  221. void genScenList();
  222. ~ScenSel(){delete difficulty;};
  223. } ;
  224. class CPreGame
  225. {
  226. public:
  227. std::string playerName;
  228. int playerColor;
  229. HighButton * highlighted;
  230. PreGameTab* currentTab;
  231. StartInfo ret;
  232. bool run;
  233. bool first; //hasn't we showed the scensel
  234. std::vector<Slider *> interested;
  235. CMusicHandler * mush;
  236. std::vector<HighButton *> btns;
  237. CPreGameTextHandler * preth ;
  238. SDL_Rect * currentMessage;
  239. SDL_Surface * behindCurMes;
  240. CDefHandler *ok, *cancel;
  241. enum EState { //where are we?
  242. mainMenu, newGame, loadGame, ScenarioList
  243. } state;
  244. struct menuItems {
  245. SDL_Surface * background, *bgAd;
  246. CDefHandler *newGame, *loadGame, *highScores,*credits, *quit;
  247. SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit;
  248. ttt fNewGame, fLoadGame, fHighScores, fCredits, fQuit;
  249. int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit
  250. } * ourMainMenu, * ourNewMenu;
  251. ScenSel * ourScenSel;
  252. Options * ourOptions;
  253. std::string map; //selected map
  254. CPreGame(); //c-tor
  255. std::string buttonText(int which);
  256. menuItems * currentItems();
  257. void(CPreGame::*handleOther)(SDL_Event&);
  258. void scenHandleEv(SDL_Event& sEvent);
  259. void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;};
  260. void quitAskBox();
  261. void quit(){exit(0);};
  262. void initScenSel();
  263. void showScenSel();
  264. void showScenList();
  265. void initOptions();
  266. void showOptions();
  267. void initNewMenu();
  268. void showNewMenu();
  269. void showMainMenu();
  270. StartInfo runLoop(); // runs mainloop of PreGame
  271. void initMainMenu(); //loads components for main menu
  272. void highlightButton(int which, int on); //highlights one from 5 main menu buttons
  273. void showCenBox (std::string data); //
  274. void showAskBox (std::string data, void(*f1)(),void(*f2)());
  275. void hideBox ();
  276. void printRating();
  277. void printMapsFrom(int from);
  278. void setTurnLength(int on);
  279. void sortMaps();
  280. };
  281. #endif //CPREGAME_H