view Turok/Turok_Config.lua @ 6:a9b8b0866ece

clear out log jam
author Nenue
date Sun, 21 Feb 2016 08:32:53 -0500
parents
children
line wrap: on
line source
-- User: Krakyn
-- Created: 12/19/2015 12:18 AM

local _G = _G
local T = LibStub("AceAddon-3.0"):GetAddon("Turok")
local TL = 'Options'
local mod = T:NewModule(TL)
local LSM = LibStub("LibSharedMedia-3.0")
local ConfigDialog = LibStub("AceConfigDialog-3.0")
--@debug
local print = function(...) _G.print(TL, ...) end
local db

local TITLE_FONT_COLOR = '|cFF88FF44'
local INPUT_FONT_COLOR = '|cFFFFFF00'
local STACK_COLOR1 = '|cFFFF8800'
local STACK_COLOR2 = '|cFFFFFF00'
local FONTVAR_COLOR = '|cFFFFAA44'
local FRAMEVAR_COLOR = '|cFFFFFF44'
local PARAMETER_COLOR = '|cFF9999FF'
local STATE_COLOR = '|cFFFF99FF'

function mod:OnInitialize()
  T:Print("config mod init")
end

function mod:OnEnable()
  T:Print("config mod enable")
  db = T.db
  LibStub("AceConfig-3.0"):RegisterOptionsTable('Turok', T.MakeOptions(), {"turok"})
  T.configDialog = ConfigDialog:AddToBlizOptions("Turok")
end

local optL = {
  background_color = 'Background color',
  foreground_color = 'Foreground color',
  width = FRAMEVAR_COLOR..'Width',
  height = FRAMEVAR_COLOR..'Height',
  alpha = FRAMEVAR_COLOR..'Alpha',
  alpha_ooc = STATE_COLOR..'Alpha (OOC)',
  label_strata = FONTVAR_COLOR..'Text Strata',
  label_font = FONTVAR_COLOR..'Font',
  label_size = FONTVAR_COLOR..'Font Size',
  label_inset = FONTVAR_COLOR..'Text Insets',
  foreground_blend = 'Foreground Blend Mode',
  background_blend = 'Background Blend Mode',
  isStatic = PARAMETER_COLOR..'Static Bar',
  duration = PARAMETER_COLOR..'Duration',
  isIcon = PARAMETER_COLOR..'Icon Only',
}

local anchors = {
  ['CENTER'] = 'Center',
  ['TOPLEFT'] = 'Top Left',
  ['TOP'] = 'Top',
  ['TOPRIGHT'] = 'Top Right',
  ['RIGHT'] = 'Right',
  ['BOTTOMRIGHT'] = 'Bottom Right',
  ['BOTTOM'] = 'Bottom',
  ['BOTTOMLEFT'] = 'Bottom Left',
  ['LEFT'] = 'Left'
}

local frames = {
  ['UIParent'] = 'UIParent',
  ['TkPowerBar'] = 'Power Bar',
  ['TekplayerCastBar'] = 'Player Castbar',
  ['TektargetCastBar'] = 'Target Castbar',
  ['TekfocusCastBar'] = 'Focus Castbar',
  ['TekpetCastBar'] = 'Pet Castbar'
}

local range = {
  ['alpha'] = {0, 1, .01},
  ['alpha_ooc'] = {0, 1, .01},
  ['label_size'] = {1, 72, 1},
  ['label_inset'] = {-30, 30, 1},
  ['width'] = {0, 1200, 1},
  ['height'] = {0, 1200, 1},
  ['raidbuff_width'] = {0, 1200, 1},
  ['raidbuff_height'] = {0, 1200, 1},
  ['duration'] = {0, 6000, 0.1 },
  ['glow_size'] = {0, 30, 1},
  ['spark_size'] = {0, 30, 1},
}

local opt_order = {
  ['width'] = 10,
  ['height'] = 15,
  ['anchor'] = 20,
  ['anchorTo'] = 25,
  ['parent'] = 30,

  ['alpha'] = 110,
  ['alpha_ooc'] = 115,
  ['label_size'] = 200,
  ['label_inset'] = 210,
  ['label_font'] = 220,

  ['background_texture'] = 300,
  ['background_color'] = 320,
  ['foreground_texture'] = 350,
  ['foreground_color'] = 370,
}
local opt_width = {

}

