CPreGame.h 6.0 KB

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