fix: handle reset properly

This commit is contained in:
Anna 2024-07-27 20:08:48 -04:00
parent c1aeff4684
commit 953016e733
Signed by: anna
GPG Key ID: D0943384CD9F87D1
3 changed files with 130 additions and 83 deletions

View File

@ -3,6 +3,7 @@ using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
namespace PartyDamage; namespace PartyDamage;
public class Evaluator { public class Evaluator {
public required Guid Id { get; init; } public required Guid Id { get; init; }
public required string Name { get; init; } public required string Name { get; init; }
@ -21,16 +22,23 @@ public class Evaluator {
} }
foreach (var payload in line.Payloads) { foreach (var payload in line.Payloads) {
if (payload is TextPayload text) { if (payload is not TextPayload text) {
var newText = new StringBuilder(); continue;
var upper = true; }
foreach (var ch in text.Text!) {
newText.Append(upper ? char.ToUpperInvariant(ch) : char.ToLowerInvariant(ch)); var newText = new StringBuilder();
upper = !upper; var upper = true;
foreach (var ch in text.Text!) {
if (!char.IsLetter(ch)) {
newText.Append(ch);
continue;
} }
text.Text = newText.ToString(); newText.Append(upper ? char.ToUpperInvariant(ch) : char.ToLowerInvariant(ch));
upper = !upper;
} }
text.Text = newText.ToString();
} }
return line; return line;
@ -80,10 +88,8 @@ public class Evaluator {
Name = "G'raha Tia", Name = "G'raha Tia",
BattleTalkImage = 73012, BattleTalkImage = 73012,
Lines = new Dictionary<Evaluation, SeString[]> { Lines = new Dictionary<Evaluation, SeString[]> {
}, },
}, },
]; ];
} }

View File

