aboutsummaryrefslogtreecommitdiffstats
path: root/SamplePlugin
diff options
context:
space:
mode:
Diffstat (limited to 'SamplePlugin')
-rw-r--r--SamplePlugin/Configuration.cs20
-rw-r--r--SamplePlugin/Dalamud.Plugin.Bootstrap.targets11
-rw-r--r--SamplePlugin/Plugin.cs73
-rw-r--r--SamplePlugin/SamplePlugin.csproj19
-rw-r--r--SamplePlugin/SamplePlugin.json12
-rw-r--r--SamplePlugin/Windows/ConfigWindow.cs59
-rw-r--r--SamplePlugin/Windows/MainWindow.cs58
-rw-r--r--SamplePlugin/packages.lock.json13
8 files changed, 265 insertions, 0 deletions
diff --git a/SamplePlugin/Configuration.cs b/SamplePlugin/Configuration.cs
new file mode 100644
index 0000000..4cdc476
--- /dev/null
+++ b/SamplePlugin/Configuration.cs
@@ -0,0 +1,20 @@
+using Dalamud.Configuration;
+using Dalamud.Plugin;
+using System;
+
+namespace SamplePlugin;
+
+[Serializable]
+public class Configuration : IPluginConfiguration
+{
+ public int Version { get; set; } = 0;
+
+ public bool IsConfigWindowMovable { get; set; } = true;
+ public bool SomePropertyToBeSavedAndWithADefault { get; set; } = true;
+
+ // the below exist just to make saving less cumbersome
+ public void Save()
+ {
+ Plugin.PluginInterface.SavePluginConfig(this);
+ }
+}
diff --git a/SamplePlugin/Dalamud.Plugin.Bootstrap.targets b/SamplePlugin/Dalamud.Plugin.Bootstrap.targets
new file mode 100644
index 0000000..11eec9c
--- /dev/null
+++ b/SamplePlugin/Dalamud.Plugin.Bootstrap.targets
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project>
+ <PropertyGroup>
+ <DalamudLibPath Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
+ <DalamudLibPath Condition="$([MSBuild]::IsOSPlatform('Linux'))">$(HOME)/.xlcore/dalamud/Hooks/dev/</DalamudLibPath>
+ <DalamudLibPath Condition="$([MSBuild]::IsOSPlatform('OSX'))">$(HOME)/Library/Application Support/XIV on Mac/dalamud/Hooks/dev/</DalamudLibPath>
+ <DalamudLibPath Condition="$(DALAMUD_HOME) != ''">$(DALAMUD_HOME)/</DalamudLibPath>
+ </PropertyGroup>
+
+ <Import Project="$(DalamudLibPath)/targets/Dalamud.Plugin.targets"/>
+</Project>
diff --git a/SamplePlugin/Plugin.cs b/SamplePlugin/Plugin.cs
new file mode 100644
index 0000000..b8e859b
--- /dev/null
+++ b/SamplePlugin/Plugin.cs
@@ -0,0 +1,73 @@
+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
+{
+ [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!;
+
+ private const string CommandName = "/pmycommand";
+
+ public Configuration Configuration { get; init; }
+
+ public readonly WindowSystem WindowSystem = new("SamplePlugin");
+ private ConfigWindow ConfigWindow { get; init; }
+ private MainWindow MainWindow { get; init; }
+
+ public Plugin()
+ {
+ Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
+
+ // 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"
+ });
+
+ PluginInterface.UiBuilder.Draw += DrawUI;
+
+ // This adds a button to the plugin installer entry of this plugin which allows
+ // to toggle the display status of the configuration ui
+ PluginInterface.UiBuilder.OpenConfigUi += ToggleConfigUI;
+
+ // Adds another button that is doing the same but for the main ui of the plugin
+ PluginInterface.UiBuilder.OpenMainUi += ToggleMainUI;
+ }
+
+ 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 toggle the display status of our main ui
+ ToggleMainUI();
+ }
+
+ private void DrawUI() => WindowSystem.Draw();
+
+ public void ToggleConfigUI() => ConfigWindow.Toggle();
+ public void ToggleMainUI() => MainWindow.Toggle();
+}
diff --git a/SamplePlugin/SamplePlugin.csproj b/SamplePlugin/SamplePlugin.csproj
new file mode 100644
index 0000000..e952b44
--- /dev/null
+++ b/SamplePlugin/SamplePlugin.csproj
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project Sdk="Microsoft.NET.Sdk">
+ <Import Project="Dalamud.Plugin.Bootstrap.targets"/>
+
+ <PropertyGroup>
+ <Version>0.0.0.1</Version>
+ <Description>A sample plugin.</Description>
+ <PackageProjectUrl>https://github.com/goatcorp/SamplePlugin</PackageProjectUrl>
+ <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
+ <IsPackable>false</IsPackable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Content Include="..\Data\goat.png">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ <Visible>false</Visible>
+ </Content>
+ </ItemGroup>
+</Project>
diff --git a/SamplePlugin/SamplePlugin.json b/SamplePlugin/SamplePlugin.json
new file mode 100644
index 0000000..c806554
--- /dev/null
+++ b/SamplePlugin/SamplePlugin.json
@@ -0,0 +1,12 @@
+{
+ "Author": "your name here",
+ "Name": "Sample Plugin",
+ "Punchline": "A short one-liner that shows up in /xlplugins.",
+ "Description": "A description that shows up in /xlplugins. List any major slash-command(s).",
+ "ApplicableVersion": "any",
+ "Tags": [
+ "sample",
+ "plugin",
+ "goats"
+ ]
+}
diff --git a/SamplePlugin/Windows/ConfigWindow.cs b/SamplePlugin/Windows/ConfigWindow.cs
new file mode 100644
index 0000000..0a0af98
--- /dev/null
+++ b/SamplePlugin/Windows/ConfigWindow.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Numerics;
+using Dalamud.Interface.Windowing;
+using ImGuiNET;
+
+namespace SamplePlugin.Windows;
+
+public class ConfigWindow : Window, IDisposable
+{
+ private Configuration Configuration;
+
+ // We give this window a constant ID using ###
+ // This allows for labels being dynamic, like "{FPS Counter}fps###XYZ counter window",
+ // and the window ID will always be "###XYZ counter window" for ImGui
+ public ConfigWindow(Plugin plugin) : base("A Wonderful Configuration Window###With a constant ID")
+ {
+ Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
+ ImGuiWindowFlags.NoScrollWithMouse;
+
+ Size = new Vector2(232, 90);
+ SizeCondition = ImGuiCond.Always;
+
+ Configuration = plugin.Configuration;
+ }
+
+ public void Dispose() { }
+
+ public override void PreDraw()
+ {
+ // Flags must be added or removed before Draw() is being called, or they won't apply
+ if (Configuration.IsConfigWindowMovable)
+ {
+ Flags &= ~ImGuiWindowFlags.NoMove;
+ }
+ else
+ {
+ Flags |= ImGuiWindowFlags.NoMove;
+ }
+ }
+
+ public override void Draw()
+ {
+ // can't ref a property, so use a local copy
+ var configValue = Configuration.SomePropertyToBeSavedAndWithADefault;
+ if (ImGui.Checkbox("Random Config Bool", ref configValue))
+ {
+ Configuration.SomePropertyToBeSavedAndWithADefault = configValue;
+ // can save immediately on change, if you don't want to provide a "Save and Close" button
+ Configuration.Save();
+ }
+
+ var movable = Configuration.IsConfigWindowMovable;
+ if (ImGui.Checkbox("Movable Config Window", ref movable))
+ {
+ Configuration.IsConfigWindowMovable = movable;
+ Configuration.Save();
+ }
+ }
+}
diff --git a/SamplePlugin/Windows/MainWindow.cs b/SamplePlugin/Windows/MainWindow.cs
new file mode 100644
index 0000000..9ac6a4d
--- /dev/null
+++ b/SamplePlugin/Windows/MainWindow.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Numerics;
+using Dalamud.Interface.Internal;
+using Dalamud.Interface.Utility;
+using Dalamud.Interface.Windowing;
+using Dalamud.Plugin.Services;
+using ImGuiNET;
+
+namespace SamplePlugin.Windows;
+
+public class MainWindow : Window, IDisposable
+{
+ private string GoatImagePath;
+ private Plugin Plugin;
+
+ // We give this window a hidden ID using ##
+ // So that the user will see "My Amazing Window" as window title,
+ // but for ImGui the ID is "My Amazing Window##With a hidden ID"
+ public MainWindow(Plugin plugin, string goatImagePath)
+ : base("My Amazing Window##With a hidden ID", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
+ {
+ SizeConstraints = new WindowSizeConstraints
+ {
+ MinimumSize = new Vector2(375, 330),
+ MaximumSize = new Vector2(float.MaxValue, float.MaxValue)
+ };
+
+ GoatImagePath = goatImagePath;
+ Plugin = plugin;
+ }
+
+ public void Dispose() { }
+
+ public override void Draw()
+ {
+ ImGui.Text($"The random config bool is {Plugin.Configuration.SomePropertyToBeSavedAndWithADefault}");
+
+ if (ImGui.Button("Show Settings"))
+ {
+ Plugin.ToggleConfigUI();
+ }
+
+ ImGui.Spacing();
+
+ ImGui.Text("Have a goat:");
+ var goatImage = Plugin.TextureProvider.GetFromFile(GoatImagePath).GetWrapOrDefault();
+ if (goatImage != null)
+ {
+ ImGuiHelpers.ScaledIndent(55f);
+ ImGui.Image(goatImage.ImGuiHandle, new Vector2(goatImage.Width, goatImage.Height));
+ ImGuiHelpers.ScaledIndent(-55f);
+ }
+ else
+ {
+ ImGui.Text("Image not found.");
+ }
+ }
+}
diff --git a/SamplePlugin/packages.lock.json b/SamplePlugin/packages.lock.json
new file mode 100644
index 0000000..19fcea9
--- /dev/null
+++ b/SamplePlugin/packages.lock.json
@@ -0,0 +1,13 @@
+{
+ "version": 1,
+ "dependencies": {
+ "net8.0-windows7.0": {
+ "DalamudPackager": {
+ "type": "Direct",
+ "requested": "[2.1.13, )",
+ "resolved": "2.1.13",
+ "contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ=="
+ }
+ }
+ }
+} \ No newline at end of file
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage