| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | #ifndef __CPREGAME_H__
 | 
					
						
							|  |  |  | #define __CPREGAME_H__
 | 
					
						
							| 
									
										
										
										
											2009-05-20 10:08:56 +00:00
										 |  |  | #include "../global.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | #include <set>
 | 
					
						
							|  |  |  | #include <SDL.h>
 | 
					
						
							| 
									
										
										
										
											2009-05-20 10:08:56 +00:00
										 |  |  | #include "../StartInfo.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | #include "GUIBase.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-27 08:04:32 +00:00
										 |  |  | #include "FunctionList.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-15 14:03:31 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * CPreGame.h, part of VCMI engine | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Authors: listed in file AUTHORS in main folder | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * License: GNU General Public License v2.0 or later | 
					
						
							|  |  |  |  * Full text of license available in license.txt file, in main folder | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-30 23:25:17 +00:00
										 |  |  | struct CMusicHandler; | 
					
						
							| 
									
										
										
										
											2010-02-08 14:38:06 +00:00
										 |  |  | class CMapInfo; | 
					
						
							|  |  |  | class CMapHeader; | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | enum EState { //where are we?
 | 
					
						
							| 
									
										
										
										
											2010-02-08 14:38:06 +00:00
										 |  |  | 	mainMenu, newGame, loadGame, campaignMain, ScenarioList, saveGame, scenarioInfo | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-08 14:38:06 +00:00
										 |  |  | enum ESortBy{_playerAm, _size, _format, _name, _viccon, _loscon}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class mapSorter | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	ESortBy sortBy; | 
					
						
							|  |  |  | 	bool operator()(const CMapHeader *a, const CMapHeader *b);; | 
					
						
							|  |  |  | 	mapSorter(ESortBy es):sortBy(es){}; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-27 08:04:32 +00:00
										 |  |  | class CTextInput : public CIntObject | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	CPicture *bg; | 
					
						
							|  |  |  | 	std::string text; | 
					
						
							|  |  |  | 	CFunctionList<void(const std::string &)> cb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void setText(const std::string &nText, bool callCb = false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CTextInput(); | 
					
						
							|  |  |  | 	CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB); | 
					
						
							|  |  |  | 	~CTextInput(); | 
					
						
							|  |  |  | 	void showAll(SDL_Surface * to); | 
					
						
							|  |  |  | 	void clickLeft(tribool down, bool previousState); | 
					
						
							|  |  |  | 	void keyPressed(const SDL_KeyboardEvent & key); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | class CMenuScreen : public CIntObject | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	CPicture *bgAd; | 
					
						
							|  |  |  | 	AdventureMapButton *buttons[5]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CMenuScreen(EState which); | 
					
						
							|  |  |  | 	~CMenuScreen(); | 
					
						
							|  |  |  | 	void showAll(SDL_Surface * to); | 
					
						
							|  |  |  | 	void show(SDL_Surface * to); | 
					
						
							|  |  |  | 	void moveTo(CMenuScreen *next); | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct FileInfo | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-10 01:42:33 +00:00
										 |  |  | 	std::string name; // file name with full path and extension
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	std::time_t date; | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | class InfoCard : public CIntObject | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	CPicture *bg;  | 
					
						
							|  |  |  | 	EState type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CHighlightableButtonsGroup *difficulty; | 
					
						
							|  |  |  | 	CDefHandler *sizes, *sFlags;; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void changeSelection(const CMapInfo *to); | 
					
						
							|  |  |  | 	void showAll(SDL_Surface * to); | 
					
						
							| 
									
										
										
										
											2009-08-22 13:59:15 +00:00
										 |  |  | 	void clickRight(tribool down, bool previousState); | 
					
						
							|  |  |  | 	void showTeamsPopup(); | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	InfoCard(EState Type); | 
					
						
							|  |  |  | 	~InfoCard(); | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class SelectionTab : public CIntObject | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	int positions; //how many entries (games/maps) can be shown
 | 
					
						
							|  |  |  | 	CPicture *bg; //general bg image
 | 
					
						
							|  |  |  | 	CSlider *slider; | 
					
						
							|  |  |  | 	std::vector<CMapInfo> allItems; | 
					
						
							|  |  |  | 	std::vector<CMapInfo*> curItems; | 
					
						
							|  |  |  | 	size_t selectionPos; | 
					
						
							|  |  |  | 	boost::function<void(CMapInfo *)> onSelect; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ESortBy sortingBy; | 
					
						
							|  |  |  | 	bool ascending; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CDefHandler *format; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-27 08:04:32 +00:00
										 |  |  | 	CTextInput *txt; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	void getFiles(std::vector<FileInfo> &out, const std::string &dirname, const std::string &ext); | 
					
						
							|  |  |  | 	void parseMaps(std::vector<FileInfo> &files, int start = 0, int threads = 1); | 
					
						
							|  |  |  | 	void parseGames(std::vector<FileInfo> &files); | 
					
						
							| 
									
										
										
										
											2009-08-27 08:04:32 +00:00
										 |  |  | 	void filter(int size, bool selectFirst = false); //0 - all
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	void select(int position); //position: <0 - positions>  position on the screen
 | 
					
						
							| 
									
										
										
										
											2009-08-27 08:04:32 +00:00
										 |  |  | 	void selectAbs(int position); //position: absolute position in curItems vector
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	int getPosition(int x, int y); //convert mouse coords to entry position; -1 means none
 | 
					
						
							|  |  |  | 	void sliderMove(int slidPos); | 
					
						
							|  |  |  | 	void sortBy(int criteria); | 
					
						
							|  |  |  | 	void sort(); | 
					
						
							|  |  |  | 	void printMaps(SDL_Surface *to); | 
					
						
							| 
									
										
										
										
											2009-08-27 08:04:32 +00:00
										 |  |  | 	int getLine(); | 
					
						
							|  |  |  | 	void selectFName(const std::string &fname); | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void showAll(SDL_Surface * to); | 
					
						
							|  |  |  | 	void clickLeft(tribool down, bool previousState); | 
					
						
							| 
									
										
										
										
											2009-08-23 18:01:08 +00:00
										 |  |  | 	void wheelScrolled(bool down, bool in); | 
					
						
							|  |  |  | 	void keyPressed(const SDL_KeyboardEvent & key); | 
					
						
							|  |  |  | 	void onDoubleClick(); | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	SelectionTab(EState Type, const boost::function<void(CMapInfo *)> &OnSelect); | 
					
						
							|  |  |  | 	~SelectionTab(); | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class OptionsTab : public CIntObject | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	enum SelType {TOWN, HERO, BONUS}; | 
					
						
							|  |  |  | 	struct SelectedBox : public CIntObject //img with current town/hero/bonus
 | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 		SelType which; | 
					
						
							|  |  |  | 		ui8 player; //serial nr
 | 
					
						
							| 
									
										
										
										
											2009-08-22 13:59:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		SDL_Surface *getImg() const; | 
					
						
							|  |  |  | 		const std::string *getText() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 		SelectedBox(SelType Which, ui8 Player); | 
					
						
							| 
									
										
										
										
											2009-08-22 13:59:15 +00:00
										 |  |  | 		void showAll(SDL_Surface * to); | 
					
						
							|  |  |  | 		void clickRight(tribool down, bool previousState); | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	struct PlayerOptionsEntry : public CIntObject | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 		PlayerSettings &s; | 
					
						
							|  |  |  | 		CPicture *bg; | 
					
						
							|  |  |  | 		AdventureMapButton *btns[6]; //left and right for town, hero, bonus
 | 
					
						
							|  |  |  | 		AdventureMapButton *flag; | 
					
						
							|  |  |  | 		SelectedBox *town; | 
					
						
							|  |  |  | 		SelectedBox *hero; | 
					
						
							|  |  |  | 		SelectedBox *bonus; | 
					
						
							| 
									
										
										
										
											2009-08-18 08:22:56 +00:00
										 |  |  | 		bool fixedHero; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		PlayerOptionsEntry(OptionsTab *owner, PlayerSettings &S); | 
					
						
							| 
									
										
										
										
											2009-08-18 08:22:56 +00:00
										 |  |  | 		void selectButtons(bool onlyHero = true); //hides unavailable buttons
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 		void showAll(SDL_Surface * to); | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2009-08-27 08:04:32 +00:00
										 |  |  | 	EState type; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	CPicture *bg; | 
					
						
							|  |  |  | 	CSlider *turnDuration; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | 	std::set<int> usedHeroes; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	std::vector<PlayerOptionsEntry *> entries; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void nextCastle(int player, int dir); //dir == -1 or +1
 | 
					
						
							|  |  |  | 	void nextHero(int player, int dir); //dir == -1 or +1
 | 
					
						
							|  |  |  | 	void nextBonus(int player, int dir); //dir == -1 or +1
 | 
					
						
							|  |  |  | 	void setTurnLength(int npos); | 
					
						
							|  |  |  | 	void flagPressed(int player); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-27 08:04:32 +00:00
										 |  |  | 	void changeSelection(const CMapHeader *to); | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	OptionsTab(EState Type/*, StartInfo &Opts*/); | 
					
						
							|  |  |  | 	~OptionsTab(); | 
					
						
							|  |  |  | 	void showAll(SDL_Surface * to); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int nextAllowedHero( int min, int max, int incl, int dir ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool canUseThisHero( int ID ); | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class CSelectionScreen : public CIntObject | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	CPicture *bg; //general bg image
 | 
					
						
							|  |  |  | 	AdventureMapButton *start, *back; | 
					
						
							|  |  |  | 	InfoCard *card; | 
					
						
							|  |  |  | 	SelectionTab *sel; | 
					
						
							|  |  |  | 	OptionsTab *opt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EState type; //new/save/load#Game
 | 
					
						
							|  |  |  | 	const CMapInfo *current; | 
					
						
							|  |  |  | 	StartInfo sInfo; | 
					
						
							|  |  |  | 	CIntObject *curTab; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CSelectionScreen(EState Type); | 
					
						
							|  |  |  | 	~CSelectionScreen(); | 
					
						
							|  |  |  | 	void toggleTab(CIntObject *tab); | 
					
						
							|  |  |  | 	void changeSelection(const CMapInfo *to); | 
					
						
							|  |  |  | 	void updateStartInfo(const CMapInfo * to); | 
					
						
							|  |  |  | 	void startGame(); | 
					
						
							|  |  |  | 	void difficultyChange(int to); | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-27 08:04:32 +00:00
										 |  |  | class CScenarioInfo : public CIntObject | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	AdventureMapButton *back; | 
					
						
							|  |  |  | 	InfoCard *card; | 
					
						
							|  |  |  | 	OptionsTab *opt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CScenarioInfo(const CMapHeader *mapInfo, const StartInfo *startInfo); | 
					
						
							|  |  |  | 	~CScenarioInfo(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-28 04:08:24 +00:00
										 |  |  | class CGPreGame : public CIntObject, public IUpdateable | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	SDL_Surface *mainbg; | 
					
						
							| 
									
										
										
										
											2010-02-08 14:38:06 +00:00
										 |  |  | 	CMenuScreen *scrs[4]; | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	SDL_Surface *nHero, *rHero, *nTown, *rTown; // none/random hero/town imgs
 | 
					
						
							|  |  |  | 	CDefHandler *bonuses; | 
					
						
							|  |  |  | 	CDefHandler *victory, *loss; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CGPreGame(); | 
					
						
							|  |  |  | 	~CGPreGame(); | 
					
						
							| 
									
										
										
										
											2009-12-28 04:08:24 +00:00
										 |  |  | 	void update(); | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | 	void run(); | 
					
						
							|  |  |  | 	void openSel(EState type); | 
					
						
							|  |  |  | 	void loadGraphics(); | 
					
						
							|  |  |  | 	void disposeGraphics(); | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 08:50:31 +00:00
										 |  |  | extern CGPreGame *CGP; | 
					
						
							| 
									
										
										
										
											2009-04-16 11:14:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif // __CPREGAME_H__
 |