Merge branch 'keep-scroll' of https://github.com/Tryibion/FlaxEngine into Tryibion-keep-scroll
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using FlaxEditor.CustomEditors;
|
using FlaxEditor.CustomEditors;
|
||||||
using FlaxEditor.SceneGraph;
|
using FlaxEditor.SceneGraph;
|
||||||
using FlaxEditor.Viewport;
|
using FlaxEditor.Viewport;
|
||||||
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
|
|
||||||
namespace FlaxEditor.Windows
|
namespace FlaxEditor.Windows
|
||||||
@@ -19,6 +21,8 @@ namespace FlaxEditor.Windows
|
|||||||
{
|
{
|
||||||
private IEnumerable<object> undoRecordObjects;
|
private IEnumerable<object> undoRecordObjects;
|
||||||
|
|
||||||
|
private readonly Dictionary<Guid, float> _actorScrollValues = new Dictionary<Guid, float>();
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool UseLayoutData => true;
|
public override bool UseLayoutData => true;
|
||||||
|
|
||||||
@@ -57,9 +61,42 @@ namespace FlaxEditor.Windows
|
|||||||
Presenter.GetUndoObjects += GetUndoObjects;
|
Presenter.GetUndoObjects += GetUndoObjects;
|
||||||
Presenter.Features |= FeatureFlags.CacheExpandedGroups;
|
Presenter.Features |= FeatureFlags.CacheExpandedGroups;
|
||||||
|
|
||||||
|
VScrollBar.ValueChanged += OnScrollValueChanged;
|
||||||
Editor.SceneEditing.SelectionChanged += OnSelectionChanged;
|
Editor.SceneEditing.SelectionChanged += OnSelectionChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
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 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] = VScrollBar.TargetValue;
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerable<object> GetUndoObjects(CustomEditorPresenter customEditorPresenter)
|
private IEnumerable<object> GetUndoObjects(CustomEditorPresenter customEditorPresenter)
|
||||||
{
|
{
|
||||||
return undoRecordObjects;
|
return undoRecordObjects;
|
||||||
@@ -75,6 +112,10 @@ namespace FlaxEditor.Windows
|
|||||||
undoRecordObjects = Editor.SceneEditing.Selection.ConvertAll(x => x.UndoRecordObject).Distinct();
|
undoRecordObjects = Editor.SceneEditing.Selection.ConvertAll(x => x.UndoRecordObject).Distinct();
|
||||||
var objects = Editor.SceneEditing.Selection.ConvertAll(x => x.EditableObject).Distinct();
|
var objects = Editor.SceneEditing.Selection.ConvertAll(x => x.EditableObject).Distinct();
|
||||||
Presenter.Select(objects);
|
Presenter.Select(objects);
|
||||||
|
|
||||||
|
// Set scroll value of window if it exists
|
||||||
|
if (Editor.SceneEditing.SelectionCount == 1)
|
||||||
|
VScrollBar.TargetValue = _actorScrollValues.GetValueOrDefault(Editor.SceneEditing.Selection[0].ID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
Reference in New Issue
Block a user