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

Commit

Permalink
Fix up AST target helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Taurenkey committed Jul 12, 2024
1 parent c2f5d5a commit 7d06389
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 85 deletions.
37 changes: 26 additions & 11 deletions XIVSlothCombo/Combos/JobHelpers/AST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
74 changes: 1 addition & 73 deletions XIVSlothCombo/Window/ConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<AddonPartyList>(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()
{
Expand Down
96 changes: 96 additions & 0 deletions XIVSlothCombo/Window/TargetHelper.cs
Original file line number Diff line number Diff line change
@@ -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<AddonPartyList>(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();
}
7 changes: 6 additions & 1 deletion XIVSlothCombo/XIVSlothCombo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<int> redundantIDs = Service.Configuration.EnabledActions.Where(x => int.TryParse(x.ToString(), out _)).OrderBy(x => x).Cast<int>().ToList();
Expand Down

0 comments on commit 7d06389

Please sign in to comment.