Skip to content

Commit

Permalink
Merge pull request #346 from FFXIV-CombatReborn/UI-refactors
Browse files Browse the repository at this point in the history
Improve logging, error handling, and code readability
  • Loading branch information
LTS-FFXIV authored Sep 13, 2024
2 parents e7cc9a0 + 318f8d0 commit 064967f
Show file tree
Hide file tree
Showing 22 changed files with 809 additions and 557 deletions.
2 changes: 1 addition & 1 deletion ECommons
Submodule ECommons updated 27 files
+2 −1 .github/FUNDING.yml
+1 −0 ECommons/Automation/NeoTaskManager/TaskManager.cs
+104 −0 ECommons/Automation/NeoTaskManager/Tasks/NeoTasks.cs
+2 −3 ECommons/DalamudServices/Svc.cs
+1 −1 ECommons/ECommons.csproj
+236 −0 ECommons/ExcelServices/ExcelCombos.cs
+0 −1 ECommons/GameFunctions/ObjectFunctions.cs
+30 −4 ECommons/GameHelpers/Player.cs
+64 −1 ECommons/GenericHelpers.cs
+135 −27 ECommons/ImGuiMethods/ImGuiEx/ImGuiEx.cs
+0 −25 ECommons/ImGuiMethods/PopupWindow.cs
+64 −0 ECommons/Reflection/DalamudReflector.cs
+18 −0 ECommons/SimpleGui/EzConfigGui.cs
+51 −0 ECommons/SimpleGui/PopupWindow.cs
+25 −5 ECommons/UIHelpers/AddonMasterImplementations/!AddonMasterBase.cs
+18 −0 ECommons/UIHelpers/AddonMasterImplementations/AirShipExplorationResult.cs
+33 −0 ECommons/UIHelpers/AddonMasterImplementations/CollectablesShop.cs
+16 −0 ECommons/UIHelpers/AddonMasterImplementations/CompanyCraftSupply.cs
+49 −0 ECommons/UIHelpers/AddonMasterImplementations/ContextMenu.cs
+27 −0 ECommons/UIHelpers/AddonMasterImplementations/DifficultySelectYesNo.cs
+25 −0 ECommons/UIHelpers/AddonMasterImplementations/LookingForGroup.cs
+29 −0 ECommons/UIHelpers/AddonMasterImplementations/LookingForGroupCondition.cs
+24 −0 ECommons/UIHelpers/AddonMasterImplementations/LookingForGroupDetail.cs
+2 −0 ECommons/UIHelpers/AddonMasterImplementations/Request.cs
+10 −10 ECommons/UIHelpers/AddonMasterImplementations/RetainerList.cs
+12 −12 ECommons/UIHelpers/AddonMasterImplementations/SelectString.cs
+6 −0 ECommons/UIHelpers/AddonMasterImplementations/Talk.cs
27 changes: 25 additions & 2 deletions RotationSolver.Basic/Helpers/StatusHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Game.ClientState.Statuses;
using ECommons.Automation;
using ECommons.GameHelpers;
using ECommons.Logging;
using RotationSolver.Basic.Configuration;

namespace RotationSolver.Basic.Helpers;
Expand Down Expand Up @@ -234,8 +235,30 @@ public static bool HasStatus(this IGameObject obj, bool isFromSelf, params Statu
/// <param name="status"></param>
public static void StatusOff(StatusID status)
{
if (Player.Object == null || !Player.Object.HasStatus(false, status)) return;
Chat.Instance.SendMessage($"/statusoff {GetStatusName(status)}");
if (Player.Object == null)
{
// Log or handle the case where Player.Object is null
PluginLog.Error("Player object is null. Cannot remove status.");
return;
}

if (!Player.Object.HasStatus(false, status))
{
// Log or handle the case where the player does not have the status
PluginLog.Error($"Player does not have the status: {GetStatusName(status)}");
return;
}

try
{
Chat.Instance.SendMessage($"/statusoff {GetStatusName(status)}");
PluginLog.Error($"Status {GetStatusName(status)} removed successfully.");
}
catch (Exception ex)
{
// Log the exception
PluginLog.Error($"Failed to remove status {GetStatusName(status)}: {ex.Message}");
}
}

internal static string GetStatusName(StatusID id)
Expand Down
64 changes: 57 additions & 7 deletions RotationSolver.Basic/Rotations/CustomRotation_GCD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ partial class CustomRotation

if (RaiseSpell(out act, false)) return act;

if (Service.Config.RaisePlayerByCasting && SwiftcastPvE.Cooldown.IsCoolingDown && RaiseSpell(out act, true)) return act;

IBaseAction.TargetOverride = null;

if (DataCenter.MergedStatus.HasFlag(AutoStatus.MoveForward)
Expand Down Expand Up @@ -106,12 +108,6 @@ partial class CustomRotation
}
}

