feat: add configurable thresholds

This commit is contained in:
Anna 2024-07-27 21:37:57 -04:00
parent 98b06cf34b
commit 5efc92e093
Signed by: anna
GPG Key ID: D0943384CD9F87D1
3 changed files with 45 additions and 17 deletions

View File

@ -28,6 +28,13 @@ public class Configuration : IPluginConfiguration {
public float ClearDelaySeconds = 10; public float ClearDelaySeconds = 10;
public bool UseEvaluatorNpc; public bool UseEvaluatorNpc;
public Guid EvaluatorId = Guid.Empty; public Guid EvaluatorId = Guid.Empty;
public Dictionary<Evaluation, float> EvaluationThresholds = new() {
[Evaluation.Best] = 0.85f,
[Evaluation.Good] = 0.65f,
[Evaluation.Fair] = 0.45f,
[Evaluation.Poor] = 0.25f,
[Evaluation.Awful] = 0f,
};
} }
public enum MeterMode { public enum MeterMode {

View File

@ -188,14 +188,14 @@ public class Plugin : IDalamudPlugin {
.ToList(); .ToList();
combatants.Sort((a, b) => a.EncDps.CompareTo(b.EncDps)); combatants.Sort((a, b) => a.EncDps.CompareTo(b.EncDps));
var rank = (float) (combatants.FindIndex(combatant => combatant.Name == "YOU") + 1) / combatants.Count; var rank = (float) (combatants.FindIndex(combatant => combatant.Name == "YOU") + 1) / combatants.Count;
var evaluation = rank switch { var thresholds = this.Config.EvaluationThresholds.ToList();
>= .85f => Evaluation.Best, thresholds.Sort((a, b) => b.Value.CompareTo(a.Value));
>= .65f => Evaluation.Good, foreach (var threshold in thresholds) {
>= .45f => Evaluation.Fair, if (rank < threshold.Value) {
>= .25f => Evaluation.Poor, continue;
_ => Evaluation.Awful, }
};
var msg = evaluator.GetLineFor(evaluation); var msg = evaluator.GetLineFor(threshold.Key);
if (msg != null) { if (msg != null) {
var bytes = msg.EncodeWithNullTerminator(); var bytes = msg.EncodeWithNullTerminator();
UIModule.Instance()->ShowBattleTalkImage( UIModule.Instance()->ShowBattleTalkImage(
@ -206,6 +206,9 @@ public class Plugin : IDalamudPlugin {
0 0
); );
} }
break;
}
} }
} }
} }

View File

@ -144,6 +144,24 @@ public class PluginUi : IDisposable {
} }
} }
} }
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);
}
}
}
} }
} }