From 6dd5148599f4caaa50e9cff5c78bf5bfcf4a9f23 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Mon, 17 Jun 2024 21:54:44 +0200 Subject: [PATCH] Add config to enable/disable recommendations when entering GC area --- Gearsetter/Configuration.cs | 1 + Gearsetter/GearsetterPlugin.cs | 28 +++++++++++++++++++++++++--- Gearsetter/Model/EquipmentItem.cs | 15 ++++++++++++--- Gearsetter/Windows/ConfigWindow.cs | 29 +++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 Gearsetter/Windows/ConfigWindow.cs diff --git a/Gearsetter/Configuration.cs b/Gearsetter/Configuration.cs index 943c402..ffc5d7f 100644 --- a/Gearsetter/Configuration.cs +++ b/Gearsetter/Configuration.cs @@ -8,6 +8,7 @@ internal sealed class Configuration : IPluginConfiguration { public int Version { get; set; } = 1; + public bool ShowRecommendationsWhenEnteringGcArea { get; set; } = true; public List StatPriorityTanks { get; set; } = new(); public List StatPriorityHealer { get; set; } = new(); public List StatPriorityMelee { get; set; } = new(); diff --git a/Gearsetter/GearsetterPlugin.cs b/Gearsetter/GearsetterPlugin.cs index e3697eb..af9929d 100644 --- a/Gearsetter/GearsetterPlugin.cs +++ b/Gearsetter/GearsetterPlugin.cs @@ -16,6 +16,7 @@ using Gearsetter.GameData; using Gearsetter.Model; using Gearsetter.Windows; using Lumina.Excel.GeneratedSheets; +using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany; namespace Gearsetter; @@ -32,6 +33,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin private readonly Configuration _configuration; private readonly GameDataHolder _gameDataHolder; private readonly EquipmentBrowserWindow _equipmentBrowserWindow; + private readonly ConfigWindow _configWindow; private readonly IReadOnlyDictionary _linkPayloads; private readonly Dictionary _classJobToArrayIndex; @@ -59,6 +61,8 @@ public sealed class GearsetterPlugin : IDalamudPlugin _gameDataHolder = new GameDataHolder(dataManager, _configuration); _equipmentBrowserWindow = new EquipmentBrowserWindow(this, _gameDataHolder, _clientState, _chatGui); _windowSystem.AddWindow(_equipmentBrowserWindow); + _configWindow = new ConfigWindow(_pluginInterface, _configuration); + _windowSystem.AddWindow(_configWindow); _commandManager.AddHandler("/gup", new CommandInfo(ShowUpgrades) { @@ -72,16 +76,32 @@ public sealed class GearsetterPlugin : IDalamudPlugin .ToDictionary(x => (byte)x, x => _pluginInterface.AddChatLinkHandler((byte)x, ChangeGearset)).AsReadOnly(); _clientState.TerritoryChanged += TerritoryChanged; _pluginInterface.UiBuilder.Draw += _windowSystem.Draw; + _pluginInterface.UiBuilder.OpenMainUi += _equipmentBrowserWindow.Toggle; + _pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle; _classJobToArrayIndex = dataManager.GetExcelSheet()! .Where(x => x.RowId > 0 && Enum.IsDefined(typeof(EClassJob), x.RowId)) .ToDictionary(x => (EClassJob)x.RowId, x => (byte)x.ExpArrayIndex); } - private void TerritoryChanged(ushort territory) + private unsafe void TerritoryChanged(ushort territory) { - if (territory == 128) - ShowUpgrades(); + try + { + var playerState = PlayerState.Instance(); + if (playerState == null) + return; + + var grandCompany = (GrandCompany)playerState->GrandCompany; + if ((grandCompany == GrandCompany.Maelstrom && territory == 128) || + (grandCompany == GrandCompany.TwinAdder && territory == 132) || + (grandCompany == GrandCompany.ImmortalFlames && territory == 130)) + ShowUpgrades(); + } + catch (Exception e) + { + _pluginLog.Warning(e, "Could not show upgrades when entering Grand Company area."); + } } @@ -312,6 +332,8 @@ public sealed class GearsetterPlugin : IDalamudPlugin public void Dispose() { + _pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle; + _pluginInterface.UiBuilder.OpenMainUi -= _equipmentBrowserWindow.Toggle; _pluginInterface.UiBuilder.Draw -= _windowSystem.Draw; _clientState.TerritoryChanged -= TerritoryChanged; _pluginInterface.RemoveChatLinkHandler(); diff --git a/Gearsetter/Model/EquipmentItem.cs b/Gearsetter/Model/EquipmentItem.cs index 60932b5..f690570 100644 --- a/Gearsetter/Model/EquipmentItem.cs +++ b/Gearsetter/Model/EquipmentItem.cs @@ -20,9 +20,18 @@ internal sealed record EquipmentItem(Item Item, bool Hq) public int PrimaryStat { get; init; } = -1; - public int Damage => ClassJob.DealsMagicDamage() - ? Item.DamageMag + Stats.Get(EBaseParam.DamageMag) - : Item.DamagePhys + Stats.Get(EBaseParam.DamagePhys); + public int Damage + { + get + { + if (ClassJob.DealsMagicDamage()) + return Item.DamageMag + Stats.Get(EBaseParam.DamageMag); + else if (ClassJob.DealsPhysicalDamage()) + return Item.DamagePhys + Stats.Get(EBaseParam.DamagePhys); + else + return 0; + } + } public bool HasAnyStat(params EBaseParam[] substats) { diff --git a/Gearsetter/Windows/ConfigWindow.cs b/Gearsetter/Windows/ConfigWindow.cs new file mode 100644 index 0000000..e61c471 --- /dev/null +++ b/Gearsetter/Windows/ConfigWindow.cs @@ -0,0 +1,29 @@ +using Dalamud.Interface.Windowing; +using Dalamud.Plugin; +using ImGuiNET; + +namespace Gearsetter.Windows; + +internal sealed class ConfigWindow : Window +{ + private readonly DalamudPluginInterface _pluginInterface; + private readonly Configuration _configuration; + + public ConfigWindow(DalamudPluginInterface pluginInterface, Configuration configuration) + : base("Gearsetter - Config###GearsetterConfig", ImGuiWindowFlags.AlwaysAutoResize) + { + _pluginInterface = pluginInterface; + _configuration = configuration; + } + + public override void Draw() + { + bool showRecommendationsWhenEnteringGcArea = _configuration.ShowRecommendationsWhenEnteringGcArea; + if (ImGui.Checkbox("Show recommendations when entering Grand Company area", + ref showRecommendationsWhenEnteringGcArea)) + { + _configuration.ShowRecommendationsWhenEnteringGcArea = showRecommendationsWhenEnteringGcArea; + _pluginInterface.SavePluginConfig(_configuration); + } + } +}