CPreGame.h 7.7 KB

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