code cleanup

This commit is contained in:
Camille 2021-12-11 14:27:58 +01:00
parent 8fcc186566
commit 58b870b99f
4 changed files with 105 additions and 109 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166 VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SamplePlugin", "SamplePlugin\SamplePlugin.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurrencyAlert", "SamplePlugin\CurrencyAlert.csproj", "{13C812E9-0D42-4B95-8646-40EEBF30636F}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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

View File

@ -2,14 +2,17 @@
using Dalamud.Plugin; using Dalamud.Plugin;
using System; using System;
namespace SamplePlugin namespace CurrencyAlert
{ {
[Serializable] [Serializable]
public class Configuration : IPluginConfiguration public class Configuration : IPluginConfiguration
{ {
public int Version { get; set; } = 1; public int Version { get; set; } = 1;
public bool PoeticsThresholdEnabled { get; set; } = true;
public int PoeticsThreshold { get; set; } = 1500; public int PoeticsThreshold { get; set; } = 1500;
public bool StormSealsThresholdEnabled { get; set; } = true;
public int StormSealsThreshold { get; set; } = 40000;
// the below exist just to make saving less cumbersome // the below exist just to make saving less cumbersome

View File

@ -4,7 +4,7 @@ using Dalamud.Plugin;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
namespace SamplePlugin namespace CurrencyAlert
{ {
public sealed class Plugin : IDalamudPlugin public sealed class Plugin : IDalamudPlugin
{ {
@ -48,8 +48,7 @@ namespace SamplePlugin
private void OnCommand(string command, string args) private void OnCommand(string command, string args)
{ {
// in response to the slash command, just display our main ui this.DrawConfigUI();
this.PluginUi.Visible = true;
} }
private void DrawUI() private void DrawUI()

View File

@ -3,22 +3,22 @@ using ImGuiNET;
using System; using System;
using System.Numerics; using System.Numerics;
namespace SamplePlugin namespace CurrencyAlert
{ {
public enum CurrencySlot
{
StormSeals = 1,
WolfMarks = 4,
Poetics = 6,
AlliedSeals = 8
};
// It is good to have this be disposable in general, in case you ever need it // It is good to have this be disposable in general, in case you ever need it
// to do any cleanup // to do any cleanup
class PluginUI : IDisposable class PluginUI : IDisposable
{ {
private Configuration configuration; private Configuration configuration;
// this extra bool exists for ImGui, since you can't ref a property
private bool visible = false;
public bool Visible
{
get { return this.visible; }
set { this.visible = value; }
}
private bool settingsVisible = false; private bool settingsVisible = false;
public bool SettingsVisible public bool SettingsVisible
{ {
@ -26,13 +26,16 @@ namespace SamplePlugin
set { this.settingsVisible = value; } set { this.settingsVisible = value; }
} }
//public unsafe InventoryManager* InventoryManager { get; } private bool poeticsAlertVisible = false;
public bool PoeticsAlertVisible
{
get { return this.poeticsAlertVisible; }
set { this.poeticsAlertVisible = value; }
}
// passing in the image here just for simplicity
public PluginUI(Configuration configuration) public PluginUI(Configuration configuration)
{ {
this.configuration = configuration; this.configuration = configuration;
//this.InventoryManager = InventoryManager.Instance();
} }
public void Dispose() public void Dispose()
@ -65,22 +68,14 @@ namespace SamplePlugin
// Allied Seal: 8 // Allied Seal: 8
// Company Seals: 1,2,3 // Company Seals: 1,2,3
uint poetics = currencyContainer->GetInventorySlot(6)->Quantity; uint poetics = currencyContainer->GetInventorySlot((int) CurrencySlot.Poetics)->Quantity;
uint wolfMarks = currencyContainer->GetInventorySlot(4)->Quantity;
uint stormSeals = currencyContainer->GetInventorySlot(1)->Quantity;
uint serpentSeals = currencyContainer->GetInventorySlot(2)->Quantity;
uint flameSeals = currencyContainer->GetInventorySlot(3)->Quantity;
bool poeticsThresholdEnabled = this.configuration.PoeticsThresholdEnabled;
uint poeticsThreshold = (uint) this.configuration.PoeticsThreshold; uint poeticsThreshold = (uint) this.configuration.PoeticsThreshold;
Visible = false; PoeticsAlertVisible = poeticsThresholdEnabled && poetics >= poeticsThreshold;
if (poetics >= poeticsThreshold) if (!PoeticsAlertVisible)
{
Visible = true;
}
if (!Visible)
{ {
return; return;
} }
@ -88,17 +83,9 @@ 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("DEPENSE TES POETICS MERDE", ref this.poeticsAlertVisible, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse | ImGuiWindowFlags.AlwaysAutoResize))
{ {
if (ImGui.Button("Show Settings")) ImGui.Text("DEPENSE TES POETICS MEEEEERDE");
{
SettingsVisible = true;
}
if (poetics >= poeticsThreshold)
{
ImGui.Text("DEPENSE TES POETICS MERDE");
}
} }
ImGui.End(); ImGui.End();
@ -112,16 +99,23 @@ namespace SamplePlugin
return; return;
} }
ImGui.SetNextWindowSize(new Vector2(232, 75), ImGuiCond.Always); ImGui.SetNextWindowSize(new Vector2(330, 120), ImGuiCond.Always);
if (ImGui.Begin("A Wonderful Configuration Window", ref this.settingsVisible, if (ImGui.Begin("Currency Alert Configuration Window", ref this.settingsVisible,
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)) ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse))
{ {
// can't ref a property, so use a local copy var poeticsThresholdEnabledConfig = this.configuration.PoeticsThresholdEnabled;
var configValue = this.configuration.PoeticsThreshold;
if (ImGui.InputInt("Poetics Threshold", ref configValue)) if (ImGui.Checkbox("Poetics Threshold Enabled", ref poeticsThresholdEnabledConfig))
{ {
this.configuration.PoeticsThreshold = configValue; this.configuration.PoeticsThresholdEnabled = poeticsThresholdEnabledConfig;
// can save immediately on change, if you don't want to provide a "Save and Close" button this.configuration.Save();
}
var poeticsThresholdConfig = this.configuration.PoeticsThreshold;
if (ImGui.InputInt("Poetics Threshold", ref poeticsThresholdConfig, 1, 1, this.configuration.PoeticsThresholdEnabled ? ImGuiInputTextFlags.None : ImGuiInputTextFlags.ReadOnly))
{
this.configuration.PoeticsThreshold = poeticsThresholdConfig;
this.configuration.Save(); this.configuration.Save();
} }
} }