mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-23 14:38:13 -05:00
Scope last selected SceneViewportWidget to SceneViewWidget (#3616)
- Remove static LastSelected SceneViewportWidget. It should be scoped to the last selected viewport within a particular Scene view - Add LastSelectedViewportWidget to SceneViewWidget - Re-add focusing the last selected widget that was hotfixed in #114 --------- Co-authored-by: aidencurtis <109600275+aidencurtis@users.noreply.github.com> Co-authored-by: Carson Kompon <carsokompo@gmail.com>
This commit is contained in:
@@ -153,7 +153,7 @@ public partial class Document
|
||||
BuildUnwrappedMeshWithSquareMapping();
|
||||
break;
|
||||
case MappingMode.Planar:
|
||||
var cameraRot = SceneViewportWidget.LastSelected.State.CameraRotation;
|
||||
var cameraRot = SceneViewWidget.Current.LastSelectedViewportWidget.State.CameraRotation;
|
||||
BuildUnwrappedMeshWithPlanarMapping( cameraRot.Left, cameraRot.Up );
|
||||
break;
|
||||
case MappingMode.UseExisting:
|
||||
|
||||
@@ -120,7 +120,7 @@ public static class SceneEditorExtensions
|
||||
currentSpeed = Math.Clamp( currentSpeed, 0.25f, 100.0f );
|
||||
|
||||
EditorPreferences.CameraSpeed = currentSpeed;
|
||||
SceneViewportWidget.LastSelected.timeSinceCameraSpeedChange = 0;
|
||||
SceneViewWidget.Current?.LastSelectedViewportWidget?.timeSinceCameraSpeedChange = 0;
|
||||
}
|
||||
|
||||
var sens = EditorPreferences.CameraSensitivity;
|
||||
|
||||
@@ -199,7 +199,7 @@ partial class TextureTool
|
||||
|
||||
private void AlignToView()
|
||||
{
|
||||
var sceneView = SceneViewportWidget.LastSelected;
|
||||
var sceneView = SceneViewWidget.Current?.LastSelectedViewportWidget;
|
||||
if ( !sceneView.IsValid() )
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Editor.MapEditor;
|
||||
|
||||
namespace Editor;
|
||||
namespace Editor;
|
||||
|
||||
public static class SceneEditorMenus
|
||||
{
|
||||
@@ -146,13 +144,17 @@ public static class SceneEditorMenus
|
||||
[Shortcut( "gameObject.align-to-view", "CTRL+SHIFT+F" )]
|
||||
public static void AlignToView()
|
||||
{
|
||||
if ( !SceneViewportWidget.LastSelected.IsValid() )
|
||||
if ( SceneViewWidget.Current is null )
|
||||
return;
|
||||
|
||||
var lastSelectedViewportWidget = SceneViewWidget.Current.LastSelectedViewportWidget;
|
||||
if ( !lastSelectedViewportWidget.IsValid() )
|
||||
return;
|
||||
|
||||
if ( EditorScene.Selection.Count == 0 )
|
||||
return;
|
||||
|
||||
var targetTransform = new Transform( SceneViewportWidget.LastSelected.State.CameraPosition, SceneViewportWidget.LastSelected.State.CameraRotation );
|
||||
var targetTransform = new Transform( lastSelectedViewportWidget.State.CameraPosition, lastSelectedViewportWidget.State.CameraRotation );
|
||||
var gos = EditorScene.Selection.OfType<GameObject>().ToArray();
|
||||
|
||||
gos.DispatchPreEdited( nameof( GameObject.LocalPosition ) );
|
||||
@@ -331,13 +333,14 @@ public static class SceneEditorMenus
|
||||
if ( !EditorScene.Selection.OfType<GameObject>().Any() )
|
||||
return;
|
||||
|
||||
if ( !SceneViewportWidget.LastSelected.IsValid() )
|
||||
var lastSelectedViewportWidget = SceneViewWidget.Current?.LastSelectedViewportWidget;
|
||||
if ( !lastSelectedViewportWidget.IsValid() )
|
||||
return;
|
||||
|
||||
var gos = EditorScene.Selection.OfType<GameObject>();
|
||||
using ( SceneEditorSession.Active.UndoScope( "Nudge Object(s)" ).WithGameObjectChanges( gos, GameObjectUndoFlags.Properties ).Push() )
|
||||
{
|
||||
var gizmoInstance = SceneViewportWidget.LastSelected.GizmoInstance;
|
||||
var gizmoInstance = lastSelectedViewportWidget.GizmoInstance;
|
||||
|
||||
var rotation = Rotation.Identity;
|
||||
if ( !gizmoInstance.Settings.GlobalSpace )
|
||||
|
||||
@@ -747,10 +747,10 @@ partial class GameObjectNode : TreeNode<GameObject>
|
||||
{
|
||||
go.Parent = parent;
|
||||
|
||||
if ( !EditorPreferences.CreateObjectsAtOrigin && !parent.IsValid() )
|
||||
if ( !EditorPreferences.CreateObjectsAtOrigin && !parent.IsValid() && SceneViewWidget.Current?.LastSelectedViewportWidget?.IsValid() == true )
|
||||
{
|
||||
// I wonder if we should be tracing and placing it on the surface?
|
||||
go.LocalPosition = SceneViewportWidget.LastSelected.State.CameraPosition + SceneViewportWidget.LastSelected.State.CameraRotation.Forward * 300;
|
||||
go.LocalPosition = SceneViewWidget.Current.LastSelectedViewportWidget.State.CameraPosition + SceneViewWidget.Current.LastSelectedViewportWidget.State.CameraRotation.Forward * 300;
|
||||
}
|
||||
|
||||
afterCreate?.Invoke( go );
|
||||
@@ -810,10 +810,10 @@ partial class GameObjectNode : TreeNode<GameObject>
|
||||
{
|
||||
go.Parent = parent;
|
||||
|
||||
if ( !EditorPreferences.CreateObjectsAtOrigin && !parent.IsValid() )
|
||||
if ( !EditorPreferences.CreateObjectsAtOrigin && !parent.IsValid() && SceneViewWidget.Current?.LastSelectedViewportWidget?.IsValid() == true )
|
||||
{
|
||||
// I wonder if we should be tracing and placing it on the surface?
|
||||
go.LocalPosition = SceneViewportWidget.LastSelected.State.CameraPosition + SceneViewportWidget.LastSelected.State.CameraRotation.Forward * 300;
|
||||
go.LocalPosition = SceneViewWidget.Current.LastSelectedViewportWidget.State.CameraPosition + SceneViewWidget.Current.LastSelectedViewportWidget.State.CameraRotation.Forward * 300;
|
||||
}
|
||||
|
||||
afterCreate?.Invoke( go );
|
||||
@@ -891,7 +891,7 @@ partial class GameObjectNode : TreeNode<GameObject>
|
||||
if ( !EditorPreferences.CreateObjectsAtOrigin && !parent.IsValid() )
|
||||
{
|
||||
// I wonder if we should be tracing and placing it on the surface?
|
||||
go.LocalPosition = SceneViewportWidget.LastSelected.State.CameraPosition + SceneViewportWidget.LastSelected.State.CameraRotation.Forward * 300;
|
||||
go.LocalPosition = SceneViewWidget.Current.LastSelectedViewportWidget.State.CameraPosition + SceneViewWidget.Current.LastSelectedViewportWidget.State.CameraRotation.Forward * 300;
|
||||
}
|
||||
|
||||
afterCreate?.Invoke( go );
|
||||
|
||||
@@ -33,6 +33,8 @@ public partial class SceneViewWidget : Widget
|
||||
|
||||
public static SceneViewWidget Current { get; private set; }
|
||||
|
||||
public SceneViewportWidget LastSelectedViewportWidget { get; set; }
|
||||
|
||||
public EditorToolManager Tools { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -338,6 +340,13 @@ file class ViewportToolBar : Widget
|
||||
|
||||
toolWidget.Focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( SceneViewWidget.Current?.LastSelectedViewportWidget?.IsValid() ?? false )
|
||||
{
|
||||
SceneViewWidget.Current.LastSelectedViewportWidget.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
// Update footer
|
||||
var footerWidget = subTool?.CreateToolFooter() ?? rootTool?.CreateToolFooter();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
public partial class SceneViewportWidget : Widget
|
||||
{
|
||||
public static SceneViewportWidget LastSelected { get; private set; }
|
||||
public static Vector2 MousePosition { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
@@ -43,7 +42,7 @@ public partial class SceneViewportWidget : Widget
|
||||
Id = id;
|
||||
if ( Id == 0 )
|
||||
{
|
||||
LastSelected = this;
|
||||
SceneView.LastSelectedViewportWidget = this;
|
||||
}
|
||||
|
||||
if ( ProjectCookie.Get<ViewportState>( $"SceneView.Viewport{Id}.Settings", null ) is ViewportState savedSettings )
|
||||
@@ -447,9 +446,9 @@ public partial class SceneViewportWidget : Widget
|
||||
//
|
||||
|
||||
var hasMouseFocus = hasMouseInput;
|
||||
if ( IsFocused )
|
||||
if ( IsFocused && SceneViewWidget.Current.IsValid() )
|
||||
{
|
||||
LastSelected = this;
|
||||
SceneViewWidget.Current.LastSelectedViewportWidget = this;
|
||||
}
|
||||
|
||||
GizmoInstance.Input.IsHovered = hasMouseFocus;
|
||||
|
||||
@@ -206,7 +206,7 @@ class CameraToolWindow : WidgetWindow
|
||||
{
|
||||
EditorToolManager.CurrentModeName = "camera.lookat";
|
||||
// maintain focus on scene even after clicking the button
|
||||
SceneViewportWidget.LastSelected?.Focus();
|
||||
SceneViewWidget.Current?.LastSelectedViewportWidget?.Focus();
|
||||
}
|
||||
|
||||
void CloseWindow()
|
||||
|
||||
@@ -107,7 +107,7 @@ class NavMeshLinkToolWindow : WidgetWindow
|
||||
isPickingEnd = false;
|
||||
isAddingNewLink = false;
|
||||
helpLabel.Text = "Pick start position for selected link. Press Ctrl or Cancel Button to cancel.";
|
||||
SceneViewportWidget.LastSelected.Focus();
|
||||
SceneViewWidget.Current?.LastSelectedViewportWidget?.Focus();
|
||||
}
|
||||
} );
|
||||
|
||||
@@ -120,7 +120,7 @@ class NavMeshLinkToolWindow : WidgetWindow
|
||||
isPickingStart = false;
|
||||
isAddingNewLink = false;
|
||||
helpLabel.Text = "Pick end position for selected link. Press Ctrl or Cancel Button to cancel.";
|
||||
SceneViewportWidget.LastSelected.Focus();
|
||||
SceneViewWidget.Current?.LastSelectedViewportWidget?.Focus();
|
||||
}
|
||||
} );
|
||||
|
||||
@@ -132,7 +132,7 @@ class NavMeshLinkToolWindow : WidgetWindow
|
||||
isAddingNewLink = true;
|
||||
isPickingStart = true;
|
||||
helpLabel.Text = "Pick start Position for new link. Press Ctrl or Cancel Button to cancel.";
|
||||
SceneViewportWidget.LastSelected.Focus();
|
||||
SceneViewWidget.Current?.LastSelectedViewportWidget?.Focus();
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user