PartyDamage/PluginUi.cs

76 lines
2.6 KiB
C#
Raw Normal View History

2024-07-25 06:50:32 +00:00
using System.Numerics;
using ImGuiNET;
namespace PartyDamage;
public class PluginUi : IDisposable {
private Plugin Plugin { get; }
internal bool Visible;
public PluginUi(Plugin plugin) {
this.Plugin = plugin;
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
}
public void Dispose() {
this.Plugin.Interface.UiBuilder.Draw -= this.Draw;
}
private void Draw() {
var anyChanged = false;
ImGui.TextUnformatted("Meter mode");
if (ImGui.BeginCombo("##mode", Enum.GetName(this.Plugin.Config.Mode))) {
using var endCombo = new OnDispose(ImGui.EndCombo);
foreach (var mode in Enum.GetValues<MeterMode>()) {
if (ImGui.Selectable(Enum.GetName(mode), mode == this.Plugin.Config.Mode)) {
anyChanged = true;
this.Plugin.Config.Mode = mode;
}
}
}
anyChanged |= ImGui.Checkbox("Use DPS bars behind party list", ref this.Plugin.Config.UseDpsBar);
var barAlpha = this.Plugin.Config.BarAlpha * 100;
if (ImGui.SliderFloat("Bar opacity", ref barAlpha, 0, 100, "%.2f%%")) {
this.Plugin.Config.BarAlpha = Math.Clamp(barAlpha / 100, 0, 1);
}
anyChanged |= ImGui.Checkbox("Alternate between values", ref this.Plugin.Config.Alternate);
using (ImGuiHelper.DisabledUnless(this.Plugin.Config.Alternate)) {
anyChanged |= ImGui.SliderFloat("Seconds before alternating", ref this.Plugin.Config.AlternateSeconds, 0.5f, 60f);
}
using (ImGuiHelper.DisabledUnless(this.Plugin.Config.Alternate && this.Plugin.Config.Mode == MeterMode.Name)) {
anyChanged |= ImGui.Checkbox("Only alternate on jobs that use mana", ref this.Plugin.Config.ManaModeAlternateOnlyManaUsers);
}
var textColour = ConvertRgba(this.Plugin.Config.DpsColour);
if (ImGui.ColorPicker3("DPS text colour", ref textColour)) {
anyChanged = true;
this.Plugin.Config.DpsColour = ConvertRgba(textColour);
}
}
private static Vector3 ConvertRgba(uint colour) {
var red = colour & 0xFF;
var green = (colour >> 8) & 0xFF;
var blue = (colour >> 16) & 0xFF;
// var alpha = colour >> 24;
return new Vector3(red / 255f, green / 255f, blue / 255f);
}
private static uint ConvertRgba(Vector3 parts) {
var red = (uint) Math.Round(parts.X * 255);
var green = (uint) Math.Round(parts.Y * 255);
var blue = (uint) Math.Round(parts.Z * 255);
return (red << 24)
| (green << 16)
| (blue << 8)
| 0xFF;
}
}