UI/Window/SettingsWindow.razor
@using Sandbox
@using Sandbox.UI
@using System
@using HC3.Persistence;

@namespace HC3.UI
@inherits Window

<root>
    <div class="settings-window">
        <div class="setting-item window-button" onclick="@(() => NewGame())">
            <Silkicon Icon="new" />
            <label>New Park</label>
        </div>
        <div class="setting-item window-button" onclick="@(() => LoadGame())">
            <Silkicon Icon="database" />
            <label>Load Park</label>
        </div>
        <div class="setting-item window-button" onclick="@(() => SaveGame())">
            <Silkicon Icon="database_save" />
            <label>Save Park</label>
        </div>
        <div class="setting-item window-button" onclick="@(() => QuitGame())">
            <Silkicon Icon="cancel" />
            <label>Quit</label>
        </div>
    </div>
</root>

@code
{
    public override string Title => "Settings";
    public override object Key => "SettingsWindow";
    public override string Icon => "cog";

    Window _windowNewGame = null;
    Window _windowLoadGame = null;

    void NewGame()
    {
        if (_windowNewGame.IsValid())
        {
            _windowNewGame?.Close();
            _windowNewGame = null;
            return;
        }
        _windowNewGame = new UI.RenameDialog($"What would you like to name the new game?", "", (s) =>
        {
            PersistenceManager.Instance.NewGame(s);
        });
        OpenSubwindow(_windowNewGame);
    }

    void LoadGame()
    {
        if (_windowLoadGame.IsValid())
        {
            _windowLoadGame?.Close();
            _windowLoadGame = null;
            return;
        }
        _windowLoadGame = new LoadGameWindow();
        OpenSubwindow(_windowLoadGame);
    }

    void SaveGame()
    {
        PersistenceManager.Instance.Save();
        Close();
    }

	void QuitGame()
	{
		Game.Close();
	}

    static SettingsWindow settingsWindow;

	public static void Show()
	{
		if ( settingsWindow.IsValid() )
		{
			settingsWindow.Close();
			settingsWindow = null;
			return;
		}

		settingsWindow = new SettingsWindow();
		WindowManager.Instance.Open( settingsWindow );

		settingsWindow.SetPosition( Mouse.Position + Vector2.Right * 100, Window.ScreenAlignment.TopLeft);
	}
}