聊天重做前缓存
This commit is contained in:
167
Movers.lua
167
Movers.lua
@@ -207,8 +207,12 @@ local function SyncMoverToFrame(name)
|
||||
local w = (frame:GetWidth() or 100) * scale
|
||||
local h = (frame:GetHeight() or 50) * scale
|
||||
|
||||
mover:SetWidth(math.max(w, 72))
|
||||
mover:SetHeight(math.max(h, 40))
|
||||
local minW = 72
|
||||
local minH = 40
|
||||
if h > w * 3 then minW = 40 end
|
||||
if w > h * 3 then minH = 24 end
|
||||
mover:SetWidth(math.max(w, minW))
|
||||
mover:SetHeight(math.max(h, minH))
|
||||
|
||||
local l = frame:GetLeft()
|
||||
local b = frame:GetBottom()
|
||||
@@ -256,17 +260,12 @@ local function SyncFrameToMover(name)
|
||||
local pos = positions[name]
|
||||
if pos then
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint(pos.point, UIParent, pos.relativePoint, pos.xOfs or 0, pos.yOfs or 0)
|
||||
|
||||
local scale = frame:GetEffectiveScale() / UIParent:GetEffectiveScale()
|
||||
local newL = frame:GetLeft() or 0
|
||||
local newB = frame:GetBottom() or 0
|
||||
local dL = newL * scale - moverL
|
||||
local dB = newB * scale - moverB
|
||||
if math.abs(dL) > 2 or math.abs(dB) > 2 then
|
||||
SFrames:Print(string.format(
|
||||
"|cffff6666[位置偏差]|r |cffaaddff%s|r anchor=%s ofs=(%.1f,%.1f) dL=%.1f dB=%.1f scale=%.2f",
|
||||
entry.label or name, pos.point, pos.xOfs or 0, pos.yOfs or 0, dL, dB, scale))
|
||||
local fScale = frame:GetEffectiveScale() / UIParent:GetEffectiveScale()
|
||||
if fScale > 0.01 and math.abs(fScale - 1) > 0.001 then
|
||||
frame:SetPoint(pos.point, UIParent, pos.relativePoint,
|
||||
(pos.xOfs or 0) / fScale, (pos.yOfs or 0) / fScale)
|
||||
else
|
||||
frame:SetPoint(pos.point, UIParent, pos.relativePoint, pos.xOfs or 0, pos.yOfs or 0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -720,11 +719,14 @@ local function CreateControlBar()
|
||||
local accent = th.accent or { 1, 0.5, 0.8, 0.98 }
|
||||
local titleC = th.title or { 1, 0.88, 1 }
|
||||
|
||||
local ROW_Y_TOP = 12
|
||||
local ROW_Y_BOT = -12
|
||||
|
||||
controlBar = CreateFrame("Frame", "SFramesLayoutControlBar", UIParent)
|
||||
controlBar:SetFrameStrata("FULLSCREEN_DIALOG")
|
||||
controlBar:SetFrameLevel(200)
|
||||
controlBar:SetWidth(480)
|
||||
controlBar:SetHeight(44)
|
||||
controlBar:SetHeight(72)
|
||||
controlBar:SetPoint("TOP", UIParent, "TOP", 0, -8)
|
||||
controlBar:SetClampedToScreen(true)
|
||||
controlBar:SetMovable(true)
|
||||
@@ -739,7 +741,7 @@ local function CreateControlBar()
|
||||
|
||||
local title = controlBar:CreateFontString(nil, "OVERLAY")
|
||||
title:SetFont(Font(), 13, "OUTLINE")
|
||||
title:SetPoint("LEFT", controlBar, "LEFT", 14, 0)
|
||||
title:SetPoint("LEFT", controlBar, "LEFT", 14, ROW_Y_TOP)
|
||||
title:SetText("Nanami 布局")
|
||||
title:SetTextColor(titleC[1], titleC[2], titleC[3], 1)
|
||||
|
||||
@@ -747,17 +749,19 @@ local function CreateControlBar()
|
||||
sep:SetTexture("Interface\\Buttons\\WHITE8x8")
|
||||
sep:SetWidth(1)
|
||||
sep:SetHeight(24)
|
||||
sep:SetPoint("LEFT", controlBar, "LEFT", 118, 0)
|
||||
sep:SetPoint("LEFT", controlBar, "LEFT", 118, ROW_Y_TOP)
|
||||
sep:SetVertexColor(panelBd[1], panelBd[2], panelBd[3], 0.5)
|
||||
|
||||
local bx = 128
|
||||
|
||||
-- Snap toggle
|
||||
-- Snap toggle (row 1)
|
||||
local snapBtn = MakeControlButton(controlBar, "", 76, bx, function()
|
||||
local cfg = GetLayoutCfg()
|
||||
cfg.snapEnabled = not cfg.snapEnabled
|
||||
if controlBar._updateSnap then controlBar._updateSnap() end
|
||||
end)
|
||||
snapBtn:ClearAllPoints()
|
||||
snapBtn:SetPoint("LEFT", controlBar, "LEFT", bx, ROW_Y_TOP)
|
||||
controlBar.snapBtn = snapBtn
|
||||
|
||||
local function UpdateSnapBtnText()
|
||||
@@ -773,7 +777,7 @@ local function CreateControlBar()
|
||||
end
|
||||
controlBar._updateSnap = UpdateSnapBtnText
|
||||
|
||||
-- Grid toggle
|
||||
-- Grid toggle (row 1)
|
||||
local gridBtn = MakeControlButton(controlBar, "", 76, bx + 84, function()
|
||||
local cfg = GetLayoutCfg()
|
||||
cfg.showGrid = not cfg.showGrid
|
||||
@@ -782,6 +786,8 @@ local function CreateControlBar()
|
||||
if cfg.showGrid then gridFrame:Show() else gridFrame:Hide() end
|
||||
end
|
||||
end)
|
||||
gridBtn:ClearAllPoints()
|
||||
gridBtn:SetPoint("LEFT", controlBar, "LEFT", bx + 84, ROW_Y_TOP)
|
||||
controlBar.gridBtn = gridBtn
|
||||
|
||||
local function UpdateGridBtnText()
|
||||
@@ -797,18 +803,20 @@ local function CreateControlBar()
|
||||
end
|
||||
controlBar._updateGrid = UpdateGridBtnText
|
||||
|
||||
-- Reset all
|
||||
-- Reset all (row 1)
|
||||
local resetBtn = MakeControlButton(controlBar, "全部重置", 76, bx + 176, function()
|
||||
M:ResetAllMovers()
|
||||
end)
|
||||
resetBtn:ClearAllPoints()
|
||||
resetBtn:SetPoint("LEFT", controlBar, "LEFT", bx + 176, ROW_Y_TOP)
|
||||
local wbGold = th.wbGold or { 1, 0.88, 0.55 }
|
||||
resetBtn._text:SetTextColor(wbGold[1], wbGold[2], wbGold[3], 1)
|
||||
|
||||
-- Close
|
||||
-- Close (row 1)
|
||||
local closeBtn = CreateFrame("Button", nil, controlBar)
|
||||
closeBtn:SetWidth(60)
|
||||
closeBtn:SetHeight(26)
|
||||
closeBtn:SetPoint("RIGHT", controlBar, "RIGHT", -10, 0)
|
||||
closeBtn:SetPoint("RIGHT", controlBar, "RIGHT", -10, ROW_Y_TOP)
|
||||
closeBtn:SetBackdrop(ROUND_BACKDROP)
|
||||
closeBtn:SetBackdropColor(0.35, 0.08, 0.10, 0.95)
|
||||
closeBtn:SetBackdropBorderColor(0.65, 0.20, 0.25, 0.90)
|
||||
@@ -837,6 +845,64 @@ local function CreateControlBar()
|
||||
end)
|
||||
controlBar.closeBtn = closeBtn
|
||||
|
||||
-- Row separator
|
||||
local rowSep = controlBar:CreateTexture(nil, "ARTWORK")
|
||||
rowSep:SetTexture("Interface\\Buttons\\WHITE8x8")
|
||||
rowSep:SetHeight(1)
|
||||
rowSep:SetPoint("LEFT", controlBar, "LEFT", 10, 0)
|
||||
rowSep:SetPoint("RIGHT", controlBar, "RIGHT", -10, 0)
|
||||
rowSep:SetVertexColor(panelBd[1], panelBd[2], panelBd[3], 0.35)
|
||||
|
||||
-- Row 2: Preset buttons
|
||||
local presetLabel = controlBar:CreateFontString(nil, "OVERLAY")
|
||||
presetLabel:SetFont(Font(), 10, "OUTLINE")
|
||||
presetLabel:SetPoint("LEFT", controlBar, "LEFT", 14, ROW_Y_BOT)
|
||||
presetLabel:SetText("预设:")
|
||||
presetLabel:SetTextColor(0.7, 0.68, 0.78, 1)
|
||||
|
||||
controlBar._presetBtns = {}
|
||||
local AB = SFrames.ActionBars
|
||||
local presets = AB and AB.PRESETS or {}
|
||||
local px = 56
|
||||
for idx = 1, 3 do
|
||||
local p = presets[idx]
|
||||
local pName = p and p.name or ("方案" .. idx)
|
||||
local pDesc = p and p.desc or ""
|
||||
local pId = idx
|
||||
local pbtn = MakeControlButton(controlBar, pName, 80, px + (idx - 1) * 88, function()
|
||||
if AB and AB.ApplyPreset then
|
||||
AB:ApplyPreset(pId)
|
||||
end
|
||||
end)
|
||||
pbtn:ClearAllPoints()
|
||||
pbtn:SetPoint("LEFT", controlBar, "LEFT", px + (idx - 1) * 88, ROW_Y_BOT)
|
||||
pbtn._text:SetFont(Font(), 9, "OUTLINE")
|
||||
pbtn._presetId = pId
|
||||
|
||||
pbtn:SetScript("OnEnter", function()
|
||||
local a2 = T().accent or { 1, 0.5, 0.8 }
|
||||
this:SetBackdropBorderColor(a2[1], a2[2], a2[3], 0.95)
|
||||
this._text:SetTextColor(1, 1, 1, 1)
|
||||
GameTooltip:SetOwner(this, "ANCHOR_BOTTOM")
|
||||
GameTooltip:AddLine(pName, 1, 0.85, 0.55)
|
||||
GameTooltip:AddLine(pDesc, 0.75, 0.75, 0.85, true)
|
||||
GameTooltip:Show()
|
||||
end)
|
||||
pbtn:SetScript("OnLeave", function()
|
||||
local th2 = T()
|
||||
local bd2 = th2.buttonBorder or { 0.35, 0.30, 0.50, 0.90 }
|
||||
local tc2 = th2.buttonText or { 0.85, 0.82, 0.92 }
|
||||
this:SetBackdropColor(th2.buttonBg and th2.buttonBg[1] or 0.16,
|
||||
th2.buttonBg and th2.buttonBg[2] or 0.12,
|
||||
th2.buttonBg and th2.buttonBg[3] or 0.22, 0.94)
|
||||
this:SetBackdropBorderColor(bd2[1], bd2[2], bd2[3], bd2[4] or 0.90)
|
||||
this._text:SetTextColor(tc2[1], tc2[2], tc2[3], 1)
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
|
||||
controlBar._presetBtns[idx] = pbtn
|
||||
end
|
||||
|
||||
controlBar:Hide()
|
||||
return controlBar
|
||||
end
|
||||
@@ -844,7 +910,7 @@ end
|
||||
--------------------------------------------------------------------------------
|
||||
-- Register mover
|
||||
--------------------------------------------------------------------------------
|
||||
function M:RegisterMover(name, frame, label, defaultPoint, defaultRelativeTo, defaultRelPoint, defaultX, defaultY, onMoved)
|
||||
function M:RegisterMover(name, frame, label, defaultPoint, defaultRelativeTo, defaultRelPoint, defaultX, defaultY, onMoved, opts)
|
||||
if not name or not frame then return end
|
||||
|
||||
registry[name] = {
|
||||
@@ -856,6 +922,7 @@ function M:RegisterMover(name, frame, label, defaultPoint, defaultRelativeTo, de
|
||||
defaultX = defaultX or 0,
|
||||
defaultY = defaultY or 0,
|
||||
onMoved = onMoved,
|
||||
alwaysShowInLayout = opts and opts.alwaysShowInLayout or false,
|
||||
}
|
||||
|
||||
CreateMoverFrame(name, registry[name])
|
||||
@@ -890,10 +957,19 @@ function M:EnterLayoutMode()
|
||||
UIParent:GetWidth(), UIParent:GetHeight(),
|
||||
UIParent:GetRight() or 0, UIParent:GetTop() or 0))
|
||||
|
||||
for name, _ in pairs(registry) do
|
||||
for name, entry in pairs(registry) do
|
||||
local frame = entry and entry.frame
|
||||
local shouldShow = entry.alwaysShowInLayout
|
||||
or (frame and frame.IsShown and frame:IsShown())
|
||||
SyncMoverToFrame(name)
|
||||
local mover = moverFrames[name]
|
||||
if mover then mover:Show() end
|
||||
if mover then
|
||||
if shouldShow then
|
||||
mover:Show()
|
||||
else
|
||||
mover:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
SFrames:Print("布局模式已开启 - 拖拽移动 | 箭头微调 | 右键重置 | Shift禁用磁吸")
|
||||
@@ -924,6 +1000,22 @@ function M:IsLayoutMode()
|
||||
return isLayoutMode
|
||||
end
|
||||
|
||||
function M:SetMoverAlwaysShow(name, alwaysShow)
|
||||
local entry = registry[name]
|
||||
if entry then
|
||||
entry.alwaysShowInLayout = alwaysShow
|
||||
end
|
||||
local mover = moverFrames[name]
|
||||
if mover and isLayoutMode then
|
||||
if alwaysShow then
|
||||
SyncMoverToFrame(name)
|
||||
mover:Show()
|
||||
else
|
||||
mover:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Reset movers
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -979,13 +1071,30 @@ function M:ApplyPosition(name, frame, defaultPoint, defaultRelTo, defaultRelPoin
|
||||
local pos = positions[name]
|
||||
if pos and pos.point and pos.relativePoint then
|
||||
frame:ClearAllPoints()
|
||||
frame:SetPoint(pos.point, UIParent, pos.relativePoint, pos.xOfs or 0, pos.yOfs or 0)
|
||||
local fScale = frame:GetEffectiveScale() / UIParent:GetEffectiveScale()
|
||||
if fScale > 0.01 and math.abs(fScale - 1) > 0.001 then
|
||||
frame:SetPoint(pos.point, UIParent, pos.relativePoint,
|
||||
(pos.xOfs or 0) / fScale, (pos.yOfs or 0) / fScale)
|
||||
else
|
||||
frame:SetPoint(pos.point, UIParent, pos.relativePoint, pos.xOfs or 0, pos.yOfs or 0)
|
||||
end
|
||||
return true
|
||||
else
|
||||
frame:ClearAllPoints()
|
||||
local relFrame = (defaultRelTo and _G[defaultRelTo]) or UIParent
|
||||
frame:SetPoint(defaultPoint or "CENTER", relFrame, defaultRelPoint or "CENTER",
|
||||
defaultX or 0, defaultY or 0)
|
||||
if relFrame == UIParent then
|
||||
local fScale = frame:GetEffectiveScale() / UIParent:GetEffectiveScale()
|
||||
if fScale > 0.01 and math.abs(fScale - 1) > 0.001 then
|
||||
frame:SetPoint(defaultPoint or "CENTER", UIParent, defaultRelPoint or "CENTER",
|
||||
(defaultX or 0) / fScale, (defaultY or 0) / fScale)
|
||||
else
|
||||
frame:SetPoint(defaultPoint or "CENTER", UIParent, defaultRelPoint or "CENTER",
|
||||
defaultX or 0, defaultY or 0)
|
||||
end
|
||||
else
|
||||
frame:SetPoint(defaultPoint or "CENTER", relFrame, defaultRelPoint or "CENTER",
|
||||
defaultX or 0, defaultY or 0)
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
@@ -996,3 +1105,7 @@ end
|
||||
function M:GetRegistry()
|
||||
return registry
|
||||
end
|
||||
|
||||
function M:SyncMoverToFrame(name)
|
||||
SyncMoverToFrame(name)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user