From 26eeb1d240fe85bc07e0a602d7a7af7983f3b473 Mon Sep 17 00:00:00 2001 From: Xinhuan Date: Mon, 2 Mar 2009 15:58:48 +0800 Subject: [PATCH] Omen now generates the config tables on demand. Omen now provides better error feedback if AceGUI-3.0-SharedMediaWidgets is not found and will continue to function (but without any config). --- Omen.lua | 232 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 133 insertions(+), 99 deletions(-) diff --git a/Omen.lua b/Omen.lua index a40d1bd..750fc64 100644 --- a/Omen.lua +++ b/Omen.lua @@ -191,6 +191,7 @@ local bars = {} -- Format: bars[i] = frame containing the i-th bar f local inRaid, inParty -- boolean variables indicating if the player is in a raid and/or party local testMode = false -- boolean: Are we in test mode? local manualToggle = false -- boolean: Did we manually toggle Omen? +local moduleOptions = {} -- Table for LoD module options registration Omen.GuidNameLookup = guidNameLookup Omen.GuidClassLookup = guidClassLookup @@ -220,6 +221,20 @@ for i = 1, 40 do rpID[i] = format("raidpet%d", i) rptID[i] = format("raidpet%dtarget", i) end +local showClassesOptionTable = { + DEATHKNIGHT = L["DEATHKNIGHT"], + DRUID = L["DRUID"], + HUNTER = L["HUNTER"], + MAGE = L["MAGE"], + PALADIN = L["PALADIN"], + PET = L["PET"], + PRIEST = L["PRIEST"], + ROGUE = L["ROGUE"], + SHAMAN = L["SHAMAN"], + WARLOCK = L["WARLOCK"], + WARRIOR = L["WARRIOR"], + ["*NOTINPARTY*"] = L["*Not in Party*"], +} ---------------------------------------------------------------------------------------- @@ -790,7 +805,9 @@ function Omen:UpdateBackdrop() else self.Title:SetHeight(db.TitleBar.Height) end - self.Options.args.TitleBar.args.Height.min = h + if self.Options then + self.Options.args.TitleBar.args.Height.min = h + end --self.FocusButton:SetPoint("TOPRIGHT", -inset, -inset) @@ -1402,16 +1419,15 @@ function Omen:UpdateBarsReal() if testMode then threatTable = newTable() - local classes = self.Options.args.ShowClasses.args.Classes.values - local key = next(classes) + local key = next(showClassesOptionTable) for i = 1, 25 do if i == 22 and myGUID then -- Because I've got myGUID == nil before threatTable[myGUID] = i*5000 else threatTable[i] = i*5000 - guidNameLookup[i] = classes[key] + guidNameLookup[i] = showClassesOptionTable[key] if key ~= "*NOTINPARTY*" then guidClassLookup[i] = key end - key = next(classes, key) or next(classes) + key = next(showClassesOptionTable, key) or next(showClassesOptionTable) end end tankGUID = 25 @@ -1813,18 +1829,110 @@ end ----------------------------------------------------------------------------- -- Omen config stuff -local outlines = { - [""] = L["None"], - ["OUTLINE"] = L["Outline"], - ["THICKOUTLINE"] = L["Thick Outline"], -} +function Omen:SetupOptions() + LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("Omen", self.GenerateOptions) + LibStub("AceConfig-3.0"):RegisterOptionsTable("OmenSlashCommand", self.OptionsSlash, "omen") -local function GetFuBarMinimapAttachedStatus(info) - return Omen:IsFuBarMinimapAttached() or db.FuBar.HideMinimapButton + -- The ordering here matters, it determines the order in the Blizzard Interface Options + local ACD3 = LibStub("AceConfigDialog-3.0") + self.optionsFrames = {} + self.optionsFrames.Omen = ACD3:AddToBlizOptions("Omen", self.versionstring, nil, "General") + self.optionsFrames.ShowWhen = ACD3:AddToBlizOptions("Omen", L["Show When..."], self.versionstring, "ShowWhen") + self.optionsFrames.ShowClasses = ACD3:AddToBlizOptions("Omen", L["Show Classes..."], self.versionstring, "ShowClasses") + self.optionsFrames.TitleBar = ACD3:AddToBlizOptions("Omen", L["Title Bar Settings"], self.versionstring, "TitleBar") + self.optionsFrames.Bars = ACD3:AddToBlizOptions("Omen", L["Bar Settings"], self.versionstring, "Bars") + self.optionsFrames.Warnings = ACD3:AddToBlizOptions("Omen", L["Warning Settings"], self.versionstring, "Warnings") + self:RegisterModuleOptions("OmenSlashCommand", self.OptionsSlash, L["Slash Command"]) + self:RegisterModuleOptions("Profiles", function() return LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) end, L["Profiles"]) + self.optionsFrames.Help = ACD3:AddToBlizOptions("Omen", L["Help File"], self.versionstring, "Help") end +function Omen:RegisterModuleOptions(name, optionTbl, displayName) + if moduleOptions then + moduleOptions[name] = optionTbl + else + self.Options.args[name] = (type(optionTbl) == "function") and optionTbl() or optionTbl + end + self.optionsFrames[name] = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Omen", displayName, self.versionstring, name) +end + +function Omen:ShowConfig() + -- Open the profiles tab before, so the menu expands + InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Profiles) + InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Omen) +end + +function Omen.GenerateOptions() + if Omen.noconfig then assert(false, Omen.noconfig) end + if not Omen.Options then + Omen.GenerateOptionsInternal() + Omen.GenerateOptionsInternal = nil + moduleOptions = nil + end + return Omen.Options +end + + +----------------------------------------------------------------------------- +-- Omen config tables + +-- Option table for the slash command only +Omen.OptionsSlash = { + type = "group", + name = L["Slash Command"], + order = -3, + args = { + intro = { + order = 1, + type = "description", + name = L["OMEN_SLASH_DESC"], + cmdHidden = true, + }, + toggle = { + type = "execute", + name = L["Toggle Omen"], + desc = L["Toggle Omen"].." ( /omen toggle )", + func = function() Omen:Toggle() end, + }, + center = { + type = "execute", + name = L["Center Omen"], + desc = L["Center Omen"].." ( /omen center )", + func = function() + Omen.Anchor:ClearAllPoints() + Omen.Anchor:SetPoint("CENTER", UIParent, "CENTER") + Omen:SetAnchors() + end, + }, + config = { + type = "execute", + name = L["Configure"], + desc = L["Open the configuration dialog"].." ( /omen config )", + func = function() Omen:ShowConfig() end, + guiHidden = true, + }, + }, +} + +-- This is to provide better error reporting feedback, and stop loading the rest of the file. +if not AceGUIWidgetLSMlists then + Omen.noconfig = 'Cannot find a library instance of "AceGUI-3.0-SharedMediaWidgets". Omen configuration will not be available.' + assert(AceGUIWidgetLSMlists, Omen.noconfig) +end + +function Omen.GenerateOptionsInternal() + local outlines = { + [""] = L["None"], + ["OUTLINE"] = L["Outline"], + ["THICKOUTLINE"] = L["Thick Outline"], + } + + local function GetFuBarMinimapAttachedStatus(info) + return Omen:IsFuBarMinimapAttached() or db.FuBar.HideMinimapButton + end + -- Option table for the AceGUI config only -local options = { +Omen.Options = { type = "group", name = "Omen", get = function(info) return db[ info[#info] ] end, @@ -2220,20 +2328,7 @@ local options = { type = "multiselect", order = 30, name = L["Show bars for these classes"], - values = { - DEATHKNIGHT = L["DEATHKNIGHT"], - DRUID = L["DRUID"], - HUNTER = L["HUNTER"], - MAGE = L["MAGE"], - PALADIN = L["PALADIN"], - PET = L["PET"], - PRIEST = L["PRIEST"], - ROGUE = L["ROGUE"], - SHAMAN = L["SHAMAN"], - WARLOCK = L["WARLOCK"], - WARRIOR = L["WARRIOR"], - ["*NOTINPARTY*"] = L["*Not in Party*"], - }, + values = showClassesOptionTable, get = function(info, k) return db.Bar.Classes[k] end, set = function(info, k, v) db.Bar.Classes[k] = v @@ -2961,80 +3056,19 @@ local options = { }, }, } -Omen.Options = options -options.args.Warnings.args.Output.order = 6 -options.args.Warnings.args.Output.inline = true -options.args.Warnings.args.Output.disabled = function() return not db.Warnings.Message end +Omen.Options.args.Warnings.args.Output.order = 6 +Omen.Options.args.Warnings.args.Output.inline = true +Omen.Options.args.Warnings.args.Output.disabled = function() return not db.Warnings.Message end --- Option table for the slash command only -local optionsSlash = { - type = "group", - name = L["Slash Command"], - order = -3, - args = { - intro = { - order = 1, - type = "description", - name = L["OMEN_SLASH_DESC"], - cmdHidden = true, - }, - toggle = { - type = "execute", - name = L["Toggle Omen"], - desc = L["Toggle Omen"].." ( /omen toggle )", - func = function() Omen:Toggle() end, - }, - center = { - type = "execute", - name = L["Center Omen"], - desc = L["Center Omen"].." ( /omen center )", - func = function() - Omen.Anchor:ClearAllPoints() - Omen.Anchor:SetPoint("CENTER", UIParent, "CENTER") - Omen:SetAnchors() - end, - }, - config = { - type = "execute", - name = L["Configure"], - desc = L["Open the configuration dialog"].." ( /omen config )", - func = function() Omen:ShowConfig() end, - guiHidden = true, - }, - }, -} -Omen.OptionsSlash = optionsSlash - -function Omen:SetupOptions() - self.optionsFrames = {} - - -- setup options table - LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("Omen", options) - LibStub("AceConfig-3.0"):RegisterOptionsTable("OmenSlashCommand", optionsSlash, "omen") - local ACD3 = LibStub("AceConfigDialog-3.0") - - -- The ordering here matters, it determines the order in the Blizzard Interface Options - self.optionsFrames.Omen = ACD3:AddToBlizOptions("Omen", self.versionstring, nil, "General") - self.optionsFrames.ShowWhen = ACD3:AddToBlizOptions("Omen", L["Show When..."], self.versionstring, "ShowWhen") - self.optionsFrames.ShowClasses = ACD3:AddToBlizOptions("Omen", L["Show Classes..."], self.versionstring, "ShowClasses") - self.optionsFrames.TitleBar = ACD3:AddToBlizOptions("Omen", L["Title Bar Settings"], self.versionstring, "TitleBar") - self.optionsFrames.Bars = ACD3:AddToBlizOptions("Omen", L["Bar Settings"], self.versionstring, "Bars") - self.optionsFrames.Warnings = ACD3:AddToBlizOptions("Omen", L["Warning Settings"], self.versionstring, "Warnings") - self:RegisterModuleOptions("OmenSlashCommand", optionsSlash, L["Slash Command"]) - self:RegisterModuleOptions("Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db), L["Profiles"]) - self.optionsFrames.Help = ACD3:AddToBlizOptions("Omen", L["Help File"], self.versionstring, "Help") + for k, v in pairs(moduleOptions) do + Omen.Options.args[k] = (type(v) == "function") and v() or v + end -- Add ordering data to the option table generated by AceDBOptions-3.0 - options.args.Profiles.order = -2 + Omen.Options.args.Profiles.order = -2 + + local h = db.Background.EdgeSize * 2 + if not db.TitleBar.UseSameBG then h = db.TitleBar.EdgeSize * 2 end + Omen.Options.args.TitleBar.args.Height.min = h end -function Omen:RegisterModuleOptions(name, optionTbl, displayName) - options.args[name] = (type(optionTbl) == "function") and optionTbl() or optionTbl - self.optionsFrames[name] = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Omen", displayName, self.versionstring, name) -end - -function Omen:ShowConfig() - -- Open the profiles tab before, so the menu expands - InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Profiles) - InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Omen) -end