Skip to content

Commit

Permalink
Fix bug where display mode was reinitialized on loading a new map
Browse files Browse the repository at this point in the history
  • Loading branch information
Rampastring committed Jan 30, 2024
1 parent c5c66cb commit 19f4ca5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/TSMapEditor/UI/UIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public UIManager(WindowManager windowManager, Map map, TheaterGraphics theaterGr

public event EventHandler RenderResolutionChanged;

private static bool InitialDisplayModeSet = false;

private Map map;
private TheaterGraphics theaterGraphics;
private EditorGraphics editorGraphics;
Expand Down Expand Up @@ -198,6 +200,11 @@ public override void Initialize()

private void SetInitialDisplayMode()
{
if (InitialDisplayModeSet)
return;

InitialDisplayModeSet = true;

Game.Window.AllowUserResizing = true;
var form = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(Game.Window.Handle);
form.MaximizeBox = false;
Expand All @@ -213,10 +220,7 @@ private void SetInitialDisplayMode()
}

WindowManager.InitGraphicsMode(width, height, borderless);

double renderScale = UserSettings.Instance.RenderScale;

WindowManager.SetRenderResolution((int)(WindowManager.WindowWidth / renderScale), (int)(WindowManager.WindowHeight / renderScale));
RefreshRenderResolution();
WindowManager.CenterOnScreen();
WindowManager.SetBorderlessMode(borderless);
}
Expand Down Expand Up @@ -251,7 +255,7 @@ private void ToggleFullscreen_Triggered(object sender, EventArgs e)
}
}

private void WindowManager_WindowSizeChangedByUser(object sender, EventArgs e)
private void RefreshRenderResolution()
{
if (Game.Window.ClientBounds.Width == 0 || Game.Window.ClientBounds.Height == 0)
return;
Expand All @@ -268,6 +272,11 @@ private void WindowManager_WindowSizeChangedByUser(object sender, EventArgs e)
}
}

private void WindowManager_WindowSizeChangedByUser(object sender, EventArgs e)
{
RefreshRenderResolution();
}

private void WindowManager_GameClosing(object sender, EventArgs e) => mapFileWatcher.StopWatching();

private void InitTheme()
Expand Down

0 comments on commit 19f4ca5

Please sign in to comment.