CurrencyAlertClassic/SamplePlugin/PluginUI.cs

132 lines
4.5 KiB
C#
Raw Normal View History

2021-12-11 00:28:51 +00:00
using FFXIVClientStructs.FFXIV.Client.Game;
using ImGuiNET;
using System;
using System.Numerics;
namespace SamplePlugin
{
// It is good to have this be disposable in general, in case you ever need it
// to do any cleanup
class PluginUI : IDisposable
{
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;
public bool SettingsVisible
{
get { return this.settingsVisible; }
set { this.settingsVisible = value; }
2021-12-11 00:28:51 +00:00
}
//public unsafe InventoryManager* InventoryManager { get; }
// passing in the image here just for simplicity
2021-12-11 11:02:01 +00:00
public PluginUI(Configuration configuration)
{
this.configuration = configuration;
2021-12-11 00:28:51 +00:00
//this.InventoryManager = InventoryManager.Instance();
}
public void Dispose()
{
2021-12-11 11:02:01 +00:00
}
public void Draw()
{
// This is our only draw handler attached to UIBuilder, so it needs to be
// able to draw any windows we might have open.
// Each method checks its own visibility/state to ensure it only draws when
// it actually makes sense.
// There are other ways to do this, but it is generally best to keep the number of
// draw delegates as low as possible.
DrawMainWindow();
DrawSettingsWindow();
}
public void DrawMainWindow()
{
2021-12-11 00:28:51 +00:00
unsafe
{
InventoryManager* inventoryManager = InventoryManager.Instance();
InventoryContainer* currencyContainer = inventoryManager->GetInventoryContainer(InventoryType.Currency);
// Poetics: 6
// Wolf Marks: 4
// Allied Seal: 8
// Company Seals: 1,2,3
uint poetics = currencyContainer->GetInventorySlot(6)->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;
uint poeticsThreshold = (uint) this.configuration.PoeticsThreshold;
Visible = false;
if (poetics >= poeticsThreshold)
{
Visible = true;
}
if (!Visible)
{
return;
}
ImGui.SetNextWindowSize(new Vector2(375, 330), ImGuiCond.FirstUseEver);
ImGui.SetNextWindowSizeConstraints(new Vector2(375, 330), new Vector2(float.MaxValue, float.MaxValue));
2021-12-11 11:02:01 +00:00
2021-12-11 00:28:51 +00:00
if (ImGui.Begin("My Amazing Window", ref this.visible, ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse))
{
if (ImGui.Button("Show Settings"))
{
SettingsVisible = true;
}
if (poetics >= poeticsThreshold)
{
ImGui.Text("DEPENSE TES POETICS MERDE");
}
}
2021-12-11 11:02:01 +00:00
2021-12-11 00:28:51 +00:00
ImGui.End();
}
}
public void DrawSettingsWindow()
{
if (!SettingsVisible)
{
return;
}
ImGui.SetNextWindowSize(new Vector2(232, 75), ImGuiCond.Always);
if (ImGui.Begin("A Wonderful Configuration Window", ref this.settingsVisible,
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse))
{
// can't ref a property, so use a local copy
2021-12-11 00:28:51 +00:00
var configValue = this.configuration.PoeticsThreshold;
if (ImGui.InputInt("Poetics Threshold", ref configValue))
{
2021-12-11 00:28:51 +00:00
this.configuration.PoeticsThreshold = configValue;
// can save immediately on change, if you don't want to provide a "Save and Close" button
this.configuration.Save();
}
}
ImGui.End();
}
}
}