WoWInterface SVN PocketPlot

[/] [trunk/] [PocketPlot/] [pocketplot_options.lua] - Rev 84

Go to most recent revision | Compare with Previous | Blame | View Log

local _, PocketPlot = ...
local widgetLists = AceGUIWidgetLSMlists
local fonts = widgetLists.font
local oldSetPoint = {}
local mover, moverText, movershown, db

local frames = {        "None",         --frames supported by mover
                                        "Minimap",
                                        "DurabilityFrame",
                                        "VehicleSeatIndicator",
                                        "MiniMapInstanceDifficulty",
                                        "GuildInstanceDifficulty",
                                        "MiniMapChallengeMode",
                                        "GarrisonLandingPageMinimapButton",
                                        "WorldStateAlwaysUpFrame",
                                }
local stratae = {"BACKGROUND", "LOW", "MEDIUM", "HIGH", "DIALOG"}
local allshapes = {     "3-Corner BL",
                                        "3-Corner BR",
                                        "3-Corner TL",
                                        "3-Corner TR",
                                        "Circle",
                                        "Compass",
                                        --"Faded Circle",       --<-- Test these more
                                        --"Faded Edges",
                                        --"Faded Square",
                                        "Fancy Frame",
                                        "Flower",
                                        "Half Round B",
                                        "Half Round L",
                                        "Half Round R",
                                        "Half Round T",
                                        "Rectangle",
                                        "Rounded",
                                        "Scalloped",
                                        "Slanted 1",
                                        "Slanted 2",
                                        "Square",
                                        "Teardrop BL",
                                        "Teardrop BR",
                                        "Teardrop TL",
                                        "Teardrop TR",
                                        "Torn",
                                        "Zigzag Round",
                                        "Zigzag Square"
                                }
PocketPlot.minimapButtonPaths = {               --the GetMinimapShape standards are TOTALLY named wrong! >.<
                ["3-Corner BL"] = "CORNER-TOPRIGHT",
                ["3-Corner BR"] = "CORNER-TOPLEFT",
                ["3-Corner TL"] = "CORNER-BOTTOMRIGHT",
                ["3-Corner TR"] = "CORNER-BOTTOMLEFT",
                ["Fancy Frame"] = "SQUARE",
                ["Half Round B"] = "SIDE-TOP",
                ["Half Round L"] = "SIDE-RIGHT",
                ["Half Round R"] = "SIDE-LEFT",
                ["Half Round T"] = "SIDE-BOTTOM",
                ["Rectangle"] = "SQUARE",
                ["Rounded"] = "SQUARE",
                ["Scalloped"] = "SQUARE",
                ["Slanted 1"] = "SQUARE",
                ["Slanted 2"] = "SQUARE",
                ["Square"] = "SQUARE",
                ["Torn"] = "SQUARE",
                ["Zigzag Square"] = "SQUARE",
                ["Circle"] = "ROUND",
                ["Compass"] = "ROUND",
                ["Flower"] = "ROUND",
                ["Teardrop BL"] = "TRICORNER-TOPRIGHT",
                ["Teardrop BR"] = "TRICORNER-TOPLEFT",
                ["Teardrop TL"] = "TRICORNER-BOTTOMRIGHT",
                ["Teardrop TR"] = "TRICORNER-BOTTOMLEFT",
                ["Zigzag Round"] = "ROUND",
        }
local minimapButtonPaths = PocketPlot.minimapButtonPaths
local fontFlags = {"None", "Outline", "Monochrome Outline"}     --, "Monochrome"}

local defaults = {
        shape = "Square",
        blips = "PPblips",
        lsmfont = "Negotiate Free",
        fontFlag = "Outline",
        zoneText = true,
        zoneSize = 14,
        clockSize = 16,
        scale = 1,
        mapPos = {x = -10, y = -10},
        bg = {r = 0, g = 0, b = 0},
        mmAlpha = 1,
        combatHide = false,
        alpha = 1,
        top = false,
        coords = true,
        clock = true,
        coordSize = 16,
        classbg = false,
        classfont = false,
        textOffset = 0,
        zoneTextOffset = 0,
        insets = 4,
        strata = "BACKGROUND",
        level = 2,
        --hideTracking = false,
}

