CPreGame.h 7.7 KB

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