diff --git a/Configuration.cs b/Configuration.cs index a2fb6b2..8ee18a8 100644 --- a/Configuration.cs +++ b/Configuration.cs @@ -7,6 +7,12 @@ public class Configuration : IPluginConfiguration { public bool UseDpsBar = true; 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 bool Alternate = true; public bool ManaModeAlternateOnlyManaUsers = true; @@ -17,4 +23,4 @@ public class Configuration : IPluginConfiguration { public enum MeterMode { Name, Mana, -} \ No newline at end of file +} diff --git a/Plugin.cs b/Plugin.cs index 8c56e90..b7f370b 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Globalization; +using System.Text; using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.Addon.Lifecycle.AddonArgTypes; using Dalamud.IoC; @@ -43,8 +44,9 @@ public class Plugin : IDalamudPlugin { private Stopwatch Watch { get; } = Stopwatch.StartNew(); private bool _ranLastTick; + private bool _showDps = true; - private readonly byte[] ManaUsers = [ + private readonly byte[] _manaUsers = [ 6, // cnj 7, // thm 19, // pld @@ -129,6 +131,11 @@ public class Plugin : IDalamudPlugin { 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++) { var (name, membersIdx) = names[i]; var lookupName = name == playerName @@ -158,6 +165,12 @@ public class Plugin : IDalamudPlugin { if (list->TargetedIndex != i) { unit.TargetGlow->SetAlpha(255); 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); } @@ -174,7 +187,17 @@ public class Plugin : IDalamudPlugin { left->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 { RGBA = 0xFFFFFFFF, }; @@ -195,34 +218,31 @@ public class Plugin : IDalamudPlugin { ? 0 : 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) { var left = (AtkTextNode*) member.MPGaugeBar->GetTextNodeById(2); var right = (AtkTextNode*) member.MPGaugeBar->GetTextNodeById(3); - if (this.Config.Alternate) { - var isCaster = Array.IndexOf(this.ManaUsers, chara->ClassJob) != -1; + if (this.Config.Alternate && !this._showDps) { + var isCaster = Array.IndexOf(this._manaUsers, chara->ClassJob) != -1; if (!this.Config.ManaModeAlternateOnlyManaUsers || isCaster) { - var elapsedSeconds = this.Watch.Elapsed.Seconds; - if (elapsedSeconds >= this.Config.AlternateSeconds * 2) { - this.Watch.Restart(); - } else if (elapsedSeconds >= this.Config.AlternateSeconds) { - left->TextColor = new ByteColor { - RGBA = 0xFFFFFFFF, - }; - right->TextColor = left->TextColor; + left->TextColor = new ByteColor { + RGBA = 0xFFFFFFFF, + }; + right->TextColor = left->TextColor; - var manaString = chara->Mana.ToString(CultureInfo.InvariantCulture); - left->SetText(manaString[..^2]); - right->SetText(manaString[^2..]); + var manaString = chara->Mana.ToString(CultureInfo.InvariantCulture); + left->SetText(manaString[..^2]); + right->SetText(manaString[^2..]); - if (this.Watch.Elapsed.Seconds >= this.Config.AlternateSeconds * 2) { - this.Watch.Restart(); - } - - return; - } + return; } } @@ -262,22 +282,13 @@ public class Plugin : IDalamudPlugin { _ => $"{combatant.EncDps / 1_000_000_000:N2}B", }; - if (this.Config.Alternate) { - var elapsedSeconds = this.Watch.Elapsed.Seconds; - if (elapsedSeconds >= this.Config.AlternateSeconds * 2) { - this.Watch.Restart(); - } else if (elapsedSeconds >= this.Config.AlternateSeconds) { - member.Name->TextColor = new ByteColor { - RGBA = 0xFFFFFFFF, - }; - member.Name->SetText(chara->Name); + if (this.Config.Alternate && !this._showDps) { + member.Name->TextColor = new ByteColor { + RGBA = 0xFFFFFFFF, + }; + member.Name->SetText(chara->Name); - if (this.Watch.Elapsed.Seconds >= this.Config.AlternateSeconds * 2) { - this.Watch.Restart(); - } - - return; - } + return; } member.Name->SetText(dpsText); diff --git a/PluginUi.cs b/PluginUi.cs index b763479..59f26a4 100644 --- a/PluginUi.cs +++ b/PluginUi.cs @@ -18,6 +18,16 @@ public class PluginUi : IDisposable { } 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; 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); 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); + } + 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.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); } 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; this.Plugin.Config.DpsColour = ConvertRgba(textColour); } + + if (anyChanged) { + this.Plugin.SaveConfig(); + } } private static Vector3 ConvertRgba(uint colour) { - var red = colour & 0xFF; - var green = (colour >> 8) & 0xFF; - var blue = (colour >> 16) & 0xFF; - // var alpha = colour >> 24; + var red = colour >> 24; + var green = (colour >> 16) & 0xFF; + var blue = (colour >> 8) & 0xFF; + // var alpha = colour & 0xFF; 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); return (red << 24) - | (green << 16) - | (blue << 8) - | 0xFF; + | (green << 16) + | (blue << 8) + | 0xFF; } -} \ No newline at end of file +}