CPreGame.h 9.0 KB

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