From 6b04e0f1b2b5b3c21fee99b9dd9b6ce79ffb5467 Mon Sep 17 00:00:00 2001 From: shagu Date: Tue, 24 Aug 2021 17:16:30 +0200 Subject: [PATCH] move-unitframes: allow to move unitframes --- mods/move-unitframes.lua | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 mods/move-unitframes.lua diff --git a/mods/move-unitframes.lua b/mods/move-unitframes.lua new file mode 100644 index 0000000..de2c2c5 --- /dev/null +++ b/mods/move-unitframes.lua @@ -0,0 +1,84 @@ +local _G = _G or getfenv(0) + +local module = ShaguTweaks:register({ + title = "Movable Unit Frames", + description = "Unit Frames can be moved while and are pressed", + enabled = nil, +}) + +local movables = { "PlayerFrame", "TargetFrame" } + +module.enable = function(self) + local unlocker = CreateFrame("Frame", nil, UIParent) + unlocker:SetAllPoints(UIParent) + + unlocker.movable = nil + unlocker:SetScript("OnUpdate", function() + if IsShiftKeyDown() and IsControlKeyDown() then + if not unlocker.movable then + for _, frame in pairs(movables) do + _G[frame]:SetUserPlaced(true) + _G[frame]:SetMovable(true) + _G[frame]:EnableMouse(true) + _G[frame]:RegisterForDrag("LeftButton") + _G[frame]:SetScript("OnDragStart", function() this:StartMoving() end) + _G[frame]:SetScript("OnDragStop", function() this:StopMovingOrSizing() end) + end + + unlocker.movable = true + unlocker.grid:Show() + end + elseif unlocker.movable then + for _, frame in pairs(movables) do + _G[frame]:SetScript("OnDragStart", function() end) + _G[frame]:SetScript("OnDragStop", function() end) + end + + unlocker.movable = nil + unlocker.grid:Hide() + end + end) + + unlocker.grid = CreateFrame("Frame", nil, WorldFrame) + unlocker.grid:SetAllPoints(WorldFrame) + unlocker.grid:Hide() + + local size = 1 + local line = {} + + local width = GetScreenWidth() + local height = GetScreenHeight() + + local ratio = width / GetScreenHeight() + local rheight = GetScreenHeight() * ratio + + local wStep = width / 64 + local hStep = rheight / 64 + + -- vertical lines + for i = 0, 64 do + if i == 64 / 2 then + line = unlocker.grid:CreateTexture(nil, 'BORDER') + line:SetTexture(.8, .6, 0) + else + line = unlocker.grid:CreateTexture(nil, 'BACKGROUND') + line:SetTexture(0, 0, 0, .2) + end + line:SetPoint("TOPLEFT", unlocker.grid, "TOPLEFT", i*wStep - (size/2), 0) + line:SetPoint('BOTTOMRIGHT', unlocker.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 = unlocker.grid:CreateTexture(nil, 'BORDER') + line:SetTexture(.8, .6, 0) + else + line = unlocker.grid:CreateTexture(nil, 'BACKGROUND') + line:SetTexture(0, 0, 0, .2) + end + + line:SetPoint("TOPLEFT", unlocker.grid, "TOPLEFT", 0, -(i*hStep) + (size/2)) + line:SetPoint('BOTTOMRIGHT', unlocker.grid, 'TOPRIGHT', 0, -(i*hStep + size/2)) + end +end