diff --git a/CurrencyAlert.sln b/CurrencyAlert.sln index 55a77fc..28f9f04 100644 --- a/CurrencyAlert.sln +++ b/CurrencyAlert.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31919.166 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SamplePlugin", "SamplePlugin\SamplePlugin.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurrencyAlert", "SamplePlugin\CurrencyAlert.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UIDev", "UIDev\UIDev.csproj", "{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}" EndProject diff --git a/SamplePlugin/Configuration.cs b/SamplePlugin/Configuration.cs index e657313..0965943 100644 --- a/SamplePlugin/Configuration.cs +++ b/SamplePlugin/Configuration.cs @@ -2,14 +2,17 @@ using Dalamud.Plugin; using System; -namespace SamplePlugin +namespace CurrencyAlert { [Serializable] public class Configuration : IPluginConfiguration { - public int Version { get; set; } = 1; - + public int Version { get; set; } = 1; + + public bool PoeticsThresholdEnabled { get; set; } = true; public int PoeticsThreshold { get; set; } = 1500; + public bool StormSealsThresholdEnabled { get; set; } = true; + public int StormSealsThreshold { get; set; } = 40000; // the below exist just to make saving less cumbersome diff --git a/SamplePlugin/Plugin.cs b/SamplePlugin/Plugin.cs index 141b962..e2c3c62 100644 --- a/SamplePlugin/Plugin.cs +++ b/SamplePlugin/Plugin.cs @@ -4,7 +4,7 @@ using Dalamud.Plugin; using System.IO; using System.Reflection; -namespace SamplePlugin +namespace CurrencyAlert { public sealed class Plugin : IDalamudPlugin { @@ -48,8 +48,7 @@ namespace SamplePlugin private void OnCommand(string command, string args) { - // in response to the slash command, just display our main ui - this.PluginUi.Visible = true; + this.DrawConfigUI(); } private void DrawUI() diff --git a/SamplePlugin/PluginUI.cs b/SamplePlugin/PluginUI.cs index a689ba9..6d65e78 100644 --- a/SamplePlugin/PluginUI.cs +++ b/SamplePlugin/PluginUI.cs @@ -1,60 +1,63 @@ using FFXIVClientStructs.FFXIV.Client.Game; -using ImGuiNET; -using System; -using System.Numerics; - -namespace SamplePlugin -{ - // It is good to have this be disposable in general, in case you ever need it - // to do any cleanup - class PluginUI : IDisposable - { - private Configuration configuration; - - // this extra bool exists for ImGui, since you can't ref a property - private bool visible = false; - public bool Visible - { - get { return this.visible; } - set { this.visible = value; } - } - - private bool settingsVisible = false; - public bool SettingsVisible - { - get { return this.settingsVisible; } - set { this.settingsVisible = value; } +using ImGuiNET; +using System; +using System.Numerics; + +namespace CurrencyAlert +{ + public enum CurrencySlot + { + StormSeals = 1, + WolfMarks = 4, + Poetics = 6, + AlliedSeals = 8 + }; + + // It is good to have this be disposable in general, in case you ever need it + // to do any cleanup + class PluginUI : IDisposable + { + private Configuration configuration; + + private bool settingsVisible = false; + public bool SettingsVisible + { + get { return this.settingsVisible; } + set { this.settingsVisible = value; } } - //public unsafe InventoryManager* InventoryManager { get; } + private bool poeticsAlertVisible = false; + public bool PoeticsAlertVisible + { + get { return this.poeticsAlertVisible; } + set { this.poeticsAlertVisible = value; } + } - // passing in the image here just for simplicity - public PluginUI(Configuration configuration) - { - this.configuration = configuration; - //this.InventoryManager = InventoryManager.Instance(); - } - - public void Dispose() - { - - } - - public void Draw() - { - // This is our only draw handler attached to UIBuilder, so it needs to be - // able to draw any windows we might have open. - // Each method checks its own visibility/state to ensure it only draws when - // it actually makes sense. - // There are other ways to do this, but it is generally best to keep the number of - // draw delegates as low as possible. - - DrawMainWindow(); - DrawSettingsWindow(); - } - - public void DrawMainWindow() - { + public PluginUI(Configuration configuration) + { + this.configuration = configuration; + } + + public void Dispose() + { + + } + + public void Draw() + { + // This is our only draw handler attached to UIBuilder, so it needs to be + // able to draw any windows we might have open. + // Each method checks its own visibility/state to ensure it only draws when + // it actually makes sense. + // There are other ways to do this, but it is generally best to keep the number of + // draw delegates as low as possible. + + DrawMainWindow(); + DrawSettingsWindow(); + } + + public void DrawMainWindow() + { unsafe { InventoryManager* inventoryManager = InventoryManager.Instance(); @@ -65,22 +68,14 @@ namespace SamplePlugin // Allied Seal: 8 // Company Seals: 1,2,3 - uint poetics = currencyContainer->GetInventorySlot(6)->Quantity; - uint wolfMarks = currencyContainer->GetInventorySlot(4)->Quantity; - uint stormSeals = currencyContainer->GetInventorySlot(1)->Quantity; - uint serpentSeals = currencyContainer->GetInventorySlot(2)->Quantity; - uint flameSeals = currencyContainer->GetInventorySlot(3)->Quantity; + uint poetics = currencyContainer->GetInventorySlot((int) CurrencySlot.Poetics)->Quantity; + bool poeticsThresholdEnabled = this.configuration.PoeticsThresholdEnabled; uint poeticsThreshold = (uint) this.configuration.PoeticsThreshold; - Visible = false; + PoeticsAlertVisible = poeticsThresholdEnabled && poetics >= poeticsThreshold; - if (poetics >= poeticsThreshold) - { - Visible = true; - } - - if (!Visible) + if (!PoeticsAlertVisible) { return; } @@ -88,44 +83,43 @@ namespace SamplePlugin ImGui.SetNextWindowSize(new Vector2(375, 330), ImGuiCond.FirstUseEver); ImGui.SetNextWindowSizeConstraints(new Vector2(375, 330), new Vector2(float.MaxValue, float.MaxValue)); - if (ImGui.Begin("My Amazing Window", ref this.visible, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)) + if (ImGui.Begin("DEPENSE TES POETICS MERDE", ref this.poeticsAlertVisible, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse | ImGuiWindowFlags.AlwaysAutoResize)) { - if (ImGui.Button("Show Settings")) - { - SettingsVisible = true; - } - - if (poetics >= poeticsThreshold) - { - ImGui.Text("DEPENSE TES POETICS MERDE"); - } + ImGui.Text("DEPENSE TES POETICS MEEEEERDE"); } ImGui.End(); - } - } - - public void DrawSettingsWindow() - { - if (!SettingsVisible) - { - return; - } - - ImGui.SetNextWindowSize(new Vector2(232, 75), ImGuiCond.Always); - if (ImGui.Begin("A Wonderful Configuration Window", ref this.settingsVisible, - ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)) - { - // can't ref a property, so use a local copy - var configValue = this.configuration.PoeticsThreshold; - if (ImGui.InputInt("Poetics Threshold", ref configValue)) - { - this.configuration.PoeticsThreshold = configValue; - // can save immediately on change, if you don't want to provide a "Save and Close" button - this.configuration.Save(); - } - } - ImGui.End(); - } - } -} + } + } + + public void DrawSettingsWindow() + { + if (!SettingsVisible) + { + return; + } + + ImGui.SetNextWindowSize(new Vector2(330, 120), ImGuiCond.Always); + if (ImGui.Begin("Currency Alert Configuration Window", ref this.settingsVisible, + ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)) + { + var poeticsThresholdEnabledConfig = this.configuration.PoeticsThresholdEnabled; + + if (ImGui.Checkbox("Poetics Threshold Enabled", ref poeticsThresholdEnabledConfig)) + { + this.configuration.PoeticsThresholdEnabled = poeticsThresholdEnabledConfig; + this.configuration.Save(); + } + + var poeticsThresholdConfig = this.configuration.PoeticsThreshold; + + if (ImGui.InputInt("Poetics Threshold", ref poeticsThresholdConfig, 1, 1, this.configuration.PoeticsThresholdEnabled ? ImGuiInputTextFlags.None : ImGuiInputTextFlags.ReadOnly)) + { + this.configuration.PoeticsThreshold = poeticsThresholdConfig; + this.configuration.Save(); + } + } + ImGui.End(); + } + } +}