From 4a3caa02addaaac83bf2d63097f150c7034351a7 Mon Sep 17 00:00:00 2001 From: shagu Date: Wed, 16 May 2018 20:38:40 +0200 Subject: [PATCH] unlock: reset frame position on middle click --- api/api.lua | 17 ++++++++++++++++- modules/unlock.lua | 11 ++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/api/api.lua b/api/api.lua index eb90ca94..c2bd500e 100644 --- a/api/api.lua +++ b/api/api.lua @@ -479,6 +479,14 @@ function pfUI.api.UpdateMovable(frame) table.insert(pfUI.movables, name) end + if not frame.posdata then + frame.posdata = { scale = frame:GetScale(), pos = {} } + + for i=1,frame:GetNumPoints() do + frame.posdata.pos[i] = { frame:GetPoint(i) } + end + end + if pfUI_config["position"][frame:GetName()] then if pfUI_config["position"][frame:GetName()]["scale"] then frame:SetScale(pfUI_config["position"][frame:GetName()].scale) @@ -488,6 +496,13 @@ function pfUI.api.UpdateMovable(frame) frame:ClearAllPoints() frame:SetPoint("TOPLEFT", pfUI_config["position"][frame:GetName()].xpos, pfUI_config["position"][frame:GetName()].ypos) end + elseif frame.posdata and frame.posdata.pos[1] then + frame:ClearAllPoints() + frame:SetScale(frame.posdata.scale) + + for id, point in pairs(frame.posdata.pos) do + frame:SetPoint(unpack(point)) + end end end @@ -862,4 +877,4 @@ function pfUI.api.GetColorGradient(perc, ...) end return pfUI.api.GetColorGradient(perc,unpack(color_tuples)) end -end \ No newline at end of file +end diff --git a/modules/unlock.lua b/modules/unlock.lua index 7bcafe0e..a59a533f 100644 --- a/modules/unlock.lua +++ b/modules/unlock.lua @@ -74,7 +74,8 @@ pfUI:RegisterModule("unlock", function () end if not frame.drag then - frame.drag = CreateFrame("Frame", nil, frame) + frame.drag = CreateFrame("Button", nil, frame) + frame.drag:RegisterForClicks("MiddleButtonUp") frame.drag:SetAllPoints(frame) frame.drag:SetFrameStrata("DIALOG") CreateBackdrop(frame.drag, nil, nil, .8) @@ -142,6 +143,7 @@ pfUI:RegisterModule("unlock", function () frame.drag:SetScript("OnMouseDown",function() + if arg1 == "MiddleButton" then return end if IsShiftKeyDown() then if strsub(frame:GetName(),0,7) == "pfCombo" then for i=1,5 do @@ -201,6 +203,7 @@ pfUI:RegisterModule("unlock", function () end) frame.drag:SetScript("OnMouseUp",function() + if arg1 == "MiddleButton" then return end frame:StopMovingOrSizing() _, _, _, xpos, ypos = frame:GetPoint() frame.drag.backdrop:SetBackdropBorderColor(.2,1,.8,1) @@ -258,6 +261,11 @@ pfUI:RegisterModule("unlock", function () pfUI.unlock:SavePosition(frame) pfUI.unlock.settingChanged = true end) + + frame.drag:SetScript("OnClick", function() + pfUI_config["position"][frame:GetName()] = nil + UpdateMovable(frame) + end) end frame:SetMovable(true) @@ -280,6 +288,7 @@ pfUI:RegisterModule("unlock", function () if frame.hideLater == true then frame:Hide() end + UpdateMovable(frame) end end