@ -47,6 +47,9 @@ public class Plugin : IDalamudPlugin {
[PluginService] [PluginService]
internal IDataManager DataManager { get; init; } internal IDataManager DataManager { get; init; }
// [PluginService]
// internal ITextureProvider TextureProvider { get; init; }
internal Configuration Config { get; } internal Configuration Config { get; }
private Client Client { get; } private Client Client { get; }
internal PluginUi Ui { get; } internal PluginUi Ui { get; }
@ -177,7 +180,7 @@ public class Plugin : IDalamudPlugin {
var job = this.DataManager.GetExcelSheet<ClassJob>()! var job = this.DataManager.GetExcelSheet<ClassJob>()!
.FirstOrDefault(j => j.Abbreviation.RawString.Equals(combatant.JobAbbr, StringComparison.InvariantCultureIgnoreCase)); .FirstOrDefault(j => j.Abbreviation.RawString.Equals(combatant.JobAbbr, StringComparison.InvariantCultureIgnoreCase));
return job?.ClassJobCategory.Row == player.ClassJob.GameData?.ClassJobCategory.Row; return job?.Role == player.ClassJob.GameData?.Role;
}) })
.ToList(); .ToList();
combatants.Sort((a, b) => a.EncDps.CompareTo(b.EncDps)); combatants.Sort((a, b) => a.EncDps.CompareTo(b.EncDps));
@ -300,10 +303,11 @@ public class Plugin : IDalamudPlugin {
AddonPartyList* list, AddonPartyList* list,
BattleChara* chara, BattleChara* chara,
int listIndex, int listIndex,
bool includeBar,
bool includeTargeted bool includeTargeted
) { ) {
var unit = list->PartyMembers[listIndex]; var unit = list->PartyMembers[listIndex];
if (unit.TargetGlow != null && (includeTargeted || list->TargetedIndex != listIndex)) { if (includeBar && unit.TargetGlow != null && (includeTargeted || list->TargetedIndex != listIndex)) {
unit.TargetGlow->SetAlpha(255); unit.TargetGlow->SetAlpha(255);
unit.TargetGlow->SetScaleX(0); unit.TargetGlow->SetScaleX(0);
unit.TargetGlow->AddRed = 0; unit.TargetGlow->AddRed = 0;
@ -388,7 +392,7 @@ public class Plugin : IDalamudPlugin {
private unsafe void ResetMembers(AddonPartyList* list) { private unsafe void ResetMembers(AddonPartyList* list) {
var members = AgentHUD.Instance()->PartyMembers; var members = AgentHUD.Instance()->PartyMembers;
for (var i = 0; i < members.Length && i < list->PartyMembers.Length; i++) { for (var i = 0; i < members.Length && i < list->PartyMembers.Length; i++) {
this.ResetMember(list, members[i].Object, i, false); this.ResetMember(list, members[i].Object, i, true, false);
} }
} }
@ -430,7 +434,7 @@ public class Plugin : IDalamudPlugin {
if (this.Config.Alternate && !this._showDps) { if (this.Config.Alternate && !this._showDps) {
var isCaster = hasChara && Array.IndexOf(this._manaUsers, chara->ClassJob) != -1; var isCaster = hasChara && Array.IndexOf(this._manaUsers, chara->ClassJob) != -1;
if (!this.Config.ManaModeAlternateOnlyManaUsers || isCaster) { if (!this.Config.ManaModeAlternateOnlyManaUsers || isCaster) {
this.ResetMember(list, chara, listIndex, true); this.ResetMember(list, chara, listIndex, false, false);
return; return;
} }
} }

View File

@ -30,95 +30,132 @@ public class PluginUi : IDisposable {
var anyChanged = false; var anyChanged = false;
// ImGui.TextUnformatted("Meter mode"); if (!ImGui.BeginTabBar("##main-tab-bar")) {
// if (ImGui.BeginCombo("##mode", Enum.GetName(this.Plugin.Config.Mode))) { return;
// 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%%")) {
anyChanged = true;
this.Plugin.Config.BarAlpha = Math.Clamp(barAlpha / 100, 0, 1);
} }
if (ImGui.TreeNodeEx("Advanced colour options")) { using var endTabBar = new OnDispose(ImGui.EndTabBar);
using var treePop = new OnDispose(ImGui.TreePop);
anyChanged |= ImGui.SliderInt("Add red", ref this.Plugin.Config.BarAddRed, 0, 255); if (ImGui.BeginTabItem("Meter")) {
anyChanged |= ImGui.SliderInt("Add green", ref this.Plugin.Config.BarAddGreen, 0, 255); using var endTabItem = new OnDispose(ImGui.EndTabItem);
anyChanged |= ImGui.SliderInt("Add blue", ref this.Plugin.Config.BarAddBlue, 0, 255);
anyChanged |= ImGui.SliderInt("Multiply red", ref this.Plugin.Config.BarMulRed, 0, 100); // ImGui.TextUnformatted("Meter mode");
anyChanged |= ImGui.SliderInt("Multiply green", ref this.Plugin.Config.BarMulGreen, 0, 100); // if (ImGui.BeginCombo("##mode", Enum.GetName(this.Plugin.Config.Mode))) {
anyChanged |= ImGui.SliderInt("Multiply blue", ref this.Plugin.Config.BarMulBlue, 0, 100); // 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%%")) {
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);
}
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();
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);
}
} }
anyChanged |= ImGui.Checkbox("Alternate between values", ref this.Plugin.Config.Alternate); if (ImGui.BeginTabItem("Evaluations")) {
using (ImGuiHelper.DisabledUnless(this.Plugin.Config.Alternate)) { using var endTabItem = new OnDispose(ImGui.EndTabItem);
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 })) { ImGui.PushTextWrapPos();
anyChanged |= ImGui.Checkbox("Only alternate on jobs that use mana", ref this.Plugin.Config.ManaModeAlternateOnlyManaUsers); using var popTextWrapPos = new OnDispose(ImGui.PopTextWrapPos);
}
var textColour = ConvertRgba(this.Plugin.Config.TextColour); 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.");
if (ImGui.ColorEdit3("DPS text colour", ref textColour)) { ImGui.Separator();
anyChanged = true;
this.Plugin.Config.TextColour = ConvertRgba(textColour);
}
if (ImGui.TreeNodeEx("Advanced colour options##text")) { anyChanged |= ImGui.Checkbox("Show an NPC text bubble rating your performance after an encounter", ref this.Plugin.Config.UseEvaluatorNpc);
using var treePop = new OnDispose(ImGui.TreePop); using (ImGuiHelper.DisabledUnless(this.Plugin.Config.UseEvaluatorNpc)) {
var current = Evaluator.Evaluators.FirstOrDefault(e => e.Id == this.Plugin.Config.EvaluatorId);
var preview = current == null
? "None"
: current.Name;
if (ImGui.BeginCombo("Evaluator", preview)) {
using var endCombo = new OnDispose(ImGui.EndCombo);
anyChanged |= ImGui.SliderInt("Add red", ref this.Plugin.Config.TextAddRed, 0, 255); if (ImGui.Selectable("None", this.Plugin.Config.EvaluatorId == Guid.Empty)) {
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);
}
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);
}
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
? "None"
: 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;
this.Plugin.Config.EvaluatorId = Guid.Empty;
}
foreach (var evaluator in Evaluator.Evaluators) {
if (ImGui.Selectable(evaluator.Name, this.Plugin.Config.EvaluatorId == evaluator.Id)) {
anyChanged = true; anyChanged = true;
this.Plugin.Config.EvaluatorId = evaluator.Id; this.Plugin.Config.EvaluatorId = Guid.Empty;
}
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;
}
} }
} }
} }
} }
if (anyChanged) { if (anyChanged) {
this.Plugin.SaveConfig(); this.Plugin.SaveConfig();
} }
// 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));
// }
// }
} }
// private int _imageId = 73000;
private static Vector3 ConvertRgba(uint colour) { private static Vector3 ConvertRgba(uint colour) {
var red = colour >> 24; var red = colour >> 24;
var green = (colour >> 16) & 0xFF; var green = (colour >> 16) & 0xFF;