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

Commit

Permalink
fix: add action id icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 11, 2023
1 parent 0331668 commit 6db1b60
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 38 deletions.
48 changes: 24 additions & 24 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,72 +240,72 @@ public enum PluginConfigBool : byte

public enum PluginConfigFloat : byte
{
[Default(8)] AutoOffAfterCombat,
[Default(3)] DrawingHeight,
[Default(8f)] AutoOffAfterCombat,
[Default(3f)] DrawingHeight,
[Default(0.2f)] SampleLength,
[Default(0.1f)] KeyBoardNoiseTimeMin,
[Default(0.2f)] KeyBoardNoiseTimeMax,

[Default(0.25f)] HealthDifference,
[Default(1)] MeleeRangeOffset,
[Default(1f)] MeleeRangeOffset,
[Default(0.1f)] MinLastAbilityAdvanced,
[Default(0.8f)] HealWhenNothingTodoBelow,
[Default(0.6f)] TargetIconSize,

[Default(0)] MistakeRatio,
[Default(0f)] MistakeRatio,

[Default(0.4f)] HealthTankRatio,
[Default(0.4f)] HealthHealerRatio,

[Default(3)] SpecialDuration,
[Default(3f)] SpecialDuration,

[Default(0.08f)] ActionAhead,
[Default(0.06f)] ActionAheadForLast0GCD,

[Default(0)] WeaponDelayMin,
[Default(0)] WeaponDelayMax,
[Default(0f)] WeaponDelayMin,
[Default(0f)] WeaponDelayMax,

[Default(1)] DeathDelayMin,
[Default(1f)] DeathDelayMin,
[Default(1.5f)] DeathDelayMax,

[Default(0.5f)] WeakenDelayMin,
[Default(1)] WeakenDelayMax,
[Default(1f)] WeakenDelayMax,

[Default(0)] HostileDelayMin,
[Default(0)] HostileDelayMax,
[Default(0f)] HostileDelayMin,
[Default(0f)] HostileDelayMax,

[Default(0)] HealDelayMin,
[Default(0)] HealDelayMax,
[Default(0f)] HealDelayMin,
[Default(0f)] HealDelayMax,

[Default(0.5f)] StopCastingDelayMin,
[Default(1)] StopCastingDelayMax,
[Default(1f)] StopCastingDelayMax,

[Default(0.5f)] InterruptDelayMin,
[Default(1)] InterruptDelayMax,
[Default(1f)] InterruptDelayMax,

[Default(3)] NotInCombatDelayMin,
[Default(4)] NotInCombatDelayMax,
[Default(3f)] NotInCombatDelayMin,
[Default(4f)] NotInCombatDelayMax,

[Default(0.1f)] ClickingDelayMin,
[Default(0.15f)] ClickingDelayMax,

[Default(0.5f)] CountdownDelayMin,
[Default(1)] CountdownDelayMax,
[Default(1f)] CountdownDelayMax,

[Default(0.6f)] CountDownAhead,

[Default(24)] MoveTargetAngle,
[Default(24f)] MoveTargetAngle,
[Default(1.85f)] HealthRatioBoss,
[Default(0.8f)] HealthRatioDying,
[Default(1.2f)] HealthRatHealthRatioDotioBoss,

[Default(16)] CooldownFontSize,
[Default(16f)] CooldownFontSize,

[Default(40)] ControlWindowGCDSize,
[Default(30)] ControlWindow0GCDSize,
[Default(30)] CooldownWindowIconSize,
[Default(40f)] ControlWindowGCDSize,
[Default(30f)] ControlWindow0GCDSize,
[Default(30f)] CooldownWindowIconSize,
[Default(1.5f)] ControlWindowNextSizeRatio,
[Default(8)] ControlProgressHeight,
[Default(8f)] ControlProgressHeight,
[Default(1.2f)] DistanceForMoving,
[Default(0.2f)] MaxPing,
}
Expand Down
38 changes: 37 additions & 1 deletion RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public static bool GetTexture(string path, out TextureWrap texture)
/// <param name="action"></param>
/// <param name="isAdjust"></param>
/// <returns></returns>
[Obsolete]
public static TextureWrap GetTexture(this IAction action, bool isAdjust = true)
{
uint iconId = 0;
Expand All @@ -161,12 +162,32 @@ public static TextureWrap GetTexture(this IAction action, bool isAdjust = true)
return GetTexture(iconId);
}

public static bool GetTexture(this IAction action, out TextureWrap texture, bool isAdjust = true)
{
uint iconId = 0;
if (action != null)
{
var id = isAdjust ? action.AdjustedID : action.ID;

if (!_actionIcons.TryGetValue(id, out iconId))
{
iconId = id == action.ID ? action.IconID : action is IBaseAction
? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(id).Icon
: Service.GetSheet<Item>().GetRow(id).Icon;

_actionIcons[id] = iconId;
}
}
return GetTexture(iconId, out texture);
}

