BrokerDisplayMap/prefs.lua

111 lines
2.8 KiB
Lua

local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local broker, db
local L = LibStub("AceLocale-3.0"):GetLocale(childName, true)
local function typecolor(objname)
return child:colorize(objname, db[objname]['active'] and (db[objname]['customTab'] and "00ffff" or (db[objname]['showText'] and "ffff00" or "ffffff")) or "ff0000")
end
local positions = {
['TOPLEFT'] = "TOPLEFT",
['TOP'] = "TOP",
['TOPRIGHT'] = "TOPRIGHT",
['LEFT'] = "LEFT",
['CENTER'] = "CENTER",
['RIGHT'] = "RIGHT",
['BOTTOMLEFT'] = "BOTTOMLEFT",
['BOTTOM'] = "BOTTOM",
['BOTTOMRIGHT'] = "BOTTOMRIGHT",
}
function child:updatePrefs(objname, brokerDefaults)
if(not broker) then return end
local p = broker['args']
p[objname] = {
['type'] = 'group',
['childGroups'] = 'tab',
['name'] = typecolor(objname),
['args'] = {},
}
db[objname] = db[objname] or CopyTable(brokerDefaults)
local s = p[objname]['args']
s['active'] = {
['name'] = L["Active"],
['type'] = "toggle",
['order'] = 1,
}
s['showText'] = {
['name'] = L["Show Text"],
['type'] = "toggle",
['order'] = 1,
}
s['customTab'] = {
['name'] = L["Custom Position"],
['type'] = "toggle",
['order'] = 1,
}
s['custom'] = {
['hidden'] = not db[objname]['customTab'],
['type'] = 'group',
['name'] = L["Custom Position"],
['order'] = 2,
['args'] = {},
}
local c = s['custom']['args']
c['anchor'] = {
['name'] = L["Anchor"],
['type'] = "select",
['values'] = positions,
}
c['relativTo'] = {
['name'] = L["Relative To Frame"],
['type'] = "input",
}
c['parentAnchor'] = {
['name'] = L["Parent Anchor"],
['type'] = "select",
['values'] = positions,
}
c['parentXOffset'] = {
['name'] = L["X-Offset"],
['type'] = "range",
['min'] = -400,
['max'] = 400,
['step'] = 1,
['isPercent'] = false,
}
c['parentYOffset'] = {
['name'] = L["Y-Offset"],
['type'] = "range",
['min'] = -400,
['max'] = 400,
['step'] = 1,
['isPercent'] = false,
}
end
function child:GetPref(info)
if(info[#info - 1] == 'custom') then
return db[info[#info-2]][info[#info - 1]][info[#info]]
end
return db[info[#info-1]][info[#info]]
end
function child:SetPref(info, value)
if(info[#info - 1] == 'custom') then
db[info[#info-2]][info[#info - 1]][info[#info]] = value
child:updatePrefs(info[#info-2])
else
db[info[#info-1]][info[#info]] = value
child:updatePrefs(info[#info-1])
end
child:updateBrokerDisplay()
end
local init = {
Setup = function(self)
db = child['db']
local config = LibStub:GetLibrary("zzConfig")
local options = child['options']
local main = options['args'][childName]
broker = config:AddConfigMenu(options, L["Broker"], 2, child, {['childGroups'] = 'tree'})
end
}
addon.RegisterCallback(init, format("Init%s", childName), 'Setup')