From 7d0638993deffa87dcff522dd5439f3aaa0f4320 Mon Sep 17 00:00:00 2001 From: Taurenkey Date: Fri, 12 Jul 2024 09:27:36 +0100 Subject: [PATCH] Fix up AST target helper --- XIVSlothCombo/Combos/JobHelpers/AST.cs | 37 +++++++--- XIVSlothCombo/Window/ConfigWindow.cs | 74 +------------------- XIVSlothCombo/Window/TargetHelper.cs | 96 ++++++++++++++++++++++++++ XIVSlothCombo/XIVSlothCombo.cs | 7 +- 4 files changed, 129 insertions(+), 85 deletions(-) create mode 100644 XIVSlothCombo/Window/TargetHelper.cs diff --git a/XIVSlothCombo/Combos/JobHelpers/AST.cs b/XIVSlothCombo/Combos/JobHelpers/AST.cs index 0399baeda..219ed86b0 100644 --- a/XIVSlothCombo/Combos/JobHelpers/AST.cs +++ b/XIVSlothCombo/Combos/JobHelpers/AST.cs @@ -23,18 +23,26 @@ private static void CheckCards(IFramework framework) if (Service.ClientState.LocalPlayer is null || Service.ClientState.LocalPlayer.ClassJob.Id != 33) return; + if (Svc.Condition[Dalamud.Game.ClientState.Conditions.ConditionFlag.BetweenAreas] || Svc.Condition[Dalamud.Game.ClientState.Conditions.ConditionFlag.Unconscious]) + { + AST_QuickTargetCards.SelectedRandomMember = null; + return; + } + if (DrawnCard != Gauge.DrawnCards[0]) { DrawnCard = Gauge.DrawnCards[0]; - if (CustomComboFunctions.IsEnabled(CustomComboPreset.AST_Cards_QuickTargetCards)) - { - AST_QuickTargetCards.SelectedRandomMember = null; - AST_QuickTargetCards.Invoke(); - } - if (DrawnCard == CardType.NONE) - AST_QuickTargetCards.SelectedRandomMember = null; + } + if (CustomComboFunctions.IsEnabled(CustomComboPreset.AST_Cards_QuickTargetCards) && AST_QuickTargetCards.SelectedRandomMember == null) + { + if (CustomComboFunctions.ActionReady(Play1)) + AST_QuickTargetCards.Invoke(); } + + if (DrawnCard == CardType.NONE) + AST_QuickTargetCards.SelectedRandomMember = null; + } internal class AST_QuickTargetCards : CustomComboFunctions @@ -46,12 +54,19 @@ internal class AST_QuickTargetCards : CustomComboFunctions public static void Invoke() { - if (GetPartySlot(2) is not null && DrawnCard is not CardType.NONE) + if (DrawnCard is not CardType.NONE) { - if (SelectedRandomMember is null || SelectedRandomMember.IsDead) + if (GetPartySlot(2) is not null) + { + if (SelectedRandomMember is null || SelectedRandomMember.IsDead) + { + SetTarget(); + Svc.Log.Debug($"Set card to {SelectedRandomMember.Name}"); + } + } + else { - SetTarget(); - Svc.Log.Debug($"Set card to {SelectedRandomMember.Name}"); + SelectedRandomMember = LocalPlayer; } } else diff --git a/XIVSlothCombo/Window/ConfigWindow.cs b/XIVSlothCombo/Window/ConfigWindow.cs index 4b55274e7..68d1d17f5 100644 --- a/XIVSlothCombo/Window/ConfigWindow.cs +++ b/XIVSlothCombo/Window/ConfigWindow.cs @@ -96,8 +96,6 @@ private void SetMinSize(IFontHandle? fontHandle = null, ILockedImFont? lockedFon public override void Draw() { - DrawTargetHelper(); - var region = ImGui.GetContentRegionAvail(); var itemSpacing = ImGui.GetStyle().ItemSpacing; @@ -191,77 +189,7 @@ public override void Draw() } } - private unsafe void DrawTargetHelper() - { - if (Combos.JobHelpers.AST.AST_QuickTargetCards.SelectedRandomMember is not null) - { - for (int i = 1; i <= 8; i++) - { - if (CustomComboFunctions.GetPartySlot(i) == Combos.JobHelpers.AST.AST_QuickTargetCards.SelectedRandomMember) - { - IntPtr partyPTR = Service.GameGui.GetAddonByName("_PartyList", 1); - if (partyPTR == IntPtr.Zero) - return; - - AddonPartyList plist = Marshal.PtrToStructure(partyPTR); - - var member = i switch - { - 1 => plist.PartyMembers[0].TargetGlow, - 2 => plist.PartyMembers[1].TargetGlow, - 3 => plist.PartyMembers[2].TargetGlow, - 4 => plist.PartyMembers[3].TargetGlow, - 5 => plist.PartyMembers[4].TargetGlow, - 6 => plist.PartyMembers[5].TargetGlow, - 7 => plist.PartyMembers[6].TargetGlow, - 8 => plist.PartyMembers[7].TargetGlow, - _ => plist.PartyMembers[0].TargetGlow, - }; - - DrawOutline(member->AtkResNode.PrevSiblingNode); - - } - } - } - } - - private unsafe void DrawOutline(AtkResNode* node) - { - var position = GetNodePosition(node); - var scale = GetNodeScale(node); - var size = new Vector2(node->Width, node->Height) * scale; - - position += ImGuiHelpers.MainViewport.Pos; - - var colour = Service.Configuration.TargetHighlightColor; - ImGui.GetForegroundDrawList(ImGuiHelpers.MainViewport).AddRect(position, position + size, ImGui.GetColorU32(colour), 0, ImDrawFlags.RoundCornersAll, 2); - } - public unsafe Vector2 GetNodePosition(AtkResNode* node) - { - var pos = new Vector2(node->X, node->Y); - var par = node->ParentNode; - while (par != null) - { - pos *= new Vector2(par->ScaleX, par->ScaleY); - pos += new Vector2(par->X, par->Y); - par = par->ParentNode; - } - - return pos; - } - - public unsafe Vector2 GetNodeScale(AtkResNode* node) - { - if (node == null) return new Vector2(1, 1); - var scale = new Vector2(node->ScaleX, node->ScaleY); - while (node->ParentNode != null) - { - node = node->ParentNode; - scale *= new Vector2(node->ScaleX, node->ScaleY); - } - - return scale; - } + public void Dispose() { diff --git a/XIVSlothCombo/Window/TargetHelper.cs b/XIVSlothCombo/Window/TargetHelper.cs new file mode 100644 index 000000000..6fe678514 --- /dev/null +++ b/XIVSlothCombo/Window/TargetHelper.cs @@ -0,0 +1,96 @@ +using Dalamud.Interface.Utility; +using ECommons.DalamudServices; +using FFXIVClientStructs.FFXIV.Client.UI; +using FFXIVClientStructs.FFXIV.Component.GUI; +using ImGuiNET; +using System; +using System.Numerics; +using System.Runtime.InteropServices; +using XIVSlothCombo.CustomComboNS.Functions; +using XIVSlothCombo.Services; + + +namespace XIVSlothCombo.Window; + +internal class TargetHelper : Dalamud.Interface.Windowing.Window +{ + internal TargetHelper() : base("###SlothComboTargeteHelper", ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.AlwaysUseWindowPadding | ImGuiWindowFlags.AlwaysAutoResize, true) + { + this.IsOpen = true; + } + + internal unsafe void DrawTargetHelper() + { + if (Combos.JobHelpers.AST.AST_QuickTargetCards.SelectedRandomMember is not null) + { + for (int i = 1; i <= 8; i++) + { + if (CustomComboFunctions.GetPartySlot(i) is null) continue; + if (CustomComboFunctions.GetPartySlot(i).GameObjectId == Combos.JobHelpers.AST.AST_QuickTargetCards.SelectedRandomMember.GameObjectId) + { + IntPtr partyPTR = Service.GameGui.GetAddonByName("_PartyList", 1); + if (partyPTR == IntPtr.Zero) + return; + + AddonPartyList plist = Marshal.PtrToStructure(partyPTR); + + var member = i switch + { + 1 => plist.PartyMembers[0].TargetGlow, + 2 => plist.PartyMembers[1].TargetGlow, + 3 => plist.PartyMembers[2].TargetGlow, + 4 => plist.PartyMembers[3].TargetGlow, + 5 => plist.PartyMembers[4].TargetGlow, + 6 => plist.PartyMembers[5].TargetGlow, + 7 => plist.PartyMembers[6].TargetGlow, + 8 => plist.PartyMembers[7].TargetGlow, + _ => plist.PartyMembers[0].TargetGlow, + }; + + DrawOutline(member->AtkResNode.PrevSiblingNode); + + } + } + } + } + + private unsafe void DrawOutline(AtkResNode* node) + { + var position = GetNodePosition(node); + var scale = GetNodeScale(node); + var size = new Vector2(node->Width, node->Height) * scale; + + position += ImGuiHelpers.MainViewport.Pos; + + var colour = Service.Configuration.TargetHighlightColor; + ImGui.GetForegroundDrawList(ImGuiHelpers.MainViewport).AddRect(position, position + size, ImGui.GetColorU32(colour), 0, ImDrawFlags.RoundCornersAll, 2); + } + public unsafe Vector2 GetNodePosition(AtkResNode* node) + { + var pos = new Vector2(node->X, node->Y); + var par = node->ParentNode; + while (par != null) + { + pos *= new Vector2(par->ScaleX, par->ScaleY); + pos += new Vector2(par->X, par->Y); + par = par->ParentNode; + } + + return pos; + } + + public unsafe Vector2 GetNodeScale(AtkResNode* node) + { + if (node == null) return new Vector2(1, 1); + var scale = new Vector2(node->ScaleX, node->ScaleY); + while (node->ParentNode != null) + { + node = node->ParentNode; + scale *= new Vector2(node->ScaleX, node->ScaleY); + } + + return scale; + } + + public override void Draw() => DrawTargetHelper(); +} diff --git a/XIVSlothCombo/XIVSlothCombo.cs b/XIVSlothCombo/XIVSlothCombo.cs index 31d613acd..6c646d00f 100644 --- a/XIVSlothCombo/XIVSlothCombo.cs +++ b/XIVSlothCombo/XIVSlothCombo.cs @@ -36,6 +36,7 @@ public sealed partial class XIVSlothCombo : IDalamudPlugin private const string Command = "/scombo"; private readonly ConfigWindow ConfigWindow; + private readonly TargetHelper TargetHelper; internal readonly AboutUs AboutUs; internal static XIVSlothCombo P = null!; internal WindowSystem ws; @@ -133,9 +134,11 @@ public XIVSlothCombo(IDalamudPluginInterface pluginInterface) Combos.JobHelpers.AST.Init(); ConfigWindow = new ConfigWindow(); + TargetHelper = new(); AboutUs = new(); ws = new(); ws.AddWindow(ConfigWindow); + ws.AddWindow(TargetHelper); Service.Interface.UiBuilder.Draw += ws.Draw; Service.Interface.UiBuilder.OpenConfigUi += OnOpenConfigUi; @@ -186,13 +189,15 @@ private static void HandleConflictedCombos() } } - private static void OnFrameworkUpdate(IFramework framework) + private void OnFrameworkUpdate(IFramework framework) { if (Service.ClientState.LocalPlayer is not null) JobID = Service.ClientState.LocalPlayer?.ClassJob?.Id; BlueMageService.PopulateBLUSpells(); + TargetHelper.Draw(); } + private static void KillRedundantIDs() { List redundantIDs = Service.Configuration.EnabledActions.Where(x => int.TryParse(x.ToString(), out _)).OrderBy(x => x).Cast().ToList();