浏览代码

Merge pull request #2712 from Laserlicht/dim_map

Dim adventuremap
Ivan Savenko 2 年之前
父节点
当前提交
cab2bddf7e

+ 19 - 0
client/adventureMap/AdventureMapInterface.cpp

@@ -153,15 +153,34 @@ void AdventureMapInterface::deactivate()
 void AdventureMapInterface::showAll(Canvas & to)
 {
 	CIntObject::showAll(to);
+	dim(to);
 	LOCPLINT->cingconsole->show(to);
 }
 
 void AdventureMapInterface::show(Canvas & to)
 {
 	CIntObject::show(to);
+	dim(to);
 	LOCPLINT->cingconsole->show(to);
 }
 
+void AdventureMapInterface::dim(Canvas & to)
+{
+	for (auto window : GH.windows().findWindows<IShowActivatable>())
+	{
+		std::shared_ptr<AdventureMapInterface> casted = std::dynamic_pointer_cast<AdventureMapInterface>(window);
+		if (!casted && !window->isPopupWindow())
+		{
+			int backgroundDimLevel = settings["adventure"]["backgroundDimLevel"].Integer();
+			Rect targetRect(0, 0, GH.screenDimensions().x, GH.screenDimensions().y);
+			ColorRGBA colorToFill(0, 0, 0, std::clamp<int>(backgroundDimLevel, 0, 255));
+			if(backgroundDimLevel > 0)
+				to.drawColor(targetRect, colorToFill);
+			return;
+		}
+	}
+}
+
 void AdventureMapInterface::tick(uint32_t msPassed)
 {
 	handleMapScrollingUpdate(msPassed);

+ 3 - 0
client/adventureMap/AdventureMapInterface.h

@@ -89,6 +89,9 @@ private:
 	/// casts current spell at specified location
 	void performSpellcasting(const int3 & castTarget);
 
+	/// dim interface if some windows opened
+	void dim(Canvas & to);
+
 protected:
 	/// CIntObject interface implementation
 

+ 1 - 1
client/render/Canvas.h

@@ -93,7 +93,7 @@ public:
 	/// renders multiple lines of text with specified parameters
 	void drawText(const Point & position, const EFonts & font, const ColorRGBA & colorDest, ETextAlignment alignment, const std::vector<std::string> & text );
 
-	/// fills selected area with solid color, ignoring any transparency
+	/// fills selected area with solid color
 	void drawColor(const Rect & target, const ColorRGBA & color);
 
 	/// Compatibility method. AVOID USAGE. To be removed once SDL abstraction layer is finished.

+ 4 - 1
client/renderSDL/SDL_Extensions.cpp

@@ -804,7 +804,10 @@ void CSDL_Ext::fillRect( SDL_Surface *dst, const Rect & dstrect, const SDL_Color
 	SDL_Rect newRect = CSDL_Ext::toSDL(dstrect);
 
 	uint32_t sdlColor = SDL_MapRGBA(dst->format, color.r, color.g, color.b, color.a);
-	SDL_FillRect(dst, &newRect, sdlColor);
+	SDL_Surface * tmp = SDL_CreateRGBSurface(0, newRect.w, newRect.h, dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask);
+	SDL_FillRect(tmp, NULL, sdlColor);
+	SDL_BlitSurface(tmp, NULL, dst, &newRect);
+	SDL_FreeSurface(tmp);
 }
 
 STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color)

+ 6 - 2
config/schemas/settings.json

@@ -226,7 +226,7 @@
 			"type" : "object",
 			"additionalProperties" : false,
 			"default" : {},
-			"required" : [ "heroMoveTime", "enemyMoveTime", "scrollSpeedPixels", "heroReminder", "quickCombat", "objectAnimation", "terrainAnimation", "forceQuickCombat", "borderScroll", "leftButtonDrag", "smoothDragging" ],
+			"required" : [ "heroMoveTime", "enemyMoveTime", "scrollSpeedPixels", "heroReminder", "quickCombat", "objectAnimation", "terrainAnimation", "forceQuickCombat", "borderScroll", "leftButtonDrag", "smoothDragging", "backgroundDimLevel" ],
 			"properties" : {
 				"heroMoveTime" : {
 					"type" : "number",
@@ -274,7 +274,11 @@
 				"smoothDragging" : {
 					"type" : "boolean",
 					"default" : true
-				}
+				},
+				"backgroundDimLevel" : {
+					"type" : "number",
+					"default" : 128
+				},
 			}
 		},
 		"battle" : {