From ace45eabf3149e79e1058c419d970c22ff98d6ab Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 12 Aug 2024 20:36:26 -0500 Subject: [PATCH 1/2] Keep properties window scroll for actors. --- Source/Editor/Windows/PropertiesWindow.cs | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Source/Editor/Windows/PropertiesWindow.cs b/Source/Editor/Windows/PropertiesWindow.cs index 9c1cbec0d..23aedf46a 100644 --- a/Source/Editor/Windows/PropertiesWindow.cs +++ b/Source/Editor/Windows/PropertiesWindow.cs @@ -1,11 +1,13 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. +using System; using System.Collections.Generic; using System.Linq; using System.Xml; using FlaxEditor.CustomEditors; using FlaxEditor.SceneGraph; using FlaxEditor.Viewport; +using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.Windows @@ -19,6 +21,8 @@ namespace FlaxEditor.Windows { private IEnumerable undoRecordObjects; + private readonly Dictionary _actorScrollValues = new Dictionary(); + /// public override bool UseLayoutData => true; @@ -57,7 +61,46 @@ namespace FlaxEditor.Windows Presenter.GetUndoObjects += GetUndoObjects; Presenter.Features |= FeatureFlags.CacheExpandedGroups; + VScrollBar.ValueChanged += OnScrollValueChanged; Editor.SceneEditing.SelectionChanged += OnSelectionChanged; + Editor.Scene.ActorRemoved += OnActorRemoved; + } + + /// + public override void OnSceneLoaded(Scene scene, Guid sceneId) + { + base.OnSceneLoaded(scene, sceneId); + + // Clear scroll values if new scene is loaded non additively + if (Level.ScenesCount > 1) + return; + _actorScrollValues.Clear(); + } + + private void OnActorRemoved(ActorNode node) + { + _actorScrollValues.Remove(node.ID.ToString()); + } + + private void OnScrollValueChanged() + { + if (Editor.SceneEditing.SelectionCount > 1) + return; + + // Clear first 10 scroll values to keep the memory down. Dont need to cache very single value in a scene. We could expose this as a editor setting in the future. + if (_actorScrollValues.Count >= 20) + { + int i = 0; + foreach (var e in _actorScrollValues) + { + if (i >= 10) + break; + _actorScrollValues.Remove(e.Key); + i += 1; + } + } + + _actorScrollValues[Editor.SceneEditing.Selection[0].ID.ToString()] = VScrollBar.TargetValue.ToString("0"); } private IEnumerable GetUndoObjects(CustomEditorPresenter customEditorPresenter) @@ -75,6 +118,15 @@ namespace FlaxEditor.Windows undoRecordObjects = Editor.SceneEditing.Selection.ConvertAll(x => x.UndoRecordObject).Distinct(); var objects = Editor.SceneEditing.Selection.ConvertAll(x => x.EditableObject).Distinct(); Presenter.Select(objects); + + // Set scroll value of window if it exists + if (Editor.SceneEditing.SelectionCount == 1) + { + if (_actorScrollValues.TryGetValue(Editor.SceneEditing.Selection[0].ID.ToString(), out var outValue)) + VScrollBar.TargetValue = Convert.ToSingle(outValue); + else + VScrollBar.TargetValue = 0; + } } /// From dcffb422e57b6f3488bb7f04b4da113c2488da0e Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 15 Aug 2024 08:37:00 -0500 Subject: [PATCH 2/2] Change actor scroll cache to use guid and float instead of strings, remove onactor removed code to keep values after undo. --- Source/Editor/Windows/PropertiesWindow.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Source/Editor/Windows/PropertiesWindow.cs b/Source/Editor/Windows/PropertiesWindow.cs index 23aedf46a..423d3af18 100644 --- a/Source/Editor/Windows/PropertiesWindow.cs +++ b/Source/Editor/Windows/PropertiesWindow.cs @@ -21,7 +21,7 @@ namespace FlaxEditor.Windows { private IEnumerable undoRecordObjects; - private readonly Dictionary _actorScrollValues = new Dictionary(); + private readonly Dictionary _actorScrollValues = new Dictionary(); /// public override bool UseLayoutData => true; @@ -63,7 +63,6 @@ namespace FlaxEditor.Windows VScrollBar.ValueChanged += OnScrollValueChanged; Editor.SceneEditing.SelectionChanged += OnSelectionChanged; - Editor.Scene.ActorRemoved += OnActorRemoved; } /// @@ -77,11 +76,6 @@ namespace FlaxEditor.Windows _actorScrollValues.Clear(); } - private void OnActorRemoved(ActorNode node) - { - _actorScrollValues.Remove(node.ID.ToString()); - } - private void OnScrollValueChanged() { if (Editor.SceneEditing.SelectionCount > 1) @@ -100,7 +94,7 @@ namespace FlaxEditor.Windows } } - _actorScrollValues[Editor.SceneEditing.Selection[0].ID.ToString()] = VScrollBar.TargetValue.ToString("0"); + _actorScrollValues[Editor.SceneEditing.Selection[0].ID] = VScrollBar.TargetValue; } private IEnumerable GetUndoObjects(CustomEditorPresenter customEditorPresenter) @@ -121,12 +115,7 @@ namespace FlaxEditor.Windows // Set scroll value of window if it exists if (Editor.SceneEditing.SelectionCount == 1) - { - if (_actorScrollValues.TryGetValue(Editor.SceneEditing.Selection[0].ID.ToString(), out var outValue)) - VScrollBar.TargetValue = Convert.ToSingle(outValue); - else - VScrollBar.TargetValue = 0; - } + VScrollBar.TargetValue = _actorScrollValues.GetValueOrDefault(Editor.SceneEditing.Selection[0].ID, 0); } ///