From e84654005e18e80ccf654df9372a96817c0aebae Mon Sep 17 00:00:00 2001 From: Kaz Wolfe Date: Sun, 23 Mar 2025 18:28:07 -0700 Subject: [PATCH] fix: Force devs to choose between ValueClamped and ValueUnclamped --- Dalamud/Interface/Animation/Easing.cs | 11 ++++++++++- .../Internal/ActiveNotification.ImGui.cs | 12 ++++++------ .../ImGuiNotification/Internal/ActiveNotification.cs | 2 +- .../Internal/Windows/ComponentDemoWindow.cs | 2 +- .../Internal/Windows/TitleScreenMenuWindow.cs | 10 +++++----- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Dalamud/Interface/Animation/Easing.cs b/Dalamud/Interface/Animation/Easing.cs index a48300a22..8191487f4 100644 --- a/Dalamud/Interface/Animation/Easing.cs +++ b/Dalamud/Interface/Animation/Easing.cs @@ -1,6 +1,8 @@ using System.Diagnostics; using System.Numerics; +using Dalamud.Utility; + namespace Dalamud.Interface.Animation; /// @@ -42,10 +44,17 @@ public abstract class Easing /// public bool IsInverse { get; set; } + /// + /// Gets the current value of the animation, following unclamped logic. + /// + [Obsolete($"This field has been deprecated. Use either {nameof(ValueClamped)} or {nameof(ValueUnclamped)} instead.", true)] + [Api13ToDo("Map this field to ValueClamped, probably.")] + public double Value => this.ValueUnclamped; + /// /// Gets the current value of the animation, from 0 to 1. /// - public double Value => Math.Clamp(this.ValueUnclamped, 0, 1); + public double ValueClamped => Math.Clamp(this.ValueUnclamped, 0, 1); /// /// Gets or sets the current value of the animation, not limited to a range of 0 to 1. diff --git a/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.ImGui.cs b/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.ImGui.cs index 16d58bea5..ab41c5521 100644 --- a/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.ImGui.cs +++ b/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.ImGui.cs @@ -21,8 +21,8 @@ internal sealed partial class ActiveNotification var opacity = Math.Clamp( (float)(this.hideEasing.IsRunning - ? (this.hideEasing.IsDone || ReducedMotions ? 0 : 1f - this.hideEasing.Value) - : (this.showEasing.IsDone || ReducedMotions ? 1 : this.showEasing.Value)), + ? (this.hideEasing.IsDone || ReducedMotions ? 0 : 1f - this.hideEasing.ValueClamped) + : (this.showEasing.IsDone || ReducedMotions ? 1 : this.showEasing.ValueClamped)), 0f, 1f); if (opacity <= 0) @@ -106,7 +106,7 @@ internal sealed partial class ActiveNotification } else if (this.expandoEasing.IsRunning) { - var easedValue = ReducedMotions ? 1f : (float)this.expandoEasing.Value; + var easedValue = ReducedMotions ? 1f : (float)this.expandoEasing.ValueClamped; if (this.underlyingNotification.Minimized) ImGui.PushStyleVar(ImGuiStyleVar.Alpha, opacity * (1f - easedValue)); else @@ -295,8 +295,8 @@ internal sealed partial class ActiveNotification { relativeOpacity = this.underlyingNotification.Minimized - ? 1f - (float)this.expandoEasing.Value - : (float)this.expandoEasing.Value; + ? 1f - (float)this.expandoEasing.ValueClamped + : (float)this.expandoEasing.ValueClamped; } else { @@ -543,7 +543,7 @@ internal sealed partial class ActiveNotification float barL, barR; if (this.DismissReason is not null) { - var v = this.hideEasing.IsDone || ReducedMotions ? 0f : 1f - (float)this.hideEasing.Value; + var v = this.hideEasing.IsDone || ReducedMotions ? 0f : 1f - (float)this.hideEasing.ValueClamped; var midpoint = (this.prevProgressL + this.prevProgressR) / 2f; var length = (this.prevProgressR - this.prevProgressL) / 2f; barL = midpoint - (length * v); diff --git a/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.cs b/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.cs index 607c7c49d..89a175a9e 100644 --- a/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.cs +++ b/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.cs @@ -226,7 +226,7 @@ internal sealed partial class ActiveNotification : IActiveNotification if (Math.Abs(underlyingProgress - this.progressBefore) < 0.000001f || this.progressEasing.IsDone || ReducedMotions) return underlyingProgress; - var state = ReducedMotions ? 1f : Math.Clamp((float)this.progressEasing.Value, 0f, 1f); + var state = ReducedMotions ? 1f : Math.Clamp((float)this.progressEasing.ValueClamped, 0f, 1f); return this.progressBefore + (state * (underlyingProgress - this.progressBefore)); } } diff --git a/Dalamud/Interface/Internal/Windows/ComponentDemoWindow.cs b/Dalamud/Interface/Internal/Windows/ComponentDemoWindow.cs index 0b704990b..c0d2e4c61 100644 --- a/Dalamud/Interface/Internal/Windows/ComponentDemoWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ComponentDemoWindow.cs @@ -147,7 +147,7 @@ internal sealed class ComponentDemoWindow : Window ImGui.Bullet(); ImGui.SetCursorPos(cursor + new Vector2(0, 10)); - ImGui.Text($"{easing.GetType().Name} ({easing.Value})"); + ImGui.Text($"{easing.GetType().Name} ({easing.ValueClamped})"); ImGuiHelpers.ScaledDummy(5); } } diff --git a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs index c1f0b2a67..3b6140b8c 100644 --- a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs +++ b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs @@ -204,7 +204,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable moveEasing.Update(); var finalPos = (i + 1) * this.shadeTexture.Value.Height * scale; - var pos = moveEasing.Value * finalPos; + var pos = moveEasing.ValueClamped * finalPos; // FIXME(goat): Sometimes, easings can overshoot and bring things out of alignment. if (moveEasing.IsDone) @@ -251,7 +251,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable this.fadeOutEasing.Update(); - using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value)) + using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.ValueClamped)) { var i = 0; foreach (var entry in entries) @@ -317,7 +317,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable var initialCursor = ImGui.GetCursorPos(); - using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)shadeEasing.Value)) + using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)shadeEasing.ValueClamped)) { var texture = this.shadeTexture.Value; ImGui.Image(texture.ImGuiHandle, new Vector2(texture.Width, texture.Height) * scale); @@ -367,7 +367,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable if (overrideAlpha) { - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, isFirst ? 1f : (float)logoEasing.Value); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, isFirst ? 1f : (float)logoEasing.ValueClamped); } else if (isFirst) { @@ -392,7 +392,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable if (overrideAlpha) { - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)logoEasing.Value : 0f); + ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)logoEasing.ValueClamped : 0f); } // Drop shadow