IBaseAction.TargetOverride = TargetType.Death;

if (Service.Config.RaisePlayerByCasting && SwiftcastPvE.Cooldown.IsCoolingDown && RaiseSpell(out act, true)) return act;

IBaseAction.TargetOverride = null;

return null;
}

Expand All @@ -132,12 +128,15 @@ private bool UseLimitBreak(out IAction? act)

private bool RaiseSpell(out IAction? act, bool mustUse)
{
act = null;

// Check if the command status has the Raise flag
if (DataCenter.CommandStatus.HasFlag(AutoStatus.Raise))
{
if (RaiseGCD(out act) || RaiseAction(out act, false)) return true;
}

act = null;
// Check if the auto status has the Raise flag
if (!DataCenter.AutoStatus.HasFlag(AutoStatus.Raise)) return false;

if (RaiseGCD(out act)) return true;
Expand Down Expand Up @@ -170,6 +169,7 @@ private bool RaiseSpell(out IAction? act, bool mustUse)

bool RaiseAction(out IAction act, bool ignoreCastingCheck)
{
// Check if the player has enough MP to cast Raise
if (Player.CurrentMp > Service.Config.LessMPNoRaise && (Raise?.CanUse(out act, skipCastingCheck: ignoreCastingCheck) ?? false)) return true;

act = null!;
Expand All @@ -196,6 +196,13 @@ protected virtual bool RaiseGCD(out IAction? act)
/// <returns></returns>
protected virtual bool DispelGCD(out IAction? act)
{
act = null;
if (DataCenter.CommandStatus.HasFlag(AutoStatus.Raise))
{

if (Role is JobRole.Healer && HasSwift) return false;
}

if (EsunaPvE.CanUse(out act)) return true;
if (DataCenter.RightNowDutyRotation?.DispelGCD(out act) ?? false) return true;
return false;
Expand All @@ -216,6 +223,12 @@ protected virtual bool EmergencyGCD(out IAction? act)

if (StandardissueElixirPvP.CanUse(out act)) return true;
#endregion
act = null;
if (DataCenter.CommandStatus.HasFlag(AutoStatus.Raise))
{

if (Role is JobRole.Healer && HasSwift) return false;
}

if (DataCenter.RightNowDutyRotation?.EmergencyGCD(out act) ?? false) return true;

Expand All @@ -230,6 +243,13 @@ protected virtual bool EmergencyGCD(out IAction? act)
[RotationDesc(DescType.MoveForwardGCD)]
protected virtual bool MoveForwardGCD(out IAction? act)
{
act = null;
if (DataCenter.CommandStatus.HasFlag(AutoStatus.Raise))
{

if (Role is JobRole.Healer && HasSwift) return false;
}

if (DataCenter.RightNowDutyRotation?.MoveForwardGCD(out act) ?? false) return true;
act = null; return false;
}
Expand All @@ -254,6 +274,13 @@ protected virtual bool HealSingleGCD(out IAction? act)
[RotationDesc(DescType.HealAreaGCD)]
protected virtual bool HealAreaGCD(out IAction? act)
{
act = null;
if (DataCenter.CommandStatus.HasFlag(AutoStatus.Raise))
{

if (Role is JobRole.Healer && HasSwift) return false;
}

if (DataCenter.RightNowDutyRotation?.HealAreaGCD(out act) ?? false) return true;
act = null!; return false;
}
Expand All @@ -266,6 +293,13 @@ protected virtual bool HealAreaGCD(out IAction? act)
[RotationDesc(DescType.DefenseSingleGCD)]
protected virtual bool DefenseSingleGCD(out IAction? act)
{
act = null;
if (DataCenter.CommandStatus.HasFlag(AutoStatus.Raise))
{

if (Role is JobRole.Healer && HasSwift) return false;
}

if (DataCenter.RightNowDutyRotation?.DefenseSingleGCD(out act) ?? false) return true;
act = null!; return false;
}
Expand All @@ -278,6 +312,14 @@ protected virtual bool DefenseSingleGCD(out IAction? act)
[RotationDesc(DescType.DefenseAreaGCD)]
protected virtual bool DefenseAreaGCD(out IAction? act)
{
act = null;

if (DataCenter.CommandStatus.HasFlag(AutoStatus.Raise))
{

if (Role is JobRole.Healer && HasSwift) return false;
}

if (DataCenter.RightNowDutyRotation?.DefenseAreaGCD(out act) ?? false) return true;
act = null; return false;
}
Expand All @@ -289,6 +331,14 @@ protected virtual bool DefenseAreaGCD(out IAction? act)
/// <returns></returns>
protected virtual bool GeneralGCD(out IAction? act)
{
act = null;

if (DataCenter.CommandStatus.HasFlag(AutoStatus.Raise))
{

if (Role is JobRole.Healer && HasSwift) return false;
}

if (DataCenter.RightNowDutyRotation?.GeneralGCD(out act) ?? false) return true;
act = null; return false;
}
Expand Down
16 changes: 10 additions & 6 deletions RotationSolver/TextureItems/StatusTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

namespace RotationSolver.TextureItems;

internal class StatusTexture(Status status) : ITexture
internal class StatusTexture : ITexture
{
readonly Status _status = status;
private readonly Status _status;

public StatusTexture(Status status)
{
_status = status ?? throw new ArgumentNullException(nameof(status));
}

public uint IconID => _status.Icon;
public StatusID ID => (StatusID)_status.RowId;
public string Name => $"{_status.Name} ({_status.RowId})";

public string Description => _status.Description?.ToString() ?? string.Empty;

public bool IsEnabled { get; set; } = true;

public StatusTexture(StatusID id)
Expand All @@ -19,7 +23,7 @@ public StatusTexture(StatusID id)
}

public StatusTexture(uint id)
: this(Service.GetSheet<Status>().GetRow(id)!)
: this(Service.GetSheet<Status>().GetRow(id) ?? throw new ArgumentException($"Invalid Status ID: {id}", nameof(id)))
{
}
}
}
19 changes: 12 additions & 7 deletions RotationSolver/UI/CooldownWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,36 @@ public override void Draw()
if (DataCenter.RightNowRotation == null) return;

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

if (RotationUpdater.AllGroupedActions == null) return;

foreach (var pair in RotationUpdater.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.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));
}

