From 1c3f1be8e93af9e31d998e7f831d710efb36f072 Mon Sep 17 00:00:00 2001 From: rawoil Date: Sat, 19 Jun 2021 13:36:22 +0800 Subject: [PATCH] add smooth feature --- oUF_Simple/core/functions.lua | 7 +++++ oUF_Simple/core/style.lua | 1 + oUF_Simple/modules/oUF_Smooth.lua | 53 +++++++++++++++++++++++++++++++++++++ oUF_Simple/oUF_Simple.toc | 1 + oUF_SimpleConfig/global.lua | 3 ++- 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 oUF_Simple/modules/oUF_Smooth.lua diff --git a/oUF_Simple/core/functions.lua b/oUF_Simple/core/functions.lua index 7e01aa6..fe6e502 100644 --- a/oUF_Simple/core/functions.lua +++ b/oUF_Simple/core/functions.lua @@ -540,3 +540,10 @@ local function CreateDragFrame(self) rLib:CreateDragFrame(self, L.dragFrames, -2, true) end L.F.CreateDragFrame = CreateDragFrame + +--ToggleSmooth +local function ToggleSmooth(self, enabled) + self.Health.Smooth = enabled + if self.Power then self.Power.Smooth = enabled end +end +L.F.ToggleSmooth = ToggleSmooth \ No newline at end of file diff --git a/oUF_Simple/core/style.lua b/oUF_Simple/core/style.lua index 73de8b8..08a44be 100644 --- a/oUF_Simple/core/style.lua +++ b/oUF_Simple/core/style.lua @@ -28,6 +28,7 @@ local function CreateStyle(self) L.F.CreateHealthText(self) self.Power = L.F.CreatePowerBar(self) L.F.CreatePowerText(self) + L.F.ToggleSmooth(self, L.C.smooth) self.Castbar = L.F.CreateCastBar(self) self.rClassBar = L.F.CreateClassBar(self) -- self.AlternativePower = L.F.CreateAltPowerBar(self) diff --git a/oUF_Simple/modules/oUF_Smooth.lua b/oUF_Simple/modules/oUF_Smooth.lua new file mode 100644 index 0000000..b5dc3d8 --- /dev/null +++ b/oUF_Simple/modules/oUF_Smooth.lua @@ -0,0 +1,53 @@ +local _, ns = ... +local oUF = ns.oUF or oUF +assert(oUF, " was unable to locate oUF install.") + +local smoothing = {} +local function Smooth(self, value) + local _, max = self:GetMinMaxValues() + if value == self:GetValue() or (self._max and self._max ~= max) then + smoothing[self] = nil + self:SetValue_(value) + else + smoothing[self] = value + end + self._max = max +end + +local function SmoothBar(self, bar) + bar.SetValue_ = bar.SetValue + bar.SetValue = Smooth +end + +local function hook(frame) + frame.SmoothBar = SmoothBar + if frame.Health and frame.Health.Smooth then + frame:SmoothBar(frame.Health) + end + if frame.Power and frame.Power.Smooth then + frame:SmoothBar(frame.Power) + end +end + + +for i, frame in ipairs(oUF.objects) do hook(frame) end +oUF:RegisterInitCallback(hook) + + +local f, min, max = CreateFrame('Frame'), math.min, math.max +f:SetScript('OnUpdate', function() + local limit = 30/GetFramerate() + for bar, value in pairs(smoothing) do + local cur = bar:GetValue() + local new = cur + min((value-cur)/3, max(value-cur, limit)) + if new ~= new then + -- Mad hax to prevent QNAN. + new = value + end + bar:SetValue_(new) + if cur == value or abs(new - value) < 2 then + bar:SetValue_(value) + smoothing[bar] = nil + end + end +end) diff --git a/oUF_Simple/oUF_Simple.toc b/oUF_Simple/oUF_Simple.toc index 9ea8a53..9692924 100644 --- a/oUF_Simple/oUF_Simple.toc +++ b/oUF_Simple/oUF_Simple.toc @@ -8,6 +8,7 @@ modules\rClassBar.lua modules\oUF_DebuffHighlight.lua modules\oUF_Swing.lua +modules\oUF_Smooth.lua core\init.lua core\functions.lua diff --git a/oUF_SimpleConfig/global.lua b/oUF_SimpleConfig/global.lua index ca69655..1101578 100644 --- a/oUF_SimpleConfig/global.lua +++ b/oUF_SimpleConfig/global.lua @@ -71,7 +71,8 @@ L.C.colors.healthbar = { L.C.colors.power = { mana = {0.1, 0.2, 1} } - +--smooth +L.C.smooth = true --fonts L.C.fonts = { expressway = rLib.mediapath .. "expressway.ttf", -- 1.7.9.5