Explorar o código

Fixed hotkeys in world view mode (added missing hotkeys + disabled non-world-view hotkeys);
Fixed minimap radar calculation for world view mode;

Fay %!s(int64=10) %!d(string=hai) anos
pai
achega
e3dc37fece

+ 13 - 17
client/mapHandler.cpp

@@ -505,40 +505,36 @@ void CMapHandler::drawWorldViewOverlay(int targetTilesX, int targetTilesY, int s
 	}
 }
 
-void CMapHandler::calculateWorldViewCameraPos(int targetTilesX, int targetTilesY, int3 &top_tile)
+void CMapHandler::calculateWorldViewCameraPos(int targetTilesX, int targetTilesY, int3 &tile)
 {
-	bool outsideLeft = top_tile.x < 0;
-	bool outsideTop = top_tile.y < 0;
-	bool outsideRight = std::max(0, top_tile.x) + targetTilesX > sizes.x;
-	bool outsideBottom = std::max(0, top_tile.y) + targetTilesY > sizes.y;
+	bool outsideLeft = tile.x < 0;
+	bool outsideTop = tile.y < 0;
+	bool outsideRight = std::max(0, tile.x) + targetTilesX > sizes.x;
+	bool outsideBottom = std::max(0, tile.y) + targetTilesY > sizes.y;
 
 	if (targetTilesX > sizes.x)
-		top_tile.x = sizes.x / 2 - targetTilesX / 2; // center viewport if the whole map can fit into the screen at once
+		tile.x = sizes.x / 2 - targetTilesX / 2; // center viewport if the whole map can fit into the screen at once
 	else if (outsideLeft)
 	{
 		if (outsideRight)
-		{
-			top_tile.x = sizes.x / 2 - targetTilesX / 2;
-		}
+			tile.x = sizes.x / 2 - targetTilesX / 2;
 		else
-			top_tile.x = 0;
+			tile.x = 0;
 	}
 	else if (outsideRight)
-		top_tile.x = sizes.x - targetTilesX;
+		tile.x = sizes.x - targetTilesX;
 
 	if (targetTilesY > sizes.y)
-		top_tile.y = sizes.y / 2 - targetTilesY / 2;
+		tile.y = sizes.y / 2 - targetTilesY / 2;
 	else if (outsideTop)
 	{
 		if (outsideBottom)
-		{
-			top_tile.y = sizes.y / 2 - targetTilesY / 2;
-		}
+			tile.y = sizes.y / 2 - targetTilesY / 2;
 		else
-			top_tile.y = 0;
+			tile.y = 0;
 	}
 	else if (outsideBottom)
-		top_tile.y = sizes.y - targetTilesY;
+		tile.y = sizes.y - targetTilesY;
 }
 
 void::CMapHandler::drawScaledRotatedElement(EMapCacheType type, SDL_Surface * baseSurf, SDL_Surface * targetSurf, ui8 rotation,

+ 10 - 0
client/widgets/AdventureMapClasses.cpp

@@ -608,6 +608,16 @@ void CMinimap::showAll(SDL_Surface * to)
 			ui16(tileCountOnScreen.y * pos.h / mapSizes.y)
 		};
 
+		if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
+		{
+			// adjusts radar so that it doesn't go out of map in world view mode (since there's no frame)
+			radar.x = std::min(std::max(pos.x, radar.x), pos.x + pos.w - radar.w);
+			radar.y = std::min(std::max(pos.y, radar.y), pos.y + pos.h - radar.h);
+
+			if (radar.x < pos.x && radar.y < pos.y)
+				return; // whole map is visible at once, no point in redrawing border
+		}
+
 		SDL_GetClipRect(to, &oldClip);
 		SDL_SetClipRect(to, &pos);
 		CSDL_Ext::drawDashedBorder(to, radar, int3(255,75,125));

+ 26 - 5
client/windows/CAdvmapInterface.cpp

