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