local function SetPosition(frame)
        local f, fname, fdata = _G[frame], frame, db[frame]
        if mover and mover:IsShown() then
                local r,_,a,x,y = mover:GetPoint()
                fdata = {["r"]=r, ["p"]=UIParent,["a"]=a,["x"]=x,["y"]=y}
        end
        f:ClearAllPoints()
        f:SetPoint(fdata.r, fdata.p, fdata.a, fdata.x, fdata.y)
        if not oldSetPoint[fname] then  --prehook
                oldSetPoint[fname] = f.SetPoint
                f.SetPoint = function(self, a,b,c,d,e, ...)
                        local a,b,c,d,e = fdata.r, fdata.p, fdata.a, fdata.x, fdata.y
                        return oldSetPoint[fname](self, a,b,c,d,e, ...)
                end
        end
end

local function MoveFrames(frame)
        if not mover then
                mover = CreateFrame("Frame", nil, UIParent)
                mover:SetBackdrop({bgFile ="Interface\\Buttons\\WHITE8x8",})
                mover:SetBackdropColor(.2,.2,.9,.6)
                mover:SetMovable(1)
                mover:SetFrameStrata("HIGH")
                mover:Hide()
                moverText = mover:CreateFontString(nil, "OVERLAY")
                moverText:SetFont("Fonts\\ARIALN.ttf", 15, "OUTLINE")
                moverText:SetParent(mover)
                moverText:SetPoint("CENTER")
                mover:SetScript("OnMouseDown", function() mover:StartMoving() end)
                mover:SetScript("OnMouseUp", function() mover:StopMovingOrSizing() SetPosition(movershown) end)
        end
        if frame == "None" then
                mover:SetScale(1)
                mover:Hide()
                mover:EnableMouse(false)
                return
        else
                mover:Show()
                moverText:SetText(frame)
                mover:EnableMouse(true)
                mover:SetScale(_G[frame]:GetScale())
                mover:ClearAllPoints()
                mover:SetAllPoints(frame)
        end
end

local function NudgeMover(xy, offset)
        local framePos = db[movershown]
        local frame = _G[movershown]
        if not framePos then
                SetPosition(movershown)
        end
        framePos[xy] = framePos[xy] + offset
        frame:ClearAllPoints()
        frame:SetPoint(framePos.r, framePos.p, framePos.a, framePos.x, framePos.y)
        mover:ClearAllPoints()
        mover:SetAllPoints(frame)
end


