main
Camille 2021-12-11 12:02:01 +01:00
parent 0d68ee0a54
commit 8fcc186566
5 changed files with 38 additions and 86 deletions

View File

@ -1,11 +1,11 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 17
VisualStudioVersion = 16.0.29709.97 VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplePlugin", "SamplePlugin\SamplePlugin.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SamplePlugin", "SamplePlugin\SamplePlugin.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UIDev", "UIDev\UIDev.csproj", "{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UIDev", "UIDev\UIDev.csproj", "{4FEC9558-EB25-419F-B86E-51B8CFDA32B7}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -1,40 +0,0 @@
# SamplePlugin
Simple example plugin for XivLauncher/Dalamud, that shows both a working plugin and an associated UI test project, to allow for building and tweaking the UI without having to run the game.
This is not designed to be the simplest possible example, but neither is it designed to cover everything you might want to do.
I'm mostly hoping this helps some people to build out their UIs without having to constantly jump in and out of game.
### Main Points
* Simple functional plugin
* Slash command
* Main UI
* Settings UI
* Image loading
* Plugin json
* Simple, slightly-improved plugin configuration handling
* Basic ImGui testbed application project
* Allows testing UI changes without needing to run the game
* UI environment provided should match what is seen in game
* Defaults to an invisible fullscreen overlay; can easily be changed to use an opaque window etc
* Currently relies more on copy/paste of your UI code than fully generic objects (though this could be done)
* Project organization
* Copies all necessary plugin files to the output directory
* Does not copy dependencies that are provided by dalamud
* Output directory can be zipped directly and have exactly what is required
* Hides data files from visual studio to reduce clutter
* Also allows having data files in different paths than VS would usually allow if done in the IDE directly
The intention is less that any of this is used directly in other projects, and more to show how similar things can be done.
The UIDev project could be used as-is, with just the UITest.cs file needing to be redone for your specific project UI.
### To Use
You'll need to fixup the library dependencies (for both projects), to point at your local dalamud binary directory.
This will either be a custom dalamud build, or `%APPDATA%\XivLauncher\addon\Hooks\` for the current live release.
After that, clear out what you don't need in UITest.cs, and implement your own local UI under Draw()

View File

@ -8,9 +8,9 @@ namespace SamplePlugin
{ {
public sealed class Plugin : IDalamudPlugin public sealed class Plugin : IDalamudPlugin
{ {
public string Name => "Sample Plugin"; public string Name => "Currency Alert";
private const string commandName = "/tsalert"; private const string commandName = "/currencyalert";
private DalamudPluginInterface PluginInterface { get; init; } private DalamudPluginInterface PluginInterface { get; init; }
private CommandManager CommandManager { get; init; } private CommandManager CommandManager { get; init; }
@ -29,9 +29,7 @@ namespace SamplePlugin
// 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 assemblyLocation = Assembly.GetExecutingAssembly().Location; var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var imagePath = Path.Combine(Path.GetDirectoryName(assemblyLocation)!, "goat.png"); this.PluginUi = new PluginUI(this.Configuration);
var goatImage = this.PluginInterface.UiBuilder.LoadImage(imagePath);
this.PluginUi = new PluginUI(this.Configuration, goatImage);
this.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand) this.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand)
{ {

View File

@ -11,8 +11,6 @@ namespace SamplePlugin
{ {
private Configuration configuration; private Configuration configuration;
private ImGuiScene.TextureWrap goatImage;
// this extra bool exists for ImGui, since you can't ref a property // this extra bool exists for ImGui, since you can't ref a property
private bool visible = false; private bool visible = false;
public bool Visible public bool Visible
@ -31,16 +29,15 @@ namespace SamplePlugin
//public unsafe InventoryManager* InventoryManager { get; } //public unsafe InventoryManager* InventoryManager { get; }
// passing in the image here just for simplicity // passing in the image here just for simplicity
public PluginUI(Configuration configuration, ImGuiScene.TextureWrap goatImage) public PluginUI(Configuration configuration)
{ {
this.configuration = configuration; this.configuration = configuration;
this.goatImage = goatImage;
//this.InventoryManager = InventoryManager.Instance(); //this.InventoryManager = InventoryManager.Instance();
} }
public void Dispose() public void Dispose()
{ {
this.goatImage.Dispose();
} }
public void Draw() public void Draw()
@ -83,11 +80,6 @@ namespace SamplePlugin
Visible = true; Visible = true;
} }
//if (wolfMarks >= 15000)
//{
// ImGui.Text("Wolf Marks: " + wolfMarks);
//}
if (!Visible) if (!Visible)
{ {
return; return;
@ -95,6 +87,7 @@ namespace SamplePlugin
ImGui.SetNextWindowSize(new Vector2(375, 330), ImGuiCond.FirstUseEver); ImGui.SetNextWindowSize(new Vector2(375, 330), ImGuiCond.FirstUseEver);
ImGui.SetNextWindowSizeConstraints(new Vector2(375, 330), new Vector2(float.MaxValue, float.MaxValue)); ImGui.SetNextWindowSizeConstraints(new Vector2(375, 330), new Vector2(float.MaxValue, float.MaxValue));
if (ImGui.Begin("My Amazing Window", ref this.visible, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)) if (ImGui.Begin("My Amazing Window", ref this.visible, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse))
{ {
if (ImGui.Button("Show Settings")) if (ImGui.Button("Show Settings"))
@ -107,6 +100,7 @@ namespace SamplePlugin
ImGui.Text("DEPENSE TES POETICS MERDE"); ImGui.Text("DEPENSE TES POETICS MERDE");
} }
} }
ImGui.End(); ImGui.End();
} }
} }