CPreGame.h 5.8 KB

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