From 30e624e5724a4a4feb5a4a29d64a1edbcc785d47 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 24 Jan 2018 16:07:26 +0200 Subject: [PATCH] Window mode can be changed mid-game, fixed "apply" button not becoming active in the settings menu when changing the window mode --- .../BarotraumaClient/Source/GameMain.cs | 22 ++++++++++++++----- .../BarotraumaClient/Source/GameSettings.cs | 13 +++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GameMain.cs b/Barotrauma/BarotraumaClient/Source/GameMain.cs index 2fd6cbcce..97d243fad 100644 --- a/Barotrauma/BarotraumaClient/Source/GameMain.cs +++ b/Barotrauma/BarotraumaClient/Source/GameMain.cs @@ -74,6 +74,12 @@ namespace Barotrauma private set; } + public static WindowMode WindowMode + { + get; + private set; + } + public static int GraphicsWidth { get; @@ -155,7 +161,7 @@ namespace Barotrauma GraphicsDeviceManager.PreferMultiSampling = false; GraphicsDeviceManager.SynchronizeWithVerticalRetrace = Config.VSyncEnabled; - if (Config.WindowMode == WindowMode.Windowed) + if (Config.WindowMode == Barotrauma.WindowMode.Windowed) { //for whatever reason, window isn't centered automatically //since MonoGame 3.6 (nuget package might be broken), so @@ -164,17 +170,23 @@ namespace Barotrauma (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - GraphicsHeight) / 2); } - GraphicsDeviceManager.HardwareModeSwitch = Config.WindowMode != WindowMode.BorderlessWindowed; - - GraphicsDeviceManager.IsFullScreen = Config.WindowMode == WindowMode.Fullscreen || Config.WindowMode == WindowMode.BorderlessWindowed; GraphicsDeviceManager.PreferredBackBufferWidth = GraphicsWidth; GraphicsDeviceManager.PreferredBackBufferHeight = GraphicsHeight; - GraphicsDeviceManager.ApplyChanges(); + SetWindowMode(Config.WindowMode); defaultViewport = GraphicsDevice.Viewport; } + public void SetWindowMode(WindowMode windowMode) + { + WindowMode = windowMode; + GraphicsDeviceManager.HardwareModeSwitch = Config.WindowMode != WindowMode.BorderlessWindowed; + GraphicsDeviceManager.IsFullScreen = Config.WindowMode == WindowMode.Fullscreen || Config.WindowMode == WindowMode.BorderlessWindowed; + + GraphicsDeviceManager.ApplyChanges(); + } + public void ResetViewPort() { GraphicsDevice.Viewport = defaultViewport; diff --git a/Barotrauma/BarotraumaClient/Source/GameSettings.cs b/Barotrauma/BarotraumaClient/Source/GameSettings.cs index 8a4e47748..730475246 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSettings.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSettings.cs @@ -90,7 +90,12 @@ namespace Barotrauma displayModeDD.SelectItem(GameMain.Config.WindowMode); - displayModeDD.OnSelected = (guiComponent, obj) => { GameMain.Config.WindowMode = (WindowMode)guiComponent.UserData; return true; }; + displayModeDD.OnSelected = (guiComponent, obj) => + { + UnsavedSettings = true; + GameMain.Config.WindowMode = (WindowMode)guiComponent.UserData; + return true; + }; y += 70; @@ -130,7 +135,6 @@ namespace Barotrauma foreach (ContentPackage contentPackage in ContentPackage.list) { contentPackageDD.AddItem(contentPackage.Name, contentPackage); - if (SelectedContentPackage == contentPackage) contentPackageDD.SelectItem(contentPackage); } @@ -237,6 +241,11 @@ namespace Barotrauma Save("config.xml"); settingsFrame.Flash(Color.Green); + + if (GameMain.WindowMode != GameMain.Config.WindowMode) + { + GameMain.Instance.SetWindowMode(GameMain.Config.WindowMode); + } if (GameMain.GraphicsWidth != GameMain.Config.GraphicsWidth || GameMain.GraphicsHeight != GameMain.Config.GraphicsHeight) {