local options = {
        name = "PocketPlot Options",
        type = "group",
        args = {
                general = {
                        name = "General",
                        type = "group",
                        args = {
                                hint = {
                                        name = "Hint: right-click the minimap to open the calendar. Shift-right-click will open the tracking menu.",
                                        type = "description",
                                        order = 1,
                                },
                                spacer = {
                                        name = "",
                                        type = "description",
                                        order = 2,
                                },
                                header0 = {
                                        name = "",
                                        type = "header",
                                        order = 3,
                                },
                                shape = {
                                        name = "Minimap Shape",
                                        desc = "Set the shape of the minimap.",
                                        type = "select",
                                        values = allshapes,
                                        get = function()
                                                                for k, v in pairs(allshapes) do
                                                                        if db.shape == v then
                                                                                return k
                                                                        end
                                                                end
                                                        end,
                                        set = function(_,key)
                                                                db.shape = allshapes[key]
                                                                PocketPlot.SetShape()
                                                                PocketPlot.ClassColors()
                                                        end,
                                        order = 4,
                                },
                                scale = {
                                        name = "Minimap Scale",
                                        desc = "Set the scale of the minimap.",
                                        type = "range",
                                        min = .25,
                                        max = 2,
                                        step = .05,
                                        get = function() return db.scale end,
                                        set = function(_,value)
                                                                db.scale = value
                                                                Minimap:SetScale(value)
                                                        end,
                                        order = 5,
                                },
                                combatHide = {
                                        name = "Hide in Combat",
                                        desc = "Hide the minimap when in combat.",
                                        type = "toggle",
                                        get = function() return db.combatHide end,
                                        set = function()
                                                                db.combatHide = not db.combatHide
                                                                PocketPlot.CombatHide()
                                                        end,
                                        order = 6,
                                },
                                strata = {
                                        name = "Minimap Strata",
                                        desc = "Set the strata of the minimap and how it layers with other elements in your interface.",
                                        type = "select",
                                        values = stratae,
                                        get = function()
                                                                for k, v in pairs(stratae) do
                                                                        if db.strata == v then
                                                                                return k
                                                                        end
                                                                end
                                                        end,
                                        set = function(_,key)
                                                                db.strata = stratae[key]
                                                                Minimap:SetFrameStrata(db.strata)
                                                        end,
                                        order = 7,
                                },
                                level = {
                                        name = "Strata Level",
                                        desc = "Nudge the minimap up and down different levels on its frame strata.",
                                        type = "range",
                                        min = 1,
                                        max = 10,
                                        step = 1,
                                        get = function() return db.level end,
                                        set = function(_,value)
                                                                db.level = value
                                                                Minimap:SetFrameLevel(db.level)
                                                        end,
                                        order = 8,
                                },
                                battleHide = {
                                        name = "Hide in Pet Battle",
                                        desc = "Hide the minimap during pet battles.",
                                        type = "toggle",
                                        get = function() return db.battleHide end,
                                        set = function()
                                                                db.battleHide = not db.battleHide
                                                                PocketPlot.PetBattleHide()
                                                        end,
                                        order = 9,
                                },
                                mmAlpha = {
                                        name = "Outdoors Alpha",
                                        desc = "Set the transparency of the minimap when outdoors. Does not take effect when indoors (prevents indoors map from displaying).",
                                        type = "range",
                                        min = 0.05,
                                        max = 1,
                                        step = .05,
                                        get = function() return db.mmAlpha end,
                                        set = function(_,value)
                                                                db.mmAlpha = value
                                                                PocketPlot.MinimapFade()
                                                        end,
                                        order = 10,
                                },
                        },
                },
                border = {
                        name = "Border",
                        type = "group",
                        args = {
                                header1 = {
                                        name = "",
                                        type = "header",
                                        order = 1,
                                },
                                border = {
                                        name = "Border Color",
                                        desc = "Select a color for the minimap's border.",
                                        type = "color",
                                        disabled = function() return db.classbg end,
                --                      hasAlpha = true,
                                        get = function() return db.bg.r, db.bg.g, db.bg.b end,
                                        set = function(_,r,g,b)
                                                                db.bg.r, db.bg.g, db.bg.b = r,g,b
                                                                PocketPlot.ClassColors()
                                                        end,
                                        order = 2,
                                },
                                insets = {
                                        name = "Border size",
                                        desc = "Set the width of the border around the minimap.",
                                        type = "range",
                                        min = .5,
                                        max = 10,
                                        step = .5,
                                        get = function() return db.insets end,
                                        set = function(_,value)
                                                                db.insets = value
                                                                local dims = Minimap:GetWidth()
                                                                PocketPlot.bg:SetHeight(dims + value)
                                                                PocketPlot.bg:SetWidth(dims + value)
                                                        end,
                                        order = 3,
                                },
                                alpha = {
                                        name = "Border Alpha",
                                        desc = "Set the alpha for the minimap border.",
                                        type = "range",
                                        min = 0,
                                        max = 1,
                                        step = .05,
                                        get = function() return db.alpha end,
                                        set = function(_,alpha)
                                                                db.alpha = alpha
                                                                PocketPlot.ClassColors()
                                                        end,
                                        order = 4,
                                },
                                classbg = {
                                        name = "Class colored border",
                                        desc = "Color the minimap border by your class.",
                                        type = "toggle",
                                        get = function() return db.classbg end,
                                        set = function()
                                                                db.classbg = not db.classbg
                                                                PocketPlot.ClassColors()
                                                        end,
                                        order = 5,
                                },
                        },
                },
                text = {
                        name = "Text",
                        type = "group",
                        args = {
                                header2 = {
                                        name = "",
                                        type = "header",
                                        order = 1,
                                },
                                font = {
                                        name = "Font",
                                        desc = "Select a font to use.",
                                        type = "select",
                                        dialogControl = "LSM30_Font",
                                        values = fonts,
                                        get = function()
                                                                return db.lsmfont
                                                        end,
                                        set = function(_,font)
                                                                db.lsmfont = font
                                                                PocketPlot.SetFonts()
                                                        end,
                                        order = 2,
                                },
                                fontFlag = {
                                        name = "Font Flag",
                                        desc = "Set how to alter the displayed font.",
                                        type = "select",
                                        values = fontFlags,
                                        get = function()
                                                                for k, v in pairs(fontFlags) do
                                                                        if db.fontFlag == v then
                                                                                return k
                                                                        end
                                                                end
                                                        end,
                                        set = function(_,key)
                                                                db.fontFlag = fontFlags[key]
                                                                PocketPlot.SetFonts()
                                                        end,
                                        order = 3,
                                },
                                classfont = {
                                        name = "Class colored text",
                                        desc = "Color the clock and coordinates by your class.",
                                        type = "toggle",
                                        get = function() return db.classfont end,
                                        set = function()
                                                                db.classfont = not db.classfont
                                                                PocketPlot.ClassColors()
                                                        end,
                                        order = 4,
                                },
                                zonesize = {
                                        name = "Zone Text Size",
                                        desc = "Change the font size of the Zone Text.",
                                        type = "range",
                                        min = 6,
                                        max = 24,
                                        step = 1,
                                        get = function() return db.zoneSize end,
                                        set = function(_,size) 
                                                                db.zoneSize = size
                                                                PocketPlot.SetFonts()
                                                        end,
                                        order = 5,
                                },
                                clocksize = {
                                        name = "Clock Text Size",
                                        desc = "Change the font size of the clock.",
                                        type = "range",
                                        min = 6,
                                        max = 24,
                                        step = 1,
                                        get = function() return db.clockSize end,
                                        set = function(_,size) 
                                                                db.clockSize = size
                                                                PocketPlot.SetFonts()
                                                        end,
                                        order = 6,
                                },
                                coordsize = {
                                        name = "Coords Text Size",
                                        desc = "Change the font size of the coordinates.",
                                        type = "range",
                                        min = 6,
                                        max = 24,
                                        step = 1,
                                        get = function() return db.coordSize end,
                                        set = function(_,size) 
                                                                db.coordSize = size
                                                                PocketPlot.SetFonts()
                                                        end,
                                        order = 7,
                                },
                                coords = {
                                        name = "Display coords",
                                        desc = "Toggle showing the coordinates display.",
                                        type = "toggle",
                                        get = function() return db.coords end,
                                        set = function()
                                                                db.coords = not db.coords
                                                                if db.coords then
                                                                        PocketPlot.coordframe:Show()
                                                                else
                                                                        PocketPlot.coordframe:Hide()
                                                                end
                                                                PocketPlot.CoordPosition()
                                                        end,
                                        order = 8,
                                },
                                clock = {
                                        name = "Display clock",
                                        desc = "Toggle showing the clock.",
                                        type = "toggle",
                                        get = function() return db.clock end,
                                        set = function()
                                                                db.clock = not db.clock
                                                                if db.clock then
                                                                        TimeManagerClockButton:Show()
                                                                else
                                                                        TimeManagerClockButton:Hide()
                                                                end
                                                                PocketPlot.CoordPosition()
                                                        end,
                                        order = 9,
                                },
                                zoneText = {
                                        name = "Display zone text",
                                        desc = "Toggle showing the zone text.",
                                        type = "toggle",
                                        get = function() return db.zoneText end,
                                        set = function()
                                                                db.zoneText = not db.zoneText
                                                                if db.zoneText then
                                                                        MinimapZoneTextButton:Show()
                                                                else
                                                                        MinimapZoneTextButton:Hide()
                                                                end
                                                        end,
                                        order = 10,
                                },
                                top = {
                                        name = "Clock/coords on top",
                                        desc = "Toggle showing the clock and coordinates above or below the map.",
                                        type = "toggle",
                                        get = function() return db.top end,
                                        set = function()
                                                                db.top = not db.top
                                                                PocketPlot.CoordPosition()
                                                        end,
                                        order = 11,
                                },
                                textOffset = {
                                        name = "Clock/Coord Offset",
                                        desc = "Vertical offset for the clock and coordinates.",
                                        type = "range",
                                        min = -50,
                                        max = 50,
                                        step = 1,
                                        get = function() return db.textOffset end,
                                        set = function(_,offset) 
                                                                db.textOffset = offset
                                                                PocketPlot.CoordPosition()
                                                        end,
                                        order = 12,
                                },
                                zoneTextOffset = {
                                        name = "Zone Text Offset",
                                        desc = "Vertical offset for the zone text.",
                                        type = "range",
                                        min = -50,
                                        max = 50,
                                        step = 1,
                                        get = function() return db.zoneTextOffset end,
                                        set = function(_,offset) 
                                                                db.zoneTextOffset = offset
                                                                MinimapZoneTextButton:ClearAllPoints()
                                                                MinimapZoneTextButton:SetPoint("TOP", Minimap, "TOP", 0, -1 + db.zoneTextOffset)
                                                        end,
                                        order = 13,
                                },
                        },
                },
                locations = {
                        name = "Locations",
                        type = "group",
                        args = {
                                header3 = {
                                        name = "",
                                        type = "header",
                                        order = 1,
                                },
                                movers = {
                                        name = "Enable mover for...",
                                        desc = "Shows an anchor to move the selected frame.",
                                        type = "select",
                                        values = frames,
                                        get = function()
                                                                if movershown then
                                                                        for k,v in pairs(frames) do
                                                                                if v == movershown then
                                                                                        return k
                                                                                end
                                                                        end
                                                                else
                                                                        return 1        --key for "None" in frames table
                                                                end
                                                        end,
                                        set = function(_,frame)
                                                                movershown = frames[frame]
                                                                MoveFrames(movershown)
                                                        end,
                                        order = 2,
                                },
                                reset = {
                                        name = "Restore Positions",
                                        desc = "Clicking this will restore all frames to their default positions.\n\n|c00E30016WARNING:|r Your UI will be reloaded in the process!",
                                        type = "execute",
                                        confirm = true,
                                        func = function()
                                                                for i=1, #frames do
                                                                        db[frames[i]] = nil
                                                                end
                                                                ReloadUI()
                                                        end,
                                        order = 3,
                                },
                                div3 = {
                                        name = " ",
                                        type = "description",
                                        order = 4,
                                },
                                nudgehelp = {
                                        name = "Nudge the selected mover...",
                                        type = "description",
                                        order = 5,
                                },
                                nudgeL = {
                                        name = "Left",
                                        desc = "Nudge the frame 1px to the left.",
                                        type = "execute",
                                        width = "half",
                                        disabled = function() return movershown == "None" or movershown == nil end,
                                        func = function()
                                                                NudgeMover("x", -1)
                                                        end,
                                        order = 6,
                                },
                                nudgeR = {
                                        name = "Right",
                                        desc = "Nudge the frame 1px to the right.",
                                        type = "execute",
                                        width = "half",
                                        disabled = function() return movershown == "None" or movershown == nil end,
                                        func = function()
                                                                NudgeMover("x", 1)
                                                        end,
                                        order = 7,
                                },
                                nudgeU = {
                                        name = "Up",
                                        desc = "Nudge the frame 1px towards the top of the screen.",
                                        type = "execute",
                                        width = "half",
                                        disabled = function() return movershown == "None" or movershown == nil end,
                                        func = function()
                                                                NudgeMover("y", 1)
                                                        end,
                                        order = 8,
                                },
                                nudgeD = {
                                        name = "Down",
                                        desc = "Nudge the frame 1px towards the bottom of the screen.",
                                        type = "execute",
                                        width = "half",
                                        disabled = function() return movershown == "None" or movershown == nil end,
                                        func = function()
                                                                NudgeMover("y", -1)
                                                        end,
                                        order = 9,
                                },
                        },
                },
                profile = {
                        name = "Profile",
                        type = "group",
                        args = {
                                header4 = {
                                        name = "",
                                        type = "header",
                                        order = 1,
                                },
                                charSpec = {
                                        name = "Character specific settings",
                                        desc = "Have this character use their own profile.  If checked, any changes made will not affect other characters.\n\n|c00E30016WARNING:|r Your UI will be reloaded in the process!",
                                        type = "toggle",
                                        width = "full",
                                        confirm = true,
                                        get = function() return PocketPlotPCDB.charSpec end,
                                        set = function()
                                                                PocketPlotPCDB.charSpec = not PocketPlotPCDB.charSpec
                                                                ReloadUI()
                                                        end,
                                        order = 2,
                                },
                                copyProfile = {
                                        name = "Copy from Default",
                                        desc = "Copy all settings from the default, global profile to this character's profile.  This will not effect other characters' specific profiles.\n\n|c00E30016WARNING:|r Your UI will be reloaded in the process!",
                                        type = "execute",
                                        confirm = true,
                                        disabled = function() return not PocketPlotPCDB.charSpec end,
                                        func = function()
                                                                PocketPlotPCDB = PocketPlotDB
                                                                PocketPlotPCDB.charSpec = true
                                                                ReloadUI()
                                                        end,
                                        order = 3,
                                },
                                resetProfile = {
                                        name = "Profile Reset",
                                        desc = "Reset this profile back to the out-of-the-box settings.  If you reset the character specific profile, the global profile will be untouched, and vice versa.  This will not effect other character specific profiles.\n\n|c00E30016WARNING:|r Your UI will be reloaded in the process!",
                                        type = "execute",
                                        confirm = true,
                                        func = function()
                                                                if PocketPlotPCDB.charSpec then
                                                                        PocketPlotPCDB = {charSpec = true}
                                                                else
                                                                        PocketPlotDB = {}
                                                                end
                                                                ReloadUI()
                                                        end,
                                        order = 4,
                                },
                        },
                },
        },
}

