CurrencyAlertClassic/SamplePlugin/Plugin.cs

68 lines
2.2 KiB
C#
Raw Normal View History

using Dalamud.Game.Command;
2021-08-26 14:11:18 +00:00
using Dalamud.IoC;
using Dalamud.Plugin;
using System.IO;
using System.Reflection;
namespace SamplePlugin
{
2021-08-26 14:11:18 +00:00
public sealed class Plugin : IDalamudPlugin
{
public string Name => "Sample Plugin";
private const string commandName = "/pmycommand";
2021-08-26 14:11:18 +00:00
private DalamudPluginInterface PluginInterface { get; init; }
private CommandManager CommandManager { get; init; }
private Configuration Configuration { get; init; }
private PluginUI PluginUi { get; init; }
2021-08-26 14:11:18 +00:00
public Plugin(
[RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,
[RequiredVersion("1.0")] CommandManager commandManager)
{
2021-08-26 14:11:18 +00:00
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
2021-08-26 14:11:18 +00:00
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var imagePath = Path.Combine(Path.GetDirectoryName(assemblyLocation)!, "goat.png");
var goatImage = this.PluginInterface.UiBuilder.LoadImage(imagePath);
this.PluginUi = new PluginUI(this.Configuration, goatImage);
2021-08-26 14:11:18 +00:00
this.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand)
{
HelpMessage = "A useful message to display in /xlhelp"
});
2021-08-26 14:11:18 +00:00
this.PluginInterface.UiBuilder.Draw += DrawUI;
this.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;
}
public void Dispose()
{
2021-08-26 14:11:18 +00:00
this.PluginUi.Dispose();
this.CommandManager.RemoveHandler(commandName);
}
private void OnCommand(string command, string args)
{
// in response to the slash command, just display our main ui
2021-08-26 14:11:18 +00:00
this.PluginUi.Visible = true;
}
private void DrawUI()
{
2021-08-26 14:11:18 +00:00
this.PluginUi.Draw();
}
private void DrawConfigUI()
{
2021-08-26 14:11:18 +00:00
this.PluginUi.SettingsVisible = true;
}
}
}