Quantcast

Added options to limit Blizzard frame integration

James Whitehead II [10-12-10 - 16:37]
Added options to limit Blizzard frame integration
Filename
BlizzardFrames.lua
Clique.lua
Clique.toc
FrameOptionsPanel.lua
diff --git a/BlizzardFrames.lua b/BlizzardFrames.lua
index 9e95f38..42b165a 100644
--- a/BlizzardFrames.lua
+++ b/BlizzardFrames.lua
@@ -1,5 +1,122 @@
 local addonName, addon = ...
+local L = addon.L

+--[[---------------------------------------------------------------------------
+--  Options panel definition
+---------------------------------------------------------------------------]]--
+
+local panel = CreateFrame("Frame")
+panel.name = "Blizzard Frame Options"
+panel.parent = addonName
+
+panel:SetScript("OnShow", function(self)
+    if not panel.initialized then
+        panel:CreateOptions()
+        panel.refresh()
+    end
+end)
+
+local function make_checkbox(name, label)
+    local frame = CreateFrame("CheckButton", "CliqueOptionsBlizzFrame" .. name, panel, "UICheckButtonTemplate")
+    frame.text = _G[frame:GetName() .. "Text"]
+    frame.type = "checkbox"
+    frame.text:SetText(label)
+    return frame
+end
+
+local function make_label(name, template)
+    local label = panel:CreateFontString("OVERLAY", "CliqueOptionsBlizzFrame" .. name, template)
+    label:SetWidth(panel:GetWidth())
+    label:SetJustifyH("LEFT")
+    label.type = "label"
+    return label
+end
+
+function panel:CreateOptions()
+    panel.initialized = true
+
+    local bits = {}
+    self.intro = make_label("Intro", "GameFontHighlightSmall")
+    self.intro:SetText(L["These options control whether or not Clique auotmatically registers certain Blizzard-created frames for binding. Changes made to these settings will not take effect until the user interface is reloaded."])
+    self.intro:SetPoint("RIGHT")
+    self.intro:SetHeight(45)
+
+    self.PlayerFrame = make_checkbox("PlayerFrame", L["Player frame"])
+    self.PetFrame = make_checkbox("PetFrame", L["Player's pet frame"])
+    self.TargetFrame = make_checkbox("TargetFrame", L["Player's target frame"])
+    self.TargetFrameToT = make_checkbox("TargetFrameToT", L["Target of target frame"])
+    self.FocusFrame = make_checkbox("FocusFrame", L["Player's focus frame"])
+    self.FocusFrameToT = make_checkbox("FocusFrameToT", L["Target of focus frame"])
+    self.arena = make_checkbox("ArenaEnemy", L["Arena enemy frames"])
+    self.party = make_checkbox("Party", L["Party member frames"])
+    self.compactraid = make_checkbox("CompactRaid", L["Compact raid frames"])
+    self.compactparty = make_checkbox("CompactParty", L["Compact party frames"])
+    self.boss = make_checkbox("BossTarget", L["Boss target frames"])
+
+    table.insert(bits, self.intro)
+    table.insert(bits, self.PlayerFrame)
+    table.insert(bits, self.PetFrame)
+    table.insert(bits, self.TargetFrame)
+    table.insert(bits, self.FocusFrame)
+    table.insert(bits, self.FocusFrameToT)
+
+    -- Group these together
+    bits[1]:SetPoint("TOPLEFT", 5, -5)
+
+    for i = 2, #bits, 1 do
+        bits[i]:SetPoint("TOPLEFT", bits[i-1], "BOTTOMLEFT", 0, 0)
+    end
+
+    local last = bits[#bits]
+
+    table.wipe(bits)
+    table.insert(bits, self.arena)
+    table.insert(bits, self.party)
+    table.insert(bits, self.compactraid)
+    table.insert(bits, self.compactparty)
+    table.insert(bits, self.boss)
+
+    bits[1]:SetPoint("TOPLEFT", last, "BOTTOMLEFT", 0, -15)
+
+    for i = 2, #bits, 1 do
+        bits[i]:SetPoint("TOPLEFT", bits[i-1], "BOTTOMLEFT", 0, 0)
+    end
+end
+
+function panel.refresh()
+    local opt = addon.settings.blizzframes
+
+    panel.PlayerFrame:SetChecked(opt.PlayerFrame)
+    panel.PetFrame:SetChecked(opt.PetFrame)
+    panel.TargetFrame:SetChecked(opt.TargetFrame)
+    panel.FocusFrame:SetChecked(opt.FocusFrame)
+    panel.FocusFrameToT:SetChecked(opt.FocusFrameToT)
+    panel.arena:SetChecked(opt.arena)
+    panel.party:SetChecked(opt.party)
+    panel.compactraid:SetChecked(opt.compactraid)
+    panel.compactparty:SetChecked(opt.compactparty)
+    panel.boss:SetChecked(opt.boss)
+end
+
+function panel.okay()
+    local opt = addon.settings.blizzframes
+    opt.PlayerFrame = panel.PlayerFrame:GetChecked()
+    opt.PetFrame = panel.PetFrame:GetChecked()
+    opt.TargetFrame = panel.TargetFrame:GetChecked()
+    opt.FocusFrame = panel.FocusFrame:GetChecked()
+    opt.FocusFrameToT = panel.FocusFrameToT:GetChecked()
+    opt.arena = panel.arena:GetChecked()
+    opt.party = panel.party:GetChecked()
+    opt.compactraid = panel.compactraid:GetChecked()
+    opt.compactparty = panel.compactparty:GetChecked()
+    opt.boss = panel.boss:GetChecked()
+end
+
+InterfaceOptions_AddCategory(panel)
+
+--[[---------------------------------------------------------------------------
+--  Blizzard Frame integration code
+---------------------------------------------------------------------------]]--
 local function enable(frame)
     if type(frame) == "string" then
         local frameName = frame
@@ -14,24 +131,21 @@ local function enable(frame)
     end
 end

-function addon:Enable_BlizzRaidPullouts()
-    hooksecurefunc("CreateFrame", function(type, name, parent, template)
-        if template == "RaidPulloutButtonTemplate" then
-            local frame = _G[tostring(name) .. "ClearButton"]
-            if frame then
-                enable(frame)
-            end
-        end
-    end)
-end
-
 function addon:Enable_BlizzCompactUnitFrames()
+    if not addon.settings.blizzframes.compactraid then
+        return
+    end
+
     hooksecurefunc("CompactUnitFrame_SetUpFrame", function(frame, ...)
         enable(frame)
     end)
 end

 function addon:Enable_BlizzArenaFrames()
+    if not addon.settings.blizzframes.arena then
+        return
+    end
+
     local frames = {
         "ArenaEnemyFrame1",
         "ArenaEnemyFrame2",
@@ -54,11 +168,17 @@ function addon:Enable_BlizzSelfFrames()
         "FocusFrameToT",
     }
     for idx, frame in ipairs(frames) do
-        enable(frame)
+        if addon.settings.blizzframes[frame] then
+            enable(frame)
+        end
     end
 end

 function addon:Enable_BlizzPartyFrames()
+    if not addon.settings.blizzframes.party then
+        return
+    end
+
     local frames = {
         "PartyMemberFrame1",
 		"PartyMemberFrame2",
@@ -77,6 +197,10 @@ function addon:Enable_BlizzPartyFrames()
 end

 function addon:Enable_BlizzCompactParty()
+    if not addon.settings.blizzframes.compactparty then
+        return
+    end
+
     local frames = {
         --"CompactPartyFrameMemberSelf",
         --"CompactPartyFrameMemberSelfBuff1",
@@ -127,6 +251,10 @@ function addon:Enable_BlizzCompactParty()
 end

 function addon:Enable_BlizzBossFrames()
+    if not addon.settings.blizzframes.boss then
+        return
+    end
+
     local frames = {
         "Boss1TargetFrame",
         "Boss2TargetFrame",
@@ -140,7 +268,6 @@ end


 function addon:EnableBlizzardFrames()
-    self:Enable_BlizzRaidPullouts()
     self:Enable_BlizzCompactUnitFrames()
     self:Enable_BlizzSelfFrames()
     self:Enable_BlizzPartyFrames()
diff --git a/Clique.lua b/Clique.lua
index e4775e3..9ed60bf 100755
--- a/Clique.lua
+++ b/Clique.lua
@@ -152,27 +152,60 @@ end
 -- forward from this point. The database consists of two sections:
 --   * settings - used to handle the basic options Clique uses
 --   * profiles - used for the binding configuration profiles, possibly shared
-local current_db_version = 3
+local current_db_version = 4
 function addon:InitializeDatabase()
+    local realmKey = GetRealmName()
+    local charKey = UnitName("player") .. " - " .. realmKey
+    addon.staticProfileKey = charKey
+
     local reset = false
     if not CliqueDB2 then
         reset = true
+    elseif type(CliqueDB2) == "table" and CliqueDB2.dbversion == 3 then
+        -- Upgrade to add 'BlizzFrames' subtable
+        local settings = CliqueDB2.settings[charKey]
+        settings.blizzframes = {
+            PlayerFrame = true,
+            PetFrame = true,
+            TargetFrame = true,
+            TargetFrameToT = true,
+            FocusFrame = true,
+            FocusFrameToT = true,
+            arena = true,
+            party = true,
+            compactraid = true,
+            compactparty = true,
+            boss = true,
+        }
+        -- Don't forget to update the version
+        CliqueDB2.dbversion = current_db_version
     elseif type(CliqueDB2) == "table" and CliqueDB2.dbversion ~= current_db_version then
         reset = true
     end

     if reset then
         CliqueDB2 = {
-            settings = {},
+            settings = {
+                blizzframes = {
+                    PlayerFrame = true,
+                    PetFrame = true,
+                    TargetFrame = true,
+                    TargetFrameToT = true,
+                    FocusFrame = true,
+                    FocusFrameToT = true,
+                    arena = true,
+                    party = true,
+                    compactraid = true,
+                    compactparty = true,
+                    boss = true,
+                }
+            },
             bindings = {},
             dbversion = current_db_version,
         }
     end
-
+
     local db = CliqueDB2
-    local realmKey = GetRealmName()
-    local charKey = UnitName("player") .. " - " .. realmKey
-    addon.staticProfileKey = charKey

     addon.db = db
     if not db.settings[charKey] then
diff --git a/Clique.toc b/Clique.toc
index f0ab0d4..5a230af 100755
--- a/Clique.toc
+++ b/Clique.toc
@@ -20,7 +20,7 @@ BindConfig.lua
 OptionsPanel.lua
 FrameOptionsPanel.lua

+BlizzardFrames.lua
+
 # HeaderTest.xml
 # HeaderTest.lua
-
-BlizzardFrames.lua
diff --git a/FrameOptionsPanel.lua b/FrameOptionsPanel.lua
index 678ee5d..ad60d8b 100644
--- a/FrameOptionsPanel.lua
+++ b/FrameOptionsPanel.lua
@@ -1,4 +1,5 @@
 local addonName, addon = ...
+local L = addon.L

 local panel = CreateFrame("Frame")
 panel.name = "Frame Editor"
@@ -7,10 +8,12 @@ panel.parent = addonName
 panel:SetScript("OnShow", function(self)
     if not panel.initialized then
         panel:CreateOptions()
+        panel.refresh()
     end
 end)

 function panel:CreateOptions()
+    panel.initialized = true
 end

 InterfaceOptions_AddCategory(panel)