ESOUI SVN TaosFollowLeader

[/] [trunk/] [TaosFollowLeader/] [ui/] [SettingsWindow.lua] - Rev 5

Compare with Previous | Blame | View Log

--[[
        Addon: Taos Follow Leader
        Author: TProg Taonnor
        Created by @Taonnor
]]--

--[[
        Local variables
]]--
local LOG_ACTIVE = false
local _panel = nil
local _choosenIconTexture = nil

--[[
        Table TFL_SettingsWindow
]]--
TFL_SettingsWindow = {}
TFL_SettingsWindow.__index = TFL_SettingsWindow

--[[
        Table Members
]]--
TFL_SettingsWindow.MainMenuName = "TaosFollowLeaderSettingsMainMenu"

--[[
        SetupLAMIcon Setups the LAM icon control "TFL_ChoosenIcon"
]]--
function TFL_SettingsHandler.SetupLAMIcon(control)
    if (LOG_ACTIVE) then 
        logger:logTrace("TFL_SettingsWindow.SetupLAMIcon")
    end

    if (control == _panel) then
        if (_choosenIconTexture == nil) then
            _choosenIconTexture = WINDOW_MANAGER:CreateControl(nil, TFL_ChoosenIcon, CT_TEXTURE)
            _choosenIconTexture:SetAnchor(RIGHT, TFL_ChoosenIcon.dropdown:GetControl(), LEFT, -48, -2)
            _choosenIconTexture:SetTexture(TFL_SettingsHandler.Icons[TFL_SettingsHandler.SavedVariables.Icon].path)
            _choosenIconTexture:SetDimensions(48, 48)
        end

                CALLBACK_MANAGER:UnregisterCallback("LAM-PanelControlsCreated", TFL_SettingsHandler.SetupLAMIcon)
    end
end

--[[
        Initialize creates settings window
]]--
function TFL_SettingsWindow.Initialize(logger, major, minor, patch)
    if (LOG_ACTIVE) then 
        logger:logTrace("TFL_SettingsWindow.Initialize")
        logger:logDebug("major, minor, patch", major, minor, patch)
    end

    local panelData = {
                type = "panel",
                name = "Taos Follow Leader",
                author = "TProg Taonnor",
                version = major .. "." .. minor .. "." .. patch,
                slashCommand = "/taosfollowleader",
                registerForDefaults = true
        }

    -- Add icon choises
    local iconChoises = {}
    for key, val in pairs(TFL_SettingsHandler.Icons) do
        table.insert(iconChoises, val.name)
    end

        local optionsData = {
                [1] = {
                        type = "header",
                        name = GetString(TFL_OPTIONS_HEADER),
                },
                [2] = {
                        type = "dropdown",
                        name = GetString(TFL_OPTIONS_ICONS_LABEL),
                        tooltip = GetString(TFL_OPTIONS_ICONS_TOOLTIP),
            choices = iconChoises,
                        getFunc = 
               function() 
                   return TFL_SettingsHandler.Icons[TFL_SettingsHandler.SavedVariables.Icon].name
               end,
                        setFunc = 
               function(value) 
                   for index, icon in ipairs(TFL_SettingsHandler.Icons) do
                      if (icon.name == value) then
                         TFL_SettingsHandler.SetIconSettings(index)
                         _choosenIconTexture:SetTexture(icon.path)
                         break
                      end
                   end
                           end,
                        default = TFL_SettingsHandler.Icons[TFL_SettingsHandler.Default.Icon],
            reference = "TFL_ChoosenIcon",
            requiresReload = true,
                },
        [3] = {
            type = "slider",
            name = GetString(TFL_OPTIONS_SIZE_LABEL),
                        tooltip = GetString(TFL_OPTIONS_SIZE_TOOLTIP),
            min = 32,
            max = 256,
            getFunc = 
                function() 
                    return TFL_SettingsHandler.SavedVariables.IconSize
                end,
            setFunc = 
                function(value)
                    TFL_SettingsHandler.SetIconSizeSettings(value)
                end,
            default = TFL_SettingsHandler.Default.IconSize,
            requiresReload = true,
        },
        }

        local LAM = LibStub("LibAddonMenu-2.0")
    -- Create settings panal
        _panel = LAM:RegisterAddonPanel(TFL_SettingsWindow.MainMenuName, panelData)

        LAM:RegisterOptionControls(TFL_SettingsWindow.MainMenuName, optionsData)

    -- Register to callback for creating preview icon
    CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", TFL_SettingsHandler.SetupLAMIcon)
end

Compare with Previous | Blame