- Replace Plugin.cs/ConfigWindow.cs skeleton with working sample code - Add MainWindow.cs (goat-image demo + PlayerState/Lumina queries) - Rename src/PluginConfiguration.cs → src/Configuration.cs (sample naming) - Add Data/goat.png sample asset - Add src/packages.lock.json (NuGet lockfile from sample) - Add PluginNameTemplate.sln solution file - Bump csproj from Dalamud.NET.Sdk 13.0.0 → 15.0.0 - Bump yaml dalamud_api_level: 13 → 15 - Update README with sample-removal walkthrough and SDK-bump section Template now builds end-to-end out of the box. Goat demo intact for verification; strip per README when implementing the real plugin.
This commit is contained in:
+66
-9
@@ -1,28 +1,85 @@
|
||||
using Dalamud.Game.Command;
|
||||
using Dalamud.IoC;
|
||||
using Dalamud.Plugin;
|
||||
using System.IO;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin.Services;
|
||||
using PluginNameTemplate.Windows;
|
||||
|
||||
namespace PluginNameTemplate;
|
||||
|
||||
public sealed class Plugin : IDalamudPlugin
|
||||
{
|
||||
[PluginService] public static IDalamudPluginInterface Pi { get; private set; } = null!;
|
||||
[PluginService] public static IPluginLog Log { get; private set; } = null!;
|
||||
[PluginService] public static ICommandManager Commands { get; private set; } = null!;
|
||||
[PluginService] internal static IDalamudPluginInterface PluginInterface { get; private set; } = null!;
|
||||
[PluginService] internal static ITextureProvider TextureProvider { get; private set; } = null!;
|
||||
[PluginService] internal static ICommandManager CommandManager { get; private set; } = null!;
|
||||
[PluginService] internal static IClientState ClientState { get; private set; } = null!;
|
||||
[PluginService] internal static IPlayerState PlayerState { get; private set; } = null!;
|
||||
[PluginService] internal static IDataManager DataManager { get; private set; } = null!;
|
||||
[PluginService] internal static IPluginLog Log { get; private set; } = null!;
|
||||
|
||||
private readonly PluginConfiguration config;
|
||||
private const string CommandName = "/pmycommand";
|
||||
|
||||
public Configuration Configuration { get; init; }
|
||||
|
||||
public readonly WindowSystem WindowSystem = new("PluginNameTemplate");
|
||||
private ConfigWindow ConfigWindow { get; init; }
|
||||
private MainWindow MainWindow { get; init; }
|
||||
|
||||
public Plugin()
|
||||
{
|
||||
this.config = PluginConfiguration.Load();
|
||||
Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
||||
|
||||
// Register your commands, hooks, windows, etc. here.
|
||||
Log.Information("PluginNameTemplate loaded.");
|
||||
// You might normally want to embed resources and load them from the manifest stream
|
||||
var goatImagePath = Path.Combine(PluginInterface.AssemblyLocation.Directory?.FullName!, "goat.png");
|
||||
|
||||
ConfigWindow = new ConfigWindow(this);
|
||||
MainWindow = new MainWindow(this, goatImagePath);
|
||||
|
||||
WindowSystem.AddWindow(ConfigWindow);
|
||||
WindowSystem.AddWindow(MainWindow);
|
||||
|
||||
CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand)
|
||||
{
|
||||
HelpMessage = "A useful message to display in /xlhelp"
|
||||
});
|
||||
|
||||
// Tell the UI system that we want our windows to be drawn through the window system
|
||||
PluginInterface.UiBuilder.Draw += WindowSystem.Draw;
|
||||
|
||||
// This adds a button to the plugin installer entry of this plugin which allows
|
||||
// toggling the display status of the configuration ui
|
||||
PluginInterface.UiBuilder.OpenConfigUi += ToggleConfigUi;
|
||||
|
||||
// Adds another button doing the same but for the main ui of the plugin
|
||||
PluginInterface.UiBuilder.OpenMainUi += ToggleMainUi;
|
||||
|
||||
// Add a simple message to the log with level set to information
|
||||
// Use /xllog to open the log window in-game
|
||||
Log.Information($"===A cool log message from {PluginInterface.Manifest.Name}===");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Unregister anything that was registered above. Order matters —
|
||||
// dispose UI before hooks, hooks before services.
|
||||
// Unregister all actions to not leak anything during disposal of plugin
|
||||
PluginInterface.UiBuilder.Draw -= WindowSystem.Draw;
|
||||
PluginInterface.UiBuilder.OpenConfigUi -= ToggleConfigUi;
|
||||
PluginInterface.UiBuilder.OpenMainUi -= ToggleMainUi;
|
||||
|
||||
WindowSystem.RemoveAllWindows();
|
||||
|
||||
ConfigWindow.Dispose();
|
||||
MainWindow.Dispose();
|
||||
|
||||
CommandManager.RemoveHandler(CommandName);
|
||||
}
|
||||
|
||||
private void OnCommand(string command, string args)
|
||||
{
|
||||
// In response to the slash command, toggle the display status of our main ui
|
||||
MainWindow.Toggle();
|
||||
}
|
||||
|
||||
public void ToggleConfigUi() => ConfigWindow.Toggle();
|
||||
public void ToggleMainUi() => MainWindow.Toggle();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user