name attribute
This commit is contained in:
parent
577ced24a4
commit
74e44d7092
14
SamplePlugin/Attribute/NameAttribute.cs
Normal file
14
SamplePlugin/Attribute/NameAttribute.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace CurrencyAlert.Enum
|
||||||
|
{
|
||||||
|
internal class NameAttribute : Attribute
|
||||||
|
{
|
||||||
|
public NameAttribute(string v)
|
||||||
|
{
|
||||||
|
Value = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Value { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,7 @@ namespace CurrencyAlert
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class Configuration : IPluginConfiguration
|
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, bool> AlertEnabled { get; set; } = new Dictionary<Currency, bool>();
|
||||||
public Dictionary<Currency, int> Threshold { get; set; } = new Dictionary<Currency , int>();
|
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);
|
this.pluginInterface!.SavePluginConfig(this);
|
||||||
}
|
}
|
||||||
|
@ -8,25 +8,19 @@ namespace CurrencyAlert.Enum
|
|||||||
{
|
{
|
||||||
public enum Currency
|
public enum Currency
|
||||||
{
|
{
|
||||||
[Slot(1), DefaultThreshold(75000)]
|
[Name("Tomestones of Poetics"), Slot(6), DefaultThreshold(1500)]
|
||||||
StormSeal,
|
|
||||||
|
|
||||||
[Slot(2), DefaultThreshold(75000)]
|
|
||||||
SerpentSeal,
|
|
||||||
|
|
||||||
[Slot(3), DefaultThreshold(75000)]
|
|
||||||
FlameSeal,
|
|
||||||
|
|
||||||
[Slot(4), DefaultThreshold(18000)]
|
|
||||||
WolfMark,
|
|
||||||
|
|
||||||
[Slot(6), DefaultThreshold(1500)]
|
|
||||||
TomestoneOfPoetics,
|
TomestoneOfPoetics,
|
||||||
|
[Name("Tomestones of Astronomy"), Slot(10), DefaultThreshold(1500)]
|
||||||
[Slot(8), DefaultThreshold(3500)]
|
TomestoneOfAstronomy,
|
||||||
AlliedSeal,
|
[Name("Storm Seals"), Slot(1), DefaultThreshold(75000)]
|
||||||
|
StormSeal,
|
||||||
[Slot(10), DefaultThreshold(1500)]
|
[Name("Serpent Seals"), Slot(2), DefaultThreshold(75000)]
|
||||||
TomestoneOfAstronomy
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,64 +1,64 @@
|
|||||||
using CurrencyAlert.Enum;
|
using CurrencyAlert.Enum;
|
||||||
using Dalamud.Game.Command;
|
using Dalamud.Game.Command;
|
||||||
using Dalamud.Game.Gui;
|
using Dalamud.Game.Gui;
|
||||||
using Dalamud.IoC;
|
using Dalamud.IoC;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using FFXIVClientStructs.FFXIV.Client.Game;
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace CurrencyAlert
|
namespace CurrencyAlert
|
||||||
{
|
{
|
||||||
public sealed class Plugin : IDalamudPlugin
|
public sealed class Plugin : IDalamudPlugin
|
||||||
{
|
{
|
||||||
public string Name => "Currency Alert";
|
public string Name => "Currency Alert";
|
||||||
|
|
||||||
private const string commandName = "/currencyalert";
|
private const string commandName = "/currencyalert";
|
||||||
|
|
||||||
private DalamudPluginInterface PluginInterface { get; init; }
|
private DalamudPluginInterface PluginInterface { get; init; }
|
||||||
private CommandManager CommandManager { get; init; }
|
private CommandManager CommandManager { get; init; }
|
||||||
private Configuration Configuration { get; init; }
|
private Configuration Configuration { get; init; }
|
||||||
private PluginUI PluginUI { get; init; }
|
private PluginUI PluginUI { get; init; }
|
||||||
|
|
||||||
[PluginService] public static ChatGui Chat { get; private set; } = null!;
|
[PluginService] public static ChatGui Chat { get; private set; } = null!;
|
||||||
|
|
||||||
public Plugin(
|
public Plugin(
|
||||||
[RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,
|
[RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,
|
||||||
[RequiredVersion("1.0")] CommandManager commandManager)
|
[RequiredVersion("1.0")] CommandManager commandManager)
|
||||||
{
|
{
|
||||||
this.PluginInterface = pluginInterface;
|
this.PluginInterface = pluginInterface;
|
||||||
this.CommandManager = commandManager;
|
this.CommandManager = commandManager;
|
||||||
|
|
||||||
this.Configuration = this.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
this.Configuration = this.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
||||||
this.Configuration.Initialize(this.PluginInterface);
|
this.Configuration.Initialize(this.PluginInterface);
|
||||||
|
|
||||||
// you might normally want to embed resources and load them from the manifest stream
|
// you might normally want to embed resources and load them from the manifest stream
|
||||||
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
|
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
|
||||||
this.PluginUI = new PluginUI(this.Configuration);
|
this.PluginUI = new PluginUI(this.Configuration);
|
||||||
|
|
||||||
this.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand)
|
this.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand)
|
||||||
{
|
{
|
||||||
HelpMessage = "Lets you configure alert thresholds for various currencies"
|
HelpMessage = "Lets you configure alert thresholds for various currencies"
|
||||||
});
|
});
|
||||||
|
|
||||||
this.PluginInterface.UiBuilder.Draw += DrawUI;
|
this.PluginInterface.UiBuilder.Draw += DrawUI;
|
||||||
this.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;
|
this.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
this.PluginUI.Dispose();
|
this.PluginUI.Dispose();
|
||||||
this.CommandManager.RemoveHandler(commandName);
|
this.CommandManager.RemoveHandler(commandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCommand(string command, string args)
|
private void OnCommand(string command, string args)
|
||||||
{
|
{
|
||||||
this.DrawConfigUI();
|
this.DrawConfigUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawUI()
|
private void DrawUI()
|
||||||
{
|
{
|
||||||
// TODO: move this logic elsewhere
|
// TODO: move this logic elsewhere
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
InventoryManager* inventoryManager = InventoryManager.Instance();
|
InventoryManager* inventoryManager = InventoryManager.Instance();
|
||||||
@ -77,15 +77,15 @@ namespace CurrencyAlert
|
|||||||
{
|
{
|
||||||
this.PluginUI.AlertVisible[currency] = false;
|
this.PluginUI.AlertVisible[currency] = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.PluginUI.Draw();
|
this.PluginUI.Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawConfigUI()
|
private void DrawConfigUI()
|
||||||
{
|
{
|
||||||
this.PluginUI.SettingsVisible = true;
|
this.PluginUI.SettingsVisible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ namespace CurrencyAlert
|
|||||||
|
|
||||||
var isVisible = this.AlertVisible[currency];
|
var isVisible = this.AlertVisible[currency];
|
||||||
|
|
||||||
if (ImGui.Begin("Currency Alert", ref isVisible,
|
if (ImGui.Begin("Currency Alert", ref isVisible,
|
||||||
ImGuiWindowFlags.NoScrollbar |
|
ImGuiWindowFlags.NoScrollbar |
|
||||||
ImGuiWindowFlags.NoScrollWithMouse |
|
ImGuiWindowFlags.NoScrollWithMouse |
|
||||||
ImGuiWindowFlags.AlwaysAutoResize |
|
ImGuiWindowFlags.AlwaysAutoResize |
|
||||||
@ -70,7 +70,8 @@ namespace CurrencyAlert
|
|||||||
ImGuiWindowFlags.NoFocusOnAppearing
|
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();
|
ImGui.End();
|
||||||
@ -85,9 +86,10 @@ namespace CurrencyAlert
|
|||||||
{
|
{
|
||||||
EnumHelper.Each<Currency>(currency =>
|
EnumHelper.Each<Currency>(currency =>
|
||||||
{
|
{
|
||||||
|
var name = EnumHelper.GetAttributeOfType<NameAttribute>(currency).Value;
|
||||||
var alertEnabled = this.configuration.AlertEnabled[currency];
|
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.AlertEnabled[currency] = alertEnabled;
|
||||||
this.configuration.Save();
|
this.configuration.Save();
|
||||||
@ -95,7 +97,7 @@ namespace CurrencyAlert
|
|||||||
|
|
||||||
var thresholdValue = this.configuration.Threshold[currency];
|
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.AlertEnabled[currency] ? ImGuiInputTextFlags.None : ImGuiInputTextFlags.ReadOnly))
|
||||||
{
|
{
|
||||||
this.configuration.Threshold[currency] = thresholdValue;
|
this.configuration.Threshold[currency] = thresholdValue;
|
||||||
|
Loading…
Reference in New Issue
Block a user