@@ -484,7 +484,7 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
 	worldViewScale1xConfig.y = 23 + 195;
 	worldViewScale1xConfig.playerColoured = false;
 	panelWorldView->addChildToPanel(
-		makeButton(291, std::bind(&CAdvMapInt::fworldViewScale1x,this), worldViewScale1xConfig, SDLK_y), ACTIVATE | DEACTIVATE);
+		makeButton(291, std::bind(&CAdvMapInt::fworldViewScale1x,this), worldViewScale1xConfig, SDLK_1), ACTIVATE | DEACTIVATE);
 
 	config::ButtonInfo worldViewScale2xConfig = config::ButtonInfo();
 	worldViewScale2xConfig.defName = "VWMAG2.DEF";
@@ -492,7 +492,7 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
 	worldViewScale2xConfig.y = 23 + 195;
 	worldViewScale2xConfig.playerColoured = false;
 	panelWorldView->addChildToPanel(
-		makeButton(291, std::bind(&CAdvMapInt::fworldViewScale2x,this), worldViewScale2xConfig, SDLK_y), ACTIVATE | DEACTIVATE);
+		makeButton(291, std::bind(&CAdvMapInt::fworldViewScale2x,this), worldViewScale2xConfig, SDLK_2), ACTIVATE | DEACTIVATE);
 
 	config::ButtonInfo worldViewScale4xConfig = config::ButtonInfo();
 	worldViewScale4xConfig.defName = "VWMAG4.DEF";
@@ -500,7 +500,7 @@ infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192) )
 	worldViewScale4xConfig.y = 23 + 195;
 	worldViewScale4xConfig.playerColoured = false;
 	panelWorldView->addChildToPanel(
-		makeButton(291, std::bind(&CAdvMapInt::fworldViewScale4x,this), worldViewScale4xConfig, SDLK_y), ACTIVATE | DEACTIVATE);
+		makeButton(291, std::bind(&CAdvMapInt::fworldViewScale4x,this), worldViewScale4xConfig, SDLK_4), ACTIVATE | DEACTIVATE);
 
 	config::ButtonInfo worldViewUndergroundConfig = config::ButtonInfo();
 	worldViewUndergroundConfig.defName = "IAM010.DEF";
@@ -560,6 +560,10 @@ void CAdvMapInt::fworldViewBack()
 {
 	changeMode(EAdvMapMode::NORMAL);
 	CGI->mh->discardWorldViewCache();
+
+	auto hero = curHero();
+	if (hero)
+		centerOn(hero);
 }
 
 void CAdvMapInt::fworldViewScale1x()
@@ -909,8 +913,19 @@ void CAdvMapInt::centerOn(int3 on)
 {
 	bool switchedLevels = on.z != position.z;
 
-	on.x -= CGI->mh->frameW;
-	on.y -= CGI->mh->frameH;
+	switch (mode)
+	{
+	default:
+	case EAdvMapMode::NORMAL:
+		on.x -= CGI->mh->frameW; // is this intentional? frame size doesn't really have to correspond to camera size...
+		on.y -= CGI->mh->frameH;
+		break;
+	case EAdvMapMode::WORLD_VIEW:
+		on.x -= CGI->mh->tilesW / 2 / worldViewScale;
+		on.y -= CGI->mh->tilesH / 2 / worldViewScale;
+		break;
+	}
+
 
 	on = LOCPLINT->repairScreenPos(on);
 
@@ -918,6 +933,8 @@ void CAdvMapInt::centerOn(int3 on)
 	updateScreen=true;
 	underground->setIndex(on.z,true); //change underground switch button image
 	underground->redraw();
+	worldViewUnderground->setIndex(on.z, true);
+	worldViewUnderground->redraw();
 	if (switchedLevels)
 		minimap.setLevel(position.z);
 	minimap.redraw();
@@ -933,6 +950,10 @@ void CAdvMapInt::centerOn(const CGObjectInstance *obj)
 
 void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 {
+
+	if (mode == EAdvMapMode::WORLD_VIEW)
+		return;
+
 	ui8 Dir = 0;
 	int k = key.keysym.sym;
 	const CGHeroInstance *h = curHero(); //selected hero