diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f907bfb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "KamiLib"] + path = KamiLib + url = https://github.com/MidoriKami/KamiLib diff --git a/CurrencyAlert.sln b/CurrencyAlert.sln index 6bc58db..2f9136a 100644 --- a/CurrencyAlert.sln +++ b/CurrencyAlert.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.0.31919.166 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurrencyAlert", "CurrencyAlert\CurrencyAlert.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KamiLib", "KamiLib\KamiLib.csproj", "{6EAC83CF-FCF8-42F0-B923-13658DD93725}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -15,6 +17,10 @@ Global {13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.Build.0 = Debug|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.ActiveCfg = Release|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.Build.0 = Release|x64 + {6EAC83CF-FCF8-42F0-B923-13658DD93725}.Debug|x64.ActiveCfg = Debug|x64 + {6EAC83CF-FCF8-42F0-B923-13658DD93725}.Debug|x64.Build.0 = Debug|x64 + {6EAC83CF-FCF8-42F0-B923-13658DD93725}.Release|x64.ActiveCfg = Release|x64 + {6EAC83CF-FCF8-42F0-B923-13658DD93725}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CurrencyAlert/Commands/OverlayCommands.cs b/CurrencyAlert/Commands/OverlayCommands.cs new file mode 100644 index 0000000..512126e --- /dev/null +++ b/CurrencyAlert/Commands/OverlayCommands.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using CurrencyAlert.Localization; +using KamiLib.ChatCommands; +using KamiLib.Interfaces; + +namespace CurrencyAlert.Commands; + +public class OverlayCommands : IPluginCommand +{ + public string CommandArgument => "overlay"; + + public IEnumerable SubCommands { get; } = new List + { + new SubCommand + { + CommandKeyword = "show", + CommandAction = () => + { + Service.Configuration.OverlaySettings.Show.Value = true; + Service.Configuration.Save(); + }, + GetHelpText = () => Strings.Commands_ShowOverlayHelp, + }, + new SubCommand + { + CommandKeyword = "hide", + CommandAction = () => + { + Service.Configuration.OverlaySettings.Show.Value = false; + Service.Configuration.Save(); + }, + GetHelpText = () => Strings.Commands_HideOverlayHelp, + }, + new SubCommand + { + CommandKeyword = "toggle", + CommandAction = () => + { + Service.Configuration.OverlaySettings.Show.Value = !Service.Configuration.OverlaySettings.Show.Value; + Service.Configuration.Save(); + }, + GetHelpText = () => Strings.Commands_ToggleOverlayHelp, + }, + }; +} \ No newline at end of file diff --git a/CurrencyAlert/Configuration.cs b/CurrencyAlert/Configuration.cs index a4ed233..dd020ad 100644 --- a/CurrencyAlert/Configuration.cs +++ b/CurrencyAlert/Configuration.cs @@ -1,38 +1,57 @@ -using CurrencyAlert.Helper; -using CurrencyAlert.Provider; -using Dalamud.Configuration; +using Dalamud.Configuration; using Dalamud.Plugin; using System; -using System.Collections.Generic; +using CurrencyAlert.DataModels; +using CurrencyAlert.Windows; +using KamiLib.Configuration; -namespace CurrencyAlert +namespace CurrencyAlert; + +[Serializable] +public class Configuration : IPluginConfiguration { - [Serializable] - public class Configuration : IPluginConfiguration - { - public int Version { get; set; } = 5; + public int Version { get; set; } = 6; - public bool UiLocked { get; set; } = false; - public Dictionary AlertEnabled { get; } = new Dictionary(); - public Dictionary Threshold { get; } = new Dictionary(); + public OverlaySettings OverlaySettings = new(); + public DisplaySettings DisplaySettings = new(); + public Setting ChatNotification = new(false); + + public TrackedCurrency[] TrackedCurrencies = { + // Grand Company Seals + new(CurrencyName.StormSeal, new Setting(75_000), new Setting(true)), + new(CurrencyName.SerpentSeals, new Setting(75_000), new Setting(true)), + new(CurrencyName.FlameSeals, new Setting(75_000), new Setting(true)), + + // PvP Currencies + new(CurrencyName.WolfMarks, new Setting(18_000), new Setting(true)), + new(CurrencyName.TrophyCrystals, new Setting(18_000), new Setting(true)), + + // Hunts + new(CurrencyName.AlliedSeals, new Setting(3_500), new Setting(true)), + new(CurrencyName.CenturioSeals, new Setting(3_500), new Setting(true)), + new(CurrencyName.SackOfNuts, new Setting(3_500), new Setting(true)), + + // FATEs + new(CurrencyName.BicolorGemstones, new Setting(800), new Setting(true)), + + // Tomestones + new(CurrencyName.Poetics, new Setting(1_400), new Setting(true)), + new(CurrencyName.NonLimitedTomestone, new Setting(1_700), new Setting(true)), + new(CurrencyName.LimitedTomestone, new Setting(1_700), new Setting(true)), + + // Crafting & Gathering + new(CurrencyName.WhiteCrafterScripts, new Setting(3_500), new Setting(true)), + new(CurrencyName.WhiteGatherersScripts, new Setting(3_500), new Setting(true)), + + new(CurrencyName.PurpleCrafterScripts, new Setting(3_500), new Setting(true)), + new(CurrencyName.PurpleGatherersScripts, new Setting(3_500), new Setting(true)), + + // Ishguard Restoration + new(CurrencyName.SkybuildersScripts, new Setting(7_500), new Setting(true)), + }; - public Configuration() - { - foreach (var currency in CurrencyProvider.Instance.GetAll()) - { - this.AlertEnabled[currency.Id] = true; - this.Threshold[currency.Id] = currency.DefaultThreshold; - } - } - - public void Initialize() - { - - } - - public void Save() - { - PluginHelper.PluginInterface.SavePluginConfig(this); - } - } -} + [NonSerialized] + private DalamudPluginInterface? pluginInterface; + public void Initialize(DalamudPluginInterface inputPluginInterface) => pluginInterface = inputPluginInterface; + public void Save() => pluginInterface!.SavePluginConfig(this); +} \ No newline at end of file diff --git a/CurrencyAlert/CurrencyAlert.csproj b/CurrencyAlert/CurrencyAlert.csproj index 0bd92bb..0bd0f23 100644 --- a/CurrencyAlert/CurrencyAlert.csproj +++ b/CurrencyAlert/CurrencyAlert.csproj @@ -1,34 +1,13 @@  - - - 0.4.0.0 + 0.5.0.0 Currency Alert - https://github.com/Lharz/xiv-currency-alert - - - 7 - Lharz - CurrencyAlert - Display alerts upon reaching configurable currencies thresholds (such as Poetics or PVP marks). - /currencyalert: shows the configuration panel. - - Currency - Utility - - - ../icon.png - - False - - - - net6.0-windows + net7.0-windows x64 enable latest @@ -47,7 +26,7 @@ - + $(DalamudLibPath)FFXIVClientStructs.dll false @@ -82,4 +61,23 @@ + + + + + + + ResXFileCodeGenerator + Strings.Designer.cs + + + + + + True + True + Strings.resx + + + diff --git a/CurrencyAlert/CurrencyAlert.json b/CurrencyAlert/CurrencyAlert.json index fadf32a..3fb3f68 100644 --- a/CurrencyAlert/CurrencyAlert.json +++ b/CurrencyAlert/CurrencyAlert.json @@ -2,15 +2,17 @@ "Author": "Lharz", "Name": "CurrencyAlert", "Punchline": "Display alerts upon reaching configurable currencies thresholds (such as Poetics or PVP marks).", - "Description": "/currencyalert: shows the configuration panel.", - "Changelog": null, + "Description": "This plugin lets you easily manage your various currencies to prevent from wasting precious resources.", "Tags": [ - "plugin", - "currency", - "tomestones", - "utility", - "other" + "Currency", + "Tomestones", + "Utility", + "Other" ], - "CategoryTags": null, - "RepoUrl": "https://github.com/Lharz/xiv-currency-alert", + "CategoryTags": [ + "Utility", + "Other", + "UI" + ], + "RepoUrl": "https://github.com/Lharz/xiv-currency-alert" } diff --git a/CurrencyAlert/DataModels/CurrencyInfo.cs b/CurrencyAlert/DataModels/CurrencyInfo.cs new file mode 100644 index 0000000..ab474bc --- /dev/null +++ b/CurrencyAlert/DataModels/CurrencyInfo.cs @@ -0,0 +1,84 @@ +using System; +using System.Linq; +using Dalamud.Utility; +using FFXIVClientStructs.FFXIV.Client.Game; +using ImGuiScene; +using KamiLib.Caching; +using Lumina.Excel.GeneratedSheets; + +namespace CurrencyAlert.DataModels; + +public class CurrencyInfo : IDisposable +{ + public uint ItemID { get; } + public string ItemName { get; } = string.Empty; + public uint IconID { get; } + public TextureWrap? IconTexture { get; } + + public CurrencyInfo(CurrencyName currency) + { + ItemID = GetItemIdForCurrency(currency); + + // Gets the item from Lumina, then checks if it is null + if (LuminaCache.Instance.GetRow(ItemID) is { } currencyItem) + { + ItemName = currencyItem.Name.ToDalamudString().TextValue; + IconID = currencyItem.Icon; + + if (IconCache.Instance.GetIcon(IconID) is { } iconTexture) + { + IconTexture = iconTexture; + } + } + } + + public void Dispose() + { + IconTexture?.Dispose(); + } + + public unsafe int GetCurrentQuantity() => InventoryManager.Instance()->GetInventoryItemCount(ItemID); + + private static uint GetItemIdForCurrency(CurrencyName currency) + { + return currency switch + { + CurrencyName.StormSeal => 20, + CurrencyName.SerpentSeals => 21, + CurrencyName.FlameSeals => 22, + CurrencyName.WolfMarks => 25, + CurrencyName.TrophyCrystals => 36656, + CurrencyName.AlliedSeals => 27, + CurrencyName.CenturioSeals => 10307, + CurrencyName.SackOfNuts => 26533, + CurrencyName.BicolorGemstones => 26807, + CurrencyName.Poetics => 28, + CurrencyName.NonLimitedTomestone => GetNonLimitedTomestoneId(), + CurrencyName.LimitedTomestone => GetLimitedTomestoneId(), + CurrencyName.WhiteCrafterScripts => 25199, + CurrencyName.WhiteGatherersScripts => 25200, + CurrencyName.PurpleCrafterScripts => 33913, + CurrencyName.PurpleGatherersScripts => 33914, + CurrencyName.SkybuildersScripts => 28063, + _ => throw new ArgumentOutOfRangeException(nameof(currency), currency, null) + }; + } + + // This will always return the ItemID of whatever tomestone is currently weekly limited + private static uint GetLimitedTomestoneId() + { + return LuminaCache.Instance + .Where(tomestone => tomestone.Tomestones.Row is 3) + .First() + .Item.Row; + } + + // This will always return the ItemID of whatever tomestone is not limited + private static uint GetNonLimitedTomestoneId() + { + return LuminaCache.Instance + .Where(tomestone => tomestone.Tomestones.Row is 2) + .First() + .Item.Row; + } +} \ No newline at end of file diff --git a/CurrencyAlert/DataModels/CurrencyName.cs b/CurrencyAlert/DataModels/CurrencyName.cs new file mode 100644 index 0000000..55c1396 --- /dev/null +++ b/CurrencyAlert/DataModels/CurrencyName.cs @@ -0,0 +1,27 @@ +namespace CurrencyAlert.DataModels; + +public enum CurrencyName +{ + StormSeal, + SerpentSeals, + FlameSeals, + + WolfMarks, + TrophyCrystals, + AlliedSeals, + CenturioSeals, + SackOfNuts, + BicolorGemstones, + + Poetics, + NonLimitedTomestone, + LimitedTomestone, + + WhiteCrafterScripts, + WhiteGatherersScripts, + + PurpleCrafterScripts, + PurpleGatherersScripts, + + SkybuildersScripts, +} diff --git a/CurrencyAlert/DataModels/DisplaySettings.cs b/CurrencyAlert/DataModels/DisplaySettings.cs new file mode 100644 index 0000000..646aa06 --- /dev/null +++ b/CurrencyAlert/DataModels/DisplaySettings.cs @@ -0,0 +1,13 @@ +using System.Numerics; +using KamiLib.Configuration; +using KamiLib.Drawing; + +namespace CurrencyAlert.DataModels; + +public class DisplaySettings +{ + public Setting ShowIcon = new(true); + public Setting ShowName = new(true); + public Setting ShowWarningText = new(true); + public Setting TextColor = new(Colors.White); +} \ No newline at end of file diff --git a/CurrencyAlert/DataModels/TrackedCurrency.cs b/CurrencyAlert/DataModels/TrackedCurrency.cs new file mode 100644 index 0000000..e661e08 --- /dev/null +++ b/CurrencyAlert/DataModels/TrackedCurrency.cs @@ -0,0 +1,30 @@ +using System.Numerics; +using ImGuiNET; +using KamiLib.Configuration; + +namespace CurrencyAlert.DataModels; + +public record TrackedCurrency(CurrencyName Name, Setting Threshold, Setting Enabled) +{ + private static DisplaySettings DisplaySettings => Service.Configuration.DisplaySettings; + + public CurrencyInfo CurrencyInfo() + { + return new CurrencyInfo(Name); + } + + public void DrawIcon() + { + if (CurrencyInfo().IconTexture is { } icon) + { + ImGui.Image(icon.ImGuiHandle, new Vector2(20.0f)); + } + } + + public void DrawName(Vector4 color) + { + ImGui.TextColored(color, CurrencyInfo().ItemName); + } +} + + diff --git a/CurrencyAlert/Entity/Currency.cs b/CurrencyAlert/Entity/Currency.cs deleted file mode 100644 index 31a46ae..0000000 --- a/CurrencyAlert/Entity/Currency.cs +++ /dev/null @@ -1,26 +0,0 @@ -using CurrencyAlert.Enum; -using CurrencyAlert.Helper; -using ImGuiScene; - -namespace CurrencyAlert.Entity -{ - internal class Currency - { - public int Id { get; } - public string Name { get; } - public CurrencyType Type { get; } - public Category Category { get; } - public TextureWrap? Image { get; } - public int DefaultThreshold { get; } - - public Currency(int id, string name, CurrencyType type, Category category, int defaultThreshold) - { - Id = id; - Name = name; - Type = type; - Category = category; - DefaultThreshold = defaultThreshold; - Image = ImageHelper.LoadImage(id.ToString()); - } - } -} diff --git a/CurrencyAlert/Enum/Category.cs b/CurrencyAlert/Enum/Category.cs deleted file mode 100644 index 4759718..0000000 --- a/CurrencyAlert/Enum/Category.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace CurrencyAlert.Enum -{ - public enum Category - { - Common, - Battle, - Other - } -} diff --git a/CurrencyAlert/Enum/CurrencyType.cs b/CurrencyAlert/Enum/CurrencyType.cs deleted file mode 100644 index 851f84a..0000000 --- a/CurrencyAlert/Enum/CurrencyType.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace CurrencyAlert.Enum -{ - public enum CurrencyType - { - TomestoneOfPoetics, - TomestoneOfAphorism, - TomestoneOfAstronomy, - TomestoneOfCausality, - - StormSeal, - SerpentSeal, - FlameSeal, - - WolfMark, - TrophyCrystal, - - AlliedSeal, - CenturioSeal, - SackOfNut, - BicolorGemstone, - - WhiteCraftersScrip, - PurpleCraftersScrip, - WhiteGatherersScrip, - PurpleGatherersScrip, - SkybuildersScrip - } -} diff --git a/CurrencyAlert/Helper/ImageHelper.cs b/CurrencyAlert/Helper/ImageHelper.cs deleted file mode 100644 index 2888bcc..0000000 --- a/CurrencyAlert/Helper/ImageHelper.cs +++ /dev/null @@ -1,24 +0,0 @@ -using ImGuiScene; -using System; -using System.IO; - -namespace CurrencyAlert.Helper -{ - internal class ImageHelper - { - public static TextureWrap? LoadImage(string imageName) - { - var assemblyLocation = PluginHelper.PluginInterface.AssemblyLocation.DirectoryName!; - var imagePath = Path.Combine(assemblyLocation, $@"images\{imageName}.png"); - - try - { - return PluginHelper.PluginInterface.UiBuilder.LoadImage(imagePath); - } - catch (SystemException e) - { - return null; - } - } - } -} diff --git a/CurrencyAlert/Helper/PluginHelper.cs b/CurrencyAlert/Helper/PluginHelper.cs deleted file mode 100644 index 024c574..0000000 --- a/CurrencyAlert/Helper/PluginHelper.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Dalamud.Game.ClientState; -using Dalamud.Game.Command; -using Dalamud.Game.Gui; -using Dalamud.IoC; -using Dalamud.Plugin; - -namespace CurrencyAlert.Helper -{ - internal class PluginHelper - { - [PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!; - [PluginService] public static ClientState ClientState { get; private set; } = null!; - [PluginService] public static CommandManager CommandManager { get; private set; } = null!; - [PluginService] public static ChatGui Chat { get; private set; } = null!; - } -} diff --git a/CurrencyAlert/Localization/LocalizationManager.cs b/CurrencyAlert/Localization/LocalizationManager.cs new file mode 100644 index 0000000..9b25e63 --- /dev/null +++ b/CurrencyAlert/Localization/LocalizationManager.cs @@ -0,0 +1,41 @@ +using System; +using System.Globalization; +using Dalamud.Logging; + +namespace CurrencyAlert.Localization; + +internal class LocalizationManager : IDisposable +{ + private static LocalizationManager? _instance; + public static LocalizationManager Instance => _instance ??= new LocalizationManager(); + + public void Initialize() + { + Strings.Culture = new CultureInfo(Service.PluginInterface.UiLanguage); + + Service.PluginInterface.LanguageChanged += OnLanguageChange; + } + + public static void Cleanup() + { + _instance?.Dispose(); + } + + public void Dispose() + { + Service.PluginInterface.LanguageChanged -= OnLanguageChange; + } + + private void OnLanguageChange(string languageCode) + { + try + { + PluginLog.Information($"Loading Localization for {languageCode}"); + Strings.Culture = new CultureInfo(languageCode); + } + catch (Exception ex) + { + PluginLog.Error(ex, "Unable to Load Localization"); + } + } +} \ No newline at end of file diff --git a/CurrencyAlert/Localization/Strings.Designer.cs b/CurrencyAlert/Localization/Strings.Designer.cs new file mode 100644 index 0000000..7217508 --- /dev/null +++ b/CurrencyAlert/Localization/Strings.Designer.cs @@ -0,0 +1,269 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CurrencyAlert.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Strings { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Strings() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CurrencyAlert.Localization.Strings", typeof(Strings).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Chat Notifications. + /// + internal static string ChatNotifications { + get { + return ResourceManager.GetString("ChatNotifications", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Above threshold. + /// + internal static string ChatWarningText { + get { + return ResourceManager.GetString("ChatWarningText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Hide Currency Alert Overlay. + /// + internal static string Commands_HideOverlayHelp { + get { + return ResourceManager.GetString("Commands_HideOverlayHelp", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Show Currency Alert Overlay. + /// + internal static string Commands_ShowOverlayHelp { + get { + return ResourceManager.GetString("Commands_ShowOverlayHelp", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Toggle Currency Alert Overlay. + /// + internal static string Commands_ToggleOverlayHelp { + get { + return ResourceManager.GetString("Commands_ToggleOverlayHelp", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Currency Configuration. + /// + internal static string CurrencyConfiguration { + get { + return ResourceManager.GetString("CurrencyConfiguration", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Currently Selected. + /// + internal static string CurrentlySelected { + get { + return ResourceManager.GetString("CurrentlySelected", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Default. + /// + internal static string Default { + get { + return ResourceManager.GetString("Default", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Display Ascending. + /// + internal static string DisplayAscending { + get { + return ResourceManager.GetString("DisplayAscending", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Display Settings. + /// + internal static string DisplaySettings { + get { + return ResourceManager.GetString("DisplaySettings", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Enabled. + /// + internal static string Enabled { + get { + return ResourceManager.GetString("Enabled", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to General Settings. + /// + internal static string GeneralSettings { + get { + return ResourceManager.GetString("GeneralSettings", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lock Position. + /// + internal static string LockOverlay { + get { + return ResourceManager.GetString("LockOverlay", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Minimal Display. + /// + internal static string MinimalOverlay { + get { + return ResourceManager.GetString("MinimalOverlay", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Opacity. + /// + internal static string Opacity { + get { + return ResourceManager.GetString("Opacity", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Overlay Settings. + /// + internal static string OverlaySettings { + get { + return ResourceManager.GetString("OverlaySettings", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You need to spend your. + /// + internal static string OverlayWarningText { + get { + return ResourceManager.GetString("OverlayWarningText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Show Currency Icon. + /// + internal static string ShowCurrencyIcon { + get { + return ResourceManager.GetString("ShowCurrencyIcon", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Show Currency Name. + /// + internal static string ShowCurrencyName { + get { + return ResourceManager.GetString("ShowCurrencyName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Show Overlay. + /// + internal static string ShowOverlay { + get { + return ResourceManager.GetString("ShowOverlay", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Show Warning Text. + /// + internal static string ShowWarningText { + get { + return ResourceManager.GetString("ShowWarningText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Text Color. + /// + internal static string TextColor { + get { + return ResourceManager.GetString("TextColor", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Threshold. + /// + internal static string Threshold { + get { + return ResourceManager.GetString("Threshold", resourceCulture); + } + } + } +} diff --git a/CurrencyAlert/Localization/Strings.resx b/CurrencyAlert/Localization/Strings.resx new file mode 100644 index 0000000..6232bb5 --- /dev/null +++ b/CurrencyAlert/Localization/Strings.resx @@ -0,0 +1,90 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + General Settings + + + Overlay Settings + + + Show Overlay + + + Lock Position + + + Minimal Display + + + Opacity + + + Display Settings + + + Show Currency Icon + + + Show Currency Name + + + Show Warning Text + + + Currency Configuration + + + Enabled + + + Threshold + + + You need to spend your + + + Above threshold + + + Show Currency Alert Overlay + + + Hide Currency Alert Overlay + + + Toggle Currency Alert Overlay + + + Currently Selected + + + Chat Notifications + + + Display Ascending + + + Text Color + + + Default + + \ No newline at end of file diff --git a/CurrencyAlert/Plugin.cs b/CurrencyAlert/Plugin.cs index 6371be0..513b41a 100644 --- a/CurrencyAlert/Plugin.cs +++ b/CurrencyAlert/Plugin.cs @@ -1,108 +1,36 @@ -using CurrencyAlert.Helper; -using CurrencyAlert.Provider; -using Dalamud.Game.Command; -using Dalamud.Game.Gui; -using Dalamud.IoC; +using CurrencyAlert.Localization; +using CurrencyAlert.System.cs; +using CurrencyAlert.Windows; using Dalamud.Plugin; -using FFXIVClientStructs.FFXIV.Client.Game; -using ImGuiNET; -using Newtonsoft.Json; -using System; -using System.Reflection; +using KamiLib; -namespace CurrencyAlert +namespace CurrencyAlert; + +public sealed class Plugin : IDalamudPlugin { - public sealed class Plugin : IDalamudPlugin + public string Name => "CurrencyAlert"; + + public Plugin(DalamudPluginInterface pluginInterface) { - public string Name => "Currency Alert"; + pluginInterface.Create(); + + KamiCommon.Initialize(pluginInterface, Name, () => Service.Configuration.Save()); + LocalizationManager.Instance.Initialize(); - private const string commandName = "/currencyalert"; + Service.Configuration = Service.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); + Service.Configuration.Initialize(Service.PluginInterface); + + KamiCommon.WindowManager.AddConfigurationWindow(new ConfigurationWindow()); + KamiCommon.WindowManager.AddWindow(new OverlayWindow()); - private Configuration Configuration { get; init; } - private PluginUI PluginUI { get; init; } - - [PluginService] public static ChatGui Chat { get; private set; } = null!; - - private bool LoggedIn => PluginHelper.ClientState.LocalPlayer != null && PluginHelper.ClientState.LocalContentId != 0; - - public Plugin(DalamudPluginInterface pluginInterface) - { - pluginInterface.Create(); - - try - { - this.Configuration = PluginHelper.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); - } - catch (Exception e) - { - this.Configuration = new Configuration(); - this.Configuration.Save(); - - PluginHelper.Chat.Print("Your CurrencyAlert configuration has been reset because of compatibility issues. Please check the plugin configuration window."); - } - - this.Configuration.Initialize(); - - var assemblyLocation = Assembly.GetExecutingAssembly().Location; - this.PluginUI = new PluginUI(this.Configuration); - - PluginHelper.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand) - { - HelpMessage = "Lets you configure alert thresholds for various currencies" - }); - - PluginHelper.PluginInterface.UiBuilder.Draw += DrawUI; - PluginHelper.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI; - } - - public void Dispose() - { - this.PluginUI.Dispose(); - PluginHelper.CommandManager.RemoveHandler(commandName); - } - - private void OnCommand(string command, string args) - { - this.DrawConfigUI(); - } - - private void DrawUI() - { - if (!this.LoggedIn) - return; - - this.UpdateAlerts(); - - this.PluginUI.Draw(); - } - - private void UpdateAlerts() - { - // TODO: move this logic elsewhere - // TODO: do this only every X seconds - unsafe - { - InventoryManager* inventoryManager = InventoryManager.Instance(); - - foreach (var currency in CurrencyProvider.Instance.GetAll()) - { - int quantity = inventoryManager->GetInventoryItemCount((uint)currency.Id); - - if (this.Configuration.AlertEnabled[currency.Id] && quantity >= this.Configuration.Threshold[currency.Id]) - { - this.PluginUI.AlertVisible[currency.Id] = true; - } - else - { - this.PluginUI.AlertVisible[currency.Id] = false; - } - } - } - } - - private void DrawConfigUI() - { - this.PluginUI.SettingsVisible = true; - } + Service.CurrencyTracker = new CurrencyTracker(); } -} + + public void Dispose() + { + KamiCommon.Dispose(); + + Service.CurrencyTracker.Dispose(); + LocalizationManager.Cleanup(); + } +} \ No newline at end of file diff --git a/CurrencyAlert/PluginUI.cs b/CurrencyAlert/PluginUI.cs deleted file mode 100644 index cd3a966..0000000 --- a/CurrencyAlert/PluginUI.cs +++ /dev/null @@ -1,145 +0,0 @@ -using CurrencyAlert.Provider; -using ImGuiNET; -using System; -using System.Collections.Generic; -using System.Numerics; - -namespace CurrencyAlert -{ - class PluginUI : IDisposable - { - private Configuration configuration; - - private bool settingsVisible = false; - public bool SettingsVisible - { - get { return settingsVisible; } - set { settingsVisible = value; } - } - public Dictionary AlertVisible { get; set; } = new Dictionary(); - - public PluginUI(Configuration configuration) - { - this.configuration = configuration; - - foreach (var currency in CurrencyProvider.Instance.GetAll()) - { - this.AlertVisible[currency.Id] = false; - } - } - - public void Dispose() - { - - } - - public void Draw() - { - DrawMainWindow(); - - if (this.SettingsVisible) - DrawSettingsWindow(); - } - - public void DrawMainWindow() - { - foreach (var currency in CurrencyProvider.Instance.GetAll()) - { - if (!this.AlertVisible[currency.Id]) - continue; - - ImGui.SetNextWindowSize(new Vector2(375, 10), ImGuiCond.FirstUseEver); - ImGui.SetNextWindowSizeConstraints(new Vector2(375, 10), new Vector2(float.MaxValue, float.MaxValue)); - - var isVisible = this.AlertVisible[currency.Id]; - - var guiOptions = ImGuiWindowFlags.NoScrollbar | - ImGuiWindowFlags.NoScrollWithMouse | - ImGuiWindowFlags.AlwaysAutoResize | - ImGuiWindowFlags.NoTitleBar | - ImGuiWindowFlags.NoFocusOnAppearing; - - if (configuration.UiLocked) - guiOptions |= ImGuiWindowFlags.NoMove; - - if (ImGui.Begin("Currency Alert", ref isVisible, guiOptions)) - { - ImGui.Text($"You need to spend your"); - - if (currency.Image != null) - { - ImGui.SameLine(); - ImGui.Image(currency.Image.ImGuiHandle, new Vector2(22, 22)); - } - - ImGui.SameLine(); - - ImGui.Text($"{currency.Name}"); - - ImGui.End(); - } - } - } - - public void DrawSettingsWindow() - { - ImGui.SetNextWindowSize(new Vector2(700, 500), ImGuiCond.FirstUseEver); - if (ImGui.Begin("Currency Alert Configuration Window", ref this.settingsVisible)) - { - var uiLocked = this.configuration.UiLocked; - - if (ImGui.Checkbox("Lock alert window", ref uiLocked)) - { - this.configuration.UiLocked = uiLocked; - this.configuration.Save(); - } - - if (ImGui.BeginTabBar("AlertsConfiguration_Tabs")) - { - foreach (var currency in CurrencyProvider.Instance.GetAll()) - { - var name = currency.Name; - var category = currency.Category; - var alertEnabled = this.configuration.AlertEnabled[currency.Id]; - - if (ImGui.BeginTabItem(category.ToString())) - { - if (currency.Image != null) - { - ImGui.Image(currency.Image.ImGuiHandle, new Vector2(22, 22)); - ImGui.SameLine(); - } - - ImGui.Text($"{currency.Name}"); - - if (ImGui.Checkbox($"Enabled##{name}", ref alertEnabled)) - { - this.configuration.AlertEnabled[currency.Id] = alertEnabled; - this.configuration.Save(); - } - - ImGui.SameLine(); - - var thresholdValue = this.configuration.Threshold[currency.Id]; - - if (ImGui.InputInt($"Threshold##{name}", ref thresholdValue, 1, 1, - this.configuration.AlertEnabled[currency.Id] ? ImGuiInputTextFlags.None : ImGuiInputTextFlags.ReadOnly)) - { - this.configuration.Threshold[currency.Id] = thresholdValue; - this.configuration.Save(); - } - - ImGui.Separator(); - - ImGui.EndTabItem(); - } - } - - ImGui.EndTabBar(); - } - - ImGui.End(); - } - } - } -} diff --git a/CurrencyAlert/Provider/CurrencyProvider.cs b/CurrencyAlert/Provider/CurrencyProvider.cs deleted file mode 100644 index 61c7511..0000000 --- a/CurrencyAlert/Provider/CurrencyProvider.cs +++ /dev/null @@ -1,46 +0,0 @@ -using CurrencyAlert.Entity; -using System.Collections.Generic; - -namespace CurrencyAlert.Provider -{ - internal sealed class CurrencyProvider - { - private static CurrencyProvider? instance = null; - public static CurrencyProvider Instance => instance ??= new CurrencyProvider(); - - private readonly List currencies; - - public CurrencyProvider() - { - currencies = new List - { - new Currency(28, "Tomestones of Poetics", Enum.CurrencyType.TomestoneOfPoetics, Enum.Category.Battle, 1400), - new Currency(43, "Tomestones of Astronomy", Enum.CurrencyType.TomestoneOfAstronomy, Enum.Category.Battle, 1700), - new Currency(44, "Tomestones of Causality", Enum.CurrencyType.TomestoneOfCausality, Enum.Category.Battle, 1700), - - new Currency(20, "Storm Seals", Enum.CurrencyType.StormSeal, Enum.Category.Common, 75000), - new Currency(21, "Serpent Seals", Enum.CurrencyType.SerpentSeal, Enum.Category.Common, 75000), - new Currency(22, "Flame Seals", Enum.CurrencyType.FlameSeal, Enum.Category.Common, 75000), - - new Currency(25, "Wolf Marks", Enum.CurrencyType.WolfMark, Enum.Category.Battle, 18000), - new Currency(36656, "Trophy Crystals", Enum.CurrencyType.TrophyCrystal, Enum.Category.Battle, 18000), - - new Currency(27, "Allied Seals", Enum.CurrencyType.AlliedSeal, Enum.Category.Battle, 3500), - new Currency(10307, "Centurio Seals", Enum.CurrencyType.CenturioSeal, Enum.Category.Battle, 3500), - new Currency(26533, "Sack of Nuts", Enum.CurrencyType.SackOfNut, Enum.Category.Battle, 3500), - new Currency(26807, "Bicolor Gemstone", Enum.CurrencyType.BicolorGemstone, Enum.Category.Battle, 800), - - new Currency(25199, "White Crafters' Scrip", Enum.CurrencyType.WhiteCraftersScrip, Enum.Category.Other, 1500), - new Currency(33913, "Purple Crafters' Scrip", Enum.CurrencyType.PurpleCraftersScrip, Enum.Category.Other, 1500), - new Currency(25200, "White Gatherers' Scrip", Enum.CurrencyType.WhiteGatherersScrip, Enum.Category.Other, 1500), - new Currency(33914, "Purple Gatherers' Scrip", Enum.CurrencyType.PurpleGatherersScrip, Enum.Category.Other, 1500), - new Currency(28063, "Skybuilders' Scrip", Enum.CurrencyType.SkybuildersScrip, Enum.Category.Other, 7500), - }; - } - - public IEnumerable GetAll() - { - return currencies; - } - } -} diff --git a/CurrencyAlert/Service.cs b/CurrencyAlert/Service.cs new file mode 100644 index 0000000..f0b953f --- /dev/null +++ b/CurrencyAlert/Service.cs @@ -0,0 +1,17 @@ +using CurrencyAlert.System.cs; +using Dalamud.Game; +using Dalamud.Game.ClientState; +using Dalamud.IoC; +using Dalamud.Plugin; + +namespace CurrencyAlert; + +public class Service +{ + [PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!; + [PluginService] public static Framework Framework { get; private set; } = null!; + [PluginService] public static ClientState ClientState { get; private set; } = null!; + + public static Configuration Configuration { get; set; } = null!; + public static CurrencyTracker CurrencyTracker { get; set; } = null!; +} \ No newline at end of file diff --git a/CurrencyAlert/System.cs/CurrencyTracker.cs b/CurrencyAlert/System.cs/CurrencyTracker.cs new file mode 100644 index 0000000..5d5f768 --- /dev/null +++ b/CurrencyAlert/System.cs/CurrencyTracker.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading; +using CurrencyAlert.DataModels; +using CurrencyAlert.Localization; +using Dalamud.Logging; +using KamiLib.ChatCommands; + +namespace CurrencyAlert.System.cs; + +public class CurrencyTracker : IDisposable +{ + private readonly CancellationTokenSource cancellationTokenSource = new(); + private readonly Stopwatch timer = new(); + + public readonly List ActiveWarnings = new(); + + public CurrencyTracker() + { + UpdateCurrencies(); + + Service.ClientState.TerritoryChanged += OnZoneChange; + } + + private void UpdateCurrencies() + { + Service.Framework.RunOnTick(UpdateCurrencies, TimeSpan.FromMilliseconds(250), 0, cancellationTokenSource.Token); + + ActiveWarnings.Clear(); + if (!Service.ClientState.IsLoggedIn) return; + + foreach (var currency in Service.Configuration.TrackedCurrencies) + { + if (currency.Enabled) + { + if (currency.CurrencyInfo().GetCurrentQuantity() >= currency.Threshold.Value) + { + ActiveWarnings.Add(currency); + } + } + } + } + + private void OnZoneChange(object? sender, ushort e) + { + if (!Service.Configuration.ChatNotification) return; + + if (timer.Elapsed.Minutes >= 5 || timer.IsRunning == false) + { + timer.Restart(); + foreach (var currency in ActiveWarnings) + { + Chat.Print($"{currency.CurrencyInfo().ItemName}", Strings.ChatWarningText); + } + } + else + { + var lockoutRemaining = TimeSpan.FromMinutes(5) - timer.Elapsed; + PluginLog.Debug($"Zone Change Messages Suppressed, '{lockoutRemaining}' Remaining"); + } + } + + public void Dispose() + { + Service.ClientState.TerritoryChanged -= OnZoneChange; + + cancellationTokenSource.Cancel(); + cancellationTokenSource.Dispose(); + } +} \ No newline at end of file diff --git a/CurrencyAlert/Windows/Components/GeneralSettingsSelectable.cs b/CurrencyAlert/Windows/Components/GeneralSettingsSelectable.cs new file mode 100644 index 0000000..81826e0 --- /dev/null +++ b/CurrencyAlert/Windows/Components/GeneralSettingsSelectable.cs @@ -0,0 +1,48 @@ +using CurrencyAlert.DataModels; +using CurrencyAlert.Localization; +using Dalamud.Interface; +using ImGuiNET; +using KamiLib.Drawing; +using KamiLib.Interfaces; + +namespace CurrencyAlert.Windows.Components; + +public class GeneralSettingsSelectable : ISelectable, IDrawable +{ + private static OverlaySettings OverlaySettings => Service.Configuration.OverlaySettings; + private static DisplaySettings DisplaySettings => Service.Configuration.DisplaySettings; + + public IDrawable Contents => this; + public string ID => "GeneralSettings"; + + public void DrawLabel() + { + ImGui.Text(Strings.GeneralSettings); + ImGuiHelpers.ScaledDummy(8.0f); + } + + public void Draw() + { + InfoBox.Instance + .AddTitle(Strings.OverlaySettings, out var innerWidth) + .AddConfigCheckbox(Strings.ShowOverlay, OverlaySettings.Show) + .AddConfigCheckbox(Strings.LockOverlay, OverlaySettings.LockPosition) + .AddConfigCheckbox(Strings.MinimalOverlay, OverlaySettings.MinimalDisplay) + .AddConfigCheckbox(Strings.DisplayAscending, OverlaySettings.AscendingDescending) + .AddDragFloat(Strings.Opacity, OverlaySettings.Opacity, 0.00f, 1.0f, innerWidth / 2.0f) + .Draw(); + + InfoBox.Instance + .AddTitle(Strings.ChatNotifications) + .AddConfigCheckbox(Strings.ChatNotifications, Service.Configuration.ChatNotification) + .Draw(); + + InfoBox.Instance + .AddTitle(Strings.DisplaySettings) + .AddConfigCheckbox(Strings.ShowCurrencyIcon, DisplaySettings.ShowIcon) + .AddConfigCheckbox(Strings.ShowCurrencyName, DisplaySettings.ShowName) + .AddConfigCheckbox(Strings.ShowWarningText, DisplaySettings.ShowWarningText) + .AddConfigColor(Strings.TextColor, Strings.Default, DisplaySettings.TextColor, Colors.White) + .Draw(); + } +} \ No newline at end of file diff --git a/CurrencyAlert/Windows/Components/TrackedCurrencySelectable.cs b/CurrencyAlert/Windows/Components/TrackedCurrencySelectable.cs new file mode 100644 index 0000000..632efb4 --- /dev/null +++ b/CurrencyAlert/Windows/Components/TrackedCurrencySelectable.cs @@ -0,0 +1,46 @@ +using System.Numerics; +using CurrencyAlert.DataModels; +using CurrencyAlert.Localization; +using Dalamud.Interface; +using ImGuiNET; +using KamiLib.Drawing; +using KamiLib.Interfaces; + +namespace CurrencyAlert.Windows.Components; + +public class TrackedCurrencySelectable : ISelectable, IDrawable +{ + public IDrawable Contents => this; + public string ID { get; } + + private readonly TrackedCurrency currency; + + public TrackedCurrencySelectable(TrackedCurrency trackedCurrency) + { + currency = trackedCurrency; + ID = currency.CurrencyInfo().ItemName; + } + + public void DrawLabel() + { + currency.DrawIcon(); + ImGui.SameLine(); + currency.DrawName(Colors.White); + } + + public void Draw() + { + InfoBox.Instance + .AddTitle(Strings.CurrentlySelected) + .AddIcon(currency.CurrencyInfo().IconID, ImGuiHelpers.ScaledVector2(40.0f), 1.0f) + .SameLine() + .AddString(currency.CurrencyInfo().ItemName) + .Draw(); + + InfoBox.Instance + .AddTitle(Strings.CurrencyConfiguration, out var innerWidth) + .AddConfigCheckbox(Strings.Enabled, currency.Enabled) + .AddInputInt(Strings.Threshold, currency.Threshold, 0, 100000, 0, 0, innerWidth / 2.0f) + .Draw(); + } +} \ No newline at end of file diff --git a/CurrencyAlert/Windows/ConfigurationWindow.cs b/CurrencyAlert/Windows/ConfigurationWindow.cs new file mode 100644 index 0000000..36333b5 --- /dev/null +++ b/CurrencyAlert/Windows/ConfigurationWindow.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Reflection; +using CurrencyAlert.Windows.Components; +using Dalamud.Interface; +using ImGuiNET; +using KamiLib.Drawing; +using KamiLib.Interfaces; +using KamiLib.Windows; + +namespace CurrencyAlert.Windows; + +public class ConfigurationWindow : SelectionWindow +{ + public ConfigurationWindow() : base("Currency Alert Configuration Window", 0.45f, 20.0f) + { + SizeConstraints = new WindowSizeConstraints + { + MinimumSize = new Vector2(600, 300), + MaximumSize = new Vector2(600,9999) + }; + + Flags |= ImGuiWindowFlags.NoScrollbar; + Flags |= ImGuiWindowFlags.NoScrollWithMouse; + } + + protected override IEnumerable GetSelectables() + { + return Service.Configuration.TrackedCurrencies + .Select(tracked => new TrackedCurrencySelectable(tracked) as ISelectable) + .Prepend(new GeneralSettingsSelectable()); + } + + protected override void DrawExtras() + { + DrawVersionNumber(); + } + + private static void DrawVersionNumber() + { + var assemblyInformation = Assembly.GetExecutingAssembly().FullName!.Split(','); + var versionString = assemblyInformation[1].Replace('=', ' '); + + var stringSize = ImGui.CalcTextSize(versionString); + + var x = ImGui.GetContentRegionAvail().X / 2 - stringSize.X / 2; + var y = ImGui.GetWindowHeight() - 20 * ImGuiHelpers.GlobalScale; + + ImGui.SetCursorPos(new Vector2(x, y)); + + ImGui.TextColored(Colors.Grey, versionString); + } +} diff --git a/CurrencyAlert/Windows/OverlayWindow.cs b/CurrencyAlert/Windows/OverlayWindow.cs new file mode 100644 index 0000000..6e23176 --- /dev/null +++ b/CurrencyAlert/Windows/OverlayWindow.cs @@ -0,0 +1,162 @@ +using System.Linq; +using System.Numerics; +using CurrencyAlert.Commands; +using CurrencyAlert.DataModels; +using CurrencyAlert.Localization; +using Dalamud.Interface.Windowing; +using ImGuiNET; +using KamiLib; +using KamiLib.Configuration; +using KamiLib.GameState; +using KamiLib.Windows; + +namespace CurrencyAlert.Windows; + +public class OverlaySettings +{ + public Setting LockPosition = new(false); + public Setting Opacity = new(1.0f); + public Setting MinimalDisplay = new(false); + public Setting Show = new(true); + public Setting AscendingDescending = new(false); +} + +public class OverlayWindow : Window +{ + private static OverlaySettings OverlaySettings => Service.Configuration.OverlaySettings; + private static DisplaySettings DisplaySettings => Service.Configuration.DisplaySettings; + + private Vector2 lastWindowSize = Vector2.Zero; + + public OverlayWindow() : base("Currency Alert Overlay") + { + KamiCommon.CommandManager.AddCommand(new OverlayCommands()); + + Flags |= ImGuiWindowFlags.NoDecoration; + Flags |= ImGuiWindowFlags.NoBringToFrontOnFocus; + Flags |= ImGuiWindowFlags.NoFocusOnAppearing; + Flags |= ImGuiWindowFlags.NoNavFocus; + Flags |= ImGuiWindowFlags.AlwaysAutoResize; + } + + public override void PreOpenCheck() + { + IsOpen = OverlaySettings.Show; + + if (Condition.IsBoundByDuty()) IsOpen = false; + if (Condition.IsInCutsceneOrQuestEvent()) IsOpen = false; + if (!Service.CurrencyTracker.ActiveWarnings.Any()) IsOpen = false; + if (!Service.ClientState.IsLoggedIn) IsOpen = false; + } + + public override void PreDraw() + { + var bgColor = ImGui.GetStyle().Colors[(int)ImGuiCol.WindowBg]; + ImGui.PushStyleColor(ImGuiCol.WindowBg, bgColor with {W = OverlaySettings.Opacity.Value}); + + var borderColor = ImGui.GetStyle().Colors[(int)ImGuiCol.Border]; + ImGui.PushStyleColor(ImGuiCol.Border, borderColor with {W = OverlaySettings.Opacity.Value}); + + if (OverlaySettings.LockPosition) + { + Flags |= DrawFlags.LockPosition; + } + else + { + Flags &= ~DrawFlags.LockPosition; + } + } + + public override void Draw() + { + ResizeWindow(); + + if (OverlaySettings.MinimalDisplay) + { + DrawMinimalDisplay(); + } + else + { + DrawNormalDisplay(); + } + } + + public override void PostDraw() + { + ImGui.PopStyleColor(); + ImGui.PopStyleColor(); + } + + private void ResizeWindow() + { + if(OverlaySettings.AscendingDescending) + { + var size = ImGui.GetWindowSize(); + + if(lastWindowSize != Vector2.Zero) + { + var offset = lastWindowSize - size; + offset.X = 0; + + if (offset != Vector2.Zero) + { + ImGui.SetWindowPos(ImGui.GetWindowPos() + offset); + } + } + + lastWindowSize = size; + } + } + + private static void DrawMinimalDisplay() + { + if (DisplaySettings.ShowWarningText) + { + ImGui.TextColored(DisplaySettings.TextColor.Value, Strings.OverlayWarningText); + ImGui.SameLine(); + } + + foreach (var currency in Service.CurrencyTracker.ActiveWarnings) + { + if (DisplaySettings.ShowIcon) + { + currency.DrawIcon(); + + if (DisplaySettings.ShowName) + { + ImGui.SameLine(); + currency.DrawName(DisplaySettings.TextColor.Value); + ImGui.SameLine(); + } + } + else if (DisplaySettings.ShowName) + { + currency.DrawName(DisplaySettings.TextColor.Value); + ImGui.SameLine(); + } + } + } + + private static void DrawNormalDisplay() + { + foreach (var currency in Service.CurrencyTracker.ActiveWarnings) + { + if (DisplaySettings.ShowWarningText) + { + ImGui.TextColored(DisplaySettings.TextColor.Value, Strings.OverlayWarningText); + ImGui.SameLine(); + } + + if (DisplaySettings.ShowIcon) + { + currency.DrawIcon(); + ImGui.SameLine(); + } + + if (DisplaySettings.ShowName) + { + currency.DrawName(DisplaySettings.TextColor.Value); + } + } + } +} diff --git a/CurrencyAlert/images/10307.png b/CurrencyAlert/images/10307.png deleted file mode 100644 index 86f94b3..0000000 Binary files a/CurrencyAlert/images/10307.png and /dev/null differ diff --git a/CurrencyAlert/images/20.png b/CurrencyAlert/images/20.png deleted file mode 100644 index cfca4a4..0000000 Binary files a/CurrencyAlert/images/20.png and /dev/null differ diff --git a/CurrencyAlert/images/21.png b/CurrencyAlert/images/21.png deleted file mode 100644 index c1d7ad0..0000000 Binary files a/CurrencyAlert/images/21.png and /dev/null differ diff --git a/CurrencyAlert/images/22.png b/CurrencyAlert/images/22.png deleted file mode 100644 index 0ad4a96..0000000 Binary files a/CurrencyAlert/images/22.png and /dev/null differ diff --git a/CurrencyAlert/images/25.png b/CurrencyAlert/images/25.png deleted file mode 100644 index fbc49be..0000000 Binary files a/CurrencyAlert/images/25.png and /dev/null differ diff --git a/CurrencyAlert/images/25199.png b/CurrencyAlert/images/25199.png deleted file mode 100644 index 235de91..0000000 Binary files a/CurrencyAlert/images/25199.png and /dev/null differ diff --git a/CurrencyAlert/images/25200.png b/CurrencyAlert/images/25200.png deleted file mode 100644 index e81ca60..0000000 Binary files a/CurrencyAlert/images/25200.png and /dev/null differ diff --git a/CurrencyAlert/images/26533.png b/CurrencyAlert/images/26533.png deleted file mode 100644 index d77adb0..0000000 Binary files a/CurrencyAlert/images/26533.png and /dev/null differ diff --git a/CurrencyAlert/images/26807.png b/CurrencyAlert/images/26807.png deleted file mode 100644 index 8e54184..0000000 Binary files a/CurrencyAlert/images/26807.png and /dev/null differ diff --git a/CurrencyAlert/images/27.png b/CurrencyAlert/images/27.png deleted file mode 100644 index ebe77e7..0000000 Binary files a/CurrencyAlert/images/27.png and /dev/null differ diff --git a/CurrencyAlert/images/28.png b/CurrencyAlert/images/28.png deleted file mode 100644 index f0568dd..0000000 Binary files a/CurrencyAlert/images/28.png and /dev/null differ diff --git a/CurrencyAlert/images/28063.png b/CurrencyAlert/images/28063.png deleted file mode 100644 index 2e125b8..0000000 Binary files a/CurrencyAlert/images/28063.png and /dev/null differ diff --git a/CurrencyAlert/images/33913.png b/CurrencyAlert/images/33913.png deleted file mode 100644 index cfd29d3..0000000 Binary files a/CurrencyAlert/images/33913.png and /dev/null differ diff --git a/CurrencyAlert/images/33914.png b/CurrencyAlert/images/33914.png deleted file mode 100644 index 71ef183..0000000 Binary files a/CurrencyAlert/images/33914.png and /dev/null differ diff --git a/CurrencyAlert/images/36656.png b/CurrencyAlert/images/36656.png deleted file mode 100644 index 7af3775..0000000 Binary files a/CurrencyAlert/images/36656.png and /dev/null differ diff --git a/CurrencyAlert/images/43.png b/CurrencyAlert/images/43.png deleted file mode 100644 index fac0d4b..0000000 Binary files a/CurrencyAlert/images/43.png and /dev/null differ diff --git a/CurrencyAlert/images/44.png b/CurrencyAlert/images/44.png deleted file mode 100644 index 096ff6b..0000000 Binary files a/CurrencyAlert/images/44.png and /dev/null differ diff --git a/CurrencyAlert/packages.lock.json b/CurrencyAlert/packages.lock.json index 9628a11..3a81152 100644 --- a/CurrencyAlert/packages.lock.json +++ b/CurrencyAlert/packages.lock.json @@ -1,12 +1,15 @@ { "version": 1, "dependencies": { - "net6.0-windows7.0": { + "net7.0-windows7.0": { "DalamudPackager": { "type": "Direct", - "requested": "[2.1.8, )", - "resolved": "2.1.8", - "contentHash": "YqagNXs9InxmqkXzq7kLveImxnodkBEicAhydMXVp7dFjC7xb76U6zGgAax4/BWIWfZeWzr5DJyQSev31kj81A==" + "requested": "[2.1.10, )", + "resolved": "2.1.10", + "contentHash": "S6NrvvOnLgT4GDdgwuKVJjbFo+8ZEj+JsEYk9ojjOR/MMfv1dIFpT8aRJQfI24rtDcw1uF+GnSSMN4WW1yt7fw==" + }, + "kamilib": { + "type": "Project" } } } diff --git a/KamiLib b/KamiLib new file mode 160000 index 0000000..f50ff89 --- /dev/null +++ b/KamiLib @@ -0,0 +1 @@ +Subproject commit f50ff8903e0adeb2dfe1d64103f54da13e055f89