unlock: entire rewrite of the unlock mode

This commit is contained in:
shagu
2018-08-11 22:02:42 +02:00
parent 7292ae19a8
commit b374bee9bc
+258 -293
View File
@@ -1,303 +1,53 @@
pfUI:RegisterModule("unlock", function ()
pfUI.unlock = CreateFrame("Button", "pfUIUnlockMode", UIParent)
pfUI.unlock:Hide()
pfUI.unlock:SetAllPoints(WorldFrame)
pfUI.unlock:SetFrameStrata("BACKGROUND")
pfUI.unlock:SetScript("OnClick", function()
this:Hide()
end)
local clusters = {
-- Name Shift Ctrl
{ "pfCombo", 5 },
{ "pfRaid", 40, 5 },
{ "pfGroup", 4 },
{ "pfLootRollFrame", 4 },
}
table.insert(UISpecialFrames, "pfUIUnlockMode")
local function GetFrames()
-- Return frames based on Ctrl and Shift state
-- 'this' [frame] the base frame
-- return [list] all frames that should be selected
function pfUI.unlock:SavePosition(frame)
local _, _, _, xpos, ypos = frame:GetPoint()
if not C.position[frame:GetName()] then
C.position[frame:GetName()] = {}
local frame = this.frame
local frames = { frame }
if IsShiftKeyDown() or IsControlKeyDown() then
-- search and add clustered frames
for id, cluster in pairs(clusters) do
local len = strlen(cluster[1])
if strsub(frame:GetName(),0,len) == cluster[1] then
if IsShiftKeyDown() and cluster[2] then
for i = 1, cluster[2] do
if _G[cluster[1] .. i] ~= frame then
table.insert(frames, _G[cluster[1] .. i])
end
end
elseif IsControlKeyDown() and cluster[3] then
local id = tonumber(strsub(frame:GetName(),len+1,len+2))
local b = 1
for i = cluster[3]+1, cluster[2], cluster[3] do
b = ( id >= i ) and i or b
end
for i = b, b + cluster[3] - 1 do
if _G[cluster[1] .. i] ~= frame then
table.insert(frames, _G[cluster[1] .. i])
end
end
end
end
end
end
C.position[frame:GetName()]["xpos"] = round(xpos)
C.position[frame:GetName()]["ypos"] = round(ypos)
UpdateMovable(frame)
return frames
end
pfUI.unlock:SetScript("OnShow", function()
if not this.setup then
local size = 1
local line = {}
local width = GetScreenWidth()
local height = GetScreenHeight()
local ratio = width / GetScreenHeight()
local rheight = GetScreenHeight() * ratio
local wStep = width / 128
local hStep = rheight / 128
-- vertical lines
for i = 0, 128 do
if i == 128 / 2 then
line = pfUI.unlock:CreateTexture(nil, 'BORDER')
line:SetTexture(.1, .5, .4)
else
line = pfUI.unlock:CreateTexture(nil, 'BACKGROUND')
line:SetTexture(0, 0, 0, .5)
end
line:SetPoint("TOPLEFT", pfUI.unlock, "TOPLEFT", i*wStep - (size/2), 0)
line:SetPoint('BOTTOMRIGHT', pfUI.unlock, 'BOTTOMLEFT', i*wStep + (size/2), 0)
end
-- horizontal lines
for i = 1, floor(height/hStep) do
if i == floor(height/hStep / 2) then
line = pfUI.unlock:CreateTexture(nil, 'BORDER')
line:SetTexture(.1, .5, .4)
else
line = pfUI.unlock:CreateTexture(nil, 'BACKGROUND')
line:SetTexture(0, 0, 0)
end
line:SetPoint("TOPLEFT", pfUI.unlock, "TOPLEFT", 0, -(i*hStep) + (size/2))
line:SetPoint('BOTTOMRIGHT', pfUI.unlock, 'TOPRIGHT', 0, -(i*hStep + size/2))
end
this.setup = true
end
for name, frame in pairs(pfUI.movables) do
local frame = frame or _G[name]
if frame then
if not frame:IsShown() then
frame.hideLater = true
end
if not frame.drag then
frame.drag = CreateFrame("Button", "pfUnlockDragger", frame)
frame.drag:RegisterForClicks("MiddleButtonUp")
frame.drag:SetAllPoints(frame)
frame.drag:SetFrameStrata("DIALOG")
CreateBackdrop(frame.drag, nil, nil, .8)
frame.drag.backdrop:SetBackdropBorderColor(.2, 1, .8)
frame.drag:EnableMouseWheel(1)
frame.drag.text = frame.drag:CreateFontString("Status", "LOW", "GameFontNormal")
frame.drag.text:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE")
frame.drag.text:ClearAllPoints()
frame.drag.text:SetAllPoints(frame.drag)
frame.drag.text:SetPoint("CENTER", 0, 0)
frame.drag.text:SetFontObject(GameFontWhite)
local label = frame:GetName()
-- Check if the frame name starts with pf if so remove it
local startsWithPf = string.sub(label, 1, string.len("pf")) == "pf"
if startsWithPf then label = (strsub(frame:GetName(),3)) end
if frame.drag:GetHeight() > (2 * frame.drag:GetWidth()) then
label = strvertical(label)
end
frame.drag.text:SetText(label)
frame.drag:SetAlpha(1)
frame.drag:SetScript("OnMouseWheel", function()
local scale = round(frame:GetScale() + arg1/10, 1)
if IsShiftKeyDown() and strsub(frame:GetName(),0,7) == "pfCombo" then
for i=1,5 do
local frame = _G["pfCombo" .. i]
pfUI.unlock:SaveScale(frame, scale)
end
elseif IsShiftKeyDown() and strsub(frame:GetName(),0,6) == "pfRaid" then
for i=1,40 do
local frame = _G["pfRaid" .. i]
pfUI.unlock:SaveScale(frame, scale)
end
elseif IsControlKeyDown() and strsub(frame:GetName(),0,6) == "pfRaid" then
local id = tonumber(strsub(frame:GetName(),7,8))
local b = 1
for i=6,40,5 do b = ( id >= i ) and i or b end
for i=b,b+4 do
local frame = _G["pfRaid" .. i]
pfUI.unlock:SaveScale(frame, scale)
end
elseif IsShiftKeyDown() and strsub(frame:GetName(),0,7) == "pfGroup" then
for i=1,4 do
local frame = _G["pfGroup" .. i]
pfUI.unlock:SaveScale(frame, scale)
end
elseif IsShiftKeyDown() and strsub(frame:GetName(),0,15) == "pfLootRollFrame" then
for i=1,4 do
local frame = _G["pfLootRollFrame" .. i]
pfUI.unlock:SaveScale(frame, scale)
end
else
pfUI.unlock:SaveScale(frame, scale)
end
-- repaint hackfix for panels
if pfUI.panel and pfUI.chat then
pfUI.panel.left:SetScale(pfUI.chat.left:GetScale())
pfUI.panel.right:SetScale(pfUI.chat.right:GetScale())
end
if frame.OnMove then frame:OnMove() end
end)
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
local cframe = _G["pfCombo" .. i]
cframe:StartMoving()
cframe:StopMovingOrSizing()
cframe.drag.backdrop:SetBackdropBorderColor(1,1,1,1)
end
end
if strsub(frame:GetName(),0,6) == "pfRaid" then
for i=1,40 do
local cframe = _G["pfRaid" .. i]
cframe:StartMoving()
cframe:StopMovingOrSizing()
cframe.drag.backdrop:SetBackdropBorderColor(1,1,1,1)
end
end
if strsub(frame:GetName(),0,7) == "pfGroup" then
for i=1,4 do
local cframe = _G["pfGroup" .. i]
cframe:StartMoving()
cframe:StopMovingOrSizing()
cframe.drag.backdrop:SetBackdropBorderColor(1,1,1,1)
end
end
if strsub(frame:GetName(),0,15) == "pfLootRollFrame" then
for i=1,4 do
local cframe = _G["pfLootRollFrame" .. i]
cframe:StartMoving()
cframe:StopMovingOrSizing()
cframe.drag.backdrop:SetBackdropBorderColor(1,1,1,1)
end
end
_, _, _, xpos, ypos = frame:GetPoint()
frame.oldPos = { xpos, ypos }
elseif IsControlKeyDown() then
if strsub(frame:GetName(),0,6) == "pfRaid" then
local id = tonumber(strsub(frame:GetName(),7,8))
local b = 1
for i=6,40,5 do b = ( id >= i ) and i or b end
for i=b,b+4 do
local cframe = _G["pfRaid" .. i]
cframe:StartMoving()
cframe:StopMovingOrSizing()
cframe.drag.backdrop:SetBackdropBorderColor(1,1,1,1)
end
frame.moveSubgroup = { b, b+4 }
end
_, _, _, xpos, ypos = frame:GetPoint()
frame.oldPos = { xpos, ypos }
else
frame.oldPos = nil
end
frame.drag.backdrop:SetBackdropBorderColor(1,1,1,1)
frame:StartMoving()
if frame.OnMove then frame:OnMove() end
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)
if frame.oldPos then
local diffxpos = frame.oldPos[1] - xpos
local diffypos = frame.oldPos[2] - ypos
if strsub(frame:GetName(),0,7) == "pfCombo" then
for i=1,5 do
local cframe = _G["pfCombo" .. i]
cframe.drag.backdrop:SetBackdropBorderColor(.2,1,.8,1)
if cframe:GetName() ~= frame:GetName() then
local _, _, _, xpos, ypos = cframe:GetPoint()
cframe:SetPoint("TOPLEFT", xpos - diffxpos, ypos - diffypos)
pfUI.unlock:SavePosition(cframe)
end
end
elseif strsub(frame:GetName(),0,6) == "pfRaid" then
local b = frame.moveSubgroup and frame.moveSubgroup[1] or 1
local e = frame.moveSubgroup and frame.moveSubgroup[2] or 40
frame.moveSubgroup = nil
for i=b,e do
local cframe = _G["pfRaid" .. i]
cframe.drag.backdrop:SetBackdropBorderColor(.2,1,.8,1)
if cframe:GetName() ~= frame:GetName() then
local _, _, _, xpos, ypos = cframe:GetPoint()
cframe:SetPoint("TOPLEFT", xpos - diffxpos, ypos - diffypos)
pfUI.unlock:SavePosition(cframe)
end
end
elseif strsub(frame:GetName(),0,7) == "pfGroup" then
for i=1,4 do
local cframe = _G["pfGroup" .. i]
cframe.drag.backdrop:SetBackdropBorderColor(.2,1,.8,1)
if cframe:GetName() ~= frame:GetName() then
local _, _, _, xpos, ypos = cframe:GetPoint()
cframe:SetPoint("TOPLEFT", xpos - diffxpos, ypos - diffypos)
pfUI.unlock:SavePosition(cframe)
end
end
elseif strsub(frame:GetName(),0,15) == "pfLootRollFrame" then
for i=1,4 do
local cframe = _G["pfLootRollFrame" .. i]
cframe.drag.backdrop:SetBackdropBorderColor(.2,1,.8,1)
if cframe:GetName() ~= frame:GetName() then
local _, _, _, xpos, ypos = cframe:GetPoint()
cframe:SetPoint("TOPLEFT", xpos - diffxpos, ypos - diffypos)
pfUI.unlock:SavePosition(cframe)
end
end
end
end
pfUI.unlock:SavePosition(frame)
pfUI.unlock.settingChanged = true
end)
frame.drag:SetScript("OnClick", function()
pfUI_config["position"][frame:GetName()] = nil
frame:ClearAllPoints()
UpdateMovable(frame)
end)
end
frame:SetMovable(true)
frame.drag:EnableMouse(true)
frame.drag:Show()
frame:Show()
end
end
end)
pfUI.unlock:SetScript("OnHide", function()
for name, frame in pairs(pfUI.movables) do
local frame = frame or _G[name]
if frame then
frame:StopMovingOrSizing()
frame:SetMovable(false)
frame.drag:EnableMouse(false)
frame.drag:Hide()
if frame.hideLater == true then
frame:Hide()
end
UpdateMovable(frame)
end
end
pfUI.unlock:Hide()
pfUI.gui:Show()
end)
function pfUI.unlock:SaveScale(frame, scale)
local function SaveScale(frame, scale)
frame:SetScale(scale)
if not C.position[frame:GetName()] then
@@ -318,6 +68,219 @@ pfUI:RegisterModule("unlock", function ()
end)
end
local function SavePosition(frame)
local _, _, _, xpos, ypos = frame:GetPoint()
if not C.position[frame:GetName()] then
C.position[frame:GetName()] = {}
end
C.position[frame:GetName()]["xpos"] = round(xpos)
C.position[frame:GetName()]["ypos"] = round(ypos)
UpdateMovable(frame)
end
local function DrawGrid()
local grid = CreateFrame("Frame", this:GetName() .. "Grid", this)
grid:SetAllPoints(this)
local size = 1
local line = {}
local width = GetScreenWidth()
local height = GetScreenHeight()
local ratio = width / GetScreenHeight()
local rheight = GetScreenHeight() * ratio
local wStep = width / 128
local hStep = rheight / 128
-- vertical lines
for i = 0, 128 do
if i == 128 / 2 then
line = grid:CreateTexture(nil, 'BORDER')
line:SetTexture(.1, .5, .4)
else
line = grid:CreateTexture(nil, 'BACKGROUND')
line:SetTexture(0, 0, 0, .5)
end
line:SetPoint("TOPLEFT", grid, "TOPLEFT", i*wStep - (size/2), 0)
line:SetPoint('BOTTOMRIGHT', grid, 'BOTTOMLEFT', i*wStep + (size/2), 0)
end
-- horizontal lines
for i = 1, floor(height/hStep) do
if i == floor(height/hStep / 2) then
line = grid:CreateTexture(nil, 'BORDER')
line:SetTexture(.1, .5, .4)
else
line = grid:CreateTexture(nil, 'BACKGROUND')
line:SetTexture(0, 0, 0)
end
line:SetPoint("TOPLEFT", grid, "TOPLEFT", 0, -(i*hStep) + (size/2))
line:SetPoint('BOTTOMRIGHT', grid, 'TOPRIGHT', 0, -(i*hStep + size/2))
end
return grid
end
local function DraggerOnMouseWheel()
local frame = this.frame
local scale = round(frame:GetScale() + arg1/10, 1)
pfUI.unlock.selection = GetFrames()
for id, frame in pairs(pfUI.unlock.selection) do
SaveScale(frame, scale)
end
-- repaint hackfix for panels
if pfUI.panel and pfUI.chat then
pfUI.panel.left:SetScale(pfUI.chat.left:GetScale())
pfUI.panel.right:SetScale(pfUI.chat.right:GetScale())
end
if frame.OnMove then frame:OnMove() end
end
local function DraggerOnMouseDown()
if arg1 == "MiddleButton" then return end
local frame = this.frame
pfUI.unlock.selection = GetFrames()
for id, frame in pairs(pfUI.unlock.selection) do
frame:StartMoving()
frame:StopMovingOrSizing()
frame.drag.backdrop:SetBackdropBorderColor(.2,1,.8,1)
end
local _, _, _, xpos, ypos = frame:GetPoint()
frame.oldPos = { xpos, ypos }
frame:StartMoving()
if frame.OnMove then frame:OnMove() end
end
local function DraggerOnMouseUp()
if arg1 == "MiddleButton" then return end
local frame = this.frame
local name = this.fname
frame:StopMovingOrSizing()
local _, _, _, xpos, ypos = frame:GetPoint()
local diffxpos = frame.oldPos[1] - xpos
local diffypos = frame.oldPos[2] - ypos
for id, frame in pairs(pfUI.unlock.selection) do
CreateBackdrop(frame.drag)
if frame:GetName() ~= name then
local _, _, _, xpos, ypos = frame:GetPoint()
frame:SetPoint("TOPLEFT", xpos - diffxpos, ypos - diffypos)
end
SavePosition(frame)
end
this.backdrop:SetBackdropBorderColor(1,1,1,1)
pfUI.unlock.settingChanged = true
end
local function DraggerOnClick()
pfUI.unlock.selection = GetFrames()
for id, frame in pairs(pfUI.unlock.selection) do
pfUI_config["position"][frame:GetName()] = nil
frame:ClearAllPoints()
UpdateMovable(frame)
end
end
local function DraggerOnEnter()
this.backdrop:SetBackdropBorderColor(1,1,1,1)
end
local function DraggerOnLeave()
CreateBackdrop(this)
end
local function CreateDragger(f)
local fname = f:GetName()
local label = string.sub(fname, 1, 2) == "pf" and strsub(fname,3) or fname
local d = CreateFrame("Button", fname .. "Drag", f)
d:RegisterForClicks("MiddleButtonUp")
d:SetAllPoints(f)
d:SetFrameStrata("DIALOG")
d:SetAlpha(1)
d:EnableMouseWheel(1)
d.text = d:CreateFontString("Status", "LOW", "GameFontNormal")
d.text:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE")
d.text:ClearAllPoints()
d.text:SetAllPoints(d)
d.text:SetPoint("CENTER", 0, 0)
d.text:SetFontObject(GameFontWhite)
d.frame = f
d.fname = fname
if d:GetHeight() > (2 * d:GetWidth()) then
label = strvertical(label)
end
d.text:SetText(label)
d:SetScript("OnMouseWheel", DraggerOnMouseWheel)
d:SetScript("OnMouseDown", DraggerOnMouseDown)
d:SetScript("OnMouseUp", DraggerOnMouseUp)
d:SetScript("OnClick", DraggerOnClick)
d:SetScript("OnEnter", DraggerOnEnter)
d:SetScript("OnLeave", DraggerOnLeave)
CreateBackdrop(d, nil, nil, .8)
return d
end
pfUI.unlock = CreateFrame("Button", "pfUnlock", UIParent)
pfUI.unlock.selection = {}
pfUI.unlock:Hide()
pfUI.unlock:SetAllPoints(WorldFrame)
pfUI.unlock:SetFrameStrata("BACKGROUND")
pfUI.unlock:SetScript("OnClick", function()
this:Hide()
end)
pfUI.unlock:SetScript("OnShow", function()
this.grid = this.grid or DrawGrid()
for name, frame in pairs(pfUI.movables) do
local frame = frame or _G[name]
if not frame:IsShown() then frame.hideLater = true end
frame.drag = frame.drag or CreateDragger(frame)
frame:SetMovable(true)
frame.drag:Show()
frame:Show()
end
end)
pfUI.unlock:SetScript("OnHide", function()
for name, frame in pairs(pfUI.movables) do
local frame = frame or _G[name]
if frame.hideLater == true then frame:Hide() end
frame:StopMovingOrSizing()
frame:SetMovable(false)
frame.drag:Hide()
UpdateMovable(frame)
end
pfUI.unlock:Hide()
pfUI.gui:Show()
end)
function pfUI.unlock:UnlockFrames()
local txt = T["|cff33ffccUnlock Mode|r\nThis mode allows you to move frames by dragging them using the mouse cursor. Frames can be scaled by scrolling up and down.\nTo scale multiple frames at once (eg. raidframes), hold down the shift key while scrolling. Click into an empty space to go back to the pfUI menu."]
CreateInfoBox(txt, 15, pfUI.unlock)
@@ -325,4 +288,6 @@ pfUI:RegisterModule("unlock", function ()
pfUI.unlock:Show()
pfUI.gui:Hide()
end
table.insert(UISpecialFrames, "pfUnlock")
end)