Quantcast

Move options panels around to be clearer

James Whitehead II [11-13-10 - 19:43]
Move options panels around to be clearer
Filename
AddonCore.lua
BlizzardFrames.lua
FrameOptionsPanel.lua
OptionsPanel.lua
diff --git a/AddonCore.lua b/AddonCore.lua
index 25165ca..548911f 100644
--- a/AddonCore.lua
+++ b/AddonCore.lua
@@ -18,7 +18,16 @@ local addonName, addon = ...
 -- Set global name of addon
 _G[addonName] = addon

--- Set up an EMERGENCY debug mode
+-- Extract version information from TOC file
+addon.version = GetAddOnMetadata(addonName, "Version")
+if addon.version == "@project-version" or addon.version == "wowi:version" then
+    addon.version = "SCM"
+end
+
+--[[-------------------------------------------------------------------------
+--  Debug support
+-------------------------------------------------------------------------]]--
+
 local EMERGENCY_DEBUG = false
 if EMERGENCY_DEBUG then
     local private = {}
@@ -40,13 +49,10 @@ if EMERGENCY_DEBUG then
     })
 end

--- Extract version information from TOC file
-addon.version = GetAddOnMetadata(addonName, "Version")
-if addon.version == "@project-version" then
-    addon.version = "SCM"
-end
+--[[-------------------------------------------------------------------------
+--  Event registration and dispatch
+-------------------------------------------------------------------------]]--

--- Event registration and dispatch
 addon.eventFrame = CreateFrame("Frame", addonName .. "EventFrame", UIParent)
 local eventMap = {}

@@ -72,6 +78,37 @@ addon.eventFrame:SetScript("OnEvent", function(frame, event, ...)
     end
 end)

