CPreGame.h 4.9 KB

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