Quantcast

Massive advancements towards working version:

James Whitehead II [09-30-10 - 20:50]
Massive advancements towards working version:

  * Fixed in-combat registration
  * Fixed out-of-combat registration
  * Adding bindings works properly
  * Attributes are updated properly after changes to bindings
  * Altered options screen to display
  * Changed display of BUTTONX and BACKSPACE, etc.
Filename
Clique.lua
Clique.xml
CliqueOptions.lua
CliqueUtils.lua
diff --git a/Clique.lua b/Clique.lua
index b876f4a..bb2e16f 100755
--- a/Clique.lua
+++ b/Clique.lua
@@ -18,7 +18,8 @@ local L = addon.L

 function addon:Initialize()
     self:InitializeDatabase()
-
+    self.ccframes = {}
+
     -- Compatability with old Clique 1.x registrations
     local oldClickCastFrames = ClickCastFrames

@@ -41,6 +42,12 @@ function addon:Initialize()
     self.header = CreateFrame("Frame", addonName .. "HeaderFrame", UIParent, "SecureHandlerBaseTemplate")
     ClickCastHeader = addon.header

+    -- Create a table within the addon header to store the frames
+    -- that are registered for click-casting
+    self.header:Execute([[
+        ccframes = table.new()
+    ]])
+
     -- OnEnter bootstrap script for group-header frames
     self.header:SetAttribute("clickcast_onenter", [===[
         local header = self:GetParent():GetFrameRef("clickcast_header")
@@ -58,6 +65,7 @@ function addon:Initialize()
         local button = self:GetAttribute("clickcast_button")
         button:SetAttribute("clickcast_onenter", self:GetAttribute("clickcast_onenter"))
         button:SetAttribute("clickcast_onleave", self:GetAttribute("clickcast_onleave"))
+        ccframes[button] = true
         self:RunFor(button, self:GetAttribute("setup_clicks"))
     ]===]):format(self.attr_setup_clicks))

@@ -67,6 +75,8 @@ function addon:Initialize()
 end

 function addon:RegisterFrame(button)
+    self.ccframes[button] = true
+
     button:RegisterForClicks("AnyDown")

     -- Wrap the OnEnter/OnLeave scripts in order to handle keybindings
@@ -74,8 +84,8 @@ function addon:RegisterFrame(button)
     addon.header:WrapScript(button, "OnLeave", addon.header:GetAttribute("setup_onleave"))

     -- Set the attributes on the frame
-    -- TODO: Fix this as it is broken
-    self.header:RunFor(button, self.header:GetAttribute("setup_clicks"))
+    self.header:SetFrameRef("cliquesetup_button", button)
+    self.header:Execute(self.header:GetAttribute("setup_clicks"), button)
 end

 function addon:Enable()
@@ -103,14 +113,17 @@ function addon:InitializeDatabase()
 end

 function ATTR(prefix, attr, suffix, value)
-    local fmt = [[self:SetAttribute("%s%s%s%s%s", "%s")]]
+    local fmt = [[button:SetAttribute("%s%s%s%s%s", "%s")]]
     return fmt:format(prefix, #prefix > 0 and "-" or "", attr, tonumber(suffix) and "" or "-", suffix, value)
 end

 -- This function will create an attribute that when run for a given frame
 -- will set the correct set of SAB attributes.
 function addon:GetClickAttribute()
-    local bits = {}
+    local bits = {
+        "local setupbutton = self:GetFrameRef('cliquesetup_button')",
+        "local button = setupbutton or self",
+    }

     for idx, entry in ipairs(self.profile.binds) do
         local prefix, suffix = entry.key:match("^(.-)([^%-]+)$")
@@ -191,9 +204,42 @@ end
 -- }

 function addon:AddBinding(entry)
-    print("Adding new binding")
-    for k,v in pairs(entry) do
-        print(k, v)
+    -- Check to see if the new binding conflicts with an existing binding
+
+    -- Validate the entry to ensure it has the correct arguments, etc.
+    table.insert(self.profile.binds, entry)
+
+    self:UpdateAttributes()
+    return true
+end
+
+function addon:UpdateAttributes()
+    if InCombatLockdown() then
+        error("panic: Clique:UpdateAttributes() called during combat")
+    end
+
+    self.header:SetAttribute("setup_clicks", self:GetClickAttribute())
+
+    local set, clr = self:GetBindingAttributes()
+    self.header:SetAttribute("setup_onenter", set)
+    self.header:SetAttribute("setup_onleave", clr)
+
+    self.header:Execute([[
+        for button, enabled in pairs(ccframes) do
+            self:RunFor(button, self:GetAttribute("setup_clicks"))
+        end
+    ]])
+
+    for button, enabled in pairs(self.ccframes) do
+        -- Unwrap any existing enter/leave scripts
+        addon.header:UnwrapScript(button, "OnEnter")
+        addon.header:UnwrapScript(button, "OnLeave")
+        addon.header:WrapScript(button, "OnEnter", addon.header:GetAttribute("setup_onenter"))
+        addon.header:WrapScript(button, "OnLeave", addon.header:GetAttribute("setup_onleave"))
+
+        -- Perform the setup of click bindings
+        self.header:SetFrameRef("cliquesetup_button", button)
+        self.header:Execute(self.header:GetAttribute("setup_clicks"), button)
     end
 end

