CPreGame.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 "GUIBase.h"
  8. #include "FunctionList.h"
  9. /*
  10. * CPreGame.h, part of VCMI engine
  11. *
  12. * Authors: listed in file AUTHORS in main folder
  13. *
  14. * License: GNU General Public License v2.0 or later
  15. * Full text of license available in license.txt file, in main folder
  16. *
  17. */
  18. struct CMusicHandler;
  19. class CMapHeader;
  20. class CCampaignHeader;
  21. class CTextInput;
  22. class CCampaign;
  23. class CGStatusBar;
  24. class CMapInfo
  25. {
  26. public:
  27. CMapHeader * mapHeader; //may be NULL if campaign
  28. CCampaignHeader * campaignHeader; //may be NULL if scenario
  29. StartInfo *scenarioOpts; //options with which scenario has been started (used only with saved games)
  30. std::string filename;
  31. bool lodCmpgn; //tells if this campaign is located in Lod file
  32. std::string date;
  33. int playerAmnt, //players in map
  34. humenPlayers; //players ALLOWED to be controlled by human
  35. int actualHumanPlayers; // >1 if multiplayer game
  36. CMapInfo(bool map = true);
  37. ~CMapInfo();
  38. //CMapInfo(const std::string &fname, const unsigned char *map);
  39. void mapInit(const std::string &fname, const unsigned char *map);
  40. void campaignInit();
  41. void countPlayers();
  42. };
  43. enum ESortBy{_playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps}; //_numOfMaps is for campaigns
  44. class mapSorter
  45. {
  46. public:
  47. ESortBy sortBy;
  48. bool operator()(const CMapInfo *aaa, const CMapInfo *bbb);
  49. mapSorter(ESortBy es):sortBy(es){};
  50. };
  51. class CMenuScreen : public CIntObject
  52. {
  53. public:
  54. enum EState { //where are we?
  55. mainMenu, newGame, loadGame, campaignMain, saveGame, scenarioInfo, campaignList
  56. };
  57. CPicture *bgAd;
  58. AdventureMapButton *buttons[5];
  59. CMenuScreen(EState which);
  60. ~CMenuScreen();
  61. void showAll(SDL_Surface * to);
  62. void show(SDL_Surface * to);
  63. void moveTo(CMenuScreen *next);
  64. };
  65. struct FileInfo
  66. {
  67. std::string name; // file name with full path and extension
  68. std::time_t date;
  69. bool inLod; //tells if this file is located in Lod
  70. };
  71. class InfoCard : public CIntObject
  72. {
  73. CPicture *bg;
  74. public:
  75. CMenuScreen::EState type;
  76. CHighlightableButtonsGroup *difficulty;
  77. CDefHandler *sizes, *sFlags;;
  78. void changeSelection(const CMapInfo *to);
  79. void showAll(SDL_Surface * to);
  80. void clickRight(tribool down, bool previousState);
  81. void showTeamsPopup();
  82. InfoCard(CMenuScreen::EState Type);
  83. ~InfoCard();
  84. };
  85. class SelectionTab : public CIntObject
  86. {
  87. private:
  88. CDefHandler *format; //map size
  89. void parseMaps(std::vector<FileInfo> &files, int start = 0, int threads = 1);
  90. void parseGames(std::vector<FileInfo> &files, bool multi);
  91. void parseCampaigns( std::vector<FileInfo> & files );
  92. void getFiles(std::vector<FileInfo> &out, const std::string &dirname, const std::string &ext);
  93. CMenuScreen::EState tabType;
  94. public:
  95. int positions; //how many entries (games/maps) can be shown
  96. CPicture *bg; //general bg image
  97. CSlider *slider;
  98. std::vector<CMapInfo> allItems;
  99. std::vector<CMapInfo*> curItems;
  100. size_t selectionPos;
  101. boost::function<void(CMapInfo *)> onSelect;
  102. ESortBy sortingBy;
  103. bool ascending;
  104. CTextInput *txt;
  105. void filter(int size, bool selectFirst = false); //0 - all
  106. void select(int position); //position: <0 - positions> position on the screen
  107. void selectAbs(int position); //position: absolute position in curItems vector
  108. int getPosition(int x, int y); //convert mouse coords to entry position; -1 means none
  109. void sliderMove(int slidPos);
  110. void sortBy(int criteria);
  111. void sort();
  112. void printMaps(SDL_Surface *to);
  113. int getLine();
  114. void selectFName(const std::string &fname);
  115. void showAll(SDL_Surface * to);
  116. void clickLeft(tribool down, bool previousState);
  117. void wheelScrolled(bool down, bool in);
  118. void keyPressed(const SDL_KeyboardEvent & key);
  119. void onDoubleClick();
  120. SelectionTab(CMenuScreen::EState Type, const boost::function<void(CMapInfo *)> &OnSelect, bool MultiPlayer=false);
  121. ~SelectionTab();
  122. };
  123. class OptionsTab : public CIntObject
  124. {
  125. CPicture *bg;
  126. public:
  127. enum SelType {TOWN, HERO, BONUS};
  128. struct SelectedBox : public CIntObject //img with current town/hero/bonus
  129. {
  130. SelType which;
  131. ui8 player; //serial nr
  132. SDL_Surface *getImg() const;
  133. const std::string *getText() const;
  134. SelectedBox(SelType Which, ui8 Player);
  135. void showAll(SDL_Surface * to);
  136. void clickRight(tribool down, bool previousState);
  137. };
  138. struct PlayerOptionsEntry : public CIntObject
  139. {
  140. PlayerSettings &s;
  141. CPicture *bg;
  142. AdventureMapButton *btns[6]; //left and right for town, hero, bonus
  143. AdventureMapButton *flag;
  144. SelectedBox *town;
  145. SelectedBox *hero;
  146. SelectedBox *bonus;
  147. bool fixedHero;
  148. PlayerOptionsEntry(OptionsTab *owner, PlayerSettings &S);
  149. void selectButtons(bool onlyHero = true); //hides unavailable buttons
  150. void showAll(SDL_Surface * to);
  151. };
  152. CMenuScreen::EState type;
  153. CSlider *turnDuration;
  154. std::set<int> usedHeroes;
  155. std::vector<PlayerOptionsEntry *> entries;
  156. void nextCastle(int player, int dir); //dir == -1 or +1
  157. void nextHero(int player, int dir); //dir == -1 or +1
  158. void nextBonus(int player, int dir); //dir == -1 or +1
  159. void setTurnLength(int npos);
  160. void flagPressed(int player);
  161. void changeSelection(const CMapHeader *to);
  162. OptionsTab(CMenuScreen::EState Type/*, StartInfo &Opts*/);
  163. ~OptionsTab();
  164. void showAll(SDL_Surface * to);
  165. int nextAllowedHero( int min, int max, int incl, int dir );
  166. bool canUseThisHero( int ID );
  167. };
  168. class CSelectionScreen : public CIntObject
  169. {
  170. CPicture *bg; //general bg image
  171. InfoCard *card;
  172. OptionsTab *opt;
  173. public:
  174. AdventureMapButton *start, *back;
  175. SelectionTab *sel;
  176. CMenuScreen::EState type; //new/save/load#Game
  177. const CMapInfo *current;
  178. StartInfo sInfo;
  179. CIntObject *curTab;
  180. bool multiPlayer;
  181. CSelectionScreen(CMenuScreen::EState Type, bool MultiPlayer = false);
  182. ~CSelectionScreen();
  183. void toggleTab(CIntObject *tab);
  184. void changeSelection(const CMapInfo *to);
  185. static void updateStartInfo( const CMapInfo * to, StartInfo & sInfo, const CMapHeader * mapHeader );
  186. void startCampaign();
  187. void startGame();
  188. void difficultyChange(int to);
  189. };
  190. class CScenarioInfo : public CIntObject
  191. {
  192. public:
  193. AdventureMapButton *back;
  194. InfoCard *card;
  195. OptionsTab *opt;
  196. CScenarioInfo(const CMapHeader *mapHeader, const StartInfo *startInfo, const CMapInfo * makeItCurrent=NULL);
  197. ~CScenarioInfo();
  198. };
  199. class CMultiMode : public CIntObject
  200. {
  201. public:
  202. CPicture *bg;
  203. CTextInput *txt;
  204. AdventureMapButton *btns[7]; //0 - hotseat, 6 - cancel
  205. CGStatusBar *bar;
  206. CMultiMode();
  207. void openHotseat();
  208. };
  209. class CHotSeatPlayers : public CIntObject
  210. {
  211. public:
  212. CPicture *bg;
  213. CTextInput *txt[8];
  214. AdventureMapButton *ok, *cancel;
  215. CGStatusBar *bar;
  216. CHotSeatPlayers(const std::string &firstPlayer);
  217. void enterSelectionScreen();
  218. };
  219. class CBonusSelection : public CIntObject
  220. {
  221. SDL_Surface * background;
  222. AdventureMapButton * startB, * backB;
  223. struct SCampPositions
  224. {
  225. std::string campPrefix;
  226. int colorSuffixLength;
  227. struct SRegionDesc
  228. {
  229. std::string infix;
  230. int xpos, ypos;
  231. };
  232. std::vector<SRegionDesc> regions;
  233. };
  234. std::vector<SCampPositions> campDescriptions;
  235. class CRegion : public CIntObject
  236. {
  237. CBonusSelection * owner;
  238. SDL_Surface * graphics[3]; //[0] - not selected, [1] - selected, [2] - striped
  239. bool accessible; //false if region should be striped
  240. bool selectable; //true if region should be selectable
  241. int myNumber; //number of region
  242. public:
  243. std::string rclickText;
  244. CRegion(CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber);
  245. ~CRegion();
  246. void clickLeft(tribool down, bool previousState);
  247. void clickRight(tribool down, bool previousState);
  248. void show(SDL_Surface * to);
  249. };
  250. std::vector<CRegion *> regions;
  251. CRegion * highlightedRegion;
  252. void loadPositionsOfGraphics();
  253. const CCampaign * ourCampaign;
  254. CMapHeader *ourHeader;
  255. CDefHandler *sizes; //icons of map sizes
  256. int whichMap;
  257. //bonus selection
  258. void updateBonusSelection();
  259. void selectBonus(int id);
  260. CHighlightableButtonsGroup * bonuses;
  261. public:
  262. StartInfo sInfo;
  263. void selectMap(int whichOne);
  264. CBonusSelection(const CCampaign * _ourCampaign, int _whichMap);
  265. ~CBonusSelection();
  266. void showAll(SDL_Surface * to);
  267. void show(SDL_Surface * to);
  268. void goBack();
  269. void startMap();
  270. };
  271. class CGPreGame : public CIntObject, public IUpdateable
  272. {
  273. public:
  274. SDL_Surface *mainbg;
  275. CMenuScreen *scrs[4];
  276. SDL_Surface *nHero, *rHero, *nTown, *rTown; // none/random hero/town imgs
  277. CDefHandler *bonuses;
  278. CDefHandler *victory, *loss;
  279. CGPreGame();
  280. ~CGPreGame();
  281. void update();
  282. void run();
  283. void openSel(CMenuScreen::EState type, bool multi = false);
  284. void loadGraphics();
  285. void disposeGraphics();
  286. };
  287. extern CGPreGame *CGP;
  288. #endif // __CPREGAME_H__