Hover over a wider margin to prevent flashing; only execute if able

This commit is contained in:
Asriel Camora
2023-11-16 14:41:18 -08:00
parent e2381eb4b5
commit 5979b8f6f5
2 changed files with 57 additions and 10 deletions
+23
View File
@@ -13,6 +13,12 @@ internal static unsafe class ImGuiExtras
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)] [DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe byte igInputTextEx(byte* label, byte* hint, byte* buf, int buf_size, Vector2 size, ImGuiInputTextFlags flags, ImGuiInputTextCallback? callback, void* user_data); private static extern unsafe byte igInputTextEx(byte* label, byte* hint, byte* buf, int buf_size, Vector2 size, ImGuiInputTextFlags flags, ImGuiInputTextCallback? callback, void* user_data);
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
private static extern bool igItemAdd(Vector4 bb, uint id, Vector4* navBb, uint flags);
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
private static extern bool igButtonBehavior(Vector4 bb, uint id, bool* outHovered, bool* outHeld, ImGuiButtonFlags flags);
// https://github.com/ImGuiNET/ImGui.NET/blob/069363672fed940ebdaa02f9b032c282b66467c7/src/ImGui.NET/Util.cs // https://github.com/ImGuiNET/ImGui.NET/blob/069363672fed940ebdaa02f9b032c282b66467c7/src/ImGui.NET/Util.cs
#region Util #region Util
@@ -136,4 +142,21 @@ internal static unsafe class ImGuiExtras
return result != 0; return result != 0;
} }
public static unsafe bool ItemAdd(Vector4 bb, uint id, out Vector4 navBb, uint flags)
{
fixed (Vector4* navBbPtr = &navBb)
{
return igItemAdd(bb, id, navBbPtr, flags);
}
}
public static unsafe bool ButtonBehavior(Vector4 bb, uint id, out bool hovered, out bool held, ImGuiButtonFlags flags)
{
fixed (bool* hoveredPtr = &hovered)
fixed (bool* heldPtr = &held)
{
return igButtonBehavior(bb, id, hoveredPtr, heldPtr, flags);
}
}
} }
+34 -10
View File
@@ -183,6 +183,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable
{ {
var spacing = ImGui.GetStyle().ItemSpacing.X; var spacing = ImGui.GetStyle().ItemSpacing.X;
var imageSize = ImGui.GetFrameHeight() * 2; var imageSize = ImGui.GetFrameHeight() * 2;
var canExecute = !Service.Condition[ConditionFlag.Crafting40];
var lastState = Macro.InitialState; var lastState = Macro.InitialState;
hoveredState = null; hoveredState = null;
@@ -191,30 +192,53 @@ public sealed unsafe class SynthHelper : Window, IDisposable
using var _color = ImRaii.PushColor(ImGuiCol.Button, Vector4.Zero); using var _color = ImRaii.PushColor(ImGuiCol.Button, Vector4.Zero);
using var _color3 = ImRaii.PushColor(ImGuiCol.ButtonHovered, Vector4.Zero); using var _color3 = ImRaii.PushColor(ImGuiCol.ButtonHovered, Vector4.Zero);
using var _color2 = ImRaii.PushColor(ImGuiCol.ButtonActive, Vector4.Zero); using var _color2 = ImRaii.PushColor(ImGuiCol.ButtonActive, Vector4.Zero);
for (var i = 0; i < Macro.Count; i++) var count = Macro.Count;
for (var i = 0; i < count; i++)
{ {
if (i % itemsPerRow != 0) if (i % itemsPerRow != 0)
ImGui.SameLine(0, spacing); ImGui.SameLine(0, spacing);
var (action, response, state) = (Macro[i].Action, Macro[i].Response, Macro[i].State); var (action, response, state) = (Macro[i].Action, Macro[i].Response, Macro[i].State);
var actionBase = action.Base(); var actionBase = action.Base();
var failedAction = response != ActionResponse.UsedAction; var failedAction = response != ActionResponse.UsedAction;
using var id = ImRaii.PushId(i); using var _id = ImRaii.PushId(i);
if (i == 0) if (i == 0)
{ {
var pos = ImGui.GetCursorScreenPos(); var pos = ImGui.GetCursorScreenPos();
var offset = new Vector2(3); var offsetVec2 = ImGui.GetStyle().ItemSpacing / 2;
ImGui.GetWindowDrawList().AddRectFilled(pos - offset, pos + new Vector2(imageSize) + offset, ImGui.GetColorU32(ImGuiColors.DalamudWhite2), 4); var offset = new Vector2((offsetVec2.X + offsetVec2.Y) / 2f);
var color = canExecute ? ImGuiColors.DalamudWhite2 : ImGuiColors.DalamudGrey3;
ImGui.GetWindowDrawList().AddRectFilled(pos - offset, pos + new Vector2(imageSize) + offset, ImGui.GetColorU32(color), 4);
} }
if (ImGui.ImageButton(action.GetIcon(RecipeData!.ClassJob).ImGuiHandle, new(imageSize), default, Vector2.One, 0, default, failedAction ? new(1, 1, 1, ImGui.GetStyle().DisabledAlpha) : Vector4.One)) bool isHovered, isHeld, isPressed;
{ {
if (i == 0) var pos = ImGui.GetCursorScreenPos();
Chat.SendMessage($"/ac \"{action.GetName(RecipeData.ClassJob)}\""); var offset = ImGui.GetStyle().ItemSpacing / 2f;
var size = new Vector2(imageSize);
// yoinked from https://github.com/goatcorp/Dalamud/blob/48e8462550141db9b1a153cab9548e60238500c7/Dalamud/Interface/Windowing/Window.cs#L551
var min = pos - offset;
var max = pos + size + offset;
var bb = new Vector4(min.X, min.Y, max.X, max.Y);
var id = ImGui.GetID($"###ButtonContainer");
var isClipped = !ImGuiExtras.ItemAdd(bb, id, out _, 0);
isPressed = ImGuiExtras.ButtonBehavior(bb, id, out isHovered, out isHeld, ImGuiButtonFlags.None);
} }
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) ImGui.ImageButton(action.GetIcon(RecipeData!.ClassJob).ImGuiHandle, new(imageSize), default, Vector2.One, 0, default, failedAction ? new(1, 1, 1, ImGui.GetStyle().DisabledAlpha) : Vector4.One);
if (isPressed)
{
if (canExecute && i == 0)
{
Chat.SendMessage($"/ac \"{action.GetName(RecipeData.ClassJob)}\"");
break;
}
}
if (isHovered)
{ {
ImGui.SetTooltip($"{action.GetName(RecipeData!.ClassJob)}\n" + ImGui.SetTooltip($"{action.GetName(RecipeData!.ClassJob)}\n" +
$"{actionBase.GetTooltip(CreateSim(lastState), true)}" + $"{actionBase.GetTooltip(CreateSim(lastState), true)}" +
$"{(i == 0 ? "Click to Execute" : string.Empty)}"); $"{(canExecute && i == 0 ? "Click to Execute" : string.Empty)}");
hoveredState = state; hoveredState = state;
} }
lastState = state; lastState = state;
@@ -223,7 +247,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable
var rows = (int)Math.Max(1, MathF.Ceiling(Service.Configuration.SynthHelperStepCount / itemsPerRow)); var rows = (int)Math.Max(1, MathF.Ceiling(Service.Configuration.SynthHelperStepCount / itemsPerRow));
for (var i = 0; i < rows; ++i) for (var i = 0; i < rows; ++i)
{ {
if (Macro.Count <= i * itemsPerRow) if (count <= i * itemsPerRow)
ImGui.Dummy(new(0, imageSize)); ImGui.Dummy(new(0, imageSize));
} }
} }