diff --git a/Clique.xml b/Clique.xml
index 0290945..1e83fd3 100755
--- a/Clique.xml
+++ b/Clique.xml
@@ -4,14 +4,14 @@
     http://wowprogramming.com/FrameXML/UI.xsd">

     <Button name="CliqueRowTemplate" enableMouse="true" virtual="true">
-        <Size x="298" y="17"/>
+        <Size x="298" y="30"/>
         <Layers>
             <Layer level="BORDER">
                 <Texture name="$parentIcon" parentKey="icon"
                     file="Interface\Icons\Ability_Druid_Nourish">
-                    <Size x="14" y="14"/>
+                    <Size x="25" y="25"/>
                     <Anchors>
-                        <Anchor point="TOPLEFT">
+                        <Anchor point="LEFT">
                             <Offset>
                                 <AbsDimension x="5" y="0"/>
                             </Offset>
@@ -19,40 +19,38 @@
                     </Anchors>
                 </Texture>
                 <FontString name="$parentName" parentKey="name"
-                    inherits="GameFontHighlightSmall" justifyH="LEFT" text="Healing Touch">
+                    inherits="GameFontHighlight" justifyH="LEFT" text="Healing Touch">
                     <Size>
-                        <AbsDimension x="175" y="14"/>
+                        <AbsDimension x="175" y="12"/>
                     </Size>
                     <Anchors>
-                        <Anchor point="LEFT" relativeTo="$parentIcon" relativePoint="RIGHT">
+                        <Anchor point="TOPLEFT" relativeTo="$parentIcon" relativePoint="TOPRIGHT">
                             <Offset>
                                 <AbsDimension x="3" y="0"/>
                             </Offset>
                         </Anchor>
                     </Anchors>
                 </FontString>
-                <!--
-                <FontString name="$parentType" parentKey="type"
-                    inherits="GameFontHighlightSmall" justifyH="CENTER" text="Spell">
+                <FontString name="$parentInfo" parentKey="type"
+                    inherits="GameFontDarkGraySmall" justifyH="LEFT" text="Spell">
                     <Size>
-                        <AbsDimension x="40" y="14"/>
+                        <AbsDimension x="40" y="12"/>
                     </Size>
                     <Anchors>
-                        <Anchor point="LEFT" relativeTo="$parentName" relativePoint="RIGHT">
+                        <Anchor point="TOPLEFT" relativeTo="$parentName" relativePoint="BOTTOMLEFT">
                             <Offset>
-                                <AbsDimension x="0" y="0"/>
+                                <AbsDimension x="0" y="-2"/>
                             </Offset>
                         </Anchor>
                     </Anchors>
                 </FontString>
-                -->
                 <FontString name="$parentBind" parentKey="bind"
                     inherits="GameFontHighlightSmall" justifyH="RIGHT" text="Alt-LeftClick">
                     <Size>
-                        <AbsDimension x="115" y="14"/>
+                        <AbsDimension x="106" y="12"/>
                     </Size>
                     <Anchors>
-                        <Anchor point="LEFT" relativeTo="$parentName" relativePoint="RIGHT">
+                        <Anchor point="TOPLEFT" relativeTo="$parentName" relativePoint="TOPRIGHT">
                             <Offset>
                                 <AbsDimension x="0" y="0"/>
                             </Offset>
@@ -68,10 +66,10 @@
             </OnMouseWheel>
         </Scripts>
         <HighlightTexture setAllPoints="true" file="Interface\QuestFrame\UI-QuestTitleHighlight" alphaMode="ADD">
-            <Size x="315" y="14"/>
+            <Size x="315" y="28"/>
             <Anchors>
                 <Anchor point="TOPLEFT">
-                    <Offset x="-1" y="0"/>
+                    <Offset x="1" y="0"/>
                 </Anchor>
             </Anchors>
         </HighlightTexture>
@@ -169,14 +167,10 @@
                         </ButtonText>
                     </Button>
                     <Slider name="$parent_VSlider" parentKey="slider" valueStep="1.0" hidden="true" orientation="VERTICAL">
-                        <Size x="18" y="200"/>
+                        <Size x="18" y="0"/>
                         <Anchors>
-                            <Anchor point="TOPRIGHT">
-                                <Offset x="-44" y="-90"/>
-                            </Anchor>
-                            <Anchor point="BOTTOMRIGHT">
-                                <Offset x="0" y="83"/>
-                            </Anchor>
+                            <Anchor point="TOPRIGHT" x="0" y="-20"/>
+                            <Anchor point="BOTTOMRIGHT"/>
                         </Anchors>
                         <Backdrop edgeFile="Interface\Buttons\UI-SliderBar-Border"
                             bgFile="Interface\Buttons\UI-SliderBar-Background"
