97 lines
3 KiB
C#
97 lines
3 KiB
C#
using System;
|
|
using System.IO;
|
|
using Dalamud.Game.Command;
|
|
using Dalamud.Interface.Windowing;
|
|
using Dalamud.IoC;
|
|
using Dalamud.Plugin;
|
|
using Dalamud.Plugin.Services;
|
|
using Dalamud.Utility;
|
|
using SamplePlugin.Windows;
|
|
|
|
namespace SamplePlugin
|
|
{
|
|
public sealed class Plugin : IDalamudPlugin
|
|
{
|
|
public static string Name => "Sample Plugin";
|
|
private const string CommandName = "/pmycommand";
|
|
|
|
[PluginService]
|
|
private DalamudPluginInterface pluginInterface { get; set; } = null!;
|
|
private ICommandManager commandManager { get; init; }
|
|
public Configuration configuration { get; init; }
|
|
internal WindowSystem windowSystem = new("SamplePlugin");
|
|
|
|
private ConfigWindow ConfigWindow { get; init; }
|
|
private MainWindow MainWindow { get; init; }
|
|
|
|
public Plugin(
|
|
[RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,
|
|
[RequiredVersion("1.0")] ICommandManager commandManager,
|
|
[RequiredVersion("1.0")] IPluginLog log
|
|
)
|
|
{
|
|
this.pluginInterface = pluginInterface;
|
|
this.commandManager = commandManager;
|
|
|
|
var pluginList = pluginInterface.InstalledPlugins;
|
|
foreach (var command in commandManager.Commands)
|
|
{
|
|
log.Information($"{command}");
|
|
}
|
|
|
|
configuration =
|
|
pluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
|
configuration.Initialize(this.pluginInterface);
|
|
|
|
// you might normally want to embed resources and load them from the manifest stream
|
|
var imagePath = Path.Combine(
|
|
this.pluginInterface.AssemblyLocation.Directory?.FullName!,
|
|
"goat.png"
|
|
);
|
|
var goatImage = this.pluginInterface.UiBuilder.LoadImage(imagePath);
|
|
|
|
ConfigWindow = new ConfigWindow(this);
|
|
MainWindow = new MainWindow(this, goatImage);
|
|
|
|
windowSystem.AddWindow(ConfigWindow);
|
|
windowSystem.AddWindow(MainWindow);
|
|
|
|
_ = this.commandManager.AddHandler(
|
|
CommandName,
|
|
new CommandInfo(OnCommand)
|
|
{
|
|
HelpMessage = "A useful message to display in /xlhelp"
|
|
}
|
|
);
|
|
|
|
this.pluginInterface.UiBuilder.Draw += DrawUI;
|
|
this.pluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
windowSystem.RemoveAllWindows();
|
|
|
|
ConfigWindow.Dispose();
|
|
MainWindow.Dispose();
|
|
|
|
_ = commandManager.RemoveHandler(CommandName);
|
|
}
|
|
|
|
private void OnCommand(string command, string args)
|
|
{
|
|
// in response to the slash command, just display our main ui
|
|
MainWindow.IsOpen = true;
|
|
}
|
|
|
|
private void DrawUI()
|
|
{
|
|
windowSystem.Draw();
|
|
}
|
|
|
|
public void DrawConfigUI()
|
|
{
|
|
ConfigWindow.IsOpen = true;
|
|
}
|
|
}
|
|
}
|