Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: change the location of some methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 17, 2023
1 parent 1a7717a commit 468ca1c
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 200 deletions.
4 changes: 2 additions & 2 deletions RotationSolver/ActionSequencer/ActionCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public void Draw(ICustomRotation rotation)
if (_action?.GetTexture(out var icon) ?? false || IconSet.GetTexture(4, out icon))
{
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * ConditionHelper.IconSize, GetHashCode().ToString()))
if (ImGuiHelper.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * ConditionHelper.IconSize, GetHashCode().ToString()))
{
if(!ImGui.IsPopupOpen(popUpKey)) ImGui.OpenPopup(popUpKey);
}
RotationConfigWindow.DrawActionOverlay(cursor, ConditionHelper.IconSize, 1);
ImGuiHelper.DrawActionOverlay(cursor, ConditionHelper.IconSize, 1);
ImguiTooltips.HoveredTooltip(name);
}

Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/ActionSequencer/ConditionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ public static void ActionSelectorPopUp(string popUpId, CollapsingHeaderGroup gro

ImGui.BeginGroup();
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * IconSize, group.GetHashCode().ToString()))
if (ImGuiHelper.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * IconSize, group.GetHashCode().ToString()))
{
action?.Invoke(item);
ImGui.CloseCurrentPopup();
}
RotationConfigWindow.DrawActionOverlay(cursor, IconSize, 1);
ImGuiHelper.DrawActionOverlay(cursor, IconSize, 1);
ImGui.EndGroup();
}
});
Expand Down
15 changes: 7 additions & 8 deletions RotationSolver/ActionSequencer/RotationCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ internal class RotationCondition : ICondition
public int Condition;

public int Param1;
public int Param2;
public float Param3;
public float Param2;

private void UpdateInfo(ICustomRotation rotation)
{
Expand Down Expand Up @@ -68,11 +67,11 @@ public bool IsTrue(ICustomRotation rotation)
switch (Condition)
{
case 0:
return fl > Param3;
return fl > Param2;
case 1:
return fl < Param3;
return fl < Param2;
case 2:
return fl == Param3;
return fl == Param2;
}
}
return false;
Expand Down Expand Up @@ -158,7 +157,7 @@ public void Draw(ICustomRotation rotation)
ImGui.SameLine();
ImGui.SetNextItemWidth(50);

ImGui.DragFloat($"##Value{GetHashCode()}", ref Param3);
ImGui.DragFloat($"##Value{GetHashCode()}", ref Param2);

break;

Expand Down Expand Up @@ -194,11 +193,11 @@ public void Draw(ICustomRotation rotation)
if (_action?.GetTexture(out var icon) ?? false || IconSet.GetTexture(4, out icon))
{
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * ConditionHelper.IconSize, GetHashCode().ToString()))
if (ImGuiHelper.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * ConditionHelper.IconSize, GetHashCode().ToString()))
{
if (!ImGui.IsPopupOpen(popUpKey)) ImGui.OpenPopup(popUpKey);
}
RotationConfigWindow.DrawActionOverlay(cursor, ConditionHelper.IconSize, 1);
ImGuiHelper.DrawActionOverlay(cursor, ConditionHelper.IconSize, 1);
}

ImGui.SameLine();
Expand Down
6 changes: 3 additions & 3 deletions RotationSolver/ActionSequencer/TargetCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ public void Draw(ICustomRotation rotation)
: IconSet.GetTexture(IsTarget ? 16u : 18u, out icon))
{
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * ConditionHelper.IconSize, GetHashCode().ToString()))
if (ImGuiHelper.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * ConditionHelper.IconSize, GetHashCode().ToString()))
{
if (!ImGui.IsPopupOpen(popUpKey)) ImGui.OpenPopup(popUpKey);
}
RotationConfigWindow.DrawActionOverlay(cursor, ConditionHelper.IconSize, 1);
ImGuiHelper.DrawActionOverlay(cursor, ConditionHelper.IconSize, 1);

