Add drag & drop of automated designs to other automated design sets.

This commit is contained in:
Ottermandias 2023-10-07 03:17:01 +02:00
parent 455bdae717
commit 363d1619bc
3 changed files with 42 additions and 7 deletions

View file

@ -247,6 +247,21 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDispos
_event.Invoke(AutomationChanged.Type.AddedDesign, set, set.Designs.Count - 1);
}
/// <remarks> Only used to move between sets. </remarks>
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)

View file

@ -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;
}
}
}
}

View file

@ -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;
}
}
}