Browse Source

Merge pull request #3513 from Laserlicht/hide_adventuremap

hide adventuremap
Ivan Savenko 1 year ago
parent
commit
cf9a4a580b

+ 2 - 0
Mods/vcmi/config/vcmi/english.json

@@ -145,6 +145,8 @@
 	"vcmi.adventureOptions.mapScrollSpeed1.help": "Set the map scrolling speed to very slow.",
 	"vcmi.adventureOptions.mapScrollSpeed5.help": "Set the map scrolling speed to very fast.",
 	"vcmi.adventureOptions.mapScrollSpeed6.help": "Set the map scrolling speed to instantaneous.",
+	"vcmi.adventureOptions.hideBackground.hover" : "Hide Background",
+	"vcmi.adventureOptions.hideBackground.help" : "{Hide Background}\n\nHide the adventuremap in the background and show a texture instead.",
 
 	"vcmi.battleOptions.queueSizeLabel.hover": "Show Turn Order Queue",
 	"vcmi.battleOptions.queueSizeNoneButton.hover": "OFF",

+ 2 - 0
Mods/vcmi/config/vcmi/german.json

@@ -145,6 +145,8 @@
 	"vcmi.adventureOptions.mapScrollSpeed1.help": "Geschwindigkeit des Kartenbildlaufs auf sehr langsam einstellen",
 	"vcmi.adventureOptions.mapScrollSpeed5.help": "Geschwindigkeit des Kartenbildlaufs auf sehr schnell einstellen",
 	"vcmi.adventureOptions.mapScrollSpeed6.help": "Geschwindigkeit des Kartenbildlaufs auf sofort einstellen",
+	"vcmi.adventureOptions.hideBackground.hover" : "Hintergrund ausblenden",
+	"vcmi.adventureOptions.hideBackground.help" : "{Hintergrund ausblenden}\n\nDie Abenteuerkarte im Hintergrund ausblenden und stattdessen eine Textur anzeigen.",
 
 	"vcmi.battleOptions.queueSizeLabel.hover": "Reihenfolge der Kreaturen anzeigen",
 	"vcmi.battleOptions.queueSizeNoneButton.hover": "AUS",

+ 10 - 0
client/adventureMap/AdventureMapInterface.cpp

@@ -31,6 +31,7 @@
 #include "../gui/Shortcut.h"
 #include "../gui/WindowHandler.h"
 #include "../render/Canvas.h"
+#include "../render/IRenderHandler.h"
 #include "../CMT.h"
 #include "../PlayerLocalState.h"
 #include "../CPlayerInterface.h"
