You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.7 KiB

5 years ago
local _, T = ...
local AB = T.ActionBook:compatible(2, 36)
assert(AB and 1, "Incompatible library bundle")
5 years ago
local L = AB:locale()
local MODERN = select(4,GetBuildInfo()) >= 8e4
5 years ago
local RegisterSimpleOptionsPanel do
local optionsForHandle, curHandle, curHandleID = {}
local f, fButtons = CreateFrame("Frame"), {}
5 years ago
f:Hide()
local function callSave()
local p = f:GetParent()
if p and type(p.OnActionChanged) == "function" then
p:OnActionChanged(curHandle)
elseif p and type(p.SaveAction) == "function" then -- DEPRECATED [2303]
5 years ago
p:SaveAction()
end
end
local function updateCheckButtonHitRect(self)
local b = self:GetParent()
b:SetHitRectInsets(0, -self:GetStringWidth()-5, 4, 4)
end
5 years ago
for i=1,3 do
local e = CreateFrame("CheckButton", nil, f, MODERN and "UICheckButtonTemplate" or "InterfaceOptionsCheckButtonTemplate")
if MODERN then
e:SetSize(24, 24)
e.Text:SetPoint("LEFT", e, "RIGHT", 2, 1)
e.Text:SetFontObject(GameFontHighlightLeft)
end
hooksecurefunc(e.Text, "SetText", updateCheckButtonHitRect)
5 years ago
e:SetMotionScriptsWhileDisabled(1)
e:SetScript("OnClick", callSave)
fButtons[i] = e
5 years ago
end
local function IsOwned(self, host)
return curHandle == self and f:GetParent() == host
5 years ago
end
local function Release(self, host)
if IsOwned(self, host) then
curHandle, curHandleID = nil
f:SetParent(nil)
f:ClearAllPoints()
f:Hide()
end
end
local function SetAction(self, host, actionTable)
local opts, op = optionsForHandle[self], f:GetParent()
5 years ago
assert(actionTable[1] == opts[0], "Invalid editor")
if curHandle and op and (op ~= host or self ~= curHandle) and type(op.OnEditorRelease) == "function" then
securecall(op.OnEditorRelease, op, curHandle)
end
5 years ago
f:SetParent(nil)
f:ClearAllPoints()
f:SetAllPoints(host)
f:SetParent(host)
curHandle, curHandleID = self, actionTable[2]
local ofsX = host.optionsColumnOffset
ofsX = type(ofsX) == "number" and ofsX or 2
5 years ago
local getState = opts.getOptionState
for i=1,#opts do
local w, oi, isChecked = fButtons[i], opts[i], false
5 years ago
w.Text:SetText(opts[oi])
w:SetPoint("TOPLEFT", ofsX, 23-21*i)
5 years ago
if getState then
isChecked = getState(actionTable, oi)
elseif actionTable[opts[i]] ~= nil then
isChecked = not not actionTable[oi]
end
w:SetChecked(isChecked)
w:Show()
end
for i=#opts+1,#fButtons do
fButtons[i]:Hide()
5 years ago
end
f:Show()
end
local function GetAction(self, into)
local opts = optionsForHandle[self]
into[1], into[2] = opts[0], curHandleID
for i=1,#opts do
into[opts[i]] = fButtons[i]:GetChecked() or nil
5 years ago
end
if opts.saveState then
opts.saveState(into)
end
end
function RegisterSimpleOptionsPanel(atype, opts)
local r = {IsOwned=IsOwned, Release=Release, SetAction=SetAction, GetAction=GetAction}
optionsForHandle[r], opts[0] = opts, atype
AB:RegisterEditorPanel(atype, r)
end
end
RegisterSimpleOptionsPanel("item", {"byName", "forceShow", "onlyEquipped",
byName=L"Also use items with the same name",
forceShow=L"Show a placeholder when unavailable",
onlyEquipped=L"Only show when equipped"
})
RegisterSimpleOptionsPanel("macro", {"forceShow",
forceShow=L"Show a placeholder when unavailable",
})
if MODERN then
RegisterSimpleOptionsPanel("extrabutton", {"forceShow",
forceShow=L"Show a placeholder when unavailable",
})
RegisterSimpleOptionsPanel("toy", {"forceShow",
forceShow=L"Show a placeholder when unavailable",
})
else
RegisterSimpleOptionsPanel("spell", {"upRank",
upRank=L"Use the highest known rank",
getOptionState=function(actionTable, _optKey)
return actionTable[3] ~= "lock-rank"
end,
saveState=function(intoTable)
intoTable[3], intoTable.upRank = not intoTable.upRank and "lock-rank" or nil
end,
})
end
AB.HUM.CreateSimpleEditorPanel = RegisterSimpleOptionsPanel