/// <summary>
/// Get texture from action Id.
/// </summary>
/// <param name="actionID"></param>
/// <param name="isAction"></param>
/// <returns></returns>
[Obsolete]
public static TextureWrap GetTexture(this ActionID actionID, bool isAction = true)
{
var id = (uint)actionID;
Expand All @@ -175,13 +196,28 @@ public static TextureWrap GetTexture(this ActionID actionID, bool isAction = tru
{
iconId = isAction
? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(id).Icon
: Service.GetSheet<Lumina.Excel.GeneratedSheets.Item>().GetRow(id).Icon;
: Service.GetSheet<Item>().GetRow(id).Icon;

_actionIcons[id] = iconId;
}
return GetTexture(iconId);
}

public static bool GetTexture(this ActionID actionID, out TextureWrap texture, bool isAction = true)
{
var id = (uint)actionID;

if (!_actionIcons.TryGetValue(id, out var iconId))
{
iconId = isAction
? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(id).Icon
: Service.GetSheet<Item>().GetRow(id).Icon;

_actionIcons[id] = iconId;
}
return GetTexture(iconId, out texture);
}

private static readonly Dictionary<IconType, uint[]> _icons = new()
{
{ IconType.Gold, new uint[40]
Expand Down
28 changes: 15 additions & 13 deletions RotationSolver/UI/RotationConfigWindowNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,16 @@ private void DrawHeader(float wholeWidth)
{
var size = MathF.Max(MathF.Min(wholeWidth, _scale * 120), _scale * MIN_COLUMN_WIDTH);

var url = "https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Images/Logo.png";
if(Service.ConfigNew.GetValue(Basic.Configuration.PluginConfigBool.DrawIconAnimation))
int realFrame = 180;
if (Service.ConfigNew.GetValue(Basic.Configuration.PluginConfigBool.DrawIconAnimation))
{
var frame = Environment.TickCount / 100; //10fps
var realFrame = frame % 60 * 3; // convert to 30 fps.
realFrame = frame % 60 * 3; // convert to 30 fps.
if (realFrame == 0) realFrame = 180;

url = $"https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Images/Logos/{realFrame: D4}.png";
}

if (IconSet.GetTexture(url, out var logo) || IconSet.GetTexture(0, out logo))
if (IconSet.GetTexture($"https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Images/Logos/{realFrame: D4}.png", out var logo)
|| IconSet.GetTexture(0, out logo))
{
DrawItemMiddle(() =>
{
Expand Down Expand Up @@ -650,8 +649,12 @@ private static void DrawRotationDescription()
ImGui.Text(" ");
ImGui.SameLine();
}
ControlWindow.DrawIAction(item.GetTexture().ImGuiHandle, DESC_SIZE * _scale, 1);
ImguiTooltips.HoveredTooltip(item.Name);

if(item.GetTexture(out var texture))
{
ControlWindow.DrawIAction(texture.ImGuiHandle, DESC_SIZE * _scale, 1);
ImguiTooltips.HoveredTooltip(item.Name);
}
notStart = true;
}
}
Expand Down Expand Up @@ -759,8 +762,7 @@ private static void DrawActions()
var index = 0;
foreach (var item in pair.OrderBy(t => t.ID))
{
var icon = item.GetTexture();
if (icon == null) continue;
if (!item.GetTexture(out var icon)) continue;

if (index++ % count != 0)
{
Expand Down Expand Up @@ -900,7 +902,7 @@ private static void DrawDebug()
}

#region Image
private unsafe static bool SilenceImageButton(IntPtr handle, Vector2 size, bool selected, string id = "")
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)));
Expand All @@ -912,7 +914,7 @@ private unsafe static bool SilenceImageButton(IntPtr handle, Vector2 size, bool
return result;
}

private unsafe static bool NoPaddingNoColorImageButton(IntPtr handle, Vector2 size, string id = "")
internal unsafe static bool NoPaddingNoColorImageButton(IntPtr handle, Vector2 size, string id = "")
{
ImGui.PushStyleColor(ImGuiCol.ButtonActive, 0);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, 0);
Expand Down Expand Up @@ -954,7 +956,7 @@ private static bool TextureButton(TextureWrap texture, float wholeWidth, float m
return result;
}

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

Expand Down
19 changes: 19 additions & 0 deletions RotationSolver/UI/SearchableConfigs/CheckBoxSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using RotationSolver.Basic.Configuration;
using RotationSolver.Localization;
using RotationSolver.UI.SearchableConfigs;
using static FFXIVClientStructs.FFXIV.Client.UI.AddonAOZNotebook;
using System.Drawing;

namespace RotationSolver.UI.SearchableSettings;

Expand Down Expand Up @@ -44,6 +46,8 @@ internal abstract class CheckBoxSearch : Searchable
{
public ISearchable[] Children { get; protected set; }

public ActionID Action { get; init; } = ActionID.None;

public CheckBoxSearch(params ISearchable[] children)
{
Children = children;
Expand All @@ -69,6 +73,21 @@ protected override void DrawMain(Job job)
ImGui.SameLine();
if(Children == null || Children.Length == 0)
{
if (Action != ActionID.None && IconSet.GetTexture(Action, out var texture))
{
ImGui.BeginGroup();
var cursor = ImGui.GetCursorPos();
var size = ImGuiHelpers.GlobalScale * 32;
if (RotationConfigWindowNew.NoPaddingNoColorImageButton(texture.ImGuiHandle, Vector2.One * size))
{
SetValue(job, !enable);
}
if (ImGui.IsItemHovered()) ShowTooltip(job);
RotationConfigWindowNew.DrawActionOverlay(cursor, size, enable ? 1 : 0);
ImGui.EndGroup();

ImGui.SameLine();
}
ImGui.Text(name);
if (ImGui.IsItemHovered()) ShowTooltip(job);
}
Expand Down

0 comments on commit 6db1b60

Please sign in to comment.