From 41884b05aceab35184086a995ac201d4ebbd173c Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 28 Jul 2024 16:35:38 -0400 Subject: [PATCH] feat: add scaling modes and filters --- Configuration.cs | 12 +++++++++ Plugin.cs | 65 ++++++++++++++++++++++++++++++++++++++++++++--- PluginUi.cs | 66 ++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 125 insertions(+), 18 deletions(-) diff --git a/Configuration.cs b/Configuration.cs index bb35dfc..4868739 100644 --- a/Configuration.cs +++ b/Configuration.cs @@ -6,6 +6,8 @@ public class Configuration : IPluginConfiguration { public int Version { get; set; } = 1; public bool UseDpsBar = true; + public DpsBarMode DpsBarMode = DpsBarMode.Party; + public bool DpsBarScaleToMax = true; public float BarAlpha = 0.5f; public int BarAddRed; public int BarAddGreen; @@ -28,6 +30,7 @@ public class Configuration : IPluginConfiguration { public float ClearDelaySeconds = 10; public bool UseEvaluatorNpc; public Guid EvaluatorId = Guid.Empty; + public Dictionary EvaluationThresholds = new() { [Evaluation.Best] = 0.85f, [Evaluation.Good] = 0.65f, @@ -35,12 +38,15 @@ public class Configuration : IPluginConfiguration { [Evaluation.Poor] = 0.25f, [Evaluation.Awful] = 0f, }; + public int EvaluationMinCombatants = 4; public int EvaluationMinSameRole; + public Dictionary EvaluatorsRandomEnabled = Evaluator.Evaluators.ToDictionary( e => e.Id, e => e.Default ); + public float EvaluationLength = 5f; public bool BlendEvaluations; } @@ -49,3 +55,9 @@ public enum MeterMode { Name, Mana, } + +public enum DpsBarMode { + Encounter, + Party, + Alliance, +} diff --git a/Plugin.cs b/Plugin.cs index 5c2f69a..bafa3b6 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -333,7 +333,7 @@ public class Plugin : IDalamudPlugin { continue; } - this.UpdateMember(list, i, member.Object, data.Encounter, combatant); + this.UpdateMember(list, i, member.Object, data.Encounter, combatant, data.Combatants.Values); } return false; @@ -436,21 +436,78 @@ public class Plugin : IDalamudPlugin { } } + private unsafe string[] GetPartyNames(bool alliance) { + var group = GroupManager.Instance()->GetGroup(); + if (group == null) { + return []; + } + + var length = group->PartyMembers.Length; + if (alliance) { + length += group->AllianceMembers.Length; + } + + var members = new string[length]; + int i; + for (i = 0; i < group->PartyMembers.Length; i++) { + var member = group->PartyMembers[i]; + members[i] = member.NameString; + } + + if (alliance) { + for (var j = 0; j < group->AllianceMembers.Length; j++) { + var member = group->AllianceMembers[j]; + members[i + j] = member.NameString; + } + } + + return members; + } + private unsafe void UpdateMember( AddonPartyList* list, int listIndex, BattleChara* chara, Encounter encounter, - Combatant combatant + Combatant combatant, + IEnumerable combatants ) { var member = list->PartyMembers[listIndex]; if (this.Config.UseDpsBar && member.TargetGlow != null) { + float denominator; + switch (this.Config.DpsBarMode) { + case DpsBarMode.Encounter: { + denominator = combatants.Select(c => c.EncDps).Max(); + break; + } + case DpsBarMode.Party: { + var party = this.GetPartyNames(false); + denominator = combatants + .Where(c => c.Name == "YOU" || party.Contains(c.Name)) + .Select(c => c.EncDps) + .Max(); + break; + } + case DpsBarMode.Alliance: { + var alliance = this.GetPartyNames(true); + denominator = combatants + .Where(c => c.Name == "YOU" || alliance.Contains(c.Name)) + .Select(c => c.EncDps) + .Max(); + break; + } + default: { + denominator = encounter.EncDps; + break; + } + } + member.TargetGlow->ToggleVisibility(true); member.TargetGlow->SetAlpha((byte) Math.Round(this.Config.BarAlpha * 255)); member.TargetGlow->SetScaleX( - encounter.EncDps == 0 + denominator == 0 ? 0 - : combatant.EncDps / encounter.EncDps + : combatant.EncDps / denominator ); member.TargetGlow->AddRed = (byte) Math.Clamp(this.Config.BarAddRed, 0, 255); member.TargetGlow->AddGreen = (byte) Math.Clamp(this.Config.BarAddGreen, 0, 255); diff --git a/PluginUi.cs b/PluginUi.cs index 5cb6e63..8a630d5 100644 --- a/PluginUi.cs +++ b/PluginUi.cs @@ -55,22 +55,60 @@ public class PluginUi : IDisposable { // } 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); + using (ImGuiHelper.DisabledUnless(this.Plugin.Config.UseDpsBar)) { + if (ImGui.BeginCombo("Bar mode", Enum.GetName(this.Plugin.Config.DpsBarMode))) { + using var endCombo = new OnDispose(ImGui.EndCombo); + + foreach (var mode in Enum.GetValues()) { + if (ImGui.Selectable(Enum.GetName(mode), this.Plugin.Config.DpsBarMode == mode)) { + anyChanged = true; + this.Plugin.Config.DpsBarMode = mode; + } + } + } + + var scalePreview = this.Plugin.Config.DpsBarScaleToMax + ? "Max DPS" + : "Total DPS"; + if (ImGui.BeginCombo("Bar scale", scalePreview)) { + using var endCombo = new OnDispose(ImGui.EndCombo); + + if (ImGui.Selectable("Max DPS", this.Plugin.Config.DpsBarScaleToMax)) { + anyChanged = true; + this.Plugin.Config.DpsBarScaleToMax = true; + } + + if (ImGui.Selectable("Total DPS", !this.Plugin.Config.DpsBarScaleToMax)) { + anyChanged = true; + this.Plugin.Config.DpsBarScaleToMax = false; + } + + foreach (var mode in Enum.GetValues()) { + if (ImGui.Selectable(Enum.GetName(mode), this.Plugin.Config.DpsBarMode == mode)) { + anyChanged = true; + this.Plugin.Config.DpsBarMode = mode; + } + } + } + + 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); + } + + if (ImGui.TreeNodeEx("Advanced colour options")) { + using var treePop = new OnDispose(ImGui.TreePop); + + 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); + } } - if (ImGui.TreeNodeEx("Advanced colour options")) { - using var treePop = new OnDispose(ImGui.TreePop); - - 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();