CPreGame.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 CMapInfo
  23. {
  24. public:
  25. CMapHeader * mapHeader; //may be NULL if campaign
  26. CCampaignHeader * campaignHeader; //may be NULL if scenario
  27. ui8 seldiff; //selected difficulty (only in saved games)
  28. std::string filename;
  29. std::string date;
  30. int playerAmnt, humenPlayers;
  31. CMapInfo(bool map = true);
  32. ~CMapInfo();
  33. //CMapInfo(const std::string &fname, const unsigned char *map);
  34. void mapInit(const std::string &fname, const unsigned char *map);
  35. void campaignInit();
  36. void countPlayers();
  37. };
  38. enum ESortBy{_playerAm, _size, _format, _name, _viccon, _loscon};
  39. class mapSorter
  40. {
  41. public:
  42. ESortBy sortBy;
  43. bool operator()(const CMapInfo *aaa, const CMapInfo *bbb);
  44. mapSorter(ESortBy es):sortBy(es){};
  45. };
  46. class CMenuScreen : public CIntObject
  47. {
  48. public:
  49. enum EState { //where are we?
  50. mainMenu, newGame, loadGame, campaignMain, ScenarioList, saveGame, scenarioInfo, campaignList
  51. };
  52. CPicture *bgAd;
  53. AdventureMapButton *buttons[5];
  54. CMenuScreen(EState which);
  55. ~CMenuScreen();
  56. void showAll(SDL_Surface * to);
  57. void show(SDL_Surface * to);
  58. void moveTo(CMenuScreen *next);
  59. };
  60. struct FileInfo
  61. {
  62. std::string name; // file name with full path and extension
  63. std::time_t date;
  64. };
  65. class InfoCard : public CIntObject
  66. {
  67. public:
  68. CPicture *bg;
  69. CMenuScreen::EState type;
  70. CHighlightableButtonsGroup *difficulty;
  71. CDefHandler *sizes, *sFlags;;
  72. void changeSelection(const CMapInfo *to);
  73. void showAll(SDL_Surface * to);
  74. void clickRight(tribool down, bool previousState);
  75. void showTeamsPopup();
  76. InfoCard(CMenuScreen::EState Type);
  77. ~InfoCard();
  78. };
  79. class SelectionTab : public CIntObject
  80. {
  81. private:
  82. CDefHandler *format; //map size
  83. void parseMaps(std::vector<FileInfo> &files, int start = 0, int threads = 1);
  84. void parseGames(std::vector<FileInfo> &files);
  85. void parseCampaigns( std::vector<FileInfo> & files );
  86. void getFiles(std::vector<FileInfo> &out, const std::string &dirname, const std::string &ext);
  87. CMenuScreen::EState tabType;
  88. public:
  89. int positions; //how many entries (games/maps) can be shown
  90. CPicture *bg; //general bg image
  91. CSlider *slider;
  92. std::vector<CMapInfo> allItems;
  93. std::vector<CMapInfo*> curItems;
  94. size_t selectionPos;
  95. boost::function<void(CMapInfo *)> onSelect;
  96. ESortBy sortingBy;
  97. bool ascending;
  98. CTextInput *txt;
  99. void filter(int size, bool selectFirst = false); //0 - all
  100. void select(int position); //position: <0 - positions> position on the screen
  101. void selectAbs(int position); //position: absolute position in curItems vector
  102. int getPosition(int x, int y); //convert mouse coords to entry position; -1 means none
  103. void sliderMove(int slidPos);
  104. void sortBy(int criteria);
  105. void sort();
  106. void printMaps(SDL_Surface *to);
  107. int getLine();
  108. void selectFName(const std::string &fname);
  109. void showAll(SDL_Surface * to);
  110. void clickLeft(tribool down, bool previousState);
  111. void wheelScrolled(bool down, bool in);
  112. void keyPressed(const SDL_KeyboardEvent & key);
  113. void onDoubleClick();
  114. SelectionTab(CMenuScreen::EState Type, const boost::function<void(CMapInfo *)> &OnSelect);
  115. ~SelectionTab();
  116. };
  117. class OptionsTab : public CIntObject
  118. {
  119. public:
  120. enum SelType {TOWN, HERO, BONUS};
  121. struct SelectedBox : public CIntObject //img with current town/hero/bonus
  122. {
  123. SelType which;
  124. ui8 player; //serial nr
  125. SDL_Surface *getImg() const;
  126. const std::string *getText() const;
  127. SelectedBox(SelType Which, ui8 Player);
  128. void showAll(SDL_Surface * to);
  129. void clickRight(tribool down, bool previousState);
  130. };
  131. struct PlayerOptionsEntry : public CIntObject
  132. {
  133. PlayerSettings &s;
  134. CPicture *bg;
  135. AdventureMapButton *btns[6]; //left and right for town, hero, bonus
  136. AdventureMapButton *flag;
  137. SelectedBox *town;
  138. SelectedBox *hero;
  139. SelectedBox *bonus;
  140. bool fixedHero;
  141. PlayerOptionsEntry(OptionsTab *owner, PlayerSettings &S);
  142. void selectButtons(bool onlyHero = true); //hides unavailable buttons
  143. void showAll(SDL_Surface * to);
  144. };
  145. CMenuScreen::EState type;
  146. CPicture *bg;
  147. CSlider *turnDuration;
  148. std::set<int> usedHeroes;
  149. std::vector<PlayerOptionsEntry *> entries;
  150. void nextCastle(int player, int dir); //dir == -1 or +1
  151. void nextHero(int player, int dir); //dir == -1 or +1
  152. void nextBonus(int player, int dir); //dir == -1 or +1
  153. void setTurnLength(int npos);
  154. void flagPressed(int player);
  155. void changeSelection(const CMapHeader *to);
  156. OptionsTab(CMenuScreen::EState Type/*, StartInfo &Opts*/);
  157. ~OptionsTab();
  158. void showAll(SDL_Surface * to);
  159. int nextAllowedHero( int min, int max, int incl, int dir );
  160. bool canUseThisHero( int ID );
  161. };
  162. class CSelectionScreen : public CIntObject
  163. {
  164. public:
  165. CPicture *bg; //general bg image
  166. AdventureMapButton *start, *back;
  167. InfoCard *card;
  168. SelectionTab *sel;
  169. OptionsTab *opt;
  170. CMenuScreen::EState type; //new/save/load#Game
  171. const CMapInfo *current;
  172. StartInfo sInfo;
  173. CIntObject *curTab;
  174. CSelectionScreen(CMenuScreen::EState Type);
  175. ~CSelectionScreen();
  176. void toggleTab(CIntObject *tab);
  177. void changeSelection(const CMapInfo *to);
  178. void updateStartInfo(const CMapInfo * to);
  179. void startGame();
  180. void difficultyChange(int to);
  181. };
  182. class CScenarioInfo : public CIntObject
  183. {
  184. public:
  185. AdventureMapButton *back;
  186. InfoCard *card;
  187. OptionsTab *opt;
  188. CScenarioInfo(const CMapHeader *mapHeader, const StartInfo *startInfo, const CMapInfo * makeItCurrent=NULL);
  189. ~CScenarioInfo();
  190. };
  191. class CMultiMode : public CIntObject
  192. {
  193. public:
  194. CPicture *bg;
  195. CTextInput *txt;
  196. AdventureMapButton *btns[7]; //0 - hotseat, 6 - cancel
  197. CMultiMode();
  198. void openHotseat();
  199. };
  200. class CHotSeatPlayers : public CIntObject
  201. {
  202. public:
  203. CPicture *bg;
  204. CTextInput *txt[8];
  205. AdventureMapButton *ok, *cancel;
  206. CHotSeatPlayers(const std::string &firstPlayer);
  207. };
  208. class CGPreGame : public CIntObject, public IUpdateable
  209. {
  210. public:
  211. SDL_Surface *mainbg;
  212. CMenuScreen *scrs[4];
  213. SDL_Surface *nHero, *rHero, *nTown, *rTown; // none/random hero/town imgs
  214. CDefHandler *bonuses;
  215. CDefHandler *victory, *loss;
  216. CGPreGame();
  217. ~CGPreGame();
  218. void update();
  219. void run();
  220. void openSel(CMenuScreen::EState type);
  221. void loadGraphics();
  222. void disposeGraphics();
  223. };
  224. extern CGPreGame *CGP;
  225. #endif // __CPREGAME_H__