CPreGame.h 7.7 KB

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