Browse Source

* a bit of custom campaign selection screen

mateuszb 15 years ago
parent
commit
40d50aaaa1
8 changed files with 457 additions and 320 deletions
  1. 1 1
      client/CAdvmapInterface.cpp
  2. 407 243
      client/CPreGame.cpp
  3. 39 18
      client/CPreGame.h
  4. 1 1
      client/GUIClasses.cpp
  5. 2 2
      hch/CCampaignHandler.cpp
  6. 7 7
      hch/CCampaignHandler.h
  7. 0 35
      lib/map.cpp
  8. 0 13
      lib/map.h

+ 1 - 1
client/CAdvmapInterface.cpp

@@ -1813,7 +1813,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 		return;
 	case SDLK_s: 
 		if(isActive())
-			GH.pushInt(new CSelectionScreen(saveGame));
+			GH.pushInt(new CSelectionScreen(CMenuScreen::saveGame));
 		return;
 	case SDLK_SPACE: //space - try to revisit current object with selected hero
 		{

File diff suppressed because it is too large
+ 407 - 243
client/CPreGame.cpp


+ 39 - 18
client/CPreGame.h

@@ -18,11 +18,24 @@
  */
 
 struct CMusicHandler;
-class CMapInfo;
 class CMapHeader;
+class CCampaignHeader;
 
-enum EState { //where are we?
-	mainMenu, newGame, loadGame, campaignMain, ScenarioList, saveGame, scenarioInfo
+class CMapInfo
+{
+public:
+	CMapHeader * mapHeader; //may be NULL if campaign
+	CCampaignHeader * campaignHeader; //may be NULL if scenario
+	ui8 seldiff; //selected difficulty (only in saved games)
+	std::string filename;
+	std::string date;
+	int playerAmnt, humenPlayers;
+	CMapInfo(bool map = true);
+	~CMapInfo();
+	//CMapInfo(const std::string &fname, const unsigned char *map);
+	void mapInit(const std::string &fname, const unsigned char *map);
+	void campaignInit();
+	void countPlayers();
 };
 
 enum ESortBy{_playerAm, _size, _format, _name, _viccon, _loscon};
@@ -31,7 +44,7 @@ class mapSorter
 {
 public:
 	ESortBy sortBy;
-	bool operator()(const CMapHeader *a, const CMapHeader *b);;
+	bool operator()(const CMapInfo *aaa, const CMapInfo *bbb);
 	mapSorter(ESortBy es):sortBy(es){};
 };
 
@@ -55,6 +68,10 @@ public:
 class CMenuScreen : public CIntObject
 {
 public:
+	enum EState { //where are we?
+		mainMenu, newGame, loadGame, campaignMain, ScenarioList, saveGame, scenarioInfo, campaignList
+	};
+
 	CPicture *bgAd;
 	AdventureMapButton *buttons[5];
 
@@ -76,7 +93,7 @@ class InfoCard : public CIntObject
 {
 public:
 	CPicture *bg; 
-	EState type;
+	CMenuScreen::EState type;
 
 	CHighlightableButtonsGroup *difficulty;
 	CDefHandler *sizes, *sFlags;;
@@ -85,12 +102,20 @@ public:
 	void showAll(SDL_Surface * to);
 	void clickRight(tribool down, bool previousState);
 	void showTeamsPopup();
-	InfoCard(EState Type);
+	InfoCard(CMenuScreen::EState Type);
 	~InfoCard();
 };
 
 class SelectionTab : public CIntObject
 {
+private:
+	CDefHandler *format; //map size
+
+	void parseMaps(std::vector<FileInfo> &files, int start = 0, int threads = 1);
+	void parseGames(std::vector<FileInfo> &files);
+	void parseCampaigns( std::vector<FileInfo> & files );
+	void getFiles(std::vector<FileInfo> &out, const std::string &dirname, const std::string &ext);
+	CMenuScreen::EState tabType; 
 public:
 	int positions; //how many entries (games/maps) can be shown
 	CPicture *bg; //general bg image
@@ -103,13 +128,9 @@ public:
 	ESortBy sortingBy;
 	bool ascending;
 
-	CDefHandler *format;
-
 	CTextInput *txt;
 
-	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);
+	
 	void filter(int size, bool selectFirst = false); //0 - all
 	void select(int position); //position: <0 - positions>  position on the screen
 	void selectAbs(int position); //position: absolute position in curItems vector
@@ -126,7 +147,7 @@ public:
 	void wheelScrolled(bool down, bool in);
 	void keyPressed(const SDL_KeyboardEvent & key);
 	void onDoubleClick();
-	SelectionTab(EState Type, const boost::function<void(CMapInfo *)> &OnSelect);
+	SelectionTab(CMenuScreen::EState Type, const boost::function<void(CMapInfo *)> &OnSelect);
 	~SelectionTab();
 };
 
@@ -162,7 +183,7 @@ public:
 		void selectButtons(bool onlyHero = true); //hides unavailable buttons
 		void showAll(SDL_Surface * to);
 	};
-	EState type;
+	CMenuScreen::EState type;
 	CPicture *bg;
 	CSlider *turnDuration;
 
@@ -177,7 +198,7 @@ public:
 	void flagPressed(int player);
 
 	void changeSelection(const CMapHeader *to);
-	OptionsTab(EState Type/*, StartInfo &Opts*/);
+	OptionsTab(CMenuScreen::EState Type/*, StartInfo &Opts*/);
 	~OptionsTab();
 	void showAll(SDL_Surface * to);
 
@@ -195,12 +216,12 @@ public:
 	SelectionTab *sel;
 	OptionsTab *opt;
 
-	EState type; //new/save/load#Game
+	CMenuScreen::EState type; //new/save/load#Game
 	const CMapInfo *current;
 	StartInfo sInfo;
 	CIntObject *curTab;
 
-	CSelectionScreen(EState Type);
+	CSelectionScreen(CMenuScreen::EState Type);
 	~CSelectionScreen();
 	void toggleTab(CIntObject *tab);
 	void changeSelection(const CMapInfo *to);
@@ -216,7 +237,7 @@ public:
 	InfoCard *card;
 	OptionsTab *opt;
 
-	CScenarioInfo(const CMapHeader *mapInfo, const StartInfo *startInfo);
+	CScenarioInfo(const CMapHeader *mapHeader, const StartInfo *startInfo, const CMapInfo * makeItCurrent=NULL);
 	~CScenarioInfo();
 };
 