-- options dialog root
T.myopts = {
  type = 'group',
  name =  TITLE_FONT_COLOR..'Turok|r',
  desc = 'Dinosaur HUD',
  handler = T,
  set = function(info,value, ...)
    local db = T.db
    local index = db
    local traversal = 'db'
    for i = 1, #info-1 do
      if type(index[info[i]]) == 'table' then
        --print('|cFFFF0000SET|r:', i, info[i])
        traversal = traversal .. '.' .. info[i]
        index = index[info[i]]
      end

    end
    --print('|cFFFF0000SET|r: hops=',#info,'index=',  traversal, ' key=', info[#info])

    if type(value) ~= 'boolean' and select('#',...) == 3 then
      --print('|cFFFF0000SET|r', 'multi-args', select('#',...))
      value = {value, ... }
    else
      --print('|cFFFF0000SET|r', 'single-arg', value)
    end

    index[info[#info]] = value
  end,
  get = function(info)
    local db = T.db
    local value = db[info[1]]
    local traversal = info[1]
    if #info > 1 then
      for i=2, #info do
        traversal = traversal .. '.' .. info[i]
        if value[info[i]] ~= nil then
          value = value[info[i]]
        end
      end
    end
    --print('|cFFFF00FFGET|r: hops=', #info, 'index=',  traversal, 'value=', value)

    if type(value) == 'table' then
      return unpack(value)
    end
    return value
  end,
}

function T:MakeOptions(dbtable, index, name, prefix)
  -- index  = option insertion destination
  -- parent = nesting point
  local parent
  if not (index and dbtable) then
    dbtable = db
    name = 'root'
    prefix = ''
    parent = T.myopts
    parent.args = {
      main = {
        order = 1,
        type = 'group',
        name = 'Global',
        get = function(info) print('db.'..info[#info]..' get')
        if type(db[info[#info]]) == 'table' then
          print('getting color data', unpack(db[info[#info]]))
          return unpack(db[info[#info]])
        end
        return db[info[#info]]
        end,
        set = function(info, value, ...) print('db.'..info[#info]..' SET')
        if select('#',...) == 3 then
          print('receiving color data', value, ...)
          value = {value, ...}
        end
        db[info[#info]] = value
        end,
        args = {},
      }}
    index = parent.args.main
    print(STACK_COLOR1..'using TurokData as index')
  else
    index.type = 'group'
    index.name = name
    index.args = {}
    parent = index
  end

  local order = 2
  for k, v in pairs(dbtable) do
    k = tostring(k)
    local kt = INPUT_FONT_COLOR .. (optL[k] or k)
    local nested = false
    --@debug@
    print(STACK_COLOR2..prefix..'.'..STACK_COLOR1..k..'|r =',v)--@debug@
    if type(v) == 'table' then
      if table.getn(v) == 4 then
        index.args[k] = {
          name = kt,
          type = 'color',
          hasAlpha = true,
          --@debug@
          print('color_pack=',unpack(v))--@debug@
        }
      else
        parent.args[k] = {}
        nested = true
        T:MakeOptions(v, parent.args[k], k, prefix .. '.' .. name)
      end
    elseif type(v) == 'string' then
      if string.match(k, "_font") then
        local font_list = {}
        for k, v in pairs(LSM:HashTable('font')) do
          font_list[v] = k
        end
        index.args[k] = {
          name = kt,
          type = 'select',
          values = font_list
        }
      elseif k:match('anchor$') or k:match('_point$') or k:match('anchorTo') then

        index.args[k] = {
          name = kt,
          type = 'select',
          values = anchors
        }

      elseif k:match('justifyH$') then
        index.args[k] = {
          name = kt,
          type = 'select',
          values = {
            ['LEFT'] = 'Left',
            ['CENTER'] = 'Center',
            ['RIGHT'] = 'Right'
          }
        }

      elseif k:match('strata$') then
        index.args[k] = {
          name = kt,
          type = 'select',
          values = {
            BACKGROUND = 'BACKGROUND (clickthrough)',
            LOW = 'LOW',
            MEDIUM = 'MEDIUM',
            HIGH = 'HIGH',
            DIALOG = 'DIALOG',
            FULLSCREEN = 'FULLSCREEN',
            FULLSCREEN_DIALOG = 'FULLSCREEN_DIALOG',
            TOOLTIP = 'TOOLTIP (clickthrough)',
          }
        }

      elseif k:match('outline$') then
        index.args[k] = {
          name = kt,
          type = 'select',
          values = {
            ['NONE'] = 'NONE',
            ['OUTLINE'] = 'OUTLINE',
            ['THICKOUTLINE'] = 'THICKOUTLINE'
          }
        }
      elseif k:match('parent') then
        index.args[k] = {
          name = kt,
          type = 'select',
          values = frames
        }
      else

        index.args[k] = {
          name = kt,
          type = 'input',
          width = 'full',
        }
      end
    elseif type(v) == 'number' then

      if not range[k] then
        range[k] = {0,150,1 }
        print('missing range values for', k)
      end

      index.args[k] ={
        name = kt,
        type = 'range',
        min = range[k][1],
        max = range[k][2],
        softMax = range[k][2],
        step = range[k][3],
        bigStep = range[k][3],
      }
    elseif type(v) == 'boolean' then

      index.args[k] = {
        name = kt,
        type = 'toggle',
      }
    end
    if nested then
      parent.args[k].order = order + (opt_order[k] and opt_order[k] or 0)
    elseif index.args[k] then
      index.args[k].order = order + (opt_order[k] and opt_order[k] or 0)
      print('  '..kt..' order = '..index.args[k].order)
    else
      print('|cFF99FFFFSkipped|r', kt)
    end
  end

  return parent
end