CurrencyAlertClassic/SamplePlugin/PluginUI.cs

143 lines
4.8 KiB
C#
Raw Normal View History

2022-01-05 14:46:15 +00:00
using CurrencyAlert.Enum;
using Dalamud.Game.Gui;
using Dalamud.IoC;
using FFXIVClientStructs.FFXIV.Client.Game;
2021-12-11 13:27:58 +00:00
using ImGuiNET;
using System;
2022-01-05 14:46:15 +00:00
using System.Collections.Generic;
2021-12-11 13:27:58 +00:00
using System.Numerics;
namespace CurrencyAlert
{
class PluginUI : IDisposable
{
private Configuration configuration;
private bool settingsVisible = false;
public bool SettingsVisible
{
2022-01-05 14:46:15 +00:00
get { return settingsVisible; }
set { settingsVisible = value; }
2021-12-11 13:27:58 +00:00
}
2022-01-05 14:46:15 +00:00
private bool debugVisible = false;
public bool DebugVisible
2021-12-11 13:27:58 +00:00
{
2022-01-05 14:46:15 +00:00
get { return debugVisible; }
set { debugVisible = value; }
2021-12-11 13:27:58 +00:00
}
2022-01-05 14:46:15 +00:00
public Dictionary<Currency, bool> AlertVisible { get; set; } = new Dictionary<Currency, bool>();
2021-12-11 13:27:58 +00:00
public PluginUI(Configuration configuration)
{
this.configuration = configuration;
2022-01-05 14:46:15 +00:00
EnumHelper.Each<Currency>(currency => this.AlertVisible[currency] = false);
2021-12-11 00:28:51 +00:00
}
2021-12-11 13:27:58 +00:00
public void Dispose()
{
}
2022-01-05 14:46:15 +00:00
2021-12-11 13:27:58 +00:00
public void Draw()
{
DrawMainWindow();
2022-01-05 14:46:15 +00:00
if (this.SettingsVisible)
DrawSettingsWindow();
if (this.DebugVisible)
DrawDebugWindow();
2021-12-11 13:27:58 +00:00
}
public void DrawMainWindow()
{
2022-01-05 14:46:15 +00:00
EnumHelper.Each<Currency>(currency =>
2021-12-11 00:28:51 +00:00
{
2022-01-05 14:46:15 +00:00
if (!this.AlertVisible[currency])
2021-12-11 00:28:51 +00:00
return;
2022-01-05 14:46:15 +00:00
ImGui.SetNextWindowSize(new Vector2(375, 10), ImGuiCond.FirstUseEver);
ImGui.SetNextWindowSizeConstraints(new Vector2(375, 10), new Vector2(float.MaxValue, float.MaxValue));
var isVisible = this.AlertVisible[currency];
2021-12-11 11:02:01 +00:00
2022-01-05 14:46:15 +00:00
if (ImGui.Begin("Currency Alert", ref isVisible,
ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse |
ImGuiWindowFlags.AlwaysAutoResize |
ImGuiWindowFlags.NoTitleBar |
ImGuiWindowFlags.NoFocusOnAppearing
))
2021-12-11 00:28:51 +00:00
{
2022-01-05 14:46:15 +00:00
ImGui.Text($"You need to spend your {currency}");
2021-12-11 00:28:51 +00:00
}
2021-12-11 11:02:01 +00:00
2021-12-11 00:28:51 +00:00
ImGui.End();
2022-01-05 14:46:15 +00:00
});
}
2021-12-11 13:27:58 +00:00
public void DrawSettingsWindow()
{
2022-01-05 14:46:15 +00:00
ImGui.SetNextWindowSize(new Vector2(400, 600), ImGuiCond.Always);
2021-12-11 13:27:58 +00:00
if (ImGui.Begin("Currency Alert Configuration Window", ref this.settingsVisible,
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse))
{
2022-01-05 14:46:15 +00:00
EnumHelper.Each<Currency>(currency =>
2021-12-11 13:27:58 +00:00
{
2022-01-05 14:46:15 +00:00
var alertEnabled = this.configuration.AlertEnabled[currency];
if (ImGui.Checkbox($"{currency.ToString()} Alert Enabled", ref alertEnabled))
{
this.configuration.AlertEnabled[currency] = alertEnabled;
this.configuration.Save();
}
var thresholdValue = this.configuration.Threshold[currency];
if (ImGui.InputInt($"{currency.ToString()} Threshold Value", ref thresholdValue, 1, 1,
this.configuration.AlertEnabled[currency] ? ImGuiInputTextFlags.None : ImGuiInputTextFlags.ReadOnly))
{
this.configuration.Threshold[currency] = thresholdValue;
this.configuration.Save();
}
});
}
#if DEBUG
if (ImGui.Button("Open Debug"))
this.DebugVisible = true;
#endif
ImGui.End();
}
2021-12-11 13:27:58 +00:00
2022-01-05 14:46:15 +00:00
public void DrawDebugWindow()
{
ImGui.SetNextWindowSize(new Vector2(375, 330), ImGuiCond.FirstUseEver);
ImGui.SetNextWindowSizeConstraints(new Vector2(375, 330), new Vector2(float.MaxValue, float.MaxValue));
2021-12-11 13:27:58 +00:00
2022-01-05 14:46:15 +00:00
if (ImGui.Begin("Currency Alert Debug", ref this.debugVisible))
{
unsafe
2021-12-11 13:27:58 +00:00
{
2022-01-05 14:46:15 +00:00
InventoryManager* inventoryManager = InventoryManager.Instance();
InventoryContainer* currencyContainer = inventoryManager->GetInventoryContainer(InventoryType.Currency);
for (var i = 0; i < 100000; ++i)
{
var item = currencyContainer->GetInventorySlot(i);
if (item == null)
continue;
ImGui.Text($"Index: {i} Value: {item->Quantity}");
}
2021-12-11 13:27:58 +00:00
}
}
2022-01-05 14:46:15 +00:00
2021-12-11 13:27:58 +00:00
ImGui.End();
}
}
}