From e5a78c8d54e6d8c70fbfdbf26c319c3f582a7a71 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 31 Oct 2026 14:20:20 -0500 Subject: [PATCH] Animate unit frame bars with ClassicAPI's SmoothStatusBarMixin Health and power bars take SmoothStatusBarMixin instead of pfUI's own OnUpdate animation, so the animation no longer runs faster at higher frame rates. The speed dropdown becomes an on/off checkbox, since the mixin's rate is fixed. A new range keeps the bar's filled share, so it doesn't jump before the animation moves on. --- api/config.lua | 21 +------------- api/ui-widgets.lua | 59 +++++++-------------------------------- api/unitframes.lua | 25 +++++++++++------ env/translations_deDE.lua | 3 +- env/translations_enUS.lua | 3 +- env/translations_esES.lua | 3 +- env/translations_frFR.lua | 3 +- env/translations_koKR.lua | 3 +- env/translations_ruRU.lua | 3 +- env/translations_zhCN.lua | 3 +- env/translations_zhTW.lua | 3 +- modules/gui.lua | 10 +------ 12 files changed, 37 insertions(+), 102 deletions(-) diff --git a/api/config.lua b/api/config.lua index 2c85f77d..5640ca16 100644 --- a/api/config.lua +++ b/api/config.lua @@ -222,7 +222,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("unitframes", nil, "ragecolor", "1,.5,.5,1") pfUI:UpdateConfig("unitframes", nil, "focuscolor", "1,1,.75,1") - pfUI:UpdateConfig("unitframes", nil, "animation_speed", "5") + pfUI:UpdateConfig("unitframes", nil, "animatebars", "1") pfUI:UpdateConfig("unitframes", nil, "portraitalpha", "0.1") pfUI:UpdateConfig("unitframes", nil, "always2dportrait", "0") pfUI:UpdateConfig("unitframes", nil, "portraittexture", "1") @@ -1143,25 +1143,6 @@ function pfUI:MigrateConfig() end end - -- migrating animation_speed (> 3.1.2) - if checkversion(3, 1, 2) then - if tonumber(pfUI_config.unitframes.animation_speed) >= 13 then - pfUI_config.unitframes.animation_speed = "13" - elseif tonumber(pfUI_config.unitframes.animation_speed) >= 8 then - pfUI_config.unitframes.animation_speed = "8" - elseif tonumber(pfUI_config.unitframes.animation_speed) >= 5 then - pfUI_config.unitframes.animation_speed = "5" - elseif tonumber(pfUI_config.unitframes.animation_speed) >= 3 then - pfUI_config.unitframes.animation_speed = "3" - elseif tonumber(pfUI_config.unitframes.animation_speed) >= 2 then - pfUI_config.unitframes.animation_speed = "2" - elseif tonumber(pfUI_config.unitframes.animation_speed) >= 1 then - pfUI_config.unitframes.animation_speed = "1" - else - pfUI_config.unitframes.animation_speed = "5" - end - end - -- migrating legacy buff/debuff naming (> 3.5.0) if checkversion(3, 5, 0) then local unitframes = { "player", "target", "focus", "group", "grouptarget", "grouppet", "raid", "ttarget", "pet", "ptarget", "fallback" } diff --git a/api/ui-widgets.lua b/api/ui-widgets.lua index 472427a9..eb53d0ac 100644 --- a/api/ui-widgets.lua +++ b/api/ui-widgets.lua @@ -2,63 +2,30 @@ setfenv(1, pfUI:GetEnvironment()) do -- statusbars - local animations = {} - local stepsize - -- native StatusBar methods the bar overrides local statusbar = CreateFrame("StatusBar") local SetValue, SetMinMaxValues = statusbar.SetValue, statusbar.SetMinMaxValues local SetOrientation, SetFrameLevel = statusbar.SetOrientation, statusbar.SetFrameLevel - local animate = CreateFrame("Frame", "pfStatusBarAnimation", UIParent) - animate:SetScript("OnUpdate", function() - stepsize = tonumber(pfUI_config.unitframes.animation_speed) - - for bar in pairs(animations) do - if not bar.val_ or abs(bar.val_ - bar.val) < stepsize then - bar:DisplayValue(bar.val) - elseif bar.val ~= bar.val_ then - bar:DisplayValue(bar.val_ + min((bar.val-bar.val_) / stepsize, max(bar.val-bar.val_, 30 / GetFramerate()))) - end - end - end) - + -- SmoothStatusBarMixin animates the bar through SetValue, so this is the + -- shown value; SetSmoothedValue sets the target local handlers = { - ["DisplayValue"] = function(self, val) + ["SetValue"] = function(self, val) local smin, smax = self:GetMinMaxValues() val = Clamp(val, smin, smax) - - -- remove animation queue - if val == self.val_ then - animations[self] = nil - end - - -- set current visible value - self.val_ = val SetValue(self, val) -- the background fills the missing part, all of an empty range self.bg:SetValue(smax > smin and (smax - val) / (smax - smin) or 1) end, - ["SetMinMaxValues"] = function(self, smin, smax, smooth) - -- smoothen the transition by keeping the value at the same percentage as before - local _, oldmax = self:GetMinMaxValues() - if smooth and oldmax > 0 and smax > 0 and oldmax ~= smax then - self.val_ = (self.val_ or self.val) / oldmax * smax - end - + -- the fill keeps its share of the bar, so a new range doesn't make it + -- jump before the smoothed value moves on from there + ["SetMinMaxValues"] = function(self, smin, smax) + local oldmin, oldmax = self:GetMinMaxValues() + local share = oldmax > oldmin and (self:GetValue() - oldmin) / (oldmax - oldmin) or 0 SetMinMaxValues(self, smin, smax) - self:DisplayValue(self.val_ or self.val) - end, - - ["SetValue"] = function(self, val) - self.val = val or 0 - - -- start animation on difference - if self.val_ ~= self.val then - animations[self] = true - end + self:SetValue(smin + share * (smax - smin)) end, ["SetStatusBarBackgroundColor"] = function(self, r, g, b, a) @@ -82,7 +49,6 @@ do -- statusbars local f = CreateFrame("StatusBar", name, parent) SetMinMaxValues(f, 0, 100) SetValue(f, 0) - f.val = 0 f.bg = CreateFrame("StatusBar", nil, f) f.bg:SetFrameLevel(f:GetFrameLevel() - 1) @@ -91,12 +57,7 @@ do -- statusbars f.bg:SetMinMaxValues(0, 1) f.bg:SetValue(1) - -- add all handler functions to the object - for name, func in pairs(handlers) do - f[name] = func - end - - return f + return Mixin(f, SmoothStatusBarMixin, handlers) end end diff --git a/api/unitframes.lua b/api/unitframes.lua index 18e3b1e3..4bbb2e14 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -1700,6 +1700,15 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick) return f end +-- animates a health or power bar to its new value, or sets it at once +local function SetBarValue(bar, value) + if C.unitframes.animatebars == "1" then + bar:SetSmoothedValue(value) + else + bar:ResetSmoothedValue(value) + end +end + function pfUI.uf:RefreshUnitState(unit) local alpha = unit.alpha_visible local unlock = pfUI.unlock and pfUI.unlock:IsShown() or nil @@ -1707,10 +1716,10 @@ function pfUI.uf:RefreshUnitState(unit) if not UnitIsConnected(unit.label .. unit.id) and not unlock then -- offline alpha = unit.alpha_offline - unit.hp.bar:SetMinMaxValues(0, 100, true) - unit.power.bar:SetMinMaxValues(0, 100, true) - unit.hp.bar:SetValue(0) - unit.power.bar:SetValue(0) + unit.hp.bar:SetMinMaxValues(0, 100) + unit.power.bar:SetMinMaxValues(0, 100) + SetBarValue(unit.hp.bar, 0) + SetBarValue(unit.power.bar, 0) elseif unit.config.faderange == "1" and not pfUI.api.UnitInRange(unit.label .. unit.id, 4) and not unlock then alpha = unit.alpha_outrange end @@ -2237,11 +2246,11 @@ function pfUI.uf:RefreshUnit(unit, component) hp = hpmax - hp end - unit.hp.bar:SetMinMaxValues(0, hpmax, true) - unit.hp.bar:SetValue(hp) + unit.hp.bar:SetMinMaxValues(0, hpmax) + SetBarValue(unit.hp.bar, hp) - unit.power.bar:SetMinMaxValues(0, powermax, true) - unit.power.bar:SetValue(power) + unit.power.bar:SetMinMaxValues(0, powermax) + SetBarValue(unit.power.bar, power) -- Hide power bar text for NPCs without real power (power == 0) local isNPC = not UnitIsPlayer(unitstr) and not UnitPlayerControlled(unitstr) diff --git a/env/translations_deDE.lua b/env/translations_deDE.lua index c62aae53..ff90d889 100644 --- a/env/translations_deDE.lua +++ b/env/translations_deDE.lua @@ -32,6 +32,7 @@ pfUI_translation["deDE"] = { ["Anchor Bags Above Chat"] = nil, ["A new installation of |cff33ffccpf|rUI ships with 4 prebuilt design profiles. Click below if you wish to load one of these profiles."] = nil, ["A new version is available"] = nil, + ["Animate Health And Power Bars"] = nil, ["Appearance"] = nil, ["Ascending"] = nil, ["Author"] = nil, @@ -371,7 +372,6 @@ pfUI_translation["deDE"] = { ["Health"] = nil, ["Health - Auto"] = nil, ["Healthbar"] = nil, - ["Healthbar Animation Speed"] = nil, ["Health Bar Color"] = nil, ["Healthbar Embedded"] = nil, ["Healthbar Height"] = nil, @@ -433,7 +433,6 @@ pfUI_translation["deDE"] = { ["Inherit Default Colors"] = nil, ["Inputbox Height"] = nil, ["Inputbox Width"] = nil, - ["Instant"] = nil, ["Integrations"] = nil, ["Invert Health Bar"] = nil, ["is not allowed in profile name"] = nil, diff --git a/env/translations_enUS.lua b/env/translations_enUS.lua index 1e46f821..9abf84e7 100644 --- a/env/translations_enUS.lua +++ b/env/translations_enUS.lua @@ -33,6 +33,7 @@ pfUI_translation["enUS"] = { ["Anchor Bags Above Chat"] = nil, ["A new installation of |cff33ffccpf|rUI ships with 4 prebuilt design profiles. Click below if you wish to load one of these profiles."] = nil, ["A new version is available"] = nil, + ["Animate Health And Power Bars"] = nil, ["Appearance"] = nil, ["Ascending"] = nil, ["Author"] = nil, @@ -381,7 +382,6 @@ pfUI_translation["enUS"] = { ["Health"] = nil, ["Health - Auto"] = nil, ["Healthbar"] = nil, - ["Healthbar Animation Speed"] = nil, ["Health Bar Color"] = nil, ["Healthbar Embedded"] = nil, ["Healthbar Height"] = nil, @@ -444,7 +444,6 @@ pfUI_translation["enUS"] = { ["Inherit Default Colors"] = nil, ["Inputbox Height"] = nil, ["Inputbox Width"] = nil, - ["Instant"] = nil, ["Integrations"] = nil, ["Invert Health Bar"] = nil, ["is not allowed in profile name"] = nil, diff --git a/env/translations_esES.lua b/env/translations_esES.lua index fe749edd..2d647d8a 100644 --- a/env/translations_esES.lua +++ b/env/translations_esES.lua @@ -32,6 +32,7 @@ pfUI_translation["esES"] = { ["Anchor Bags Above Chat"] = nil, ["A new installation of |cff33ffccpf|rUI ships with 4 prebuilt design profiles. Click below if you wish to load one of these profiles."] = "Una nueva instalación de |cff33ffccpf|rUI viene con 4 perfiles de diseño preconfigurados. Haga clic debajo si deseas cargar uno de estos perfiles.", ["A new version is available"] = "Una nueva versión está disponible", + ["Animate Health And Power Bars"] = nil, ["Appearance"] = "Apariencia", ["Ascending"] = "Ascendiendo", ["Author"] = "Autor", @@ -371,7 +372,6 @@ pfUI_translation["esES"] = { ["Health"] = "Salud", ["Health - Auto"] = "Salud - Auto", ["Healthbar"] = "Barra de salud", - ["Healthbar Animation Speed"] = "Velocidad de animación de la barra de salud", ["Health Bar Color"] = "Color de la barra de salud", ["Healthbar Embedded"] = "Barra de salud embebida", ["Healthbar Height"] = "Altura de la barra de salud", @@ -433,7 +433,6 @@ pfUI_translation["esES"] = { ["Inherit Default Colors"] = "Color predeterminado", ["Inputbox Height"] = "Altura de la barra de entrada", ["Inputbox Width"] = "Ancho de la barra de entrada", - ["Instant"] = "Instantáneo", ["Integrations"] = "Integraciones", ["Invert Health Bar"] = "Invertir la barra de salud", ["is not allowed in profile name"] = "no se permite en el nombre de perfil", diff --git a/env/translations_frFR.lua b/env/translations_frFR.lua index d0a7e1bd..632dcded 100644 --- a/env/translations_frFR.lua +++ b/env/translations_frFR.lua @@ -32,6 +32,7 @@ pfUI_translation["frFR"] = { ["Anchor Bags Above Chat"] = nil, ["A new installation of |cff33ffccpf|rUI ships with 4 prebuilt design profiles. Click below if you wish to load one of these profiles."] = "Une nouvelle installation de |cff33ffccpf|rUI est livrée avec 4 profils de conception prédéfinis, Cliquez ci-dessous si vous souhaitez charger l'un de ces profils", ["A new version is available"] = "Une nouvelle version est disponible", + ["Animate Health And Power Bars"] = nil, ["Appearance"] = "Apparence", ["Ascending"] = "Ascendante", ["Author"] = "Auteur", @@ -371,7 +372,6 @@ pfUI_translation["frFR"] = { ["Health"] = "Point de vie", ["Health - Auto"] = "Points de vie - Automatique", ["Healthbar"] = "Barre des points de vie", - ["Healthbar Animation Speed"] = "Vitesse de l'animation des barres de vie", ["Health Bar Color"] = "Couleur de la barre des points de vie", ["Healthbar Embedded"] = "Barres de vies intégrées", ["Healthbar Height"] = "Hauteur des barres de vies", @@ -433,7 +433,6 @@ pfUI_translation["frFR"] = { ["Inherit Default Colors"] = "Hériter des couleurs par défaut", ["Inputbox Height"] = "Hauteur du champ de saisie du texte", ["Inputbox Width"] = "Largeur du champ de saisie du texte", - ["Instant"] = "Instantané", ["Integrations"] = nil, ["Invert Health Bar"] = "Inverser les barres de vie", ["is not allowed in profile name"] = "n'est pas autorisé comme nom de profil", diff --git a/env/translations_koKR.lua b/env/translations_koKR.lua index f903be8f..227f9187 100644 --- a/env/translations_koKR.lua +++ b/env/translations_koKR.lua @@ -32,6 +32,7 @@ pfUI_translation["koKR"] = { ["Anchor Bags Above Chat"] = nil, ["A new installation of |cff33ffccpf|rUI ships with 4 prebuilt design profiles. Click below if you wish to load one of these profiles."] = nil, ["A new version is available"] = nil, + ["Animate Health And Power Bars"] = nil, ["Appearance"] = "외관 설정", ["Ascending"] = nil, ["Author"] = nil, @@ -371,7 +372,6 @@ pfUI_translation["koKR"] = { ["Health"] = nil, ["Health - Auto"] = "체력-자동", ["Healthbar"] = nil, - ["Healthbar Animation Speed"] = "체력바 애니메이션 속도", ["Health Bar Color"] = nil, ["Healthbar Embedded"] = "체력바에 겹쳐보기", ["Healthbar Height"] = "체력바 높이", @@ -433,7 +433,6 @@ pfUI_translation["koKR"] = { ["Inherit Default Colors"] = nil, ["Inputbox Height"] = "챗팅 입력창 높이", ["Inputbox Width"] = "챗팅 입력창 넓이", - ["Instant"] = "즉시", ["Integrations"] = nil, ["Invert Health Bar"] = "체력바 반전", ["is not allowed in profile name"] = "프로필 이름에 허용되지 않습니다.", diff --git a/env/translations_ruRU.lua b/env/translations_ruRU.lua index 0ae36d95..77caf7fc 100644 --- a/env/translations_ruRU.lua +++ b/env/translations_ruRU.lua @@ -32,6 +32,7 @@ pfUI_translation["ruRU"] = { ["Anchor Bags Above Chat"] = nil, ["A new installation of |cff33ffccpf|rUI ships with 4 prebuilt design profiles. Click below if you wish to load one of these profiles."] = "Новая установка |cff33ffccpf|rUI предлагает 4 предварительно созданных профиля дизайна. Нажмите ниже, если вы хотите загрузить один из этих профилей.", ["A new version is available"] = "Доступна новая версия", + ["Animate Health And Power Bars"] = nil, ["Appearance"] = "Внешний вид", ["Ascending"] = "По возрастанию", ["Author"] = "Автор", @@ -371,7 +372,6 @@ pfUI_translation["ruRU"] = { ["Health"] = "Здоровье", ["Health - Auto"] = "Здоровье - автоматически", ["Healthbar"] = "Панель здоровья", - ["Healthbar Animation Speed"] = "Скорость анимации панели здоровья", ["Health Bar Color"] = "Цвет панели здоровья", ["Healthbar Embedded"] = "На панели здоровья", ["Healthbar Height"] = "Высота панели здоровья", @@ -433,7 +433,6 @@ pfUI_translation["ruRU"] = { ["Inherit Default Colors"] = "Наследовать цвета по умолчанию", ["Inputbox Height"] = "Высота поля ввода", ["Inputbox Width"] = "Ширина поля ввода", - ["Instant"] = "Мгновенно", ["Integrations"] = "Встраиваемые", ["Invert Health Bar"] = "Инвертировать панель здоровья", ["is not allowed in profile name"] = "не разрешено в имени профиля", diff --git a/env/translations_zhCN.lua b/env/translations_zhCN.lua index a76e2c28..90a60d99 100644 --- a/env/translations_zhCN.lua +++ b/env/translations_zhCN.lua @@ -32,6 +32,7 @@ pfUI_translation["zhCN"] = { ["Anchor Bags Above Chat"] = "将背包锚定在聊天框上方", ["A new installation of |cff33ffccpf|rUI ships with 4 prebuilt design profiles. Click below if you wish to load one of these profiles."] = "pfUI的新安装自带4以下四种预设风格.点击下方可选择其一", ["A new version is available"] = "发现新版本!", + ["Animate Health And Power Bars"] = nil, ["Appearance"] = "外观设置", ["Ascending"] = "上移", ["Author"] = "作者", @@ -371,7 +372,6 @@ pfUI_translation["zhCN"] = { ["Health"] = "生命值", ["Health - Auto"] = "动态生命值和百分比", ["Healthbar"] = "血条", - ["Healthbar Animation Speed"] = "掉血动画速度", ["Health Bar Color"] = "血条颜色", ["Healthbar Embedded"] = "血条上显示动态头像", ["Healthbar Height"] = "血条高度", @@ -433,7 +433,6 @@ pfUI_translation["zhCN"] = { ["Inherit Default Colors"] = "继承默认颜色", ["Inputbox Height"] = "输入框高度", ["Inputbox Width"] = "输入框宽度", - ["Instant"] = "极快", ["Integrations"] = "整合", ["Invert Health Bar"] = "血量反色显示", ["is not allowed in profile name"] = "在配置文件名中不允许", diff --git a/env/translations_zhTW.lua b/env/translations_zhTW.lua index 0d00d1e6..7d4543a0 100644 --- a/env/translations_zhTW.lua +++ b/env/translations_zhTW.lua @@ -32,6 +32,7 @@ pfUI_translation["zhTW"] = { ["Anchor Bags Above Chat"] = nil, ["A new installation of |cff33ffccpf|rUI ships with 4 prebuilt design profiles. Click below if you wish to load one of these profiles."] = "pfUI的安裝內建有四種風格.點選以下讀取其一", ["A new version is available"] = nil, + ["Animate Health And Power Bars"] = nil, ["Appearance"] = "外觀設置", ["Ascending"] = "下移", ["Author"] = nil, @@ -371,7 +372,6 @@ pfUI_translation["zhTW"] = { ["Health"] = nil, ["Health - Auto"] = "動態生命值和百分比", ["Healthbar"] = "生命條", - ["Healthbar Animation Speed"] = "掉血動畫速度", ["Health Bar Color"] = nil, ["Healthbar Embedded"] = "血條上顯示動態頭像", ["Healthbar Height"] = "生命條高度", @@ -433,7 +433,6 @@ pfUI_translation["zhTW"] = { ["Inherit Default Colors"] = nil, ["Inputbox Height"] = "輸入框高度", ["Inputbox Width"] = "輸入框寬度", - ["Instant"] = "極快", ["Integrations"] = nil, ["Invert Health Bar"] = "血量反色顯示", ["is not allowed in profile name"] = "在設定檔名中不允許", diff --git a/modules/gui.lua b/modules/gui.lua index 7ab6a5ae..13f078ca 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -907,14 +907,6 @@ pfUI:RegisterModule("gui", function () "HORIZONTAL:" .. T["Horizontal"], "VERTICAL:" .. T["Vertical"], }, - ["uf_animationspeed"] = { - "1:" .. T["Instant"], - "2:" .. T["Very Fast"], - "3:" .. T["Fast"], - "5:" .. T["Medium"], - "8:" .. T["Slow"], - "13:" .. T["Very Slow"], - }, ["xpanchors"] = { "__NONONIL__:" .. T["No Anchor"], "pfChatLeft:" .. T["Left Chat Frame"], @@ -2050,7 +2042,7 @@ pfUI:RegisterModule("gui", function () CreateGUIEntry(T["Unit Frames"], T["General"], function() CreateConfig(nil, T["Disable pfUI Unit Frames"], C.unitframes, "disable", "checkbox") - CreateConfig(nil, T["Healthbar Animation Speed"], C.unitframes, "animation_speed", "dropdown", pfUI.gui.dropdowns.uf_animationspeed) + CreateConfig(nil, T["Animate Health And Power Bars"], C.unitframes, "animatebars", "checkbox") CreateConfig(nil, T["Portrait Alpha"], C.unitframes, "portraitalpha") CreateConfig(nil, T["Always Use 2D Portraits"], C.unitframes, "always2dportrait", "checkbox") CreateConfig(nil, T["Enable 2D Portraits As Fallback"], C.unitframes, "portraittexture", "checkbox")