@@ -308,6 +302,11 @@
 				<Anchors>
 					<Anchor point="BOTTOMLEFT" />
 				</Anchors>
+                <Scripts>
+                    <OnClick>
+                        CliqueConfig:Button_Add(self)
+                    </OnClick>
+                </Scripts>
 			</Button>
 			<Button name="$parentButton2" parentKey="button_edit" inherits="MagicButtonTemplate">
 				<Size x="80" y="22"/>
diff --git a/CliqueOptions.lua b/CliqueOptions.lua
index 2b7a427..332752f 100755
--- a/CliqueOptions.lua
+++ b/CliqueOptions.lua
@@ -1,7 +1,7 @@
 local addonName, addon = ...
 local L = addon.L

-local MAX_ROWS = 19
+local MAX_ROWS = 12

 function CliqueConfig:OnShow()
     if not self.initialized then
@@ -22,11 +22,13 @@ function CliqueConfig:SetupGUI()
     end

     self.rows[1]:ClearAllPoints()
-    self.rows[1]:SetPoint("TOPLEFT", "CliqueConfigPage1Column1", "BOTTOMLEFT", 0, -6)
+    self.rows[1]:SetPoint("TOPLEFT", "CliqueConfigPage1Column1", "BOTTOMLEFT", 0, -3)
+    self.rows[1]:SetPoint("RIGHT", CliqueConfigPage1Column2, "RIGHT", 0, 0)

     for i = 2, MAX_ROWS do
         self.rows[i]:ClearAllPoints()
         self.rows[i]:SetPoint("TOPLEFT", self.rows[i - 1], "BOTTOMLEFT")
+        self.rows[i]:SetPoint("RIGHT", CliqueConfigPage1Column2, "RIGHT", 0, 0)
     end

     -- Set text elements using localized values
@@ -150,6 +152,12 @@ function CliqueConfig:Spellbook_OnBinding(button, key)
     end
 end

+function CliqueConfig:Button_Add(button)
+    if SpellBookFrame and not SpellBookFrame:IsVisible() then
+        ShowUIPanel(SpellBookFrame)
+    end
+end
+
 function CliqueConfig:SetNotification(text)
 end

@@ -183,8 +191,6 @@ function CliqueConfig:UpdateList()
     end

     -- Sort the bindings
-    -- TODO: Use a custom sort function here
-
     local sort = {}
     for uid, entry in pairs(binds) do
         sort[#sort + 1] = entry
@@ -200,7 +206,7 @@ function CliqueConfig:UpdateList()
         if not page.slider:IsShown() then
             -- Adjust column positions
             for idx, row in ipairs(self.rows) do
-                row.bind:SetWidth(100)
+                row.bind:SetWidth(90)
             end
             page.slider:SetValue(0)
             page.slider:Show()
@@ -208,7 +214,7 @@ function CliqueConfig:UpdateList()
     elseif page.slider:IsShown() then
         -- Move column positions back and hide the slider
         for idx, row in ipairs(self.rows) do
-            row.bind:SetWidth(115)
+            row.bind:SetWidth(105)
         end
         page.slider:Hide()
     end
diff --git a/CliqueUtils.lua b/CliqueUtils.lua
index 58dc082..cd43a6b 100644
--- a/CliqueUtils.lua
+++ b/CliqueUtils.lua
@@ -35,7 +35,7 @@ function addon:GetPrefixString(split)
     return prefix
 end

-local convertMap = {
+local convertMap = setmetatable({
     LSHIFT = L["LShift"],
     RSHIFT = L["RShift"],
     SHIFT = L["Shift"],
@@ -48,7 +48,15 @@ local convertMap = {
     BUTTON1 = L["LeftButton"],
     BUTTON2 = L["RightButton"],
     BUTTON3 = L["MiddleButton"],
-}
+}, {
+    __index = function(t, k, v)
+        if k:match("^BUTTON(%d+)$") then
+            return k:gsub("^BUTTON(%d+)$", "Button%1")
+        else
+            return k:sub(1,1) .. k:sub(2, -1):lower()
+        end
+    end,
+})

 local function convert(item, ...)
     if not item then
@@ -79,7 +87,7 @@ function addon:GetBindingIcon(binding)
 end

 function addon:GetBindingKeyComboText(binding)
-    return strconcat(convert(strsplit("-", binding.binding)))
+    return strconcat(convert(strsplit("-", binding.key)))
 end

 function addon:GetBindingActionText(binding)
@@ -116,7 +124,7 @@ local binMap = {

 function addon:GetBinaryBindingKey(binding)
     ret = {"0", "0", "0", "0", "0", "0", "0", "0", "0"}
-    splits = {strsplit("-", binding.binding)}
+    splits = {strsplit("-", binding.key)}
     for idx, modifier in ipairs(splits) do
         local bit = binMap[modifier]
         if bit then