more stuff

main
Zynh0722 2024-02-06 23:13:53 -08:00
parent 3d75087d9f
commit 907574e436
3 changed files with 59 additions and 39 deletions

View File

@ -1,8 +1,8 @@
using Dalamud.Game.Command; using System.IO;
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.Plugin; using Dalamud.Plugin;
using System.IO;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using SamplePlugin.Windows; using SamplePlugin.Windows;
@ -13,51 +13,59 @@ namespace SamplePlugin
public string Name => "Sample Plugin"; public string Name => "Sample Plugin";
private const string CommandName = "/pmycommand"; private const string CommandName = "/pmycommand";
private DalamudPluginInterface PluginInterface { get; init; } private DalamudPluginInterface pluginInterface { get; init; }
private ICommandManager CommandManager { get; init; } private ICommandManager commandManager { get; init; }
public Configuration Configuration { get; init; } public Configuration configuration { get; init; }
public WindowSystem WindowSystem = new("SamplePlugin"); internal WindowSystem windowSystem = new("SamplePlugin");
private ConfigWindow ConfigWindow { get; init; } private ConfigWindow ConfigWindow { get; init; }
private MainWindow MainWindow { get; init; } private MainWindow MainWindow { get; init; }
public Plugin( public Plugin(
[RequiredVersion("1.0")] DalamudPluginInterface pluginInterface, [RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,
[RequiredVersion("1.0")] ICommandManager commandManager) [RequiredVersion("1.0")] ICommandManager commandManager
)
{ {
this.PluginInterface = pluginInterface; this.pluginInterface = pluginInterface;
this.CommandManager = commandManager; this.commandManager = commandManager;
this.Configuration = this.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); configuration =
this.Configuration.Initialize(this.PluginInterface); pluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
configuration.Initialize(this.pluginInterface);
// you might normally want to embed resources and load them from the manifest stream // 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 imagePath = Path.Combine(
var goatImage = this.PluginInterface.UiBuilder.LoadImage(imagePath); this.pluginInterface.AssemblyLocation.Directory?.FullName!,
"goat.png"
);
var goatImage = this.pluginInterface.UiBuilder.LoadImage(imagePath);
ConfigWindow = new ConfigWindow(this); ConfigWindow = new ConfigWindow(this);
MainWindow = new MainWindow(this, goatImage); MainWindow = new MainWindow(this, goatImage);
WindowSystem.AddWindow(ConfigWindow); windowSystem.AddWindow(ConfigWindow);
WindowSystem.AddWindow(MainWindow); windowSystem.AddWindow(MainWindow);
this.CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand) _ = this.commandManager.AddHandler(
{ CommandName,
HelpMessage = "A useful message to display in /xlhelp" new CommandInfo(OnCommand)
}); {
HelpMessage = "A useful message to display in /xlhelp"
}
);
this.PluginInterface.UiBuilder.Draw += DrawUI; this.pluginInterface.UiBuilder.Draw += DrawUI;
this.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI; this.pluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI;
} }
public void Dispose() public void Dispose()
{ {
this.WindowSystem.RemoveAllWindows(); this.windowSystem.RemoveAllWindows();
ConfigWindow.Dispose(); ConfigWindow.Dispose();
MainWindow.Dispose(); MainWindow.Dispose();
this.CommandManager.RemoveHandler(CommandName); this.commandManager.RemoveHandler(CommandName);
} }
private void OnCommand(string command, string args) private void OnCommand(string command, string args)
@ -68,7 +76,7 @@ namespace SamplePlugin
private void DrawUI() private void DrawUI()
{ {
this.WindowSystem.Draw(); this.windowSystem.Draw();
} }
public void DrawConfigUI() public void DrawConfigUI()

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Numerics; using System.Numerics;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using ImGuiNET; using ImGuiNET;
@ -9,15 +9,19 @@ public class ConfigWindow : Window, IDisposable
{ {
private Configuration Configuration; private Configuration Configuration;
public ConfigWindow(Plugin plugin) : base( public ConfigWindow(Plugin plugin)
"A Wonderful Configuration Window", : base(
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | "A Wonderful Configuration Window",
ImGuiWindowFlags.NoScrollWithMouse) ImGuiWindowFlags.NoResize
| ImGuiWindowFlags.NoCollapse
| ImGuiWindowFlags.NoScrollbar
| ImGuiWindowFlags.NoScrollWithMouse
)
{ {
this.Size = new Vector2(232, 75); this.Size = new Vector2(232, 75);
this.SizeCondition = ImGuiCond.Always; this.SizeCondition = ImGuiCond.Always;
this.Configuration = plugin.Configuration; this.Configuration = plugin.configuration;
} }
public void Dispose() { } public void Dispose() { }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Numerics; using System.Numerics;
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
@ -11,8 +11,11 @@ public class MainWindow : Window, IDisposable
private IDalamudTextureWrap GoatImage; private IDalamudTextureWrap GoatImage;
private Plugin Plugin; private Plugin Plugin;
public MainWindow(Plugin plugin, IDalamudTextureWrap goatImage) : base( public MainWindow(Plugin plugin, IDalamudTextureWrap goatImage)
"My Amazing Window", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse) : base(
"My Amazing Window",
ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse
)
{ {
this.SizeConstraints = new WindowSizeConstraints this.SizeConstraints = new WindowSizeConstraints
{ {
@ -31,7 +34,9 @@ public class MainWindow : Window, IDisposable
public override void Draw() public override void Draw()
{ {
ImGui.Text($"The random config bool is {this.Plugin.Configuration.SomePropertyToBeSavedAndWithADefault}"); ImGui.Text(
$"The random config bool is {this.Plugin.configuration.SomePropertyToBeSavedAndWithADefault}"
);
if (ImGui.Button("Show Settings")) if (ImGui.Button("Show Settings"))
{ {
@ -42,7 +47,10 @@ public class MainWindow : Window, IDisposable
ImGui.Text("Have a goat:"); ImGui.Text("Have a goat:");
ImGui.Indent(55); ImGui.Indent(55);
ImGui.Image(this.GoatImage.ImGuiHandle, new Vector2(this.GoatImage.Width, this.GoatImage.Height)); ImGui.Image(
this.GoatImage.ImGuiHandle,
new Vector2(this.GoatImage.Width, this.GoatImage.Height)
);
ImGui.Unindent(55); ImGui.Unindent(55);
} }
} }