Nenue@6: -- User: Krakyn Nenue@6: -- Created: 12/19/2015 12:18 AM Nenue@6: Nenue@6: local _G = _G Nenue@6: local T = LibStub("AceAddon-3.0"):GetAddon("Turok") Nenue@6: local TL = 'Options' Nenue@6: local mod = T:NewModule(TL) Nenue@6: local LSM = LibStub("LibSharedMedia-3.0") Nenue@6: local ConfigDialog = LibStub("AceConfigDialog-3.0") Nenue@6: --@debug Nenue@6: local print = function(...) _G.print(TL, ...) end Nenue@6: local db Nenue@6: Nenue@6: local TITLE_FONT_COLOR = '|cFF88FF44' Nenue@6: local INPUT_FONT_COLOR = '|cFFFFFF00' Nenue@6: local STACK_COLOR1 = '|cFFFF8800' Nenue@6: local STACK_COLOR2 = '|cFFFFFF00' Nenue@6: local FONTVAR_COLOR = '|cFFFFAA44' Nenue@6: local FRAMEVAR_COLOR = '|cFFFFFF44' Nenue@6: local PARAMETER_COLOR = '|cFF9999FF' Nenue@6: local STATE_COLOR = '|cFFFF99FF' Nenue@6: Nenue@6: function mod:OnInitialize() Nenue@6: T:Print("config mod init") Nenue@6: end Nenue@6: Nenue@6: function mod:OnEnable() Nenue@6: T:Print("config mod enable") Nenue@6: db = T.db Nenue@6: LibStub("AceConfig-3.0"):RegisterOptionsTable('Turok', T.MakeOptions(), {"turok"}) Nenue@6: T.configDialog = ConfigDialog:AddToBlizOptions("Turok") Nenue@6: end Nenue@6: Nenue@6: local optL = { Nenue@6: background_color = 'Background color', Nenue@6: foreground_color = 'Foreground color', Nenue@6: width = FRAMEVAR_COLOR..'Width', Nenue@6: height = FRAMEVAR_COLOR..'Height', Nenue@6: alpha = FRAMEVAR_COLOR..'Alpha', Nenue@6: alpha_ooc = STATE_COLOR..'Alpha (OOC)', Nenue@6: label_strata = FONTVAR_COLOR..'Text Strata', Nenue@6: label_font = FONTVAR_COLOR..'Font', Nenue@6: label_size = FONTVAR_COLOR..'Font Size', Nenue@6: label_inset = FONTVAR_COLOR..'Text Insets', Nenue@6: foreground_blend = 'Foreground Blend Mode', Nenue@6: background_blend = 'Background Blend Mode', Nenue@6: isStatic = PARAMETER_COLOR..'Static Bar', Nenue@6: duration = PARAMETER_COLOR..'Duration', Nenue@6: isIcon = PARAMETER_COLOR..'Icon Only', Nenue@6: } Nenue@6: Nenue@6: local anchors = { Nenue@6: ['CENTER'] = 'Center', Nenue@6: ['TOPLEFT'] = 'Top Left', Nenue@6: ['TOP'] = 'Top', Nenue@6: ['TOPRIGHT'] = 'Top Right', Nenue@6: ['RIGHT'] = 'Right', Nenue@6: ['BOTTOMRIGHT'] = 'Bottom Right', Nenue@6: ['BOTTOM'] = 'Bottom', Nenue@6: ['BOTTOMLEFT'] = 'Bottom Left', Nenue@6: ['LEFT'] = 'Left' Nenue@6: } Nenue@6: Nenue@6: local frames = { Nenue@6: ['UIParent'] = 'UIParent', Nenue@6: ['TkPowerBar'] = 'Power Bar', Nenue@6: ['TekplayerCastBar'] = 'Player Castbar', Nenue@6: ['TektargetCastBar'] = 'Target Castbar', Nenue@6: ['TekfocusCastBar'] = 'Focus Castbar', Nenue@6: ['TekpetCastBar'] = 'Pet Castbar' Nenue@6: } Nenue@6: Nenue@6: local range = { Nenue@6: ['alpha'] = {0, 1, .01}, Nenue@6: ['alpha_ooc'] = {0, 1, .01}, Nenue@6: ['label_size'] = {1, 72, 1}, Nenue@6: ['label_inset'] = {-30, 30, 1}, Nenue@6: ['width'] = {0, 1200, 1}, Nenue@6: ['height'] = {0, 1200, 1}, Nenue@6: ['raidbuff_width'] = {0, 1200, 1}, Nenue@6: ['raidbuff_height'] = {0, 1200, 1}, Nenue@6: ['duration'] = {0, 6000, 0.1 }, Nenue@6: ['glow_size'] = {0, 30, 1}, Nenue@6: ['spark_size'] = {0, 30, 1}, Nenue@6: } Nenue@6: Nenue@6: local opt_order = { Nenue@6: ['width'] = 10, Nenue@6: ['height'] = 15, Nenue@6: ['anchor'] = 20, Nenue@6: ['anchorTo'] = 25, Nenue@6: ['parent'] = 30, Nenue@6: Nenue@6: ['alpha'] = 110, Nenue@6: ['alpha_ooc'] = 115, Nenue@6: ['label_size'] = 200, Nenue@6: ['label_inset'] = 210, Nenue@6: ['label_font'] = 220, Nenue@6: Nenue@6: ['background_texture'] = 300, Nenue@6: ['background_color'] = 320, Nenue@6: ['foreground_texture'] = 350, Nenue@6: ['foreground_color'] = 370, Nenue@6: } Nenue@6: local opt_width = { Nenue@6: Nenue@6: } Nenue@6: Nenue@6: -- options dialog root Nenue@6: T.myopts = { Nenue@6: type = 'group', Nenue@6: name = TITLE_FONT_COLOR..'Turok|r', Nenue@6: desc = 'Dinosaur HUD', Nenue@6: handler = T, Nenue@6: set = function(info,value, ...) Nenue@6: local db = T.db Nenue@6: local index = db Nenue@6: local traversal = 'db' Nenue@6: for i = 1, #info-1 do Nenue@6: if type(index[info[i]]) == 'table' then Nenue@6: --print('|cFFFF0000SET|r:', i, info[i]) Nenue@6: traversal = traversal .. '.' .. info[i] Nenue@6: index = index[info[i]] Nenue@6: end Nenue@6: Nenue@6: end Nenue@6: --print('|cFFFF0000SET|r: hops=',#info,'index=', traversal, ' key=', info[#info]) Nenue@6: Nenue@6: if type(value) ~= 'boolean' and select('#',...) == 3 then Nenue@6: --print('|cFFFF0000SET|r', 'multi-args', select('#',...)) Nenue@6: value = {value, ... } Nenue@6: else Nenue@6: --print('|cFFFF0000SET|r', 'single-arg', value) Nenue@6: end Nenue@6: Nenue@6: index[info[#info]] = value Nenue@6: end, Nenue@6: get = function(info) Nenue@6: local db = T.db Nenue@6: local value = db[info[1]] Nenue@6: local traversal = info[1] Nenue@6: if #info > 1 then Nenue@6: for i=2, #info do Nenue@6: traversal = traversal .. '.' .. info[i] Nenue@6: if value[info[i]] ~= nil then Nenue@6: value = value[info[i]] Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: --print('|cFFFF00FFGET|r: hops=', #info, 'index=', traversal, 'value=', value) Nenue@6: Nenue@6: if type(value) == 'table' then Nenue@6: return unpack(value) Nenue@6: end Nenue@6: return value Nenue@6: end, Nenue@6: } Nenue@6: Nenue@6: function T:MakeOptions(dbtable, index, name, prefix) Nenue@6: -- index = option insertion destination Nenue@6: -- parent = nesting point Nenue@6: local parent Nenue@6: if not (index and dbtable) then Nenue@6: dbtable = db Nenue@6: name = 'root' Nenue@6: prefix = '' Nenue@6: parent = T.myopts Nenue@6: parent.args = { Nenue@6: main = { Nenue@6: order = 1, Nenue@6: type = 'group', Nenue@6: name = 'Global', Nenue@6: get = function(info) print('db.'..info[#info]..' get') Nenue@6: if type(db[info[#info]]) == 'table' then Nenue@6: print('getting color data', unpack(db[info[#info]])) Nenue@6: return unpack(db[info[#info]]) Nenue@6: end Nenue@6: return db[info[#info]] Nenue@6: end, Nenue@6: set = function(info, value, ...) print('db.'..info[#info]..' SET') Nenue@6: if select('#',...) == 3 then Nenue@6: print('receiving color data', value, ...) Nenue@6: value = {value, ...} Nenue@6: end Nenue@6: db[info[#info]] = value Nenue@6: end, Nenue@6: args = {}, Nenue@6: }} Nenue@6: index = parent.args.main Nenue@6: print(STACK_COLOR1..'using TurokData as index') Nenue@6: else Nenue@6: index.type = 'group' Nenue@6: index.name = name Nenue@6: index.args = {} Nenue@6: parent = index Nenue@6: end Nenue@6: Nenue@6: local order = 2 Nenue@6: for k, v in pairs(dbtable) do Nenue@6: k = tostring(k) Nenue@6: local kt = INPUT_FONT_COLOR .. (optL[k] or k) Nenue@6: local nested = false Nenue@6: --@debug@ Nenue@6: print(STACK_COLOR2..prefix..'.'..STACK_COLOR1..k..'|r =',v)--@debug@ Nenue@6: if type(v) == 'table' then Nenue@6: if table.getn(v) == 4 then Nenue@6: index.args[k] = { Nenue@6: name = kt, Nenue@6: type = 'color', Nenue@6: hasAlpha = true, Nenue@6: --@debug@ Nenue@6: print('color_pack=',unpack(v))--@debug@ Nenue@6: } Nenue@6: else Nenue@6: parent.args[k] = {} Nenue@6: nested = true Nenue@6: T:MakeOptions(v, parent.args[k], k, prefix .. '.' .. name) Nenue@6: end Nenue@6: elseif type(v) == 'string' then Nenue@6: if string.match(k, "_font") then Nenue@6: local font_list = {} Nenue@6: for k, v in pairs(LSM:HashTable('font')) do Nenue@6: font_list[v] = k Nenue@6: end Nenue@6: index.args[k] = { Nenue@6: name = kt, Nenue@6: type = 'select', Nenue@6: values = font_list Nenue@6: } Nenue@6: elseif k:match('anchor$') or k:match('_point$') or k:match('anchorTo') then Nenue@6: Nenue@6: index.args[k] = { Nenue@6: name = kt, Nenue@6: type = 'select', Nenue@6: values = anchors Nenue@6: } Nenue@6: Nenue@6: elseif k:match('justifyH$') then Nenue@6: index.args[k] = { Nenue@6: name = kt, Nenue@6: type = 'select', Nenue@6: values = { Nenue@6: ['LEFT'] = 'Left', Nenue@6: ['CENTER'] = 'Center', Nenue@6: ['RIGHT'] = 'Right' Nenue@6: } Nenue@6: } Nenue@6: Nenue@6: elseif k:match('strata$') then Nenue@6: index.args[k] = { Nenue@6: name = kt, Nenue@6: type = 'select', Nenue@6: values = { Nenue@6: BACKGROUND = 'BACKGROUND (clickthrough)', Nenue@6: LOW = 'LOW', Nenue@6: MEDIUM = 'MEDIUM', Nenue@6: HIGH = 'HIGH', Nenue@6: DIALOG = 'DIALOG', Nenue@6: FULLSCREEN = 'FULLSCREEN', Nenue@6: FULLSCREEN_DIALOG = 'FULLSCREEN_DIALOG', Nenue@6: TOOLTIP = 'TOOLTIP (clickthrough)', Nenue@6: } Nenue@6: } Nenue@6: Nenue@6: elseif k:match('outline$') then Nenue@6: index.args[k] = { Nenue@6: name = kt, Nenue@6: type = 'select', Nenue@6: values = { Nenue@6: ['NONE'] = 'NONE', Nenue@6: ['OUTLINE'] = 'OUTLINE', Nenue@6: ['THICKOUTLINE'] = 'THICKOUTLINE' Nenue@6: } Nenue@6: } Nenue@6: elseif k:match('parent') then Nenue@6: index.args[k] = { Nenue@6: name = kt, Nenue@6: type = 'select', Nenue@6: values = frames Nenue@6: } Nenue@6: else Nenue@6: Nenue@6: index.args[k] = { Nenue@6: name = kt, Nenue@6: type = 'input', Nenue@6: width = 'full', Nenue@6: } Nenue@6: end Nenue@6: elseif type(v) == 'number' then Nenue@6: Nenue@6: if not range[k] then Nenue@6: range[k] = {0,150,1 } Nenue@6: print('missing range values for', k) Nenue@6: end Nenue@6: Nenue@6: index.args[k] ={ Nenue@6: name = kt, Nenue@6: type = 'range', Nenue@6: min = range[k][1], Nenue@6: max = range[k][2], Nenue@6: softMax = range[k][2], Nenue@6: step = range[k][3], Nenue@6: bigStep = range[k][3], Nenue@6: } Nenue@6: elseif type(v) == 'boolean' then Nenue@6: Nenue@6: index.args[k] = { Nenue@6: name = kt, Nenue@6: type = 'toggle', Nenue@6: } Nenue@6: end Nenue@6: if nested then Nenue@6: parent.args[k].order = order + (opt_order[k] and opt_order[k] or 0) Nenue@6: elseif index.args[k] then Nenue@6: index.args[k].order = order + (opt_order[k] and opt_order[k] or 0) Nenue@6: print(' '..kt..' order = '..index.args[k].order) Nenue@6: else Nenue@6: print('|cFF99FFFFSkipped|r', kt) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: return parent Nenue@6: end