CurrencyAlertClassic/SamplePlugin/Plugin.cs

65 lines
1.9 KiB
C#

using Dalamud.Game.Command;
using Dalamud.Plugin;
using System;
using System.IO;
using System.Reflection;
namespace SamplePlugin
{
public class Plugin : IDalamudPlugin
{
public string Name => "Sample Plugin";
private const string commandName = "/pmycommand";
private DalamudPluginInterface pi;
private Configuration configuration;
private PluginUI ui;
public void Initialize(DalamudPluginInterface pluginInterface)
{
this.pi = pluginInterface;
this.configuration = this.pi.GetPluginConfig() as Configuration ?? new Configuration();
this.configuration.Initialize(this.pi);
// you might normally want to embed resources and load them from the manifest stream
var imagePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"goat.png");
var goatImage = this.pi.UiBuilder.LoadImage(imagePath);
this.ui = new PluginUI(this.configuration, goatImage);
this.pi.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand)
{
HelpMessage = "A useful message to display in /xlhelp"
});
this.pi.UiBuilder.OnBuildUi += DrawUI;
this.pi.UiBuilder.OnOpenConfigUi += (sender, args) => DrawConfigUI();
}
public void Dispose()
{
this.ui.Dispose();
this.pi.CommandManager.RemoveHandler(commandName);
this.pi.Dispose();
}
private void OnCommand(string command, string args)
{
// in response to the slash command, just display our main ui
this.ui.Visible = true;
}
private void DrawUI()
{
this.ui.Draw();
}
private void DrawConfigUI()
{
this.ui.SettingsVisible = true;
}
}
}