mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-24 00:10:10 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using Sandbox;
|
|
|
|
namespace Editor
|
|
{
|
|
public partial class Window
|
|
{
|
|
string _stateCookie;
|
|
|
|
/// <summary>
|
|
/// A unique identifier for this window, to store the window state across sessions using the <see cref="Cookie">Cookie</see> library.
|
|
/// </summary>
|
|
public string StateCookie
|
|
{
|
|
get => _stateCookie;
|
|
set
|
|
{
|
|
if ( _stateCookie == value ) return;
|
|
_stateCookie = value;
|
|
|
|
RestoreFromStateCookie();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called whenever the window should restore its state via the <see cref="EditorCookie">EditorCookie</see> library,
|
|
/// that was previously saved in <see cref="SaveToStateCookie"/>.<br/>
|
|
/// You should use <see cref="StateCookie"/> in the cookie name.
|
|
/// </summary>
|
|
public virtual void RestoreFromStateCookie()
|
|
{
|
|
if ( string.IsNullOrWhiteSpace( StateCookie ) )
|
|
return;
|
|
|
|
var state = EditorCookie.GetString( $"Window.{StateCookie}.State", null );
|
|
var geo = EditorCookie.GetString( $"Window.{StateCookie}.Geometry", null );
|
|
|
|
if ( geo != null ) RestoreGeometry( geo );
|
|
if ( state != null ) RestoreState( state );
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called whenever the window should save its state via the <see cref="EditorCookie">EditorCookie</see> library,
|
|
/// to be later restored in <see cref="RestoreFromStateCookie"/>. This is useful to carry data across game sessions.<br/>
|
|
/// You should use <see cref="StateCookie"/> in the cookie name.
|
|
/// </summary>
|
|
[Event( "app.exit" )]
|
|
public virtual void SaveToStateCookie()
|
|
{
|
|
if ( string.IsNullOrWhiteSpace( StateCookie ) )
|
|
return;
|
|
|
|
if ( !this.IsValid() )
|
|
return;
|
|
|
|
var state = SaveState();
|
|
var geo = SaveGeometry();
|
|
|
|
EditorCookie.SetString( $"Window.{StateCookie}.State", state );
|
|
EditorCookie.SetString( $"Window.{StateCookie}.Geometry", geo );
|
|
}
|
|
}
|
|
}
|