name attribute

main
Camille 2022-01-06 10:56:52 +01:00
parent 577ced24a4
commit 74e44d7092
5 changed files with 101 additions and 91 deletions

View File

@ -0,0 +1,14 @@
using System;
namespace CurrencyAlert.Enum
{
internal class NameAttribute : Attribute
{
public NameAttribute(string v)
{
Value = v;
}
public string Value { get; }
}
}

View File

@ -9,7 +9,7 @@ namespace CurrencyAlert
[Serializable]
public class Configuration : IPluginConfiguration
{
public int Version { get; set; } = 2;
public int Version { get; set; } = 4;
public Dictionary<Currency, bool> AlertEnabled { get; set; } = new Dictionary<Currency, bool>();
public Dictionary<Currency, int> Threshold { get; set; } = new Dictionary<Currency , int>();
@ -29,7 +29,7 @@ namespace CurrencyAlert
});
}
public void Save()
public void Save()
{
this.pluginInterface!.SavePluginConfig(this);
}

View File

@ -8,25 +8,19 @@ namespace CurrencyAlert.Enum
{
public enum Currency
{
[Slot(1), DefaultThreshold(75000)]
StormSeal,
[Slot(2), DefaultThreshold(75000)]
SerpentSeal,
[Slot(3), DefaultThreshold(75000)]
FlameSeal,
[Slot(4), DefaultThreshold(18000)]
WolfMark,
[Slot(6), DefaultThreshold(1500)]
[Name("Tomestones of Poetics"), Slot(6), DefaultThreshold(1500)]
TomestoneOfPoetics,
[Slot(8), DefaultThreshold(3500)]
AlliedSeal,
[Slot(10), DefaultThreshold(1500)]
TomestoneOfAstronomy
[Name("Tomestones of Astronomy"), Slot(10), DefaultThreshold(1500)]
TomestoneOfAstronomy,
[Name("Storm Seals"), Slot(1), DefaultThreshold(75000)]
StormSeal,
[Name("Serpent Seals"), Slot(2), DefaultThreshold(75000)]
SerpentSeal,
[Name("Flame Seals"), Slot(3), DefaultThreshold(75000)]
FlameSeal,
[Name("Wolf Marks"), Slot(4), DefaultThreshold(18000)]
WolfMark,
[Name("Allied Seals"), Slot(8), DefaultThreshold(3500)]
AlliedSeal
}
}

View File

@ -1,64 +1,64 @@
using CurrencyAlert.Enum;
using Dalamud.Game.Command;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.IoC;
using Dalamud.Plugin;
using FFXIVClientStructs.FFXIV.Client.Game;
using System.IO;
using System.Reflection;
namespace CurrencyAlert
{
public sealed class Plugin : IDalamudPlugin
{
public string Name => "Currency Alert";
private const string commandName = "/currencyalert";
private DalamudPluginInterface PluginInterface { get; init; }
private CommandManager CommandManager { get; init; }
private Configuration Configuration { get; init; }
private PluginUI PluginUI { get; init; }
[PluginService] public static ChatGui Chat { get; private set; } = null!;
public Plugin(
[RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,
[RequiredVersion("1.0")] CommandManager commandManager)
{
this.PluginInterface = pluginInterface;
this.CommandManager = commandManager;
this.Configuration = this.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
this.Configuration.Initialize(this.PluginInterface);
// you might normally want to embed resources and load them from the manifest stream
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
this.PluginUI = new PluginUI(this.Configuration);
this.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand)
{
HelpMessage = "Lets you configure alert thresholds for various currencies"
using System.IO;
using System.Reflection;
namespace CurrencyAlert
{
public sealed class Plugin : IDalamudPlugin
{
public string Name => "Currency Alert";
private const string commandName = "/currencyalert";
private DalamudPluginInterface PluginInterface { get; init; }
private CommandManager CommandManager { get; init; }
private Configuration Configuration { get; init; }
private PluginUI PluginUI { get; init; }
[PluginService] public static ChatGui Chat { get; private set; } = null!;
public Plugin(
[RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,
[RequiredVersion("1.0")] CommandManager commandManager)
{
this.PluginInterface = pluginInterface;
this.CommandManager = commandManager;
this.Configuration = this.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
this.Configuration.Initialize(this.PluginInterface);
// you might normally want to embed resources and load them from the manifest stream
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
this.PluginUI = new PluginUI(this.Configuration);
this.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand)
{
HelpMessage = "Lets you configure alert thresholds for various currencies"
});
this.PluginInterface.UiBuilder.Draw += DrawUI;
this.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;
this.PluginInterface.UiBuilder.Draw += DrawUI;
this.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;
}
public void Dispose()
{
this.PluginUI.Dispose();
this.CommandManager.RemoveHandler(commandName);
}
private void OnCommand(string command, string args)
{
this.DrawConfigUI();
}
private void DrawUI()
{
// TODO: move this logic elsewhere
public void Dispose()
{
this.PluginUI.Dispose();
this.CommandManager.RemoveHandler(commandName);
}
private void OnCommand(string command, string args)
{
this.DrawConfigUI();
}
private void DrawUI()
{
// TODO: move this logic elsewhere
unsafe
{
InventoryManager* inventoryManager = InventoryManager.Instance();
@ -77,15 +77,15 @@ namespace CurrencyAlert
{
this.PluginUI.AlertVisible[currency] = false;
}
});
}
this.PluginUI.Draw();
}
private void DrawConfigUI()
{
this.PluginUI.SettingsVisible = true;
}
}
}
});
}
this.PluginUI.Draw();
}
private void DrawConfigUI()
{
this.PluginUI.SettingsVisible = true;
}
}
}

View File

@ -62,7 +62,7 @@ namespace CurrencyAlert
var isVisible = this.AlertVisible[currency];
if (ImGui.Begin("Currency Alert", ref isVisible,
if (ImGui.Begin("Currency Alert", ref isVisible,
ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse |
ImGuiWindowFlags.AlwaysAutoResize |
@ -70,7 +70,8 @@ namespace CurrencyAlert
ImGuiWindowFlags.NoFocusOnAppearing
))
{
ImGui.Text($"You need to spend your {currency}");
var name = EnumHelper.GetAttributeOfType<NameAttribute>(currency).Value;
ImGui.Text($"You need to spend your {name}");
}
ImGui.End();
@ -85,9 +86,10 @@ namespace CurrencyAlert
{
EnumHelper.Each<Currency>(currency =>
{
var name = EnumHelper.GetAttributeOfType<NameAttribute>(currency).Value;
var alertEnabled = this.configuration.AlertEnabled[currency];
if (ImGui.Checkbox($"{currency.ToString()} Alert Enabled", ref alertEnabled))
if (ImGui.Checkbox($"{name} Alert Enabled", ref alertEnabled))
{
this.configuration.AlertEnabled[currency] = alertEnabled;
this.configuration.Save();
@ -95,7 +97,7 @@ namespace CurrencyAlert
var thresholdValue = this.configuration.Threshold[currency];
if (ImGui.InputInt($"{currency.ToString()} Threshold Value", ref thresholdValue, 1, 1,
if (ImGui.InputInt($"{name} Threshold Value", ref thresholdValue, 1, 1,
this.configuration.AlertEnabled[currency] ? ImGuiInputTextFlags.None : ImGuiInputTextFlags.ReadOnly))
{
this.configuration.Threshold[currency] = thresholdValue;