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

Commit

Permalink
fix: fixed auto cancel and texture icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jun 19, 2023
1 parent a1315ca commit f5af92c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
14 changes: 14 additions & 0 deletions RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ public static class IconSet
static readonly SortedDictionary<string, TextureWrap> _texturesPath = new();
static readonly HashSet<string> _loadingTexturePath = new();

static readonly Dictionary<uint, uint> _actionIcons = new();

public static TextureWrap GetTexture(this IAction action, bool isAdjust = true)
{
uint iconId = 0;
if (action != null && !_actionIcons.TryGetValue(isAdjust ? action.AdjustedID : action.ID, out iconId))
{
iconId = action is IBaseAction ? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(action.AdjustedID).Icon
: Service.GetSheet<Lumina.Excel.GeneratedSheets.Item>().GetRow(action.AdjustedID).Icon;
_actionIcons[action.AdjustedID] = iconId;
}
return GetTexture(iconId);
}

public static TextureWrap GetTexture(this ITexture text) => GetTexture(text?.IconID ?? 0);

public static TextureWrap GetTexture(uint id)
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Commands/RSCommands_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ private static void CancelState()
static float _lastCountdownTime = 0;
internal static void UpdateRotationState()
{
if(DataCenter.StateType == StateCommandType.Cancel && ActionUpdater._cancelTime != DateTime.MinValue)
if(ActionUpdater._cancelTime != DateTime.MinValue &&
(DataCenter.StateType == StateCommandType.Cancel || DataCenter.InCombat))
{
ActionUpdater._cancelTime = DateTime.MinValue;
}
Expand Down
21 changes: 4 additions & 17 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ static void DrawCommandAction(IAction gcd, IAction ability, SpecialCommandType c

ImGui.SetCursorPosX(ImGui.GetCursorPosX() + Math.Max(0, strWidth / 2 - width / 2));

var texture = GetTexture(gcd);
var texture = IconSet.GetTexture(gcd);
if(texture != null)
{
DrawIAction(texture.ImGuiHandle, baseId + nameof(gcd), gcdW, command, help);
texture = GetTexture(ability);
texture = IconSet.GetTexture(ability);
if (texture != null)
{
ImGui.SameLine();
Expand Down Expand Up @@ -234,7 +234,7 @@ static void HighLight(Vector2 pt, Vector2 size, float thickness = 2f)

static void DrawCommandAction(IAction ability, SpecialCommandType command, Vector4 color)
{
DrawCommandAction(GetTexture(ability), command, color);
DrawCommandAction(IconSet.GetTexture(ability), command, color);
}

static void DrawCommandAction(uint iconId, SpecialCommandType command, Vector4 color)
Expand Down Expand Up @@ -346,19 +346,6 @@ static string GetHelp(StateCommandType command)
return help += "\n \n" + LocalizationManager.RightLang.ConfigWindow_Control_ResetButtonOrKeyCommand;
}

static readonly Dictionary<uint, uint> _actionIcons = new();

static TextureWrap GetTexture(IAction action, bool isAdjust = true)
{
uint iconId = 0;
if(action != null && !_actionIcons.TryGetValue(isAdjust ? action.AdjustedID : action.ID, out iconId))
{
iconId = action is IBaseAction ? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(action.AdjustedID).Icon
: Service.GetSheet<Lumina.Excel.GeneratedSheets.Item>().GetRow(action.AdjustedID).Icon;
_actionIcons[action.AdjustedID] = iconId;
}
return IconSet.GetTexture(iconId);
}

static void DrawIAction(nint handle, string id, float width, SpecialCommandType command, string help)
{
Expand Down Expand Up @@ -440,7 +427,7 @@ static void DrawIAction(nint handle, string id, float width, StateCommandType co

internal static (Vector2, Vector2) DrawIAction(IAction action, float width, float percent, bool isAdjust = true)
{
var texture = GetTexture(action, isAdjust);
var texture = IconSet.GetTexture(action, isAdjust);
if (texture == null) return (default, default);
var result = DrawIAction(texture.ImGuiHandle, width, action == null ? -1 : percent);
if (action != null) ImGuiHelper.HoveredString(action.Name, () =>
Expand Down
21 changes: 14 additions & 7 deletions RotationSolver/UI/PainterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,21 @@ public override void UpdateOnFrame(XIVPainter.XIVPainter painter)

var d = DateTime.Now.Millisecond / 1000f;
var ratio = (float)DrawingHelper.EaseFuncRemap(EaseFuncType.None, EaseFuncType.Cubic)(d);
List<IDrawing3D> subItems = new List<IDrawing3D>() { _target, _targetImage };
List<IDrawing3D> subItems = new List<IDrawing3D>();

_target.Color = ImGui.GetColorU32(Service.Config.TargetColor);
_target.Center = act.Target.Position;
_target.Radius = targetRadius * ratio;

_targetImage.Position = act.Target.Position;
_targetImage.SetTexture(act.GetTexture(), Service.Config.TargetIconSize);
if(Service.Config.TargetIconSize > 0)
{
_targetImage.Position = act.Target.Position;
_targetImage.SetTexture(act.GetTexture(true), Service.Config.TargetIconSize);
subItems.Add(_targetImage);
}
else
{
_target.Color = ImGui.GetColorU32(Service.Config.TargetColor);
_target.Center = act.Target.Position;
_target.Radius = targetRadius * ratio;
subItems.Add(_target);
}

if (DataCenter.HostileTargets.Contains(act.Target) || act.Target == Player.Object && !act.IsFriendly)
{
Expand Down

0 comments on commit f5af92c

Please sign in to comment.