using Dalamud.Game.Command; using Dalamud.IoC; using Dalamud.Plugin; using System.IO; using Dalamud.Interface.Windowing; using Dalamud.Plugin.Services; using SamplePlugin.Windows; namespace SamplePlugin { public sealed class Plugin : IDalamudPlugin { public string Name => "Sample Plugin"; private const string CommandName = "/pmycommand"; private DalamudPluginInterface PluginInterface { get; init; } private ICommandManager CommandManager { get; init; } public Configuration Configuration { get; init; } public 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) { 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 imagePath = Path.Combine(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() { this.WindowSystem.RemoveAllWindows(); ConfigWindow.Dispose(); MainWindow.Dispose(); this.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() { this.WindowSystem.Draw(); } public void DrawConfigUI() { ConfigWindow.IsOpen = true; } } }