using System.IO; using Dalamud.Game.Command; using Dalamud.Interface.Windowing; using Dalamud.IoC; using Dalamud.Plugin; 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; } 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 ) { this.pluginInterface = pluginInterface; this.commandManager = commandManager; 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() { 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; } } }