if (!showItems.Any()) continue;

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

ImGui.Text(pair.Key);

uint started = 0;
uint itemIndex = 0;
foreach (var item in showItems)
{
if (started++ % count != 0)
if (itemIndex++ % count != 0)
{
ImGui.SameLine();
}
ControlWindow.DrawIAction(item, width, 1f);
}
}
}

}
27 changes: 22 additions & 5 deletions RotationSolver/UI/CtrlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,37 @@ public override void PreDraw()
ImGui.PushStyleColor(ImGuiCol.WindowBg, bgColor);

Flags = BaseFlags;

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

ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0);
base.PreDraw();

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

}
}

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

}
finally
{
ImGui.PopStyleColor();
ImGui.PopStyleVar();
}
}
}
29 changes: 20 additions & 9 deletions RotationSolver/UI/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,36 @@ public static class FontManager
{
public unsafe static ImFontPtr GetFont(float size)
{
var style = new Dalamud.Interface.GameFonts.GameFontStyle(Dalamud.Interface.GameFonts.GameFontStyle.GetRecommendedFamilyAndSize(Dalamud.Interface.GameFonts.GameFontFamily.Axis, size));
// Get the recommended font style based on the specified size
var style = new Dalamud.Interface.GameFonts.GameFontStyle(
Dalamud.Interface.GameFonts.GameFontStyle.GetRecommendedFamilyAndSize(
Dalamud.Interface.GameFonts.GameFontFamily.Axis, size));

// Create a new game font handle
var handle = Svc.PluginInterface.UiBuilder.FontAtlas.NewGameFontHandle(style);

try
{
var font = handle.Lock().ImFont;

if ((nint)font.NativePtr == nint.Zero)
// Lock the handle to get the font
using (var lockedHandle = handle.Lock())
{
return ImGui.GetFont();
var font = lockedHandle.ImFont;

// Check if the font pointer is valid
if (new IntPtr(font.NativePtr) == IntPtr.Zero)
{
return ImGui.GetFont();
}

// Scale the font to the desired size
font.Scale = size / font.FontSize;
return font;
}
font.Scale = size / font.FontSize;
return font;
}
catch
catch (Exception)
{
return ImGui.GetFont();
}
}
}
}
}
Loading

0 comments on commit 064967f

Please sign in to comment.