From 08a51982ffc0cc522217d68da9e790a3a0878832 Mon Sep 17 00:00:00 2001 From: shagu Date: Tue, 24 Aug 2021 17:17:24 +0200 Subject: [PATCH] nameplate-scale: enable ui scale on nameplates --- mods/nameplate-scale.lua | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 mods/nameplate-scale.lua diff --git a/mods/nameplate-scale.lua b/mods/nameplate-scale.lua new file mode 100644 index 0000000..095e5a6 --- /dev/null +++ b/mods/nameplate-scale.lua @@ -0,0 +1,49 @@ +local _G = _G or getfenv(0) +local GetExpansion = ShaguTweaks.GetExpansion + +-- tbc does not allow to rescale nameplates (secure_frames) +if GetExpansion() == "tbc" then return end + +local module = ShaguTweaks:register({ + title = "UI-Scale Nameplates", + description = "Let the nameplates honor the UI-Scale of other elements", + enabled = true, +}) + +module.enable = function(self) + if ShaguPlates then return end + + table.insert(ShaguTweaks.libnameplate.OnInit, function(plate) + local owidth = plate:GetWidth() + local oheight = plate:GetHeight() + + -- create new plate + local new = CreateFrame("Frame", nil, plate) + plate.new = new + + new:SetScale(UIParent:GetScale()) + new:SetAllPoints(plate) + new.plate = plate + + plate.healthbar:SetParent(new) + plate.healthbar:SetFrameLevel(1) + + plate:SetWidth(owidth*UIParent:GetScale()) + plate:SetHeight(oheight*UIParent:GetScale()) + + for i, object in pairs({plate:GetRegions()}) do + object:SetParent(new) + end + + new:SetScript("OnShow", function() + -- adjust sizes + this:SetScale(UIParent:GetScale()) + this.plate:SetWidth(owidth*UIParent:GetScale()) + this.plate:SetHeight(oheight*UIParent:GetScale()) + end) + end) + + table.insert(ShaguTweaks.libnameplate.OnUpdate, function() + this.new:SetAlpha(this:GetAlpha()) + end) +end