Quantcast

Working proof-of-concept implementation of in-combat registration

James Whitehead II [09-26-10 - 21:22]
Working proof-of-concept implementation of in-combat registration
Filename
ClickCastTemplate.xml
Clique.lua
Clique.toc
CliqueTest.lua
CliqueTest.xml
diff --git a/ClickCastTemplate.xml b/ClickCastTemplate.xml
index a5cdfb5..3fe483f 100644
--- a/ClickCastTemplate.xml
+++ b/ClickCastTemplate.xml
@@ -9,5 +9,4 @@
           <Attribute name="_onleave" type="string" value="local snippet = self:GetAttribute('clickcast_onleave'); if snippet then self:Run(snippet) end"/>
       </Attributes>
   </Button>
-
 </Ui>
diff --git a/Clique.lua b/Clique.lua
index e6a359b..a5c2220 100755
--- a/Clique.lua
+++ b/Clique.lua
@@ -37,7 +37,7 @@ function addon:Initialize()
     end

     -- Registration for group headers (in-combat safe)
-    addon.header = CreateFrame("Frame", addonName .. "HeaderFrame", UIParent, "SecureHandlerAttributeTemplate")
+    addon.header = CreateFrame("Frame", addonName .. "HeaderFrame", UIParent, "SecureHandlerBaseTemplate")
     ClickCastHeader = addon.header

     addon.header:SetAttribute("clickcast_onenter", [===[
@@ -50,17 +50,12 @@ function addon:Initialize()
         header:RunAttribute("setup_onleave", self:GetName())
     ]===])

-    local _onattributechanged = [===[
-        if name == "clickcast_register" then
-            local button = self:GetFrameRef("clickcast_button")
-            button:SetAttribute("clickcast_onenter", self:GetAttribute("clickcast_onenter"))
-            button:SetAttribute("clickcast_onleave", self:GetAttribute("clickcast_onleave"))
-        elseif name == "clickcast_unregister" then
-            local button = value
-        end
-    ]===]
-
-    addon.header:SetAttribute("_onattributechanged", _onattributechanged)
+    addon.header:SetAttribute("clickcast_register", [===[
+        local button = self:GetAttribute("clickcast_button")
+        print("Registering ", button, " for clickcasting")
+        button:SetAttribute("clickcast_onenter", self:GetAttribute("clickcast_onenter"))
+        button:SetAttribute("clickcast_onleave", self:GetAttribute("clickcast_onleave"))
+    ]===])
 end

 function addon:Enable()
@@ -114,50 +109,6 @@ function addon:AddBinding(entry)
     end
 end

-function addon:RunTest()
-        -- Create a fake "group header" to test things properly
-    local groupheader = CreateFrame("Button", "MyGroupHeader", UIParent, "SecureGroupHeaderTemplate")
-    SecureHandler_OnLoad(groupheader)
-
-    -- Ensure the group header has a reference to the click-cast header
-    groupheader:SetFrameRef("clickcast_header", addon.header)
-
-    -- Set up the group header to display a solo/party/raid frame
-    groupheader.showRaid = true
-    groupheader.showParty = true
-    groupheader.showPlayer = true
-    groupheader.showSolo = true
-    groupheader.point = "TOP"
-    groupheader.template = "ClickCastUnitTemplate"
-    groupheader.templateType = "Button"
-    groupheader:SetAttribute("initialConfigFunction", [==[
-        self:SetSize(125, 25)
-        self:SetBackdrop(GameTooltip:GetBackdrop())
-        self:SetAttribute("shift-type1", "spell")
-        self:SetAttribute("shift-spell1", "Regrowth")
-        self:SetAttribute("shift-unit1", "player")
-
-        self:SetAttribute("type-cliquebutton1", "spell")
-        self:SetAttribute("spell-cliquebutton1", "Lifebloom")
-        self:SetAttribute("unit-cliquebutton1", "player")
-    ]==])
-
-    groupheader:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
-    groupheader:Show()
-
-    -- TODO: Remove these bindings
-    addon.header:SetAttribute("setup_onenter", [[
-        local buttonName = ...
-        print("Setting up click-bindings for: " .. buttonName)
-        self:ClearBinding("F")
-        self:SetBindingClick(true, "F", buttonName, "cliquebutton1")
-    ]])
-    addon.header:SetAttribute("setup_onleave", [[
-        print("Removing click-bindings")
-        self:ClearBinding("F")
-    ]])
-end
-
 SLASH_CLIQUE1 = "/clique"
 SlashCmdList["CLIQUE"] = function(msg, editbox)
     ShowUIPanel(CliqueConfig)
diff --git a/Clique.toc b/Clique.toc
index d3caede..0c677e5 100755
--- a/Clique.toc
+++ b/Clique.toc
@@ -9,8 +9,13 @@
 AddonCore.lua
 Localization.enUS.lua

+ClickCastTemplate.xml
+
 Clique.xml

 CliqueUtils.lua
 Clique.lua
 CliqueOptions.lua
