WoWInterface SVN EasyDaily

[/] [trunk/] [EasyDaily/] [options.lua] - Rev 158

Compare with Previous | Blame | View Log

--[[
    Desc:
    Info: $Id: options.lua 42 2009-05-20 22:32:24Z draake $
]]

local _G = _G
local pairs, ipairs, type, select, tonumber, tostring = pairs, ipairs, type, select, tonumber, tostring

local tinsert, tremove, tsort = table.insert, table.remove, table.sort
local sformat = string.format

local EasyDaily = EasyDaily

local L = LibStub("AceLocale-3.0"):GetLocale("EasyDaily_Base")

local LDBIcon = LibStub("LibDBIcon-1.0")

--------------------------------------------------------------------------------------------------
-- Content
--------------------------------------------------------------------------------------------------

function EasyDaily:GetHandleDesc(h)
    
    if h:GetVal("hval") == "quest" then
        
        local name, index, questType, questTag = h:GetVal("name"), h:GetVal("index"), h:GetVal("type"), h:GetVal("tag")
        
        local questComplete = self:QuestCompleteToday(name)
        
        -- Description
        local desc = ""
        
        local reset, done = h:GetVal("reset"), h:GetVal("count")
        
        if questComplete then
            desc = desc .. sformat("\n%s: %s", self:Colorize(L["Completed"], 1, .8, 0), self:Colorize(YES, 0, 1, 0))
            if reset then
                desc = desc .. sformat("\n%s: %s", self:Colorize(L["Reset"], 1, .8, 0), date("%A, %B %d - %I:%M:%S %p", reset))
            end
        else
            desc = desc .. sformat("\n%s: %s", self:Colorize(L["Completed"], 1, .8, 0), self:Colorize(NO, 1, 0, 0))
        end
        
        desc = desc .. sformat("\n%s: %s\n", self:Colorize(L["Done"], 1, .8, 0), done)
        
        if index then
            desc = desc .. sformat("\n%s: %s", self:Colorize("ID", 1, .8, 0), index)
        end
        
        local tagText, typeText = self:TagOptToTagText(questTag), self:TypeOptToTypeText(questType)
        if tagText and typeText then
            desc = desc .. sformat("\n%s: %s %s", self:Colorize(L["Type"], 1, .8, 0), tagText, typeText)
        end
        
        return desc
        
    end
    
end

--------------------------------------------------------------------------------------------------
-- Option Registration and Table Creation
--------------------------------------------------------------------------------------------------