var description = _action != null ? string.Format(LocalizationManager.RightLang.ActionSequencer_ActionTarget, _action.Name)
: IsTarget
Expand Down Expand Up @@ -208,7 +208,7 @@ void DrawStatusIcon()
if (IconSet.GetTexture(Status?.Icon ?? 16220, out var icon)
|| IconSet.GetTexture(16220, out icon))
{
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, new Vector2(ConditionHelper.IconSize * 3 / 4, ConditionHelper.IconSize) * ImGuiHelpers.GlobalScale, GetHashCode().ToString()))
if (ImGuiHelper.NoPaddingNoColorImageButton(icon.ImGuiHandle, new Vector2(ConditionHelper.IconSize * 3 / 4, ConditionHelper.IconSize) * ImGuiHelpers.GlobalScale, GetHashCode().ToString()))
{
if (!ImGui.IsPopupOpen(popupId)) ImGui.OpenPopup(popupId);
}
Expand Down
12 changes: 6 additions & 6 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,22 @@ static void DrawCommandAction(uint iconId, StateCommandType command, Vector4 col
static void DrawIAction(nint handle, string id, float width, SpecialCommandType command, string help)
{
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(handle, Vector2.One * width, id))
if (ImGuiHelper.NoPaddingNoColorImageButton(handle, Vector2.One * width, id))
{
Svc.Commands.ProcessCommand(command.GetCommandStr());
}
RotationConfigWindow.DrawActionOverlay(cursor, width, IconSet.GetTexture(0u, out var text) && text.ImGuiHandle == handle ? 0 : 1);
ImGuiHelper.DrawActionOverlay(cursor, width, IconSet.GetTexture(0u, out var text) && text.ImGuiHandle == handle ? 0 : 1);
ImguiTooltips.HoveredTooltip(help);
}

static void DrawIAction(nint handle, string id, float width, StateCommandType command, string help)
{
var cursor = ImGui.GetCursorPos();
if(RotationConfigWindow.NoPaddingNoColorImageButton(handle, Vector2.One * width, id))
if(ImGuiHelper.NoPaddingNoColorImageButton(handle, Vector2.One * width, id))
{
Svc.Commands.ProcessCommand(command.GetCommandStr());
}
RotationConfigWindow.DrawActionOverlay(cursor, width, 1);
ImGuiHelper.DrawActionOverlay(cursor, width, 1);
ImguiTooltips.HoveredTooltip(help);
}

Expand All @@ -340,7 +340,7 @@ internal static (Vector2, Vector2) DrawIAction(IAction action, float width, floa
if (!action.GetTexture(out var texture, isAdjust)) return (default, default);

var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(texture.ImGuiHandle, Vector2.One * width, action.Name))
if (ImGuiHelper.NoPaddingNoColorImageButton(texture.ImGuiHandle, Vector2.One * width, action.Name))
{
if (!DataCenter.State)
{
Expand All @@ -363,7 +363,7 @@ internal static (Vector2, Vector2) DrawIAction(IAction action, float width, floa
}
}
var size = ImGui.GetItemRectSize();
RotationConfigWindow.DrawActionOverlay(cursor, width, action == null ? -1 : percent);
ImGuiHelper.DrawActionOverlay(cursor, width, action == null ? -1 : percent);
ImguiTooltips.HoveredTooltip(action.Name);

return (cursor, size);
Expand Down
140 changes: 140 additions & 0 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ECommons.DalamudServices;
using ImGuiScene;
using RotationSolver.Basic.Configuration;
using RotationSolver.Commands;
using RotationSolver.Localization;
Expand Down Expand Up @@ -131,4 +132,143 @@ public static void SelectableCombo(string popUp, string[] items, ref int index)
ImGui.EndPopup();
}
}

internal static void DrawItemMiddle(Action drawAction, float wholeWidth, float width, bool leftAlign = true)
{
if (drawAction == null) return;
var distance = (wholeWidth - width) / 2;
if (leftAlign) distance = MathF.Max(distance, 0);
ImGui.SetCursorPosX(distance);
drawAction();
}

#region Image
internal unsafe static bool SilenceImageButton(IntPtr handle, Vector2 size, bool selected, string id = "")
{
ImGui.PushStyleColor(ImGuiCol.ButtonActive, ImGui.ColorConvertFloat4ToU32(*ImGui.GetStyleColorVec4(ImGuiCol.HeaderActive)));
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ImGui.ColorConvertFloat4ToU32(*ImGui.GetStyleColorVec4(ImGuiCol.HeaderHovered)));
ImGui.PushStyleColor(ImGuiCol.Button, selected ? ImGui.ColorConvertFloat4ToU32(*ImGui.GetStyleColorVec4(ImGuiCol.Header)) : 0);

