Pārlūkot izejas kodu

* generally finished custom campaign selection screen
* minor fixes

mateuszb 16 gadi atpakaļ
vecāks
revīzija
5db0c9da16
4 mainītis faili ar 43 papildinājumiem un 10 dzēšanām
  1. 37 6
      client/CPreGame.cpp
  2. 1 1
      client/CPreGame.h
  3. 4 2
      hch/CCampaignHandler.cpp
  4. 1 1
      hch/CCampaignHandler.h

+ 37 - 6
client/CPreGame.cpp

@@ -629,12 +629,23 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::function<void(
 	txt = NULL;
 	tabType = Type;
 
-// 	if (Type != CMenuScreen::campaignList)
-	/*{*/
+ 	if (Type != CMenuScreen::campaignList)
+	{
 		bg = new CPicture(BitmapHandler::loadBitmap("SCSELBCK.bmp"), 0, 0, true);
 		pos.w = bg->pos.w;
 		pos.h = bg->pos.h;
-	/*}*/
+	}
+	else
+	{
+		SDL_Surface * tmp1 = BitmapHandler::loadBitmap("CAMCUST.bmp");
+		SDL_Surface * tmp = CSDL_Ext::newSurface(400, tmp1->h);
+		blitAt(tmp1, 0, 0, tmp);
+		SDL_FreeSurface(tmp1);
+		bg = new CPicture(tmp, 0, 0, true);
+		pos.w = bg->pos.w;
+		pos.h = bg->pos.h;
+		bg->pos.x = bg->pos.y = 0;
+	}
 
 	std::vector<FileInfo> toParse;
 	switch(tabType)
@@ -672,9 +683,10 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::function<void(
 	}
 
 
-	//size filter buttons
+	
 	if (tabType != CMenuScreen::campaignList)
 	{
+		//size filter buttons
 		{
 			int sizes[] = {36, 72, 108, 144, 0};
 			const char * names[] = {"SCSMBUT.DEF", "SCMDBUT.DEF", "SCLGBUT.DEF", "SCXLBUT.DEF", "SCALBUT.DEF"};
@@ -682,6 +694,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::function<void(
 				new AdventureMapButton("", CGI->generaltexth->zelp[54+i].second, bind(&SelectionTab::filter, this, sizes[i], true), 158 + 47*i, 46, names[i]);
 		}
 
+		//sort buttons buttons
 		{
 			int xpos[] = {23, 55, 88, 121, 306, 339};
 			const char * names[] = {"SCBUTT1.DEF", "SCBUTT2.DEF", "SCBUTCP.DEF", "SCBUTT3.DEF", "SCBUTT4.DEF", "SCBUTT5.DEF"};
@@ -689,6 +702,12 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::function<void(
 				new AdventureMapButton("", CGI->generaltexth->zelp[107+i].second, bind(&SelectionTab::sortBy, this, i), xpos[i], 86, names[i]);
 		}
 	}
+	else
+	{
+		//sort by buttons
+		new AdventureMapButton("", "", bind(&SelectionTab::sortBy, this, _numOfMaps), 23, 86, "CamCusM.DEF"); //by num of maps
+		new AdventureMapButton("", "", bind(&SelectionTab::sortBy, this, _name), 55, 86, "CamCusL.DEF"); //by name
+	}
 
 	slider = new CSlider(372, 86, tabType != CMenuScreen::saveGame ? 480 : 430, bind(&SelectionTab::sliderMove, this, _1), positions, curItems.size(), 0, false, 1);
 	format =  CDefHandler::giveDef("SCSELC.DEF");
@@ -1914,7 +1933,19 @@ bool mapSorter::operator()(const CMapInfo *aaa, const CMapInfo *bbb)
 	}
 	else //if we are sorting campaigns
 	{
-		return aaa->campaignHeader->name < bbb->campaignHeader->name; //sort by names
+		switch(sortBy)
+		{
+			case _numOfMaps: //by number of maps in campaign
+				return CGI->generaltexth->campaignRegionNames[ aaa->campaignHeader->mapVersion ].size() < 
+					CGI->generaltexth->campaignRegionNames[ bbb->campaignHeader->mapVersion ].size();
+				break;
+			case _name: //by name
+				return aaa->campaignHeader->name < bbb->campaignHeader->name;
+				break;
+			default:
+				return aaa->campaignHeader->name < bbb->campaignHeader->name;
+				break;
+		}
 	}
 }
 
@@ -2073,4 +2104,4 @@ void CBonusSelection::showAll( SDL_Surface * to )
 {
 	CIntObject::showAll(to);
 	blitAt(background, pos.x, pos.y, to);
-}
+}

+ 1 - 1
client/CPreGame.h

@@ -41,7 +41,7 @@ public:
 	void countPlayers();
 };
 
-enum ESortBy{_playerAm, _size, _format, _name, _viccon, _loscon};
+enum ESortBy{_playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps}; //_numOfMaps is for campaigns
 
 class mapSorter
 {

+ 4 - 2
hch/CCampaignHandler.cpp

@@ -73,7 +73,7 @@ CCampaign * CCampaignHandler::getCampaign( const std::string & name )
 	int howManyScenarios = VLC->generaltexth->campaignRegionNames[ret->header.mapVersion].size();
 	for(int g=0; g<howManyScenarios; ++g)
 	{
-		CCampaignScenario sc = readScenarioFromMemory(cmpgn, it, ret->header.version);
+		CCampaignScenario sc = readScenarioFromMemory(cmpgn, it, ret->header.version, ret->header.mapVersion);
 		ret->scenarios.push_back(sc);
 	}
 
@@ -122,7 +122,7 @@ CCampaignHeader CCampaignHandler::readHeaderFromMemory( const unsigned char *buf
 	return ret;
 }
 
-CCampaignScenario CCampaignHandler::readScenarioFromMemory( const unsigned char *buffer, int & outIt, int version )
+CCampaignScenario CCampaignHandler::readScenarioFromMemory( const unsigned char *buffer, int & outIt, int version, int mapVersion )
 {
 	struct HLP
 	{
@@ -143,6 +143,8 @@ CCampaignScenario CCampaignHandler::readScenarioFromMemory( const unsigned char
 	CCampaignScenario ret;
 	ret.mapName = readString(buffer, outIt);
 	ret.packedMapSize = readNormalNr(buffer, outIt); outIt += 4;
+	if(mapVersion == 18)//unholy alliance
+		outIt++;
 	ret.preconditionRegion = buffer[outIt++];
 	ret.regionColor = buffer[outIt++];
 	ret.difficulty = buffer[outIt++];

+ 1 - 1
hch/CCampaignHandler.h

@@ -112,7 +112,7 @@ public:
 class DLL_EXPORT CCampaignHandler
 {
 	static CCampaignHeader readHeaderFromMemory( const unsigned char *buffer, int & outIt );
-	static CCampaignScenario readScenarioFromMemory( const unsigned char *buffer, int & outIt, int version );
+	static CCampaignScenario readScenarioFromMemory( const unsigned char *buffer, int & outIt, int version, int mapVersion );
 	static CScenarioTravel readScenarioTravelFromMemory( const unsigned char * buffer, int & outIt , int version);
 	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