From 65b41f5c52fee2b330362b62059c3fbea6bb37bb Mon Sep 17 00:00:00 2001 From: Asriel Camora Date: Sat, 18 Nov 2023 01:47:45 -0800 Subject: [PATCH] Add drag & drop for macro editor (both action hotbars & moving actions) --- Craftimizer/Windows/MacroEditor.cs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Craftimizer/Windows/MacroEditor.cs b/Craftimizer/Windows/MacroEditor.cs index 7383ca1..f84223b 100644 --- a/Craftimizer/Windows/MacroEditor.cs +++ b/Craftimizer/Windows/MacroEditor.cs @@ -975,6 +975,16 @@ private void DrawActionHotbars() } if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.SetTooltip($"{actions[i].GetName(RecipeData!.ClassJob)}\n{actionBase.GetTooltip(sim, true)}"); + + using var _padding = ImRaii.PushStyle(ImGuiStyleVar.WindowPadding, Vector2.Zero); + using (var _source = ImRaii.DragDropSource()) + { + if (_source) + { + ImGuiExtras.SetDragDropPayload("macroActionInsert", actions[i]); + ImGui.ImageButton(actions[i].GetIcon(RecipeData!.ClassJob).ImGuiHandle, new(imageSize)); + } + } } else ImGui.Dummy(new(imageSize)); @@ -1207,8 +1217,26 @@ private void DrawMacro() ImGui.PopClipRect(); } if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) - { ImGui.SetTooltip($"{action.GetName(RecipeData!.ClassJob)}\n{actionBase.GetTooltip(CreateSim(lastState), true)}"); + + using var _padding = ImRaii.PushStyle(ImGuiStyleVar.WindowPadding, Vector2.Zero); + using (var _source = ImRaii.DragDropSource()) + { + if (_source) + { + ImGuiExtras.SetDragDropPayload("macroAction", i); + ImGui.ImageButton(action.GetIcon(RecipeData!.ClassJob).ImGuiHandle, new(imageSize)); + } + } + using (var _target = ImRaii.DragDropTarget()) + { + if (_target) + { + if (ImGuiExtras.AcceptDragDropPayload("macroAction", out int j)) + Macro.Move(j, i); + else if (ImGuiExtras.AcceptDragDropPayload("macroActionInsert", out ActionType newAction)) + Macro.Insert(i, newAction); + } } lastState = state; }