From 363d1619bcbe7d55fced993a30e10a8536e4ec62 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 7 Oct 2023 03:17:01 +0200 Subject: [PATCH] Add drag & drop of automated designs to other automated design sets. --- Glamourer/Automation/AutoDesignManager.cs | 15 ++++++++++ Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs | 5 +++- .../Gui/Tabs/AutomationTab/SetSelector.cs | 29 +++++++++++++++---- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Glamourer/Automation/AutoDesignManager.cs b/Glamourer/Automation/AutoDesignManager.cs index 14fb084..72206c4 100644 --- a/Glamourer/Automation/AutoDesignManager.cs +++ b/Glamourer/Automation/AutoDesignManager.cs @@ -247,6 +247,21 @@ public class AutoDesignManager : ISavable, IReadOnlyList, IDispos _event.Invoke(AutomationChanged.Type.AddedDesign, set, set.Designs.Count - 1); } + /// Only used to move between sets. + public void MoveDesignToSet(AutoDesignSet from, int idx, AutoDesignSet to) + { + if (ReferenceEquals(from, to)) + return; + + var design = from.Designs[idx]; + to.Designs.Add(design); + from.Designs.RemoveAt(idx); + Save(); + Glamourer.Log.Debug($"Moved design {idx} from design set {from.Name} to design set {to.Name}."); + _event.Invoke(AutomationChanged.Type.AddedDesign, to, to.Designs.Count - 1); + _event.Invoke(AutomationChanged.Type.DeletedDesign, from, idx); + } + public void DeleteDesign(AutoDesignSet set, int which) { if (which >= set.Designs.Count || which < 0) diff --git a/Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs b/Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs index a10f1ff..a1c1fcf 100644 --- a/Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs +++ b/Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs @@ -346,7 +346,10 @@ public class SetPanel { ImGui.TextUnformatted($"Moving design #{index + 1:D2}..."); if (ImGui.SetDragDropPayload(dragDropLabel, nint.Zero, 0)) - _dragIndex = index; + { + _dragIndex = index; + _selector._dragDesignIndex = index; + } } } } diff --git a/Glamourer/Gui/Tabs/AutomationTab/SetSelector.cs b/Glamourer/Gui/Tabs/AutomationTab/SetSelector.cs index 10b6383..2aaf120 100644 --- a/Glamourer/Gui/Tabs/AutomationTab/SetSelector.cs +++ b/Glamourer/Gui/Tabs/AutomationTab/SetSelector.cs @@ -42,6 +42,8 @@ public class SetSelector : IDisposable private int _dragIndex = -1; private Action? _endAction; + internal int _dragDesignIndex = -1; + public SetSelector(AutoDesignManager manager, AutomationChanged @event, Configuration config, ActorService actors, ObjectManager objects) { _manager = manager; @@ -320,15 +322,30 @@ public class SetSelector : IDisposable const string dragDropLabel = "DesignSetDragDrop"; using (var target = ImRaii.DragDropTarget()) { - if (target.Success && ImGuiUtil.IsDropping(dragDropLabel)) + if (target.Success) { - if (_dragIndex >= 0) + if (ImGuiUtil.IsDropping(dragDropLabel)) { - var idx = _dragIndex; - _endAction = () => _manager.MoveSet(idx, index); - } + if (_dragIndex >= 0) + { + var idx = _dragIndex; + _endAction = () => _manager.MoveSet(idx, index); + } - _dragIndex = -1; + _dragIndex = -1; + } + else if (ImGuiUtil.IsDropping("DesignDragDrop")) + { + if (_dragDesignIndex >= 0) + { + var idx = _dragDesignIndex; + var setTo = set; + var setFrom = Selection!; + _endAction = () => _manager.MoveDesignToSet(setFrom, idx, setTo); + } + + _dragDesignIndex = -1; + } } }