CurrencyAlertClassic/SamplePlugin/PluginUI.cs

155 lines
5.3 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-06 09:56:52 +00:00
if (ImGui.Begin("Currency Alert", ref isVisible,
2022-01-05 14:46:15 +00:00
ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse |
ImGuiWindowFlags.AlwaysAutoResize |
ImGuiWindowFlags.NoTitleBar |
ImGuiWindowFlags.NoFocusOnAppearing
))
2021-12-11 00:28:51 +00:00
{
2022-01-06 09:56:52 +00:00
var name = EnumHelper.GetAttributeOfType<NameAttribute>(currency).Value;
ImGui.Text($"You need to spend your {name}");
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-06 09:56:52 +00:00
var name = EnumHelper.GetAttributeOfType<NameAttribute>(currency).Value;
2022-01-05 14:46:15 +00:00
var alertEnabled = this.configuration.AlertEnabled[currency];
2022-01-19 10:14:20 +00:00
2022-01-06 09:56:52 +00:00
if (ImGui.Checkbox($"{name} Alert Enabled", ref alertEnabled))
2022-01-05 14:46:15 +00:00
{
this.configuration.AlertEnabled[currency] = alertEnabled;
this.configuration.Save();
}
var thresholdValue = this.configuration.Threshold[currency];
2022-01-06 09:56:52 +00:00
if (ImGui.InputInt($"{name} Threshold Value", ref thresholdValue, 1, 1,
2022-01-05 14:46:15 +00:00
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();
2022-01-19 10:14:20 +00:00
EnumHelper.Each<InventoryType>(type =>
2022-01-05 14:46:15 +00:00
{
2022-01-19 10:14:20 +00:00
InventoryContainer* currencyContainer = inventoryManager->GetInventoryContainer(type);
if (currencyContainer == null)
{
return; // TODO: log something
}
ImGui.Text($"----- {type.ToString()} -----");
for (var i = 0; i < int.MaxValue; ++i)
{
var item = currencyContainer->GetInventorySlot(i);
if (item == null)
break;
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();
}
}
}