Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and improve performance and readability #410

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Actions/ActionTargetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private bool IsSpecialAbility(uint iD)
/// <returns>
/// <c>true</c> if the battle character meets the criteria for targeting; otherwise, <c>false</c>.
/// </returns>
private bool GeneralCheck(IBattleChara gameObject, bool skipStatusProvideCheck)
public bool GeneralCheck(IBattleChara gameObject, bool skipStatusProvideCheck)
{
if (!gameObject.IsTargetable) return false;

Expand Down
13 changes: 4 additions & 9 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public const string
Parent = nameof(AddEnemyListToHostile))]
private static readonly bool _onlyAttackInEnemyList = false;

[JobConfig, UI("Gemdraughts/Tinctures/Pots", Filter = AutoActionUsage, PvPFilter = JobFilterType.NoJob)]
[JobConfig, UI("Only used automatically if coded into the rotation", Filter = AutoActionUsage, PvPFilter = JobFilterType.NoJob)]
private readonly TinctureUseType _TinctureType = TinctureUseType.Nowhere;

[ConditionBool, UI("Automatically use Anti-Knockback role actions (Arms Length, Surecast)", Filter = AutoActionUsage)]
Expand Down Expand Up @@ -316,7 +316,7 @@ public const string
PvEFilter = JobFilterType.Tank)]
private static readonly bool _autoTankStance = true;

[ConditionBool, UI("Auto provoke non-tank attacking targets", Description = "Automatically use provoke when an enemy is attacking a non-tank member of the party.",
[ConditionBool, UI("Auto provoke when there is another tank in party", Description = "Automatically use provoke when an enemy is attacking a non-tank member of the party while there is more than one tank in party.",
Parent = nameof(UseAbility), PvEFilter = JobFilterType.Tank)]
private static readonly bool _autoProvokeForTank = true;

Expand Down Expand Up @@ -391,11 +391,6 @@ public const string
[Range(0.100f, 2.500f, ConfigUnitType.Seconds, 0.001f)]
public float isFirstAbilityTimer { get; set; } = 0.600f;

[UI("Max Attack Target Count Tracking", Description = "Don't fuck with this if you dont know what it does",
Filter = Extra)]
[Range(8, 100, ConfigUnitType.None, 1)]
public int internalAttackTargetCount { get; set; } = 48;

[UI("Auto turn off RSR when combat is over more for more then...",
Parent = nameof(AutoOffAfterCombat))]
[Range(0, 600, ConfigUnitType.Seconds)]
Expand Down Expand Up @@ -468,15 +463,15 @@ public const string
Filter = HealingActionCondition, Section = 3)]
private static readonly bool _healOutOfCombat = false;

