Bladeren bron

- fixed #841 and #840
- fixed several crashes

Ivan Savenko 14 jaren geleden
bovenliggende
commit
2eca314e92
4 gewijzigde bestanden met toevoegingen van 39 en 24 verwijderingen
  1. 3 3
      client/CAdvmapInterface.cpp
  2. 30 11
      client/CPreGame.cpp
  3. 5 2
      client/CPreGame.h
  4. 1 8
      lib/CCampaignHandler.cpp

+ 3 - 3
client/CAdvmapInterface.cpp

@@ -735,7 +735,7 @@ void CResDataBar::deactivate()
 CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
 {
 	bg = BitmapHandler::loadBitmap(defname);
-//fz	SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
+	SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
 	graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
 	pos = genRect(bg->h, bg->w, pos.x+x, pos.y+y);
 
@@ -752,7 +752,7 @@ CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int
 CResDataBar::CResDataBar()
 {
 	bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
-//fz	SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
+	SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
 	graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
 	pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
 
@@ -1200,7 +1200,7 @@ int CAdvMapInt::getNextHeroIndex(int startIndex)
 	} 
 	while (((LOCPLINT->wanderingHeroes[i]->movement == 0) || isHeroSleeping(LOCPLINT->wanderingHeroes[i])) && (i != startIndex));
 
-	if ((LOCPLINT->wanderingHeroes[i]->movement > 0) && !isHeroSleeping(LOCPLINT->wanderingHeroes[i]))
+	if ((LOCPLINT->wanderingHeroes[i]->movement != 0) && !isHeroSleeping(LOCPLINT->wanderingHeroes[i]))
 		return i;
 	else
 		return -1;

+ 30 - 11
client/CPreGame.cpp

@@ -743,10 +743,13 @@ void CSelectionScreen::changeSelection( const CMapInfo *to )
 
 void CSelectionScreen::startCampaign()
 {
-	CCampaign * ourCampaign = CCampaignHandler::getCampaign(SEL->current->filename, SEL->current->lodCmpgn);
-	CCampaignState * campState = new CCampaignState();
-	campState->camp = ourCampaign;
-	GH.pushInt( new CBonusSelection(campState) );
+	if (SEL->current)
+	{
+		CCampaign * ourCampaign = CCampaignHandler::getCampaign(SEL->current->filename, SEL->current->lodCmpgn);
+		CCampaignState * campState = new CCampaignState();
+		campState->camp = ourCampaign;
+		GH.pushInt( new CBonusSelection(campState) );
+	}
 }
 
 void CSelectionScreen::startGame()
@@ -1109,7 +1112,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::function<void(
 				toParse[g].inLod = false;
 			}
 			//add lod cmpgns
-			cpm = CCampaignHandler::getCampaignHeaders(CCampaignHandler::ALL);
+			cpm = CCampaignHandler::getCampaignHeaders(CCampaignHandler::Custom);
 			for (int g = 0; g < cpm.size(); g++)
 			{
 				FileInfo fi;
@@ -2660,19 +2663,36 @@ CHotSeatPlayers::CHotSeatPlayers(const std::string &firstPlayer)
 {
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
 	bg = new CPicture("MUHOTSEA.bmp");
-	bg->convertToScreenBPP(); //so we could draw without problems
-	bg->printAtMiddleWBLoc(CGI->generaltexth->allTexts[446], 185, 55, FONT_BIG, 50, zwykly, *bg); //HOTSEAT	Please enter names
 	pos = bg->center(); //center, window has size of bg graphic
 
+	std::string text = CGI->generaltexth->allTexts[446];
+	boost::replace_all(text, "\t","\n");
+	Rect boxRect(25, 20, 315, 50);
+	title = new CTextBox(text, boxRect, 0, FONT_BIG, CENTER, zwykly);//HOTSEAT	Please enter names
+
 	for(int i = 0; i < ARRAY_COUNT(txt); i++)
+	{
 		txt[i] = new CTextInput(Rect(60, 85 + i*30, 280, 16), *bg);
-
-	txt[0]->setText(firstPlayer);
-	txt[0]->giveFocus();
+		txt[i]->cb += boost::bind(&CHotSeatPlayers::onChange, this, _1);
+	}
 
 	ok = new AdventureMapButton(CGI->generaltexth->zelp[560], bind(&CHotSeatPlayers::enterSelectionScreen, this), 95, 338, "MUBCHCK.DEF", SDLK_RETURN);
 	cancel = new AdventureMapButton(CGI->generaltexth->zelp[561], bind(&CGuiHandler::popIntTotally, ref(GH), this), 205, 338, "MUBCANC.DEF", SDLK_ESCAPE);
 	bar = new CGStatusBar(new CPicture(Rect(7, 381, 348, 18), 0));//226, 472
+
+	txt[0]->setText(firstPlayer, true);
+	txt[0]->giveFocus();
+}
+
+void CHotSeatPlayers::onChange(std::string newText)
+{
+	size_t namesCount = 0;
+
+	for(int i = 0; i < ARRAY_COUNT(txt); i++)
+		if(!txt[i]->text.empty())
+			namesCount++;
+
+	ok->block(namesCount < 2);
 }
 
 void CHotSeatPlayers::enterSelectionScreen()
@@ -2682,7 +2702,6 @@ void CHotSeatPlayers::enterSelectionScreen()
 		if(txt[i]->text.length())
 			names[j++] = txt[i]->text;
 
-	assert(names.size() > 1); //two players at least - after all, it's hot seat mode...
 	GDefaultOptions.setPlayerName(names.begin()->second); //remember selected name
 
 	GH.popInts(2); //pop MP mode window and this

+ 5 - 2
client/CPreGame.h

@@ -353,14 +353,17 @@ public:
 /// Hot seat player window
 class CHotSeatPlayers : public CIntObject
 {
-public:
 	CPicture *bg;
+	CTextBox *title;
 	CTextInput *txt[8];
 	AdventureMapButton *ok, *cancel;
 	CGStatusBar *bar;
 
-	CHotSeatPlayers(const std::string &firstPlayer);
+	void onChange(std::string newText);
 	void enterSelectionScreen();
+
+public:
+	CHotSeatPlayers(const std::string &firstPlayer);
 };
 
 /// Campaign screen where you can choose one out of three starting bonuses

+ 1 - 8
lib/CCampaignHandler.cpp

@@ -56,14 +56,7 @@ std::vector<CCampaignHeader> CCampaignHandler::getCampaignHeaders(GetMode mode)
 	{
 		BOOST_FOREACH(Entry e, bitmaph->entries)
 		{
-			if( e.type == FILE_CAMPAIGN && e.name != "TOSBLK1" )
-			{
-				ret.push_back( getHeader(e.name, true) );
-			}
-		}
-		BOOST_FOREACH(Entry e, bitmaph_ab->entries)
-		{
-			if( e.type == FILE_CAMPAIGN && e.name != "TOSBLK1" )
+			if( e.type == FILE_CAMPAIGN )
 			{
 				ret.push_back( getHeader(e.name, true) );
 			}