local function SetUpDB()
        if PocketPlotPCDB.charSpec then
                --set defaults if new charSpec DB
                for k,v in pairs(defaults) do
                        if type(PocketPlotPCDB[k]) == "nil" then
                                PocketPlotPCDB[k] = v
                        end
                end
                db = PocketPlotPCDB
        else
                db = PocketPlotDB
        end
        PocketPlot.db = db
end

local function OnLoad()
        PocketPlotDB = PocketPlotDB or {}
        PocketPlotPCDB = PocketPlotPCDB or {}
                if PocketPlotPCDB.charSpec == nil then
                        PocketPlotPCDB.charSpec = false
                end
        for k,v in pairs(defaults) do
            if type(PocketPlotDB[k]) == "nil" then
                PocketPlotDB[k] = v
            end
        end
        SetUpDB()

        LibStub("AceConfig-3.0"):RegisterOptionsTable("PocketPlot", options)
        PocketPlot.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("PocketPlot", "PocketPlot", nil, "general")
        PocketPlot.optionsFrame.border = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("PocketPlot", "Border", "PocketPlot", "border")
        PocketPlot.optionsFrame.text = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("PocketPlot", "Text", "PocketPlot", "text")
        PocketPlot.optionsFrame.locations = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("PocketPlot", "Locations", "PocketPlot", "locations")
        PocketPlot.optionsFrame.profile = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("PocketPlot", "Profile", "PocketPlot", "profile")
        
        SlashCmdList["POCKETPLOT"] = function()
                InterfaceOptionsFrame_OpenToCategory("PocketPlot")
                InterfaceOptionsFrame_OpenToCategory("PocketPlot")
        end
        SLASH_POCKETPLOT1 = "/pocketplot"
        SLASH_POCKETPLOT2 = "/pp"
        
        --restore moved frame positions--
        for i=1, #frames do
                if db[frames[i]] then
                        SetPosition(frames[i])
                end
        end
        
        OnLoad = nil
        SetUpDB = nil
end

local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(self, event, addon)
        if addon == "PocketPlot" then
                OnLoad()
        end
end)

Go to most recent revision | Compare with Previous | Blame