From 4618711119de93c17395efa666f7d79312cc1152 Mon Sep 17 00:00:00 2001 From: shagu Date: Sun, 2 Jun 2019 19:37:09 +0200 Subject: [PATCH] uf_tukui: use hooks to refresh on config change --- modules/uf_tukui.lua | 81 +++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/modules/uf_tukui.lua b/modules/uf_tukui.lua index 7a300b63..8bdc0aa6 100644 --- a/modules/uf_tukui.lua +++ b/modules/uf_tukui.lua @@ -1,72 +1,91 @@ pfUI:RegisterModule("uf_tukui", function () - -- do not go further on disabled UFs - if C.unitframes.disable == "1" then return end + if C.unitframes.disable == "1" or C.unitframes.layout ~= "tukui" then return end - local default_border = C.appearance.border.default - if C.appearance.border.unitframes ~= "-1" then - default_border = C.appearance.border.unitframes - end + -- update player layout + local hookUpdateConfigPlayer = pfUI.uf.player.UpdateConfig + function pfUI.uf.player.UpdateConfig() + -- run default unitframe update function + hookUpdateConfigPlayer(pfUI.uf.player) - local pspacing = C.unitframes.player.pspace - local tspacing = C.unitframes.target.pspace + -- load configs + local default_border = C.appearance.border.default + if C.appearance.border.unitframes ~= "-1" then + default_border = C.appearance.border.unitframes + end - if C.unitframes.layout == "tukui" then - -- Player + local pspacing = C.unitframes.player.pspace + local tspacing = C.unitframes.target.pspace + + -- adjust layout pfUI.uf.player:UpdateFrameSize() pfUI.uf.player:SetFrameStrata("LOW") - pfUI.uf.player:SetHeight(pfUI.uf.player:GetHeight() + 2*default_border + C.global.font_size + 2*default_border + pspacing) + pfUI.uf.player:SetHeight(pfUI.uf.player:GetHeight() + 2*default_border + (C.global.font_size * 1.5) + pspacing) - pfUI.uf.player.caption = CreateFrame("Frame", "pfPlayerCaption", pfUI.uf.player) - pfUI.uf.player.caption:SetHeight(C.global.font_size + 2*default_border) + pfUI.uf.player.caption = pfUI.uf.player.caption or CreateFrame("Frame", "pfPlayerCaption", pfUI.uf.player) + pfUI.uf.player.caption:SetHeight(C.global.font_size * 1.5) pfUI.uf.player.caption:SetPoint("BOTTOMRIGHT",pfUI.uf.player, "BOTTOMRIGHT",0, 0) pfUI.uf.player.caption:SetPoint("BOTTOMLEFT",pfUI.uf.player, "BOTTOMLEFT",0, 0) pfUI.uf.player.hpLeftText:SetParent(pfUI.uf.player.caption) pfUI.uf.player.hpLeftText:ClearAllPoints() - pfUI.uf.player.hpLeftText:SetPoint("TOPLEFT",pfUI.uf.player.caption, "TOPLEFT", default_border, 1) - pfUI.uf.player.hpLeftText:SetPoint("BOTTOMRIGHT",pfUI.uf.player.caption, "BOTTOMRIGHT", -default_border, 0) + pfUI.uf.player.hpLeftText:SetPoint("LEFT",pfUI.uf.player.caption, "LEFT", default_border, 0) pfUI.uf.player.hpCenterText:SetParent(pfUI.uf.player.caption) pfUI.uf.player.hpCenterText:ClearAllPoints() - pfUI.uf.player.hpCenterText:SetPoint("TOPLEFT",pfUI.uf.player.caption, "TOPLEFT", default_border, 1) - pfUI.uf.player.hpCenterText:SetPoint("BOTTOMRIGHT",pfUI.uf.player.caption, "BOTTOMRIGHT", -default_border, 0) + pfUI.uf.player.hpCenterText:SetPoint("CENTER",pfUI.uf.player.caption, "CENTER", 0, 0) pfUI.uf.player.hpRightText:SetParent(pfUI.uf.player.caption) pfUI.uf.player.hpRightText:ClearAllPoints() - pfUI.uf.player.hpRightText:SetPoint("TOPLEFT",pfUI.uf.player.caption, "TOPLEFT", default_border, 1) - pfUI.uf.player.hpRightText:SetPoint("BOTTOMRIGHT",pfUI.uf.player.caption, "BOTTOMRIGHT", -default_border, 0) + pfUI.uf.player.hpRightText:SetPoint("RIGHT",pfUI.uf.player.caption, "RIGHT", -default_border, 0) pfUI.castbar.player:SetAllPoints(pfUI.uf.player.caption) - UpdateMovable(pfUI.castbar.player) + UpdateMovable(pfUI.castbar.player, true) CreateBackdrop(pfUI.uf.player.caption, default_border) + end - -- Target + -- update target layout + local hookUpdateConfigTarget = pfUI.uf.target.UpdateConfig + function pfUI.uf.target.UpdateConfig() + -- run default unitframe update function + hookUpdateConfigTarget(pfUI.uf.target) + + -- load configs + local default_border = C.appearance.border.default + if C.appearance.border.unitframes ~= "-1" then + default_border = C.appearance.border.unitframes + end + + local pspacing = C.unitframes.player.pspace + local tspacing = C.unitframes.target.pspace + + -- adjust layout pfUI.uf.target:UpdateFrameSize() pfUI.uf.target:SetFrameStrata("LOW") - pfUI.uf.target:SetHeight(pfUI.uf.target:GetHeight() + 2*default_border + C.global.font_size + 2*default_border + tspacing) + pfUI.uf.target:SetHeight(pfUI.uf.target:GetHeight() + 2*default_border + (C.global.font_size * 1.5) + tspacing) - pfUI.uf.target.caption = CreateFrame("Frame", "pfTargetCaption", pfUI.uf.target) - pfUI.uf.target.caption:SetHeight(C.global.font_size + 2*default_border) + pfUI.uf.target.caption = pfUI.uf.target.caption or CreateFrame("Frame", "pfTargetCaption", pfUI.uf.target) + pfUI.uf.target.caption:SetHeight(C.global.font_size * 1.5) pfUI.uf.target.caption:SetPoint("BOTTOMRIGHT",pfUI.uf.target,"BOTTOMRIGHT", 0, 0) pfUI.uf.target.caption:SetPoint("BOTTOMLEFT",pfUI.uf.target,"BOTTOMLEFT", 0, 0) pfUI.uf.target.hpLeftText:SetParent(pfUI.uf.target.caption) pfUI.uf.target.hpLeftText:ClearAllPoints() - pfUI.uf.target.hpLeftText:SetPoint("TOPLEFT",pfUI.uf.target.caption, "TOPLEFT", default_border, 1) - pfUI.uf.target.hpLeftText:SetPoint("BOTTOMRIGHT",pfUI.uf.target.caption, "BOTTOMRIGHT", -default_border, 0) + pfUI.uf.target.hpLeftText:SetPoint("LEFT",pfUI.uf.target.caption, "LEFT", default_border, 0) pfUI.uf.target.hpCenterText:SetParent(pfUI.uf.target.caption) pfUI.uf.target.hpCenterText:ClearAllPoints() - pfUI.uf.target.hpCenterText:SetPoint("TOPLEFT",pfUI.uf.target.caption, "TOPLEFT", default_border, 1) - pfUI.uf.target.hpCenterText:SetPoint("BOTTOMRIGHT",pfUI.uf.target.caption, "BOTTOMRIGHT", -default_border, 0) + pfUI.uf.target.hpCenterText:SetPoint("CENTER",pfUI.uf.target.caption, "CENTER", 0, 0) pfUI.uf.target.hpRightText:SetParent(pfUI.uf.target.caption) pfUI.uf.target.hpRightText:ClearAllPoints() - pfUI.uf.target.hpRightText:SetPoint("TOPLEFT",pfUI.uf.target.caption, "TOPLEFT", default_border, 1) - pfUI.uf.target.hpRightText:SetPoint("BOTTOMRIGHT",pfUI.uf.target.caption, "BOTTOMRIGHT", -default_border, 0) + pfUI.uf.target.hpRightText:SetPoint("RIGHT",pfUI.uf.target.caption, "RIGHT", -default_border, 0) pfUI.castbar.target:SetAllPoints(pfUI.uf.target.caption) - UpdateMovable(pfUI.castbar.target) + UpdateMovable(pfUI.castbar.target, true) CreateBackdrop(pfUI.uf.target.caption, default_border) end + + -- trigger updates + pfUI.uf.player.UpdateConfig() + pfUI.uf.target.UpdateConfig() end)