+--[[-------------------------------------------------------------------------
+--  Message support
+-------------------------------------------------------------------------]]--
+
+local messageMap = {}
+
+function addon:RegisterMessage(name, handler)
+    assert(messageMap[name] == nil, "Attempt to re-register message: " .. tostring(name))
+    messageMap[name] = handler and handler or name
+end
+
+function addon:UnregisterMessage(name)
+    assert(type(event) == "string", "Invalid argument to 'UnregisterMessage'")
+    messageMap[name] = nil
+end
+
+function addon:FireMessage(name, ...)
+    assert(type(event) == "string", "Invalid argument to 'FireMessage'")
+    local handler = messageMap[name]
+    local handler_t = type(handler)
+    if handler_t == "function" then
+        handler(name, ...)
+    elseif handler_t == "string" and addon[handler] then
+        addon[handler](addon, event, ...)
+    end
+end
+
+--[[-------------------------------------------------------------------------
+--  Setup Initialize/Enable support
+-------------------------------------------------------------------------]]--
+
 addon:RegisterEvent("PLAYER_LOGIN", "Enable")
 addon:RegisterEvent("ADDON_LOADED", function(event, ...)
     if ... == addonName then
@@ -87,7 +124,10 @@ addon:RegisterEvent("ADDON_LOADED", function(event, ...)
     end
 end)

--- Localization setup
+--[[-------------------------------------------------------------------------
+--  Localization
+-------------------------------------------------------------------------]]--
+
 addon.L = addon.L or setmetatable({}, {
     __index = function(t, k)
         rawset(t, k, k)
@@ -116,5 +156,61 @@ function addon:RegisterLocale(locale, tbl)
     end
 end

--- Debug messages
-addon.debug = false
+--[[-------------------------------------------------------------------------
+--  Addon 'About' Dialog for Interface Options
+--
+--  Some of this code was taken from/inspired by tekKonfigAboutPanel
+-------------------------------------------------------------------------]]--
+
+local about = CreateFrame("Frame", addonName .. "AboutPanel", InterfaceOptionsFramePanelContainer)
+about.name = addonName
+about:Hide()
+
+function about.OnShow(frame)
+    local fields = {"Version", "Author", "X-Category", "X-License", "X-Email", "X-Website", "X-Credits"}
+	local notes = GetAddOnMetadata(addonName, "Notes")
+
+    local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
+
+	title:SetPoint("TOPLEFT", 16, -16)
+	title:SetText(addonName)
+
+	local subtitle = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
+	subtitle:SetHeight(32)
+	subtitle:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
+	subtitle:SetPoint("RIGHT", about, -32, 0)
+	subtitle:SetNonSpaceWrap(true)
+	subtitle:SetJustifyH("LEFT")
+	subtitle:SetJustifyV("TOP")
+	subtitle:SetText(notes)
+
+	local anchor
+	for _,field in pairs(fields) do
+		local val = GetAddOnMetadata(addonName, field)
+		if val then
+			local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
+			title:SetWidth(75)
+			if not anchor then title:SetPoint("TOPLEFT", subtitle, "BOTTOMLEFT", -2, -8)
+			else title:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -6) end
+			title:SetJustifyH("RIGHT")
+			title:SetText(field:gsub("X%-", ""))
+
+			local detail = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
+			detail:SetPoint("LEFT", title, "RIGHT", 4, 0)
+			detail:SetPoint("RIGHT", -16, 0)
+			detail:SetJustifyH("LEFT")
+			detail:SetText(val)
+
+			anchor = title
+		end
+	end
+
+    -- Clear the OnShow so it only happens once
+	frame:SetScript("OnShow", nil)
+end
+
+addon.optpanels = addon.optpanels or {}
+addon.optpanels.ABOUT = about
+
+about:SetScript("OnShow", about.OnShow)
+InterfaceOptions_AddCategory(about)
diff --git a/BlizzardFrames.lua b/BlizzardFrames.lua
index 1c85936..77876ca 100644
--- a/BlizzardFrames.lua
+++ b/BlizzardFrames.lua
@@ -20,7 +20,6 @@ local panel = CreateFrame("Frame")
 panel.name = "Blizzard Frame Options"
 panel.parent = addonName

-addon.optpanels = addon.optpanels or {}
 addon.optpanels["BLIZZFRAMES"] = panel

 panel:SetScript("OnShow", function(self)
@@ -127,7 +126,7 @@ function panel.okay()
     opt.boss = not not panel.boss:GetChecked()
 end

-InterfaceOptions_AddCategory(panel)
+InterfaceOptions_AddCategory(panel, addon.optpanels.ABOUT)

 --[[---------------------------------------------------------------------------
 --  Blizzard Frame integration code
diff --git a/FrameOptionsPanel.lua b/FrameOptionsPanel.lua
index cf761ee..3bc2104 100644
--- a/FrameOptionsPanel.lua
+++ b/FrameOptionsPanel.lua
@@ -14,7 +14,6 @@ local panel = CreateFrame("Frame")
 panel.name = "Frame Blacklist"
 panel.parent = addonName

-addon.optpanels = addon.optpanels or {}
 addon.optpanels["BLACKLIST"] = panel

 panel:SetScript("OnShow", function(self)
@@ -195,4 +194,4 @@ function panel.refresh()
     panel:UpdateScrollFrame()
 end

-InterfaceOptions_AddCategory(panel)
+InterfaceOptions_AddCategory(panel, addon.optpanels.ABOUT)
diff --git a/OptionsPanel.lua b/OptionsPanel.lua
index 523d607..73019ab 100644
--- a/OptionsPanel.lua
+++ b/OptionsPanel.lua
@@ -12,10 +12,10 @@ local addonName, addon = ...
 local L = addon.L

 local panel = CreateFrame("Frame")
-panel.name = addonName
+panel.name = L["General Options"]
+panel.parent = addonName

-addon.optpanels = addon.optpanels or {}
-addon.optpanels["GENERAL"] = panel
+addon.optpanels.GENERAL = panel

 panel:SetScript("OnShow", function(self)
     if not panel.initialized then
@@ -399,6 +399,4 @@ function addon:UpdateOptionsPanel()
     end
 end

-InterfaceOptions_AddCategory(panel)
-
-LibStub("tekKonfig-AboutPanel").new(addonName, addonName)
+InterfaceOptions_AddCategory(panel, addon.optpanels.ABOUT)