@@ -168,6 +169,15 @@ void AdventureMapInterface::show(Canvas & to)
 
 void AdventureMapInterface::dim(Canvas & to)
 {
+	if(settings["adventure"]["hideBackground"].Bool())
+		for (auto window : GH.windows().findWindows<IShowActivatable>())
+		{
+			if(!std::dynamic_pointer_cast<AdventureMapInterface>(window) && std::dynamic_pointer_cast<CIntObject>(window) && std::dynamic_pointer_cast<CIntObject>(window)->pos.w >= 800 && std::dynamic_pointer_cast<CIntObject>(window)->pos.w >= 600)
+			{
+				to.fillTexture(GH.renderHandler().loadImage(ImagePath::builtin("DiBoxBck")));
+				return;
+			}
+		}
 	for (auto window : GH.windows().findWindows<IShowActivatable>())
 	{
 		if (!std::dynamic_pointer_cast<AdventureMapInterface>(window) && !std::dynamic_pointer_cast<RadialMenu>(window) && !window->isPopupWindow())

+ 14 - 0
client/render/Canvas.cpp

@@ -182,6 +182,20 @@ void Canvas::drawColorBlended(const Rect & target, const ColorRGBA & color)
 	CSDL_Ext::fillRectBlended(surface, realTarget, CSDL_Ext::toSDL(color));
 }
 
+void Canvas::fillTexture(const std::shared_ptr<IImage>& image)
+{
+	assert(image);
+	if (!image)
+		return;
+		
+	Rect imageArea = Rect(Point(0, 0), image->dimensions());
+	for (int y=0; y < surface->h; y+= imageArea.h)
+	{
+		for (int x=0; x < surface->w; x+= imageArea.w)
+			image->draw(surface, renderArea.x + x, renderArea.y + y);
+	}
+}
+
 SDL_Surface * Canvas::getInternalSurface()
 {
 	return surface;

+ 3 - 0
client/render/Canvas.h

@@ -99,6 +99,9 @@ public:
 	/// fills selected area with blended color
 	void drawColorBlended(const Rect & target, const ColorRGBA & color);
 
+	/// fills canvas with texture
+	void fillTexture(const std::shared_ptr<IImage>& image);
+
 	/// Compatibility method. AVOID USAGE. To be removed once SDL abstraction layer is finished.
 	SDL_Surface * getInternalSurface();
 

+ 7 - 0
client/windows/settings/AdventureOptionsTab.cpp

@@ -134,6 +134,10 @@ AdventureOptionsTab::AdventureOptionsTab()
 	{
 		return setBoolSetting("gameTweaks", "skipAdventureMapAnimations", value);
 	});
+	addCallback("hideBackgroundChanged", [](bool value)
+	{
+		return setBoolSetting("adventure", "hideBackground", value);
+	});
 	build(config);
 
 	std::shared_ptr<CToggleGroup> playerHeroSpeedToggle = widget<CToggleGroup>("heroMovementSpeedPicker");
@@ -179,4 +183,7 @@ AdventureOptionsTab::AdventureOptionsTab()
 
 	std::shared_ptr<CToggleButton> skipAdventureMapAnimationsCheckbox = widget<CToggleButton>("skipAdventureMapAnimationsCheckbox");
 	skipAdventureMapAnimationsCheckbox->setSelected(settings["gameTweaks"]["skipAdventureMapAnimations"].Bool());
+
+	std::shared_ptr<CToggleButton> hideBackgroundCheckbox = widget<CToggleButton>("hideBackgroundCheckbox");
+	hideBackgroundCheckbox->setSelected(settings["adventure"]["hideBackground"].Bool());
 }

+ 5 - 1
config/schemas/settings.json

@@ -241,7 +241,7 @@
 			"type" : "object",
 			"additionalProperties" : false,
 			"default" : {},
-			"required" : [ "heroMoveTime", "enemyMoveTime", "scrollSpeedPixels", "heroReminder", "quickCombat", "objectAnimation", "terrainAnimation", "forceQuickCombat", "borderScroll", "leftButtonDrag", "smoothDragging", "backgroundDimLevel" ],
+			"required" : [ "heroMoveTime", "enemyMoveTime", "scrollSpeedPixels", "heroReminder", "quickCombat", "objectAnimation", "terrainAnimation", "forceQuickCombat", "borderScroll", "leftButtonDrag", "smoothDragging", "backgroundDimLevel", "hideBackground" ],
 			"properties" : {
 				"heroMoveTime" : {
 					"type" : "number",
@@ -294,6 +294,10 @@
 					"type" : "number",
 					"default" : 128
 				},
+				"hideBackground" : {
+					"type" : "boolean",
+					"default" : false
+				}
 			}
 		},
 		"battle" : {

+ 8 - 0
config/widgets/settings/adventureOptionsTab.json

@@ -297,6 +297,9 @@
 				},
 				{
 					"text": "vcmi.adventureOptions.showGrid.hover"
+				},
+				{
+					"text": "vcmi.adventureOptions.hideBackground.hover"
 				}
 			]
 		},
@@ -324,6 +327,11 @@
 					"name": "showGridCheckbox",
 					"help": "vcmi.adventureOptions.showGrid",
 					"callback": "showGridChanged"
+				},
+				{
+					"name": "hideBackgroundCheckbox",
+					"help": "vcmi.adventureOptions.hideBackground",
+					"callback": "hideBackgroundChanged"
 				}
 			]
 		},