@@ -234,7 +255,7 @@ public:
 	~CGPreGame();
 	void update();
 	void run();
-	void openSel(EState type);
+	void openSel(CMenuScreen::EState type);
 	void loadGraphics();
 	void disposeGraphics();
 };

+ 1 - 1
client/GUIClasses.cpp

@@ -2999,7 +2999,7 @@ void CSystemOptionsWindow::bmainmenuf()
 void CSystemOptionsWindow::bsavef()
 {
 	GH.popIntTotally(this);
-	GH.pushInt(new CSelectionScreen(saveGame));
+	GH.pushInt(new CSelectionScreen(CMenuScreen::saveGame));
 	/*using namespace boost::posix_time;
 	std::ostringstream fnameStream;
 	fnameStream << second_clock::local_time();

+ 2 - 2
hch/CCampaignHandler.cpp

@@ -40,14 +40,14 @@ std::vector<CCampaignHeader> CCampaignHandler::getCampaignHeaders()
 		if(fs::is_regular_file(file->status())
 			&& boost::ends_with(file->path().filename(), ext))
 		{
-			ret.push_back( getHeader( file->path().string(), fs::file_size( file->path() ) ) );
+			ret.push_back( getHeader( file->path().string() ) );
 		}
 	}
 
 	return ret;
 }
 
-CCampaignHeader CCampaignHandler::getHeader( const std::string & name, int size )
+CCampaignHeader CCampaignHandler::getHeader( const std::string & name )
 {
 	int realSize;
 	unsigned char * cmpgn = CLodHandler::getUnpackedFile(name, &realSize);

+ 7 - 7
hch/CCampaignHandler.h

@@ -111,16 +111,16 @@ public:
 
 class DLL_EXPORT CCampaignHandler
 {
-	CCampaignHeader readHeaderFromMemory( const unsigned char *buffer, int & outIt );
-	CCampaignScenario readScenarioFromMemory( const unsigned char *buffer, int & outIt );
-	CScenarioTravel readScenarioTravelFromMemory( const unsigned char * buffer, int & outIt );
-	CCampaignHeader getHeader( const std::string & name, int size );
-	std::vector<ui32> locateH3mStarts(const unsigned char * buffer, int start, int size);
+	static CCampaignHeader readHeaderFromMemory( const unsigned char *buffer, int & outIt );
+	static CCampaignScenario readScenarioFromMemory( const unsigned char *buffer, int & outIt );
+	static CScenarioTravel readScenarioTravelFromMemory( const unsigned char * buffer, int & outIt );
+	static std::vector<ui32> locateH3mStarts(const unsigned char * buffer, int start, int size);
 	static bool startsAt( const unsigned char * buffer, int size, int pos ); //a simple heuristic that checks if a h3m starts at given pos
 public:
-	std::vector<CCampaignHeader> getCampaignHeaders();
+	static std::vector<CCampaignHeader> getCampaignHeaders();
+	static CCampaignHeader getHeader( const std::string & name );
 
-	CCampaign * getCampaign(const std::string & name);
+	static CCampaign * getCampaign(const std::string & name);
 };
 
 

+ 0 - 35
lib/map.cpp

@@ -2106,41 +2106,6 @@ void Mapa::checkForObjectives()
 	}
 }
 
-void CMapInfo::countPlayers()
-{
-	playerAmnt = humenPlayers = 0;
-	for(int i=0;i<PLAYER_LIMIT;i++)
-	{
-		if(players[i].canHumanPlay)
-		{
-			playerAmnt++;
-			humenPlayers++;
-		}
-		else if(players[i].canComputerPlay)
-		{
-			playerAmnt++;
-		}
-	}
-}
-
-CMapInfo::CMapInfo(const std::string &fname, const unsigned char *map )
-{
-	init(fname, map);
-}
-
-CMapInfo::CMapInfo()
-{
-	version = invalid;
-}
-
-void CMapInfo::init(const std::string &fname, const unsigned char *map )
-{
-	filename = fname;
-	int i = 0;
-	initFromMemory(map, i);
-	countPlayers();
-}
-
 LossCondition::LossCondition()
 {
 	obj = NULL;

+ 0 - 13
lib/map.h

@@ -247,19 +247,6 @@ public:
 	}
 };
 
-class DLL_EXPORT CMapInfo : public CMapHeader
-{
-public:
-	ui8 seldiff; //selected difficulty (only in saved games)
-	std::string filename;
-	std::string date;
-	int playerAmnt, humenPlayers;
-	CMapInfo();
-	CMapInfo(const std::string &fname, const unsigned char *map);
-	void init(const std::string &fname, const unsigned char *map);
-	void countPlayers();
-};
-
 struct DLL_EXPORT Mapa : public CMapHeader
 {
 	ui32 checksum;

Some files were not shown because too many files changed in this diff