diff --git a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetFilterView.cs b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetFilterView.cs index 351095b..055c1fd 100644 --- a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetFilterView.cs +++ b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetFilterView.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Reflection; using SmartAddresser.Editor.Core.Models.Shared.AssetGroups; using SmartAddresser.Editor.Foundation.CustomDrawers; @@ -15,16 +16,20 @@ internal sealed class AssetFilterView : IDisposable { private const string RemoveMenuName = "Remove Filter"; private const string MoveUpMenuName = "Move Up Filter"; + private const string MoveUpByMenuName = "Move Up Filter By"; private const string PasteMenuName = "Paste Filter As New"; private const string PasteValuesMenuName = "Paste Filter Values"; private const string MoveDownMenuName = "Move Down Filter"; + private const string MoveDownByMenuName = "Move Down Filter By"; private const string CopyMenuName = "Copy Filter"; private readonly Subject _copyMenuExecutedSubject = new Subject(); private readonly ICustomDrawer _drawer; private readonly Subject _mouseButtonClickedSubject = new Subject(); private readonly Subject _moveDownMenuExecutedSubject = new Subject(); + private readonly Subject _moveDownByMenuExecutedSubject = new Subject(); private readonly Subject _moveUpMenuExecutedSubject = new Subject(); + private readonly Subject _moveUpByMenuExecutedSubject = new Subject(); private readonly Subject _pasteMenuExecutedSubject = new Subject(); private readonly Subject _pasteValuesMenuExecutedSubject = new Subject(); private readonly Subject _removeMenuExecutedSubject = new Subject(); @@ -49,7 +54,9 @@ public AssetFilterView(IAssetFilter filter) public IObservable RemoveMenuExecutedAsObservable => _removeMenuExecutedSubject; public IObservable MoveUpMenuExecutedAsObservable => _moveUpMenuExecutedSubject; + public IObservable MoveUpByMenuExecutedAsObservable => _moveUpByMenuExecutedSubject; public IObservable MoveDownMenuExecutedAsObservable => _moveDownMenuExecutedSubject; + public IObservable MoveDownByMenuExecutedAsObservable => _moveDownByMenuExecutedSubject; public IObservable ValueChangedAsObservable => _valueChangedSubject; public IObservable CopyMenuExecutedAsObservable => _copyMenuExecutedSubject; public IObservable PasteMenuExecutedSubject => _pasteMenuExecutedSubject; @@ -71,6 +78,9 @@ public void Dispose() public event Func CanPaste; public event Func CanPasteValues; + public event Func> GetMoveUpByOptions; + public event Func> GetMoveDownByOptions; + public void DoLayout() { var attribute = Filter.GetType().GetCustomAttribute(); @@ -115,8 +125,26 @@ public void DoLayout() () => _removeMenuExecutedSubject.OnNext(Empty.Default)); menu.AddItem(new GUIContent(MoveUpMenuName), false, () => _moveUpMenuExecutedSubject.OnNext(Empty.Default)); + + var moveUpByList = GetMoveUpByOptions?.Invoke(); + if (moveUpByList == null || moveUpByList.Count == 0) + menu.AddDisabledItem(new GUIContent(MoveUpByMenuName), false); + else + foreach (var count in moveUpByList) + menu.AddItem(new GUIContent($"{MoveUpByMenuName}/{count}"), false, + () => _moveUpByMenuExecutedSubject.OnNext(count)); + menu.AddItem(new GUIContent(MoveDownMenuName), false, () => _moveDownMenuExecutedSubject.OnNext(Empty.Default)); + + var moveDownByList = GetMoveDownByOptions?.Invoke(); + if (moveDownByList == null || moveDownByList.Count == 0) + menu.AddDisabledItem(new GUIContent(MoveDownByMenuName), false); + else + foreach (var count in moveDownByList) + menu.AddItem(new GUIContent($"{MoveDownByMenuName}/{count}"), false, + () => _moveDownByMenuExecutedSubject.OnNext(count)); + menu.AddItem(new GUIContent(CopyMenuName), false, () => _copyMenuExecutedSubject.OnNext(Empty.Default)); diff --git a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetFilterViewPresenter.cs b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetFilterViewPresenter.cs index 3ef039a..4d5ec5a 100644 --- a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetFilterViewPresenter.cs +++ b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetFilterViewPresenter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using SmartAddresser.Editor.Core.Models.Shared.AssetGroups; using SmartAddresser.Editor.Foundation.CommandBasedUndo; using SmartAddresser.Editor.Foundation.TinyRx; @@ -37,9 +38,13 @@ public AssetFilterViewPresenter(IList filterCollection, AssetFilte view.CanPaste += CanPaste; view.CanPasteValues += CanPasteValues; + view.GetMoveUpByOptions += GetMoveUpByOptions; + view.GetMoveDownByOptions += GetMoveDownByOptions; view.RemoveMenuExecutedAsObservable.Subscribe(_ => Remove()).DisposeWith(_disposable); view.MoveUpMenuExecutedAsObservable.Subscribe(_ => MoveUp()).DisposeWith(_disposable); + view.MoveUpByMenuExecutedAsObservable.Subscribe(MoveUpBy).DisposeWith(_disposable); view.MoveDownMenuExecutedAsObservable.Subscribe(_ => MoveDown()).DisposeWith(_disposable); + view.MoveDownByMenuExecutedAsObservable.Subscribe(MoveDownBy).DisposeWith(_disposable); view.CopyMenuExecutedAsObservable.Subscribe(_ => Copy()).DisposeWith(_disposable); view.PasteMenuExecutedSubject.Subscribe(_ => Paste()).DisposeWith(_disposable); view.PasteValuesMenuExecutedSubject.Subscribe(_ => PasteValues()).DisposeWith(_disposable); @@ -51,6 +56,8 @@ public void Dispose() { _view.CanPaste -= CanPaste; _view.CanPasteValues -= CanPasteValues; + _view.GetMoveUpByOptions -= GetMoveUpByOptions; + _view.GetMoveDownByOptions -= GetMoveDownByOptions; _disposable.Dispose(); } @@ -92,38 +99,48 @@ private void Remove() } private void MoveUp() + { + MoveUpBy(1); + } + + private void MoveUpBy(int d) { var index = _filterCollection.IndexOf(_filter); - if (index == 0) + if (index - d < 0) return; - _history.Register($"Move Up Filter {_filter.Id} {index}", () => + _history.Register($"Move Up Filter {_filter.Id} {index} By {d}", () => { _filterCollection.RemoveAt(index); - _filterCollection.Insert(index - 1, _filter); + _filterCollection.Insert(index - d, _filter); _saveService.Save(); }, () => { - _filterCollection.RemoveAt(index - 1); + _filterCollection.RemoveAt(index - d); _filterCollection.Insert(index, _filter); _saveService.Save(); }); } private void MoveDown() + { + MoveDownBy(1); + } + + private void MoveDownBy(int d) { var index = _filterCollection.IndexOf(_filter); - if (index == _filterCollection.Count - 1) + if (index + d >= _filterCollection.Count) return; - _history.Register($"Move Down Filter {_filter.Id} {index}", () => + _history.Register($"Move Down Filter {_filter.Id} {index} By {d}", () => { _filterCollection.RemoveAt(index); - _filterCollection.Insert(index + 1, _filter); + _filterCollection.Insert(index + d, _filter); _saveService.Save(); }, () => { - _filterCollection.RemoveAt(index + 1); + _filterCollection.RemoveAt(index + d); _filterCollection.Insert(index, _filter); _saveService.Save(); }); @@ -179,5 +196,17 @@ private void PasteValues() _saveService.Save(); }); } + + private ICollection GetMoveUpByOptions() + { + var index = _filterCollection.IndexOf(_filter); + return index == 0 ? Array.Empty() : Enumerable.Range(1, index).ToArray(); + } + + private ICollection GetMoveDownByOptions() + { + var index = _filterCollection.IndexOf(_filter); + return index == _filterCollection.Count - 1 ? Array.Empty() : Enumerable.Range(1, _filterCollection.Count - index - 1).ToArray(); + } } } diff --git a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelPresenter.cs b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelPresenter.cs index d3ecd43..209e290 100644 --- a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelPresenter.cs +++ b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelPresenter.cs @@ -130,11 +130,15 @@ private void SetupViewEventHandlers() _view.CanPasteGroup += CanPasteGroup; _view.CanPasteGroupValues += CanPasteGroupValues; _view.CanPasteFilter += CanPasteFilter; + _view.GetMoveUpByOptions += GetMoveUpByOptions; + _view.GetMoveDownByOptions += GetMoveDownByOptions; _view.NameChangedAsObservable.Subscribe(SetGroupName).DisposeWith(_viewEventDisposables); _view.AddFilterButtonClickedAsObservable.Subscribe(_ => AddFilter()).DisposeWith(_viewEventDisposables); _view.RemoveGroupMenuExecutedAsObservable.Subscribe(_ => RemoveGroup()).DisposeWith(_viewEventDisposables); _view.MoveUpMenuExecutedAsObservable.Subscribe(_ => MoveUpGroup()).DisposeWith(_viewEventDisposables); + _view.MoveUpByMenuExecutedAsObservable.Subscribe(MoveUpByGroup).DisposeWith(_viewEventDisposables); _view.MoveDownMenuExecutedAsObservable.Subscribe(_ => MoveDownGroup()).DisposeWith(_viewEventDisposables); + _view.MoveDownByMenuExecutedAsObservable.Subscribe(MoveDownByGroup).DisposeWith(_viewEventDisposables); _view.CopyGroupMenuExecutedAsObservable.Subscribe(_ => CopyGroup()).DisposeWith(_viewEventDisposables); _view.PasteGroupMenuExecutedSubject.Subscribe(_ => PasteGroup()).DisposeWith(_viewEventDisposables); _view.PasteGroupValuesMenuExecutedSubject.Subscribe(_ => PasteGroupValues()) @@ -178,44 +182,54 @@ void RemoveGroup() } void MoveUpGroup() + { + MoveUpByGroup(1); + } + + void MoveUpByGroup(int d) { if (!_didSetupView) return; var index = _groups.IndexOf(_group); - if (index == 0) + if (index - d < 0) return; - _history.Register($"Move Up Group {_group.Id} {index}", () => + _history.Register($"Move Up Group {_group.Id} {index} By {d}", () => { _groups.RemoveAt(index); - _groups.Insert(index - 1, _group); + _groups.Insert(index - d, _group); _saveService.Save(); }, () => { - _groups.RemoveAt(index - 1); + _groups.RemoveAt(index - d); _groups.Insert(index, _group); _saveService.Save(); }); } void MoveDownGroup() + { + MoveDownByGroup(1); + } + + void MoveDownByGroup(int d) { if (!_didSetupView) return; var index = _groups.IndexOf(_group); - if (index == _groups.Count - 1) + if (index + d >= _groups.Count) return; - _history.Register($"Move Down Filter {_group.Id} {index}", () => + _history.Register($"Move Down Group {_group.Id} {index} By {d}", () => { _groups.RemoveAt(index); - _groups.Insert(index + 1, _group); + _groups.Insert(index + d, _group); _saveService.Save(); }, () => { - _groups.RemoveAt(index + 1); + _groups.RemoveAt(index + d); _groups.Insert(index, _group); _saveService.Save(); }); @@ -337,6 +351,8 @@ private void CleanupViewEventHandlers() _view.CanPasteGroup -= CanPasteGroup; _view.CanPasteGroupValues -= CanPasteGroupValues; _view.CanPasteFilter -= CanPasteFilter; + _view.GetMoveUpByOptions -= GetMoveUpByOptions; + _view.GetMoveDownByOptions -= GetMoveDownByOptions; } private bool CanPasteGroup() @@ -362,5 +378,23 @@ private bool CanPasteFilter() return typeof(IAssetFilter).IsAssignableFrom(ObjectCopyBuffer.Type); } + + private ICollection GetMoveUpByOptions() + { + if (!_didSetupView) + return Array.Empty(); + + var index = _groups.IndexOf(_group); + return index == 0 ? Array.Empty() : Enumerable.Range(1, index).ToArray(); + } + + private ICollection GetMoveDownByOptions() + { + if (!_didSetupView) + return Array.Empty(); + + var index = _groups.IndexOf(_group); + return index == _groups.Count - 1 ? Array.Empty() : Enumerable.Range(1, _groups.Count - index - 1).ToArray(); + } } } diff --git a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelView.cs b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelView.cs index cf52fed..5e45e7b 100644 --- a/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelView.cs +++ b/Assets/SmartAddresser/Editor/Core/Tools/Addresser/Shared/AssetGroups/AssetGroupPanelView.cs @@ -18,7 +18,9 @@ internal sealed class AssetGroupPanelView : IDisposable private const string RenameMenuName = "Rename"; private const string RemoveMenuName = "Remove"; private const string MoveUpMenuName = "Move Up"; + private const string MoveUpByMenuName = "Move Up By"; private const string MoveDownMenuName = "Move Down"; + private const string MoveDownByMenuName = "Move Down By"; private const string CopyMenuName = "Copy"; private const string PasteMenuName = "Paste As New"; private const string PasteValuesMenuName = "Paste Values"; @@ -32,7 +34,9 @@ internal sealed class AssetGroupPanelView : IDisposable private readonly List _filterViewsOrder = new List(); private readonly Subject _moveDownMenuExecutedSubject = new Subject(); + private readonly Subject _moveDownByMenuExecutedSubject = new Subject(); private readonly Subject _moveUpMenuExecutedSubject = new Subject(); + private readonly Subject _moveUpByMenuExecutedSubject = new Subject(); private readonly Subject _nameChangedSubject = new Subject(); private readonly Subject _pasteFilterMenuExecutedSubject = new Subject(); private readonly Subject _pasteGroupMenuExecutedSubject = new Subject(); @@ -49,8 +53,12 @@ internal sealed class AssetGroupPanelView : IDisposable public IObservable MoveUpMenuExecutedAsObservable => _moveUpMenuExecutedSubject; + public IObservable MoveUpByMenuExecutedAsObservable => _moveUpByMenuExecutedSubject; + public IObservable MoveDownMenuExecutedAsObservable => _moveDownMenuExecutedSubject; + public IObservable MoveDownByMenuExecutedAsObservable => _moveDownByMenuExecutedSubject; + public IObservable CopyGroupMenuExecutedAsObservable => _copyGroupMenuExecutedSubject; public IObservable PasteGroupMenuExecutedSubject => _pasteGroupMenuExecutedSubject; @@ -72,7 +80,9 @@ public void Dispose() _nameChangedSubject.Dispose(); _addFilterButtonClickedSubject.Dispose(); _moveUpMenuExecutedSubject.Dispose(); + _moveUpByMenuExecutedSubject.Dispose(); _moveDownMenuExecutedSubject.Dispose(); + _moveDownByMenuExecutedSubject.Dispose(); _copyGroupMenuExecutedSubject.Dispose(); _pasteGroupMenuExecutedSubject.Dispose(); _pasteGroupValuesMenuExecutedSubject.Dispose(); @@ -84,6 +94,9 @@ public void Dispose() public event Func CanPasteGroupValues; public event Func CanPasteFilter; + public event Func> GetMoveUpByOptions; + public event Func> GetMoveDownByOptions; + public AssetFilterView AddFilterView(IAssetFilter filter, int index = -1) { var filterView = new AssetFilterView(filter); @@ -162,10 +175,28 @@ public void DoLayout() menu.AddItem(new GUIContent(MoveUpMenuName), false, () => _moveUpMenuExecutedSubject.OnNext(Empty.Default)); + // Move Up By + var moveUpByList = GetMoveUpByOptions?.Invoke(); + if (moveUpByList == null || moveUpByList.Count == 0) + menu.AddDisabledItem(new GUIContent(MoveUpByMenuName), false); + else + foreach (var count in moveUpByList) + menu.AddItem(new GUIContent($"{MoveUpByMenuName}/{count}"), false, + () => _moveUpByMenuExecutedSubject.OnNext(count)); + // Move Down menu.AddItem(new GUIContent(MoveDownMenuName), false, () => _moveDownMenuExecutedSubject.OnNext(Empty.Default)); + // Move Down By + var moveDownByList = GetMoveDownByOptions?.Invoke(); + if (moveDownByList == null || moveDownByList.Count == 0) + menu.AddDisabledItem(new GUIContent(MoveDownByMenuName), false); + else + foreach (var count in moveDownByList) + menu.AddItem(new GUIContent($"{MoveDownByMenuName}/{count}"), false, + () => _moveDownByMenuExecutedSubject.OnNext(count)); + // Copy Group menu.AddItem(new GUIContent(CopyMenuName), false, () => _copyGroupMenuExecutedSubject.OnNext(Empty.Default));