Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Prowl.Editor/EditorApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,24 @@ public class EditorApplication : Game
// All registered panel types (from [EditorWindow] attribute scan)
private readonly List<(Type type, string path)> _registeredPanels = new();

public override void InitializeWindow(string title, int width, int height)
{
var instance = EditorSettings.Instance;
Window.InitWindow(title, width, height, instance.WindowMaximized ? Silk.NET.Windowing.WindowState.Maximized : Silk.NET.Windowing.WindowState.Normal, false);

Window.Position = new Silk.NET.Maths.Vector2D<int>(
instance.WindowX > -1 ? instance.WindowX : Window.Position.X,
instance.WindowY > -1 ? instance.WindowY : Window.Position.Y);
}

public override void Initialize()
{
Instance = this;
Application.IsEditor = true;
Application.IsPlaying = false;

// Set invariant culture for consistent number parsing/formatting in the editor (e.g. asset import settings)
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
InitializeFont();

PaperInstance.TextMode = Prowl.Quill.TextRenderMode.Bitmap;
Expand Down Expand Up @@ -129,6 +141,34 @@ public override void Initialize()

// Set Windows title bar to match Darkest theme color
ApplyDarkTitleBar();

// Attach to the window events to save the position and state of the window
Window.InternalWindow.Move += (position) =>
{
EditorSettings.Instance.WindowX = position.X;
EditorSettings.Instance.WindowY = position.Y;

EditorSettings.Instance.Save();
};

Window.InternalWindow.Resize += (size) =>
{
EditorSettings.Instance.WindowWidth = size.X;
EditorSettings.Instance.WindowHeight = size.Y;
EditorSettings.Instance.Save();
};

Window.InternalWindow.StateChanged += (state) =>
{
EditorSettings.Instance.WindowMaximized = state == Silk.NET.Windowing.WindowState.Maximized;

EditorSettings.Instance.Save();
};

Window.InternalWindow.Closing += () =>
{
SaveEditorWindowState();
};
}

[DllImport("dwmapi.dll", PreserveSig = true)]
Expand Down Expand Up @@ -909,10 +949,27 @@ private void RestoreAutoSavedScene(string path)
// Project Switching
// ================================================================

/// <summary>
/// Saves the editor window position, size and maximization state.
/// </summary>
public void SaveEditorWindowState()
{
EditorSettings.Instance.WindowX = Window.Position.X;
EditorSettings.Instance.WindowY = Window.Position.Y;

EditorSettings.Instance.WindowWidth = Window.Size.X;
EditorSettings.Instance.WindowHeight = Window.Size.Y;

EditorSettings.Instance.WindowMaximized = Window.InternalWindow.WindowState == Silk.NET.Windowing.WindowState.Maximized;

EditorSettings.Instance.Save();
}

/// <summary>Save layout and settings for the current project.</summary>
public void SaveProjectState()
{
if (Project.Current == null) return;
SaveEditorWindowState();
Docking.LayoutSerializer.Save(_dockSpace);
ProjectSettingsRegistry.SaveAll();
}
Expand Down
10 changes: 10 additions & 0 deletions Prowl.Editor/Settings/EditorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public class EditorSettings
public bool ReimportOnFocusOnly { get; set; } = true;
public int ThumbnailSize { get; set; } = 32;

public int WindowX { get; set; } = -1;

public int WindowY { get; set; } = -1;

public int WindowWidth { get; set; } = 1280;

public int WindowHeight { get; set; } = 800;

public bool WindowMaximized { get; set; } = false;

// Shortcuts — only user-overridden bindings are stored
public Dictionary<string, ShortcutBinding> ShortcutOverrides { get; set; } = new();

Expand Down
11 changes: 10 additions & 1 deletion Prowl.Runtime/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ public abstract class Game

public bool DrawGizmos { get; set; }

public void Run(string title, int width, int height)
/// <summary>
/// Added a separate method to initialize the window as it might be needed to restore the latest saved state of the window (size, position, etc.) when the game is launched again.
/// This allows for better user experience by remembering their preferences.
/// </summary>
public virtual void InitializeWindow(string title, int width, int height)
{
Window.InitWindow(title, width, height, Silk.NET.Windowing.WindowState.Normal, false);
}

public void Run(string title, int width, int height)
{
InitializeWindow(title, width, height);

Window.Load += () =>
{
Expand Down
6 changes: 6 additions & 0 deletions Prowl.Runtime/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public static class Window
public static event Action<WindowState>? StateChanged;
public static event Action<string[]>? FileDrop;

public static Vector2D<int> Position
{
get { return InternalWindow.Position; }
set { InternalWindow.Position = value; }
}

public static Vector2D<int> Size
{
get { return InternalWindow.Size; }
Expand Down
Loading