feat: add colours

This commit is contained in:
Anna 2024-07-25 04:32:25 -04:00
parent 05e2d87142
commit 3c2bb14f1c
Signed by: anna
GPG Key ID: D0943384CD9F87D1
3 changed files with 91 additions and 48 deletions

View File

@ -7,6 +7,12 @@ public class Configuration : IPluginConfiguration {
public bool UseDpsBar = true; public bool UseDpsBar = true;
public float BarAlpha = 0.5f; public float BarAlpha = 0.5f;
public int BarAddRed;
public int BarAddGreen;
public int BarAddBlue;
public int BarMulRed = 100;
public int BarMulGreen = 100;
public int BarMulBlue = 100;
public MeterMode Mode = MeterMode.Mana; public MeterMode Mode = MeterMode.Mana;
public bool Alternate = true; public bool Alternate = true;
public bool ManaModeAlternateOnlyManaUsers = true; public bool ManaModeAlternateOnlyManaUsers = true;

View File

@ -1,5 +1,6 @@
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Text;
using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.Addon.Lifecycle;
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes; using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using Dalamud.IoC; using Dalamud.IoC;
@ -43,8 +44,9 @@ public class Plugin : IDalamudPlugin {
private Stopwatch Watch { get; } = Stopwatch.StartNew(); private Stopwatch Watch { get; } = Stopwatch.StartNew();
private bool _ranLastTick; private bool _ranLastTick;
private bool _showDps = true;
private readonly byte[] ManaUsers = [ private readonly byte[] _manaUsers = [
6, // cnj 6, // cnj
7, // thm 7, // thm
19, // pld 19, // pld
@ -129,6 +131,11 @@ public class Plugin : IDalamudPlugin {
this._ranLastTick = true; this._ranLastTick = true;
if (this.Watch.Elapsed.TotalMilliseconds > this.Config.AlternateSeconds * 1_000) {
this.Watch.Restart();
this._showDps ^= true;
}
for (var i = 0; i < names.Count; i++) { for (var i = 0; i < names.Count; i++) {
var (name, membersIdx) = names[i]; var (name, membersIdx) = names[i];
var lookupName = name == playerName var lookupName = name == playerName
@ -158,6 +165,12 @@ public class Plugin : IDalamudPlugin {
if (list->TargetedIndex != i) { if (list->TargetedIndex != i) {
unit.TargetGlow->SetAlpha(255); unit.TargetGlow->SetAlpha(255);
unit.TargetGlow->SetScaleX(0); unit.TargetGlow->SetScaleX(0);
unit.TargetGlow->AddRed = 0;
unit.TargetGlow->AddGreen = 0;
unit.TargetGlow->AddBlue = 0;
unit.TargetGlow->MultiplyRed = 100;
unit.TargetGlow->MultiplyGreen = 100;
unit.TargetGlow->MultiplyBlue = 100;
unit.TargetGlow->ToggleVisibility(true); unit.TargetGlow->ToggleVisibility(true);
} }
@ -174,7 +187,17 @@ public class Plugin : IDalamudPlugin {
left->SetText(manaString[..^2]); left->SetText(manaString[..^2]);
right->SetText(manaString[^2..]); right->SetText(manaString[^2..]);
unit.Name->SetText(member.Object->Name); // fixme: need to figure out a way to get the game to repop
var defaultName = new StringBuilder("\ue06a");
foreach (var digit in member.Object->Level.ToString(CultureInfo.InvariantCulture)) {
var offset = digit - '0';
defaultName.Append((char) ('\ue060' + offset));
}
defaultName.Append(' ');
defaultName.Append(member.Object->NameString);
unit.Name->SetText(defaultName.ToString());
unit.Name->TextColor = new ByteColor { unit.Name->TextColor = new ByteColor {
RGBA = 0xFFFFFFFF, RGBA = 0xFFFFFFFF,
}; };
@ -195,34 +218,31 @@ public class Plugin : IDalamudPlugin {
? 0 ? 0
: combatant.EncDps / encounter.EncDps : combatant.EncDps / encounter.EncDps
); );
member.TargetGlow->AddRed = (byte) Math.Clamp(this.Config.BarAddRed, 0, 255);
member.TargetGlow->AddGreen = (byte) Math.Clamp(this.Config.BarAddGreen, 0, 255);
member.TargetGlow->AddBlue = (byte) Math.Clamp(this.Config.BarAddBlue, 0, 255);
member.TargetGlow->MultiplyRed = (byte) Math.Clamp(this.Config.BarMulRed, 0, 100);
member.TargetGlow->MultiplyGreen = (byte) Math.Clamp(this.Config.BarMulGreen, 0, 100);
member.TargetGlow->MultiplyBlue = (byte) Math.Clamp(this.Config.BarMulBlue, 0, 100);
} }
if (this.Config.Mode == MeterMode.Mana) { if (this.Config.Mode == MeterMode.Mana) {
var left = (AtkTextNode*) member.MPGaugeBar->GetTextNodeById(2); var left = (AtkTextNode*) member.MPGaugeBar->GetTextNodeById(2);
var right = (AtkTextNode*) member.MPGaugeBar->GetTextNodeById(3); var right = (AtkTextNode*) member.MPGaugeBar->GetTextNodeById(3);
if (this.Config.Alternate) { if (this.Config.Alternate && !this._showDps) {
var isCaster = Array.IndexOf(this.ManaUsers, chara->ClassJob) != -1; var isCaster = Array.IndexOf(this._manaUsers, chara->ClassJob) != -1;
if (!this.Config.ManaModeAlternateOnlyManaUsers || isCaster) { if (!this.Config.ManaModeAlternateOnlyManaUsers || isCaster) {
var elapsedSeconds = this.Watch.Elapsed.Seconds; left->TextColor = new ByteColor {
if (elapsedSeconds >= this.Config.AlternateSeconds * 2) { RGBA = 0xFFFFFFFF,
this.Watch.Restart(); };
} else if (elapsedSeconds >= this.Config.AlternateSeconds) { right->TextColor = left->TextColor;
left->TextColor = new ByteColor {
RGBA = 0xFFFFFFFF,
};
right->TextColor = left->TextColor;
var manaString = chara->Mana.ToString(CultureInfo.InvariantCulture); var manaString = chara->Mana.ToString(CultureInfo.InvariantCulture);
left->SetText(manaString[..^2]); left->SetText(manaString[..^2]);
right->SetText(manaString[^2..]); right->SetText(manaString[^2..]);
if (this.Watch.Elapsed.Seconds >= this.Config.AlternateSeconds * 2) { return;
this.Watch.Restart();
}
return;
}
} }
} }
@ -262,22 +282,13 @@ public class Plugin : IDalamudPlugin {
_ => $"{combatant.EncDps / 1_000_000_000:N2}B", _ => $"{combatant.EncDps / 1_000_000_000:N2}B",
}; };
if (this.Config.Alternate) { if (this.Config.Alternate && !this._showDps) {
var elapsedSeconds = this.Watch.Elapsed.Seconds; member.Name->TextColor = new ByteColor {
if (elapsedSeconds >= this.Config.AlternateSeconds * 2) { RGBA = 0xFFFFFFFF,
this.Watch.Restart(); };
} else if (elapsedSeconds >= this.Config.AlternateSeconds) { member.Name->SetText(chara->Name);
member.Name->TextColor = new ByteColor {
RGBA = 0xFFFFFFFF,
};
member.Name->SetText(chara->Name);
if (this.Watch.Elapsed.Seconds >= this.Config.AlternateSeconds * 2) { return;
this.Watch.Restart();
}
return;
}
} }
member.Name->SetText(dpsText); member.Name->SetText(dpsText);

View File

@ -18,6 +18,16 @@ public class PluginUi : IDisposable {
} }
private void Draw() { private void Draw() {
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;
}
var anyChanged = false; var anyChanged = false;
ImGui.TextUnformatted("Meter mode"); ImGui.TextUnformatted("Meter mode");
@ -35,30 +45,46 @@ public class PluginUi : IDisposable {
anyChanged |= ImGui.Checkbox("Use DPS bars behind party list", ref this.Plugin.Config.UseDpsBar); anyChanged |= ImGui.Checkbox("Use DPS bars behind party list", ref this.Plugin.Config.UseDpsBar);
var barAlpha = this.Plugin.Config.BarAlpha * 100; var barAlpha = this.Plugin.Config.BarAlpha * 100;
if (ImGui.SliderFloat("Bar opacity", ref barAlpha, 0, 100, "%.2f%%")) { if (ImGui.SliderFloat("Bar opacity", ref barAlpha, 0, 100, "%.2f%%")) {
anyChanged = true;
this.Plugin.Config.BarAlpha = Math.Clamp(barAlpha / 100, 0, 1); 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);
}
anyChanged |= ImGui.Checkbox("Alternate between values", ref this.Plugin.Config.Alternate); anyChanged |= ImGui.Checkbox("Alternate between values", ref this.Plugin.Config.Alternate);
using (ImGuiHelper.DisabledUnless(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); anyChanged |= ImGui.SliderFloat("Seconds before alternating", ref this.Plugin.Config.AlternateSeconds, 0.1f, 60f);
} }
using (ImGuiHelper.DisabledUnless(this.Plugin.Config.Alternate && this.Plugin.Config.Mode == MeterMode.Name)) { 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); anyChanged |= ImGui.Checkbox("Only alternate on jobs that use mana", ref this.Plugin.Config.ManaModeAlternateOnlyManaUsers);
} }
var textColour = ConvertRgba(this.Plugin.Config.DpsColour); var textColour = ConvertRgba(this.Plugin.Config.DpsColour);
if (ImGui.ColorPicker3("DPS text colour", ref textColour)) { if (ImGui.ColorEdit3("DPS text colour", ref textColour)) {
anyChanged = true; anyChanged = true;
this.Plugin.Config.DpsColour = ConvertRgba(textColour); this.Plugin.Config.DpsColour = ConvertRgba(textColour);
} }
if (anyChanged) {
this.Plugin.SaveConfig();
}
} }
private static Vector3 ConvertRgba(uint colour) { private static Vector3 ConvertRgba(uint colour) {
var red = colour & 0xFF; var red = colour >> 24;
var green = (colour >> 8) & 0xFF; var green = (colour >> 16) & 0xFF;
var blue = (colour >> 16) & 0xFF; var blue = (colour >> 8) & 0xFF;
// var alpha = colour >> 24; // var alpha = colour & 0xFF;
return new Vector3(red / 255f, green / 255f, blue / 255f); return new Vector3(red / 255f, green / 255f, blue / 255f);
} }
@ -69,8 +95,8 @@ public class PluginUi : IDisposable {
var blue = (uint) Math.Round(parts.Z * 255); var blue = (uint) Math.Round(parts.Z * 255);
return (red << 24) return (red << 24)
| (green << 16) | (green << 16)
| (blue << 8) | (blue << 8)
| 0xFF; | 0xFF;
} }
} }