PartyDamage/PluginUi.cs

203 lines
9.0 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() {
2024-07-25 08:32:25 +00:00
if (!this.Visible) {
return;
}
ImGui.SetNextWindowSize(new Vector2(700, 300), ImGuiCond.FirstUseEver);
using var end = new OnDispose(ImGui.End);
if (!ImGui.Begin("Party Damage", ref this.Visible)) {
return;
}
2024-07-25 06:50:32 +00:00
var anyChanged = false;
2024-07-28 00:08:48 +00:00
if (!ImGui.BeginTabBar("##main-tab-bar")) {
return;
2024-07-25 06:50:32 +00:00
}
2024-07-28 00:08:48 +00:00
using var endTabBar = new OnDispose(ImGui.EndTabBar);
2024-07-25 08:32:25 +00:00
2024-07-28 00:08:48 +00:00
if (ImGui.BeginTabItem("Meter")) {
using var endTabItem = new OnDispose(ImGui.EndTabItem);
2024-07-25 08:32:25 +00:00
2024-07-28 00:08:48 +00:00
// ImGui.TextUnformatted("Meter mode");
// if (ImGui.BeginCombo("##mode", Enum.GetName(this.Plugin.Config.Mode))) {
// using var endCombo = new OnDispose(ImGui.EndCombo);
2024-07-25 06:50:32 +00:00
2024-07-28 00:08:48 +00:00
// 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;
// }
// }
// }
2024-07-25 06:50:32 +00:00
2024-07-28 00:08:48 +00:00
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%%")) {
anyChanged = true;
this.Plugin.Config.BarAlpha = Math.Clamp(barAlpha / 100, 0, 1);
}
2024-07-25 20:01:02 +00:00
2024-07-28 00:08:48 +00:00
if (ImGui.TreeNodeEx("Advanced colour options")) {
using var treePop = new OnDispose(ImGui.TreePop);
2024-07-25 20:01:02 +00:00
2024-07-28 00:08:48 +00:00
anyChanged |= ImGui.SliderInt("Add red", ref this.Plugin.Config.BarAddRed, 0, 255);
anyChanged |= ImGui.SliderInt("Add green", ref this.Plugin.Config.BarAddGreen, 0, 255);
anyChanged |= ImGui.SliderInt("Add blue", ref this.Plugin.Config.BarAddBlue, 0, 255);
anyChanged |= ImGui.SliderInt("Multiply red", ref this.Plugin.Config.BarMulRed, 0, 100);
anyChanged |= ImGui.SliderInt("Multiply green", ref this.Plugin.Config.BarMulGreen, 0, 100);
anyChanged |= ImGui.SliderInt("Multiply blue", ref this.Plugin.Config.BarMulBlue, 0, 100);
}
ImGui.Spacing();
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.1f, 60f);
}
using (ImGuiHelper.DisabledUnless(this.Plugin.Config is { Alternate: true, Mode: MeterMode.Mana })) {
anyChanged |= ImGui.Checkbox("Only alternate on jobs that use mana", ref this.Plugin.Config.ManaModeAlternateOnlyManaUsers);
}
ImGui.Spacing();
var textColour = ConvertRgba(this.Plugin.Config.TextColour);
if (ImGui.ColorEdit3("DPS text colour", ref textColour)) {
anyChanged = true;
this.Plugin.Config.TextColour = ConvertRgba(textColour);
}
if (ImGui.TreeNodeEx("Advanced colour options##text")) {
using var treePop = new OnDispose(ImGui.TreePop);
anyChanged |= ImGui.SliderInt("Add red", ref this.Plugin.Config.TextAddRed, 0, 255);
anyChanged |= ImGui.SliderInt("Add green", ref this.Plugin.Config.TextAddGreen, 0, 255);
anyChanged |= ImGui.SliderInt("Add blue", ref this.Plugin.Config.TextAddBlue, 0, 255);
anyChanged |= ImGui.SliderInt("Multiply red", ref this.Plugin.Config.TextMulRed, 0, 100);
anyChanged |= ImGui.SliderInt("Multiply green", ref this.Plugin.Config.TextMulGreen, 0, 100);
anyChanged |= ImGui.SliderInt("Multiply blue", ref this.Plugin.Config.TextMulBlue, 0, 100);
}
ImGui.Spacing();
2024-07-25 08:32:25 +00:00
2024-07-28 00:08:48 +00:00
anyChanged |= ImGui.Checkbox("Clear results after encounter ends", ref this.Plugin.Config.ClearResultsOnInactive);
using (ImGuiHelper.DisabledUnless(this.Plugin.Config.ClearResultsOnInactive)) {
anyChanged |= ImGui.SliderFloat("Seconds to delay before clearing", ref this.Plugin.Config.ClearDelaySeconds, 0, 300);
}
2024-07-25 22:21:46 +00:00
}
2024-07-28 00:08:48 +00:00
if (ImGui.BeginTabItem("Evaluations")) {
using var endTabItem = new OnDispose(ImGui.EndTabItem);
ImGui.PushTextWrapPos();
using var popTextWrapPos = new OnDispose(ImGui.PopTextWrapPos);
ImGui.TextUnformatted("These evaluations are based on your relative rank compared to other players playing the same role (tank, healer, melee, magical ranged, physical ranged). This means that you will always receive the highest evaluation if you are the only member of your role. These evaluations should not be taken too seriously.");
ImGui.Separator();
2024-07-28 00:08:48 +00:00
anyChanged |= ImGui.Checkbox("Show an NPC text bubble rating your performance after an encounter", ref this.Plugin.Config.UseEvaluatorNpc);
using (ImGuiHelper.DisabledUnless(this.Plugin.Config.UseEvaluatorNpc)) {
var current = Evaluator.Evaluators.FirstOrDefault(e => e.Id == this.Plugin.Config.EvaluatorId);
var preview = current == null
2024-07-28 01:15:28 +00:00
? this.Plugin.Config.EvaluatorId == Evaluator.RandomId
? "Random"
: "None"
2024-07-28 00:08:48 +00:00
: current.Name;
if (ImGui.BeginCombo("Evaluator", preview)) {
using var endCombo = new OnDispose(ImGui.EndCombo);
if (ImGui.Selectable("None", this.Plugin.Config.EvaluatorId == Guid.Empty)) {
anyChanged = true;
2024-07-28 00:08:48 +00:00
this.Plugin.Config.EvaluatorId = Guid.Empty;
}
2024-07-28 01:15:28 +00:00
if (ImGui.Selectable("Random", this.Plugin.Config.EvaluatorId == Evaluator.RandomId)) {
anyChanged = true;
this.Plugin.Config.EvaluatorId = Evaluator.RandomId;
}
2024-07-28 00:08:48 +00:00
foreach (var evaluator in Evaluator.Evaluators) {
if (ImGui.Selectable(evaluator.Name, this.Plugin.Config.EvaluatorId == evaluator.Id)) {
anyChanged = true;
this.Plugin.Config.EvaluatorId = evaluator.Id;
}
}
}
2024-07-28 01:37:57 +00:00
if (ImGui.TreeNodeEx("Evaluation thresholds")) {
using var treePop = new OnDispose(ImGui.TreePop);
ImGui.TextUnformatted("If your rank is equal to or above the thresholds defined below, you will get the ranking specified. For example, if best is set to 85% and good is set to 65% and you were 3/4 (75%), you would be evaluated as good.");
ImGui.Spacing();
foreach (var evaluation in Enum.GetValues<Evaluation>()) {
if (!this.Plugin.Config.EvaluationThresholds.TryGetValue(evaluation, out var threshold)) {
threshold = 0f;
}
threshold *= 100f;
if (ImGui.SliderFloat(Enum.GetName(evaluation), ref threshold, 0, 100)) {
anyChanged = true;
this.Plugin.Config.EvaluationThresholds[evaluation] = Math.Clamp(threshold / 100, 0, 1);
}
}
}
}
}
2024-07-27 20:54:23 +00:00
2024-07-28 00:08:48 +00:00
2024-07-25 08:32:25 +00:00
if (anyChanged) {
this.Plugin.SaveConfig();
}
2024-07-28 00:08:48 +00:00
// ImGui.InputInt("image id", ref this._imageId);
// if (this.Plugin.TextureProvider.TryGetFromGameIcon(new GameIconLookup((uint) this._imageId), out var tex)) {
// if (tex.TryGetWrap(out var wrap, out _)) {
// ImGui.Image(wrap.ImGuiHandle, new Vector2(wrap.Width, wrap.Height));
// }
// }
2024-07-25 06:50:32 +00:00
}
2024-07-28 00:08:48 +00:00
// private int _imageId = 73000;
2024-07-25 06:50:32 +00:00
private static Vector3 ConvertRgba(uint colour) {
2024-07-25 08:32:25 +00:00
var red = colour >> 24;
var green = (colour >> 16) & 0xFF;
var blue = (colour >> 8) & 0xFF;
// var alpha = colour & 0xFF;
2024-07-25 06:50:32 +00:00
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)
2024-07-25 08:32:25 +00:00
| (green << 16)
| (blue << 8)
| 0xFF;
2024-07-25 06:50:32 +00:00
}
2024-07-25 08:32:25 +00:00
}