CPreGame.h 9.3 KB

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