local getFunc = function(info)
    return info.arg and EasyDaily.db.profile[info.arg] or EasyDaily.db.profile[info[#info]]
end
local setFunc = function(info, value)
    local key = info.arg or info[#info]
    EasyDaily.db.profile[key] = value
end

local isDisabled = function()
    return ( not EasyDaily:IsEnabled() )
end

local GetOptMods = function(...)
    local optMods = { ["ctrl"] = L["Ctrl"], ["alt"] = L["Alt"], ["shift"] = L["Shift"], ["none"] = L["None"], ["disable"] = L["Disable"] }
    for i = 1, select("#", ...), 1 do
        local v = EasyDaily:GetPVar( "mod_" .. EasyDaily:SelectOne(i, ...) )
        if v and v ~= "disable" then
            optMods[v] = nil
        end
    end
    return optMods
end

local getOptions = function()
    local self = EasyDaily
    if ( not self.options ) then -- static options; run once; etc...
        self.options = {
            type = "group",
            name = sformat("EasyDaily (%s)", self.version.text),
            icon = "Interface\\Icons\\INV_Misc_TabardSummer01",
            childGroups = "tree",
            plugins = {},
            args = {
                enabled = {
                    order = 1,
                    width = "half",
                    type = "toggle",
                    name = L["Enabled"],
                    desc = L["Enable/Disable the addon."],
                    get = function() return self:IsEnabled() end,
                    set = function(info, value) self[value and "Enable" or "Disable"](self) end,
                },
                debug = {
                    order = 2,
                    type = "toggle",
                    name = L["Debug"],
                    desc = L["Enable/Disable debug mode."],
                    get = getFunc,
                    set = setFunc,
                    disabled = isDisabled,
                },
                minimapIcon = {
                    order = 3,
                    type = "toggle",
                    name = L["Minimap Icon"],
                    desc = L["Show an icon on the Minimap."],
                    get = function() return not self.db.profile.minimapIcon.hide end,
                    set = function(info, value) self.db.profile.minimapIcon.hide = not value; LDBIcon[value and "Show" or "Hide"](self, "EasyDaily") end,
                    disabled = function() return not LDBIcon end,
                },
                general = {
                    order = 10,
                    type = "group",
                    name = L["General"],
                    disabled = isDisabled,
                    args = {
                        debugmode = {
                            order = 0,
                            type = "group",
                            guiInline = true,
                            name = "Debug Mode",
                            disabled = isDisabled,
                            hidden = function() return ( not self.db.profile.debug ) end,
                            args = {
                                debuglevel = {
                                    order = 1,
                                    type = "select",
                                    style = "dropdown",
                                    name = "Debug Level",
                                    desc = "Sets the debug level.",
                                    values = { [1] = "Helpful", [2] = "Verbose", [3] = "Maintenance" },
                                    get = getFunc,
                                    set = setFunc,
                                },
                                resetall = {
                                    order = 2,
                                    type = "execute",
                                    name = "Reset All",
                                    confirm = true,
                                    confirmText = "Are you want to reset the current profile and the entire quest database? This cannot be undone.",
                                    desc = "Resets the current profile and the entire quest database.",
                                    func = function() self.db:ResetDB("Default"); self:ResetDatabase(); self.db.profile.debug = true; end,
                                },
                            },
                        },
                        gossipdisplay = {
                            order = 1,
                            type = "group",
                            guiInline = true,
                            name = L["Gossip/Quest Window"],
                            args = {
                                stickyturnin = {
                                    order = 1,
                                    hidden = true,
                                    type = "toggle",
                                    name = "Sticky Turn-in",
                                    desc = "Turn-in sequences will run to completion once they've been started regardless of its modifier's status.",
                                    get = getFunc,
                                    set = setFunc,
                                },
                                gossipicons = {
                                    order = 2,
                                    type = "toggle",
                                    name = L["Enhanced Gossip Icons"],
                                    desc = L["Replaces the default gossip icons with color coded versions."],
                                    get = getFunc,
                                    set = function(...) setFunc(...); self:RefreshGossipOrQuestFrame(); end,
                                },
                                gossipstate = {
                                    order = 3,
                                    type = "toggle",
                                    name = L["Quest Status Text"],
                                    desc = L["Displays a quest's state next to its name in the gossip window."],
                                    get = getFunc,
                                    set = function(...) setFunc(...); self:RefreshGossipOrQuestFrame(); end,
                                },
                                acceptshared = {
                                    order = 4,
                                    type = "toggle",
                                    name = L["Accept Shared Quests"],
                                    desc = L["Shared quests are accepted regardless of their modifiers status."],
                                    get = getFunc,
                                    set = setFunc,
                                },
                            },
                        },
                        rewards = {
                            order = 2,
                            type = "group",
                            guiInline = true,
                            name = L["Quest Rewards"],
                            args = {
                                multiple = {
                                    order = 1,
                                    type = "toggle",
                                    name = L["Multiple Rewards"],
                                    desc = L["Auto-Select rewards for quests with more than one reward."],
                                    get = getFunc,
                                    set = setFunc,
                                },
                            },
                        },
                        popups = {
                            order = 3,
                            type = "group",
                            guiInline = true,
                            name = L["Quest Confirmation Pop-ups"],
                            args = {
                                skipflag = {
                                    order = 1,
                                    type = "toggle",
                                    name = L["Disable PvP Pop-up"],
                                    desc = L["Disables the confirmation pop-up that appears when accepting a daily quest that flags you for pvp."],
                                    get = getFunc,
                                    set = setFunc,
                                },
                                skipmoney = {
                                    order = 2,
                                    type = "toggle",
                                    name = L["Disable Gold Pop-up"],
                                    desc = L["Disables the confirmation pop-up that appears when completing a daily quest that requires gold."],
                                    get = getFunc,
                                    set = setFunc,
                                },
                            },
                        },
                        activetags = {
                            order = 5,
                            type = "group",
                            guiInline = true,
                            name = L["Quest Tags"],
                            args = {
                                tag_normal = {
                                    order = 1,
                                    type = "toggle",
                                    name = DUNGEON_DIFFICULTY1,
                                    desc = sformat(L["Enables Auto Turn-in for %s tagged quests."], DUNGEON_DIFFICULTY1),
                                    get = getFunc,
                                    set = setFunc,
                                },
                                tag_elite = {
                                    order = 2,
                                    type = "toggle",
                                    name = ELITE,
                                    desc = sformat(L["Enables Auto Turn-in for %s tagged quests."], ELITE),
                                    get = getFunc,
                                    set = setFunc,
                                },
                                tag_group = {
                                    order = 3,
                                    type = "toggle",
                                    name = GROUP,
                                    desc = sformat(L["Enables Auto Turn-in for %s tagged quests."], GROUP),
                                    get = getFunc,
                                    set = setFunc,
                                },
                                tag_dungeon = {
                                    order = 4,
                                    type = "toggle",
                                    name = LFG_TYPE_NORMAL_DUNGEON,
                                    desc = sformat(L["Enables Auto Turn-in for %s tagged quests."], LFG_TYPE_NORMAL_DUNGEON),
                                    get = getFunc,
                                    set = setFunc,
                                },
                                tag_heroic = {
                                    order = 5,
                                    type = "toggle",
                                    name = LFG_TYPE_HEROIC_DUNGEON,
                                    desc = sformat(L["Enables Auto Turn-in for %s tagged quests."], LFG_TYPE_HEROIC_DUNGEON),
                                    get = getFunc,
                                    set = setFunc,
                                },
                                tag_raid = {
                                    order = 6,
                                    type = "toggle",
                                    name = RAID,
                                    desc = sformat(L["Enables Auto Turn-in for %s tagged quests."], RAID),
                                    get = getFunc,
                                    set = setFunc,
                                },
                                tag_pvp = {
                                    order = 7,
                                    type = "toggle",
                                    name = PVP,
                                    desc = sformat(L["Enables Auto Turn-in for %s tagged quests."], PVP),
                                    get = getFunc,
                                    set = setFunc,
                                },
                            },
                        },
                        modifiers = {
                            order = 10,
                            type = "group",
                            guiInline = true,
                            name = L["Selection Modifiers"],
                            args = {
                                modifierstext = {
                                    order = 1,
                                    type = "description",
                                    name = L["Note: The modifier 'None' refers to when no modifier is being held. Setting the modifier to 'Disable' disables the option."],
                                },
                                mod_normal = {
                                    order = 2,
                                    type = "select",
                                    style = "dropdown",
                                    name = DUNGEON_DIFFICULTY1,
                                    desc = sformat(L["Use this modifier to Auto Turn-in %s quests."], DUNGEON_DIFFICULTY1),
                                    values = function()
                                        return GetOptMods("override", "suspend")
                                    end,
                                    get = getFunc,
                                    set = setFunc,
                                },
                                mod_daily = {
                                    order = 3,
                                    type = "select",
                                    style = "dropdown",
                                    name = DAILY,
                                    desc = sformat(L["Use this modifier to Auto Turn-in %s quests."], DAILY),
                                    values = function()
                                        return GetOptMods("override", "suspend")
                                    end,
                                    get = getFunc,
                                    set = setFunc,
                                },
                                mod_repeat = {
                                    order = 4,
                                    type = "select",
                                    style = "dropdown",
                                    name = L["Repeatable"],
                                    desc = sformat(L["Use this modifier to Auto Turn-in %s quests."], L["Repeatable"]),
                                    values = function()
                                        return GetOptMods("override", "suspend")
                                    end,
                                    get = getFunc,
                                    set = setFunc,
                                },
                                mod_override = {
                                    order = 5,
                                    type = "select",
                                    style = "dropdown",
                                    name = L["Force"],
                                    desc = L["Use this modifier to forcibly Auto Turn-in any quest. Overrides all settings."],
                                    values = function()
                                        return GetOptMods("normal", "daily", "repeat", "suspend")
                                    end,
                                    get = getFunc,
                                    set = setFunc,
                                },
                                mod_suspend = {
                                    order = 6,
                                    type = "select",
                                    style = "dropdown",
                                    name = L["Suspend"],
                                    desc = L["Use this modifier to suspend the Auto Turn-in process."],
                                    values = function()
                                        return GetOptMods("normal", "daily", "repeat", "override")
                                    end,
                                    get = getFunc,
                                    set = setFunc,
                                },
                            },
                        },
                    },
                },
                quests = {
                    order = 20,
                    type = "group",
                    name = L["Quests"],
                    args = {
                        enableall = {
                            order = 1,
                            type = "execute",
                            name = "Enable All",
                            desc = "Enables all quests",
                            func = function(info) self:Debug( self:GetLinearArgs(info.options, unpack(info, 1, #info - 1)) ); self:SetAllQuestStates(true) end,
                        },
                        disableall = {
                            order = 2,
                            type = "execute",
                            name = "Disable All",
                            desc = "Disables all quests",
                            func = function() self:SetAllQuestStates(false) end,
                        },
                        daily = {
                            order = 3,
                            type = "group",
                            childGroups = "tab",
                            name = DAILY,
                            args = {
                                questedit = {
                                    order = 1,
                                    type = "toggle",
                                    name = L["Edit"],
                                    desc = L["Enable/Disable edit mode."],
                                    get = getFunc,
                                    set = setFunc,
                                    disabled = isDisabled,
                                },
                            },
                        },
                        repeatable = {
                            order = 4,
                            type = "group",
                            childGroups = "tab",
                            name = L["Repeatable"],
                            args = {
                                questedit = {
                                    order = 1,
                                    type = "toggle",
                                    name = L["Edit"],
                                    desc = L["Enable/Disable edit mode."],
                                    get = getFunc,
                                    set = setFunc,
                                    disabled = isDisabled,
                                },
                            },
                        },
                        normal = {
                            order = 5,
                            type = "group",
                            childGroups = "tab",
                            name = DUNGEON_DIFFICULTY1,
                            args = {
                                questedit = {
                                    order = 1,
                                    type = "toggle",
                                    name = L["Edit"],
                                    desc = L["Enable/Disable edit mode."],
                                    get = getFunc,
                                    set = setFunc,
                                    disabled = isDisabled,
                                },
                            },
                        },
                    },
                },
            },
        }
        self.options.plugins.profiles = { profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) }
    end
    
    for i, h in pairs(self.handlers.quest) do
        
        local option
        
        if ( h:GetVal("type") == "daily" ) then
            option = self.options.args.quests.args.daily.args
        elseif ( h:GetVal("type") == "repeat" ) then
            option = self.options.args.quests.args.repeatable.args
        elseif ( h:GetVal("type") == "normal" ) then
            option = self.options.args.quests.args.normal.args
        end
        
        if option then
            
            local cat1, cat2 = self:GetQuestCategoryInfo( h:GetVal("name") )
            
            -- Option Table
            local cat1key = sformat("c1-%s", cat1)
            if ( not option[cat1key] )then
                option[cat1key] = {
                    type = "group",
                    name = cat1,
                    args = {},
                }
            end
            
            local cat2key = sformat("c2-%s", cat2)
            if ( not option[cat1key].args[cat2key] )then
                option[cat1key].args[cat2key] = {
                    type = "group",
                    name = cat2,
                    args = {
                        state = {
                            order = 1,
                            type = "toggle",
                            tristate = true,
                            name = "Enable",
                            desc = "Enable all quests in this category",
                            get = function(info)
                                local t = EasyDaily:GetLinearArgs(info.options, unpack(info, 1, #info - 1))
                                local state
                                for i in pairs(t.args) do
                                    i = tonumber(i)
                                    if i then
                                        local c = EasyDaily.handlers.quest[i]:GetVal("enable")
                                        if state ~= nil then
                                            if state ~= c then
                                                return
                                            end
                                        else
                                            state = c
                                        end
                                    end
                                end
                                return state
                            end,
                            set = function(info, value)
                                local t = EasyDaily:GetLinearArgs(info.options, unpack(info, 1, #info - 1))
                                local state
                                for i in pairs(t.args) do
                                    i = tonumber(i)
                                    if i then
                                        EasyDaily.handlers.quest[i]:SetVal("enable", toboolean(value))
                                    end
                                end
                            end,
                        },
                    },
                }
            end
            
            local idkey = tostring(i)
            if ( not option[cat1key].args[cat2key].args[idkey] ) then
                option[cat1key].args[cat2key].args[idkey] = {
                    type = "group",
                    name = function()
                        local name = h:GetVal("name")
                        if self:QuestCompleteToday(name) then 
                            return self:Colorize(name, .5, .5, .5)
                        elseif ( not h:GetVal("enable") ) then
                            return self:Colorize(name, 1, 0, 0)
                        else
                            return name
                        end 
                    end,
                    args = {
                        state = {
                            order = 1,
                            width = "half",
                            type = "toggle",
                            name = "Enable",
                            desc = L["Toggle this quest's state."],
                            get = function(info) return h:GetVal("enable") end,
                            set = function(info, value) h:SetVal("enable", value); self:RefreshGossipOrQuestFrame(); end,
                        },
                        header = {
                            order = 2,
                            name = "Header",
                            desc = "",
                            hidden = function() return ( not self.db.profile.questedit ) end,
                            type = "input",
                            get = function(info) return h:GetVal("header") end,
                            set = function(info, value) h:SetVal("header", value); end,
                            validate = function() end,
                        },
                        side = {
                            order = 3,
                            type = "select",
                            style = "dropdown",
                            name = "Side",
                            desc = "Select which side this quest is available for.",
                            hidden = function() return ( not self.db.profile.questedit ) end,
                            values = { [0] = L["None"], [1] = FACTION_ALLIANCE, [2] = FACTION_HORDE, [3] = L["Both"] },
                            get = function(info) return h:GetVal("side") end,
                            set = function(info, value) return h:SetVal("side", value) end,
                        },
                        tag = {
                            order = 4,
                            type = "select",
                            style = "dropdown",
                            name = "Tag",
                            desc = "Select which tag applies to this quest.",
                            hidden = function() return ( not self.db.profile.questedit ) end,
                            values = { ["normal"] = DUNGEON_DIFFICULTY1, ["group"] = GROUP, ["dungeon"] = LFG_TYPE_NORMAL_DUNGEON, ["raid"] = RAID, ["heroic"] = LFG_TYPE_HEROIC_DUNGEON, ["pvp"] = PVP, ["elite"] = ELITE },
                            get = function(info) return h:GetVal("tag") end,
                            set = function(info, value) return h:SetVal("tag", value) end,
                        },
                        type = {
                            order = 5,
                            type = "select",
                            style = "dropdown",
                            name = "Type",
                            desc = "Select which type this quest is.",
                            hidden = function() return ( not self.db.profile.questedit ) end,
                            values = { ["normal"] = DUNGEON_DIFFICULTY1, ["daily"] = DAILY, ["repeat"] = L["Repeatable"] },
                            get = function(info) return h:GetVal("type") end,
                            set = function(info, value) h:SetVal("type", value) end,
                        },
                        questdesc = {
                            order = 50,
                            width = "full",
                            type = "description",
                            name = function() return self:GetHandleDesc(h) end,
                            hidden = function() return ( self.db.profile.questedit ) end,
                        },
                    },
                }
            end
            
        end
        
    end
    
    return self.options
end

function EasyDaily:SetupOptions()
    
    local AceConfigDialog = LibStub("AceConfigDialog-3.0")
    local AceConfig = LibStub("AceConfig-3.0")
    
    -- Register Options
    AceConfig:RegisterOptionsTable("EasyDaily", getOptions, "edtest")
    AceConfigDialog:SetDefaultSize("EasyDaily", 790, 540)
--~     AceConfigDialog:AddToBlizOptions("EasyDaily", "EasyDaily")
    
    -- Slash Commands
    local AceConsole = LibStub("AceConsole-3.0")
    local optFunc = function()
        AceConfigDialog:Open("EasyDaily")
    end
    
    local slashCom = {
        "ed",
        "easydaily",
        "daily",
    }
    
    for _, slash in pairs(slashCom) do
        AceConsole:RegisterChatCommand(slash, optFunc)
    end
    
    -- Create LDB Launcher
        local LDBObj = LibStub("LibDataBroker-1.1"):NewDataObject("EasyDaily", {
                type = "launcher",
                label = "EasyDaily",
                OnClick = function(button, click)
--~             if click == "RightButton" then
                if AceConfigDialog.OpenFrames["EasyDaily"] then
                    AceConfigDialog:Close("EasyDaily")
                else
                    AceConfigDialog:Open("EasyDaily")
                end
--~             else
--~                 AceConfigDialog:Close("EasyDaily")
--~             end
                end,
                icon = "Interface\\Icons\\INV_Misc_TabardSummer01",
                OnTooltipShow = function(tooltip)
            
                        if not tooltip or not tooltip.AddLine then return end
            
                        tooltip:AddLine("EasyDaily")
--~                     tooltip:AddLine( self:ColorizePattern(L["[Left-Click] to toggle the quest window"], "%[(.-)%]", 1, 1, 0) )
                        tooltip:AddLine( self:ColorizePattern(L["[Right-Click] to toggle the options menu"], "%[(.-)%]", 1, 1, 0) )
            
            tooltip:AddLine(" ")
--~             tooltip:AddLine( self:Colorize(L["Quick Info"], 1, 1, 1) )
--~             tooltip:AddLine(" ")
            
            local cur, max = self:GetDailyStats()
            tooltip:AddLine( self:ColorizePattern( sformat(L["Completed [%s] of [%s] dailies"], cur, max), "%[(.-)%]", 1, 1, 0 ) )
            
            local reset = GetQuestResetTime()
            if reset and reset > 0 then
                local text = self:ColorizePattern( self.LibAbacus:FormatDurationExtended(reset, false, true), "(%d+)", 1, 1, 0 )
                tooltip:AddLine( self:ColorizePattern( sformat(L["The [new day] begins in %s"], text), "%[(.-)%]", 1, 1, 0 ) )
            end
            
                end,
        })
        if LDBIcon then
                LDBIcon:Register("EasyDaily", LDBObj, self.db.profile.minimapIcon)
        end
    
end

function EasyDaily:CreateResetSlash()
    
    -- Hard Resest slash command
    StaticPopupDialogs["EASYDAILY_RESETALL"] = {
        text = "Are you want to reset EasyDaily's current profile and the entire quest database? This cannot be undone and will reload your UI.",
        button1 = YES,
        button2 = NO,
        OnAccept = function()
            EasyDaily.db:ResetDB("Default")
            EasyDaily:ResetDatabase()
            ReloadUI()
        end,
        showAlert = 1,
        timeout = 0,
        exclusive = 1,
        hideOnEscape = 1,
        whileDead = 1,
    }
    
    SlashCmdList["EDRESET"] = function() StaticPopup_Show("EASYDAILY_RESETALL") end
    SLASH_EDRESET1 = "/edreset"
    
end

Compare with Previous | Blame