var result = NoPaddingImageButton(handle, size, id);
ImGui.PopStyleColor(3);

return result;
}

internal unsafe static bool NoPaddingNoColorImageButton(IntPtr handle, Vector2 size, string id = "")
{
ImGui.PushStyleColor(ImGuiCol.ButtonActive, 0);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, 0);
ImGui.PushStyleColor(ImGuiCol.Button, 0);
var result = NoPaddingImageButton(handle, size, id);
ImGui.PopStyleColor(3);

return result;
}

internal static bool NoPaddingImageButton(IntPtr handle, Vector2 size, string id = "")
{
var padding = ImGui.GetStyle().FramePadding;
ImGui.GetStyle().FramePadding = Vector2.Zero;

ImGui.PushID(id);
var result = ImGui.ImageButton(handle, size);
ImGui.PopID();
if (ImGui.IsItemHovered())
{
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
}

ImGui.GetStyle().FramePadding = padding;
return result;
}

internal static bool TextureButton(TextureWrap texture, float wholeWidth, float maxWidth, string id = "")
{
if (texture == null) return false;

var size = new Vector2(texture.Width, texture.Height) * MathF.Min(1, MathF.Min(maxWidth, wholeWidth) / texture.Width);

var result = false;
DrawItemMiddle(() =>
{
result = NoPaddingNoColorImageButton(texture.ImGuiHandle, size, id);
}, wholeWidth, size.X);
return result;
}

internal static void DrawActionOverlay(Vector2 cursor, float width, float percent)
{
var pixPerUnit = width / 82;

if (percent < 0)
{
if (IconSet.GetTexture("ui/uld/icona_frame_hr1.tex", out var cover))
{
ImGui.SetCursorPos(cursor - new Vector2(pixPerUnit * 3, pixPerUnit * 4));

var step = new Vector2(88f / cover.Width, 96f / cover.Height);
var start = new Vector2((96f * 0 + 4f) / cover.Width, (96f * 2) / cover.Height);

//Out Size is 88, 96
//Inner Size is 82, 82
ImGui.Image(cover.ImGuiHandle, new Vector2(pixPerUnit * 88, pixPerUnit * 96),
start, start + step);
}
}
else if (percent < 1)
{
if (IconSet.GetTexture("ui/uld/icona_recast_hr1.tex", out var cover))
{
ImGui.SetCursorPos(cursor - new Vector2(pixPerUnit * 3, pixPerUnit * 0));

var P = (int)(percent * 81);


var step = new Vector2(88f / cover.Width, 96f / cover.Height);
var start = new Vector2(P % 9 * step.X, P / 9 * step.Y);

//Out Size is 88, 96
//Inner Size is 82, 82
ImGui.Image(cover.ImGuiHandle, new Vector2(pixPerUnit * 88, pixPerUnit * 96),
start, start + step);
}
}
else
{
if (IconSet.GetTexture("ui/uld/icona_frame_hr1.tex", out var cover))
{

ImGui.SetCursorPos(cursor - new Vector2(pixPerUnit * 3, pixPerUnit * 4));

//Out Size is 88, 96
//Inner Size is 82, 82
ImGui.Image(cover.ImGuiHandle, new Vector2(pixPerUnit * 88, pixPerUnit * 96),
new Vector2(4f / cover.Width, 0f / cover.Height),
new Vector2(92f / cover.Width, 96f / cover.Height));
}
}

if (percent > 1)
{
if (IconSet.GetTexture("ui/uld/icona_recast2_hr1.tex", out var cover))
{
ImGui.SetCursorPos(cursor - new Vector2(pixPerUnit * 3, pixPerUnit * 0));

var P = (int)(percent % 1 * 81);

var step = new Vector2(88f / cover.Width, 96f / cover.Height);
var start = new Vector2((P % 9 + 9) * step.X, P / 9 * step.Y);

//Out Size is 88, 96
//Inner Size is 82, 82
ImGui.Image(cover.ImGuiHandle, new Vector2(pixPerUnit * 88, pixPerUnit * 96),
start, start + step);
}
}

ImGui.SetCursorPosY(cursor.Y);
}
#endregion

}
Loading

0 comments on commit 468ca1c

Please sign in to comment.