+
+CliqueTest.xml
+CliqueTest.lua
diff --git a/CliqueTest.lua b/CliqueTest.lua
new file mode 100644
index 0000000..9a466c5
--- /dev/null
+++ b/CliqueTest.lua
@@ -0,0 +1,65 @@
+local addonName, addon = ...
+
+function addon:RunTest()
+    function CliqueTest_Unit_OnShow(self)
+        local unit = self:GetAttribute("unit")
+        if not unit or not UnitExists(unit) then
+            return
+        end
+        local name = UnitName(unit)
+        self.name:SetText(name)
+        self.healthBar:SetMinMaxValues(0, UnitHealthMax(unit))
+        self.powerBar:SetMinMaxValues(0, UnitPowerMax(unit))
+        self.healthBar:SetValue(UnitHealth(unit))
+        self.powerBar:SetValue(UnitPower(unit))
+    end
+
+    -- Create a fake "group header" to test things properly
+    local groupheader = CreateFrame("Button", "MyGroupHeader", UIParent, "SecureGroupHeaderTemplate")
+    SecureHandler_OnLoad(groupheader)
+
+    -- Ensure the group header has a reference to the click-cast header
+    groupheader:SetFrameRef("clickcast_header", addon.header)
+
+    -- Set header attributes
+    groupheader:SetAttribute("showParty", true)
+    groupheader:SetAttribute("showRaid", true)
+    groupheader:SetAttribute("showPlayer", true)
+    groupheader:SetAttribute("showSolo", true)
+    groupheader:SetAttribute("maxColumns", 8)
+    groupheader:SetAttribute("unitsPerColumn", 5)
+    groupheader:SetAttribute("columnAnchorPoint", "TOP")
+    groupheader:SetAttribute("point", "LEFT")
+    groupheader:SetAttribute("template", "CliqueTest_UnitTemplate")
+    groupheader:SetAttribute("templateType", "Button")
+    groupheader:SetAttribute("xOffset", -1)
+    groupheader:SetAttribute("yOffset", -1)
+
+    -- Set up the group header to display a solo/party/raid frame
+    groupheader:SetAttribute("initialConfigFunction", [==[
+        self:SetAttribute("shift-type1", "spell")
+        self:SetAttribute("shift-spell1", "Flash Heal")
+
+        self:SetAttribute("type-cliquebutton1", "spell")
+        self:SetAttribute("spell-cliquebutton1", "Flash Heal")
+
+        -- Register this frame with the global click-cast header
+        local header = self:GetParent():GetFrameRef("clickcast_header")
+        header:SetAttribute("clickcast_button", self)
+        header:RunAttribute("clickcast_register")
+    ]==])
+
+    addon.header:SetAttribute("setup_onenter", [[
+        local buttonName = ...
+        self:ClearBinding("F")
+        self:SetBindingClick(true, "F", buttonName, "cliquebutton1")
+    ]])
+    addon.header:SetAttribute("setup_onleave", [[
+        self:ClearBinding("F")
+    ]])
+
+    groupheader:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
+    groupheader:Show()
+end
+
+
diff --git a/CliqueTest.xml b/CliqueTest.xml
new file mode 100644
index 0000000..dd4887b
--- /dev/null
+++ b/CliqueTest.xml
@@ -0,0 +1,50 @@
+<Ui
+  xmlns="http://www.blizzard.com/wow/ui/"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.blizzard.com/wow/ui/
+  http://wowprogramming.com/FrameXML/UI.xsd">
+
+  <Button name="CliqueTest_UnitTemplate" inherits="ClickCastUnitTemplate,SecureActionButtonTemplate" virtual="true">
+      <Size x="34" y="34"/>
+      <Anchors>
+          <Anchor point="TOPLEFT">
+              <Offset x="1" y="-1"/>
+          </Anchor>
+      </Anchors>
+      <Layers>
+          <Layer level="OVERLAY">
+              <FontString name="$parent_Name" parentKey="name"
+                  inherits="GameFontHighlight" setAllPoints="true"/>
+              <Texture name="$parent_Selected" parentKey="selected" setAllPoints="true"
+                  file="Interface\Buttons\CheckButtonHilight" alphaMode="ADD" hidden="true"/>
+          </Layer>
+      </Layers>
+      <Frames>
+          <StatusBar name="$parent_HealthBar" parentKey="healthBar">
+              <Size x="34" y="30"/>
+              <Anchors>
+                  <Anchor point="TOPLEFT"/>
+              </Anchors>
+              <BarTexture file="Interface\Buttons\UI-Listbox-Highlight2"/>
+              <BarColor r="1.0" g="1.0" b="1.0" a="0.6"/>
+          </StatusBar>
+          <StatusBar name="$parent_PowerBar" parentKey="powerBar">
+              <Size x="34" y="3"/>
+              <Anchors>
+                  <Anchor point="TOPLEFT" relativeTo="$parent_HealthBar"
+                      relativePoint="BOTTOMLEFT">
+                      <Offset x="0" y="-1"/>
+                  </Anchor>
+              </Anchors>
+              <BarTexture file="Interface\TargetingFrame\UI-TargetingFrame-BarFill"/>
+              <BarColor r="1.0" g="1.0" b="1.0" a="0.6"/>
+          </StatusBar>
+      </Frames>
+      <Scripts>
+          <OnShow>
+              CliqueTest_Unit_OnShow(self)
+          </OnShow>
+      </Scripts>
+      <HighlightTexture file="Interface\Buttons\ButtonHilight-Square" alphaMode="ADD"/>
+  </Button>
+</Ui>