[ConditionBool, UI("Heal solo instance NPCs. (Experimental)",
[ConditionBool, UI("Heal solo instance NPCs", Description = "Experimental.",
Filter = HealingActionCondition, Section = 3)]
private static readonly bool _friendlyBattleNPCHeal = false;

[ConditionBool, UI("Heal and raise Party NPCs.",
Filter = HealingActionCondition, Section = 3)]
private static readonly bool _friendlyPartyNPCHealRaise = true;

[ConditionBool, UI("Heal/Dance partner your chocobo. (Experimental)",
[ConditionBool, UI("Heal/Dance partner your chocobo", Description = "Experimental.",
Filter = HealingActionCondition, Section = 3)]
private static readonly bool _chocoboPartyMember = false;

Expand Down
3 changes: 0 additions & 3 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,6 @@ public static IBattleChara[] AllHostileTargets
// Check if the target is an enemy.
if (!b.IsEnemy()) return false;

// Check if the target is dead.
if (b.CurrentHp <= 1) return false;

// Check if the target is targetable.
if (!b.IsTargetable) return false;

Expand Down
5 changes: 2 additions & 3 deletions RotationSolver.Basic/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ internal static bool CanProvoke(this IGameObject target)
{
if (target == null) return false;

// Assuming DataCenter.FateId is an ID, not an IGameObject
if (target.DataId == DataCenter.FateId) return false;
if (DataCenter.FateId != 0 && target.FateId() == DataCenter.FateId) return false;

//Removed the listed names.
if (OtherConfiguration.NoProvokeNames.TryGetValue(Svc.ClientState.TerritoryType, out var ns1))
Expand Down Expand Up @@ -194,7 +193,7 @@ internal static bool IsDeathToRaise(this IGameObject obj)

internal static bool IsAlive(this IGameObject obj)
{
return obj is not IBattleChara b || b.CurrentHp > 1 && obj.IsTargetable;
return obj is not IBattleChara b || b.CurrentHp > 0 && obj.IsTargetable;
}

/// <summary>
Expand Down
21 changes: 21 additions & 0 deletions RotationSolver/Data/UiString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ internal enum UiString
[Description("The condition set you chose, click to modify.")]
ConfigWindow_ConditionSetDesc,

[Description("Condition Set")]
ConfigWindow_ConditionSet,

[Description("Action Condition")]
ConfigWindow_ActionSet,

[Description("Trait Condition")]
ConfigWindow_TraitSet,

[Description("Target Condition")]
ConfigWindow_TargetSet,

[Description("Rotation Condition")]
ConfigWindow_RotationSet,

[Description("Named Condition")]
ConfigWindow_NamedSet,

[Description("Territory Condition")]
ConfigWindow_Territoryset,

[Description("No rotations loaded! Please see the rotations tab!")]
ConfigWindow_NoRotation,

Expand Down
18 changes: 9 additions & 9 deletions RotationSolver/UI/ConditionDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,13 @@ void AddButton()
using var popUp = ImRaii.Popup("Popup" + conditionSet.GetHashCode().ToString());
if (popUp)
{
AddOneCondition<ConditionSet>();
AddOneCondition<ActionCondition>();
AddOneCondition<TraitCondition>();
AddOneCondition<TargetCondition>();
AddOneCondition<RotationCondition>();
AddOneCondition<NamedCondition>();
AddOneCondition<TerritoryCondition>();
AddOneCondition<ConditionSet>(UiString.ConfigWindow_ConditionSet.GetDescription());
AddOneCondition<ActionCondition>(UiString.ConfigWindow_ActionSet.GetDescription());
AddOneCondition<TraitCondition>(UiString.ConfigWindow_TraitSet.GetDescription());
AddOneCondition<TargetCondition>(UiString.ConfigWindow_TargetSet.GetDescription());
AddOneCondition<RotationCondition>(UiString.ConfigWindow_RotationSet.GetDescription());
AddOneCondition<NamedCondition>(UiString.ConfigWindow_NamedSet.GetDescription());
AddOneCondition<TerritoryCondition>(UiString.ConfigWindow_Territoryset.GetDescription());
if (ImGui.Selectable(UiString.ActionSequencer_FromClipboard.GetDescription()))
{
var str = ImGui.GetClipboardText();
Expand All @@ -582,9 +582,9 @@ void AddButton()
}
}

void AddOneCondition<T>() where T : ICondition
void AddOneCondition<T>(string description) where T : ICondition
{
if (ImGui.Selectable(typeof(T).ToString()))
if (ImGui.Selectable(description))
{
conditionSet.Conditions.Add(Activator.CreateInstance<T>());
ImGui.CloseCurrentPopup();
Expand Down
37 changes: 21 additions & 16 deletions RotationSolver/UI/CooldownWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,42 @@ public override void Draw()
{
if (DataCenter.RightNowRotation == null) return;

var width = Service.Config.CooldownWindowIconSize;
var config = Service.Config;
var width = config.CooldownWindowIconSize;
const float IconSpacingFactor = 6f / 82f;
var count = Math.Max(1, (int)MathF.Floor(ImGui.GetColumnWidth() / (width * (1 + IconSpacingFactor) + ImGui.GetStyle().ItemSpacing.X)));
var style = ImGui.GetStyle();
var columnWidth = ImGui.GetColumnWidth();
var count = Math.Max(1, (int)MathF.Floor(columnWidth / (width * (1 + IconSpacingFactor) + style.ItemSpacing.X)));

if (RotationUpdater.AllGroupedActions == null) return;
var allGroupedActions = RotationUpdater.AllGroupedActions;
if (allGroupedActions == null) return;

foreach (var pair in RotationUpdater.AllGroupedActions)
foreach (var pair in allGroupedActions)
{
var showItems = pair.OrderBy(a => a.SortKey)
.Where(a => a.IsInCooldown && (a is not IBaseAction b || !b.Info.IsLimitBreak));

if (!Service.Config.ShowGcdCooldown)
{
showItems = showItems.Where(i => !(i is IBaseAction a && a.Info.IsGeneralGCD));
}
var showItems = pair
.Where(a => a.IsInCooldown && (a is not IBaseAction b || !b.Info.IsLimitBreak))
.Where(a => config.ShowGcdCooldown || !(a is IBaseAction b && b.Info.IsGeneralGCD))
.Where(a => config.ShowItemsCooldown || !(a is IBaseItem))
.OrderBy(a => a.SortKey)
.ToList();

if (!showItems.Any()) continue;

if (!Service.Config.ShowItemsCooldown && showItems.Any(i => i is IBaseItem)) continue;

ImGui.Text(pair.Key);

ImGui.Columns(count, null, false);
uint itemIndex = 0;
foreach (var item in showItems)
{
if (itemIndex++ % count != 0)
ControlWindow.DrawIAction(item, width, 1f);
itemIndex++;
if (itemIndex % count != 0)
{
ImGui.SameLine();
ImGui.NextColumn();
}
ControlWindow.DrawIAction(item, width, 1f);
}
ImGui.Columns(1);
ImGui.NewLine();
}
}
}
34 changes: 9 additions & 25 deletions RotationSolver/UI/CtrlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,27 @@ internal abstract class CtrlWindow(string name) : Window(name, BaseFlags)

public override void PreDraw()
{
Vector4 bgColor = Service.Config.IsControlWindowLock
? Service.Config.ControlWindowLockBg
: Service.Config.ControlWindowUnlockBg;
var config = Service.Config;
Vector4 bgColor = config.IsControlWindowLock
? config.ControlWindowLockBg
: config.ControlWindowUnlockBg;
ImGui.PushStyleColor(ImGuiCol.WindowBg, bgColor);

Flags = BaseFlags;
if (Service.Config.IsControlWindowLock)
if (config.IsControlWindowLock)
{
Flags |= ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove;
}

ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0);

try
{
base.PreDraw();
}
catch (Exception)
{

}
base.PreDraw();
}

public override void PostDraw()
{
try
{
base.PostDraw();
}
catch (Exception)
{

}
finally
{
ImGui.PopStyleColor();
ImGui.PopStyleVar();
}
base.PostDraw();
ImGui.PopStyleColor();
ImGui.PopStyleVar();
}
}
2 changes: 1 addition & 1 deletion RotationSolver/UI/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public unsafe static ImFontPtr GetFont(float size)
var font = lockedHandle.ImFont;

// Check if the font pointer is valid
if (new IntPtr(font.NativePtr) == IntPtr.Zero)
if (font.NativePtr == null)
{
return ImGui.GetFont();
}
Expand Down
18 changes: 11 additions & 7 deletions RotationSolver/UI/ImguiTooltips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ internal static class ImguiTooltips
/// <param name="text">The text to display in the tooltip.</param>
public static void HoveredTooltip(string? text)
{
if (!ImGui.IsItemHovered()) return;
ShowTooltip(text);
if (ImGui.IsItemHovered() && !string.IsNullOrEmpty(text))
{
ShowTooltip(() => ImGui.Text(text));
}
}

/// <summary>
Expand All @@ -33,8 +35,10 @@ public static void HoveredTooltip(string? text)
/// <param name="text">The text to display in the tooltip.</param>
public static void ShowTooltip(string? text)
{
if (string.IsNullOrEmpty(text)) return;
ShowTooltip(() => ImGui.Text(text));
if (!string.IsNullOrEmpty(text))
{
ShowTooltip(() => ImGui.Text(text));
}
}

/// <summary>
Expand All @@ -43,14 +47,14 @@ public static void ShowTooltip(string? text)
/// <param name="act">The action to perform to render the tooltip content.</param>
public static void ShowTooltip(Action act)
{
if (act == null) return;
if (Service.Config == null || !Service.Config.ShowTooltips) return;
if (act == null || Service.Config == null || !Service.Config.ShowTooltips) return;

ImGui.SetNextWindowBgAlpha(1);

using var color = ImRaii.PushColor(ImGuiCol.BorderShadow, ImGuiColors.DalamudWhite);

ImGui.SetNextWindowSizeConstraints(new Vector2(150, 0) * ImGuiHelpers.GlobalScale, new Vector2(1200, 1500) * ImGuiHelpers.GlobalScale);
var globalScale = ImGuiHelpers.GlobalScale;
ImGui.SetNextWindowSizeConstraints(new Vector2(150, 0) * globalScale, new Vector2(1200, 1500) * globalScale);
ImGui.SetWindowPos(TOOLTIP_ID, ImGui.GetIO().MousePos);

if (ImGui.Begin(TOOLTIP_ID, TOOLTIP_FLAG))
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/UI/NextActionWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public override void PostDraw()

public override unsafe void Draw()
{
var width = Service.Config.ControlWindowGCDSize
* Service.Config.ControlWindowNextSizeRatio;
var config = Service.Config;
var width = config.ControlWindowGCDSize * config.ControlWindowNextSizeRatio;
DrawGcdCooldown(width, false);

var percent = 0f;
Expand Down
8 changes: 7 additions & 1 deletion RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using ExCSS;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.Fate;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Common.Component.BGCollision;
using Lumina.Excel.GeneratedSheets;
Expand Down Expand Up @@ -2758,7 +2759,7 @@ private static unsafe void DrawTargetData()
{
ImGui.Text($"Owner: {owner.Name}");
}

if (target is IBattleChara battleChara)
{
ImGui.Text($"HP: {battleChara.CurrentHp} / {battleChara.MaxHp}");
Expand All @@ -2768,7 +2769,12 @@ private static unsafe void DrawTargetData()
ImGui.Text($"Rank: {battleChara.GetObjectNPC()?.Rank.ToString() ?? string.Empty}");
ImGui.Text($"Has Positional: {battleChara.HasPositional()}");
ImGui.Text($"Is Dying: {battleChara.IsDying()}");
ImGui.Text($"Is Alive: {battleChara.IsAlive()}");
ImGui.Text($"Is Party: {battleChara.IsParty()}");
ImGui.Text($"Is Enemy: {battleChara.IsEnemy()}");
ImGui.Text($"Is In EnemiesList: {battleChara.IsInEnemiesList()}");
ImGui.Text($"Is Attackable: {battleChara.IsAttackable()}");
ImGui.Text($"CanProvoke: {battleChara.CanProvoke()}");
ImGui.Text($"EventType: {battleChara.GetEventType()}");
ImGui.Text($"NamePlate: {battleChara.GetNamePlateIcon()}");
ImGui.Text($"StatusFlags: {battleChara.StatusFlags}");
Expand Down
15 changes: 8 additions & 7 deletions RotationSolver/UI/RotationConfigWindowTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class TabSkipAttribute : Attribute
[AttributeUsage(AttributeTargets.Field)]
internal class TabIconAttribute : Attribute
{
public uint Icon { get; set; }
public uint Icon { get; init; }
}

/// <summary>
Expand Down Expand Up @@ -64,10 +64,10 @@ internal enum RotationConfigWindowTab : byte
/// </summary>
public struct IncompatiblePlugin
{
public string Name { get; set; }
public string Icon { get; set; }
public string Url { get; set; }
public string Features { get; set; }
public string Name { get; init; }
public string Icon { get; init; }
public string Url { get; init; }
public string Features { get; init; }

/// <summary>
/// Checks if the plugin is installed.
Expand All @@ -78,12 +78,13 @@ public readonly bool IsInstalled
get
{
var name = this.Name;
return Svc.PluginInterface.InstalledPlugins.Any(x =>
var installedPlugins = Svc.PluginInterface.InstalledPlugins;
return installedPlugins.Any(x =>
(x.Name.Equals(name, StringComparison.OrdinalIgnoreCase) || x.InternalName.Equals(name, StringComparison.OrdinalIgnoreCase)) && x.IsLoaded);
}
}

public CompatibleType Type { get; set; }
public CompatibleType Type { get; init; }
}

/// <summary>
Expand Down
Loading