mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 05:48:07 -04:00
* SceneEditorSession: make game vs editor scenes more distinct, Scene is whichever is currently active * Route prefab update, model reload etc events to both scenes if needed * SceneTree update checking a bit cleaner * Bring back GameEditorSessions instead, so undo, selection etc can all be linked 1:1 with scenes again * tweak and tidy
73 lines
1.6 KiB
C#
73 lines
1.6 KiB
C#
namespace Editor;
|
|
|
|
/// <summary>
|
|
/// The scene dock is the actual tab that is shown in the editor. Its main
|
|
/// job is to host the SceneViewWidget and to switch the active session when
|
|
/// the dock is hovered or focused. It also destroys the session when the dock
|
|
/// is closed.
|
|
/// </summary>
|
|
/// Sol: does this need to exist? can't we just dock the view widget directly?
|
|
public partial class SceneDock : Widget
|
|
{
|
|
public SceneEditorSession Session => _editorSession.GameSession ?? _editorSession;
|
|
private SceneEditorSession _editorSession;
|
|
|
|
public SceneDock( SceneEditorSession session ) : base( null )
|
|
{
|
|
_editorSession = session;
|
|
|
|
Layout = Layout.Row();
|
|
Layout.Add( new SceneViewWidget( session, this ) );
|
|
DeleteOnClose = true;
|
|
|
|
Name = session.Scene.Source?.ResourcePath;
|
|
}
|
|
|
|
protected override bool OnClose()
|
|
{
|
|
if ( _editorSession.HasUnsavedChanges )
|
|
{
|
|
this.ShowUnsavedChangesDialog(
|
|
assetName: _editorSession.Scene.Name,
|
|
assetType: _editorSession.IsPrefabSession ? "prefab" : "scene",
|
|
onSave: () => _editorSession.Save( false ) );
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override void OnDestroyed()
|
|
{
|
|
base.OnDestroyed();
|
|
|
|
_editorSession.Destroy();
|
|
_editorSession = null;
|
|
}
|
|
|
|
protected override void OnVisibilityChanged( bool visible )
|
|
{
|
|
base.OnVisibilityChanged( visible );
|
|
|
|
if ( visible )
|
|
{
|
|
Session.MakeActive();
|
|
}
|
|
}
|
|
|
|
protected override void OnFocus( FocusChangeReason reason )
|
|
{
|
|
base.OnFocus( reason );
|
|
|
|
Session.MakeActive();
|
|
}
|
|
|
|
protected override void OnMousePress( MouseEvent e )
|
|
{
|
|
base.OnMousePress( e );
|
|
|
|
Session.MakeActive();
|
|
}
|
|
}
|