CPreGame.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. InfoCard(EState Type);
  54. ~InfoCard();
  55. };
  56. class SelectionTab : public CIntObject
  57. {
  58. public:
  59. int positions; //how many entries (games/maps) can be shown
  60. CPicture *bg; //general bg image
  61. CSlider *slider;
  62. std::vector<CMapInfo> allItems;
  63. std::vector<CMapInfo*> curItems;
  64. size_t selectionPos;
  65. boost::function<void(CMapInfo *)> onSelect;
  66. ESortBy sortingBy;
  67. bool ascending;
  68. CDefHandler *format;
  69. void getFiles(std::vector<FileInfo> &out, const std::string &dirname, const std::string &ext);
  70. void parseMaps(std::vector<FileInfo> &files, int start = 0, int threads = 1);
  71. void parseGames(std::vector<FileInfo> &files);
  72. void filter(int size); //0 - all
  73. void select(int position); //position: <0 - positions> position on the screen
  74. int getPosition(int x, int y); //convert mouse coords to entry position; -1 means none
  75. void sliderMove(int slidPos);
  76. void sortBy(int criteria);
  77. void sort();
  78. void printMaps(SDL_Surface *to);
  79. void showAll(SDL_Surface * to);
  80. void clickLeft(tribool down, bool previousState);
  81. SelectionTab(EState Type, const boost::function<void(CMapInfo *)> &OnSelect);
  82. ~SelectionTab();
  83. };
  84. class OptionsTab : public CIntObject
  85. {
  86. public:
  87. enum SelType {TOWN, HERO, BONUS};
  88. struct SelectedBox : public CIntObject //img with current town/hero/bonus
  89. {
  90. SelType which;
  91. ui8 player; //serial nr
  92. void showAll(SDL_Surface * to);
  93. SelectedBox(SelType Which, ui8 Player);
  94. };
  95. struct PlayerOptionsEntry : public CIntObject
  96. {
  97. PlayerSettings &s;
  98. CPicture *bg;
  99. AdventureMapButton *btns[6]; //left and right for town, hero, bonus
  100. AdventureMapButton *flag;
  101. SelectedBox *town;
  102. SelectedBox *hero;
  103. SelectedBox *bonus;
  104. PlayerOptionsEntry(OptionsTab *owner, PlayerSettings &S);
  105. void showAll(SDL_Surface * to);
  106. };
  107. CPicture *bg;
  108. CSlider *turnDuration;
  109. std::set<int> usedHeroes;
  110. std::vector<PlayerOptionsEntry *> entries;
  111. void nextCastle(int player, int dir); //dir == -1 or +1
  112. void nextHero(int player, int dir); //dir == -1 or +1
  113. void nextBonus(int player, int dir); //dir == -1 or +1
  114. void setTurnLength(int npos);
  115. void flagPressed(int player);
  116. void changeSelection(const CMapInfo *to);
  117. OptionsTab(EState Type/*, StartInfo &Opts*/);
  118. ~OptionsTab();
  119. void showAll(SDL_Surface * to);
  120. int nextAllowedHero( int min, int max, int incl, int dir );
  121. bool canUseThisHero( int ID );
  122. };
  123. class CSelectionScreen : public CIntObject
  124. {
  125. public:
  126. CPicture *bg; //general bg image
  127. AdventureMapButton *start, *back;
  128. InfoCard *card;
  129. SelectionTab *sel;
  130. OptionsTab *opt;
  131. EState type; //new/save/load#Game
  132. const CMapInfo *current;
  133. StartInfo sInfo;
  134. CIntObject *curTab;
  135. CSelectionScreen(EState Type);
  136. ~CSelectionScreen();
  137. void toggleTab(CIntObject *tab);
  138. void changeSelection(const CMapInfo *to);
  139. void updateStartInfo(const CMapInfo * to);
  140. void startGame();
  141. void difficultyChange(int to);
  142. };
  143. class CGPreGame : public CIntObject
  144. {
  145. public:
  146. SDL_Surface *mainbg;
  147. CMenuScreen *scrs[3];
  148. SDL_Surface *nHero, *rHero, *nTown, *rTown; // none/random hero/town imgs
  149. CDefHandler *bonuses;
  150. CDefHandler *victory, *loss;
  151. CGPreGame();
  152. ~CGPreGame();
  153. void run();
  154. void openSel(EState type);
  155. void loadGraphics();
  156. void disposeGraphics();
  157. };
  158. extern CGPreGame *CGP;
  159. #endif // __CPREGAME_H__