Quantcast

Implemented macros, srsly.

James Whitehead II [10-05-10 - 18:47]
Implemented macros, srsly.
Filename
BindConfig.lua
Clique.lua
Clique.xml
Utils.lua
diff --git a/BindConfig.lua b/BindConfig.lua
index a35cbc1..60fcd42 100755
--- a/BindConfig.lua
+++ b/BindConfig.lua
@@ -55,9 +55,14 @@ function CliqueConfig:SetupGUI()
     self.page1.button_spell:SetText(L["Bind spell"])
     self.page1.button_other:SetText(L["Bind other"])
     self.page1.button_options:SetText(L["Options"])
-
+
+    self.page2.button_binding:SetText(L["Set binding"])
     self.page2.button_save:SetText(L["Save"])
     self.page2.button_cancel:SetText(L["Cancel"])
+    local desc = L["You can use this page to create a custom macro to be run when activating a binding on a unit. When creating this macro you should keep in mind that you will need to specify the target of any actions in the macro by using the 'mouseover' unit, which is the unit you are clicking on. For example, you can do any of the following:\n\n/cast [target=mouseover] Regrowth\n/cast [@mouseover] Regrowth\n/cast [@mouseovertarget] Taunt\n\nHover over the 'Set binding' button below and either click or press a key with any modifiers you would like included. Then edit the box below to contain the macro you would like to have run when this binding is activated."]
+
+    self.page2.desc:SetText(desc)
+    self.page2.editbox = CliqueScrollFrameEditBox

     self.page1:Show()
 end
@@ -192,7 +197,16 @@ function CliqueConfig:Button_OnClick(button)
     -- Click handler for "Edit" button
     elseif button == self.page1.button_options then
         InterfaceOptionsFrame_OpenToCategory("Clique")
-    elseif button == self.page2.button_cancel then
+    elseif button == self.page2.button_save then
+        -- Check the input
+        local key = self.page2.key
+        local macrotext = self.page2.editbox:GetText()
+        local succ, err = addon:AddBinding{
+            key = key,
+            type = "macro",
+            macrotext = macrotext,
+        }
+        self:UpdateList()
         self.page2:Hide()
         self.page1:Show()
     elseif button == self.page2.button_cancel then
@@ -334,6 +348,14 @@ function CliqueConfig:BindingButton_OnClick(button, key)
     end
 end

+function CliqueConfig:MacroBindingButton_OnClick(button, key)
+    local key = addon:GetCapturedKey(key)
+    if key then
+        self.page2.key = key
+        self.page2.bindText:SetText(addon:GetBindingKeyComboText(key))
+    end
+end
+
 function CliqueConfig:AcceptSetBinding()
     local dialog = CliqueDialog
     local key = dialog.key
diff --git a/Clique.lua b/Clique.lua
index 7746d6b..e36a5c1 100755
--- a/Clique.lua
+++ b/Clique.lua
@@ -134,7 +134,7 @@ function addon:InitializeDatabase()
 end

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

diff --git a/Clique.xml b/Clique.xml
index ced18d8..7988e6c 100755
--- a/Clique.xml
+++ b/Clique.xml
@@ -166,9 +166,12 @@
                 <Scripts>
                     <OnLoad>
                         self:RegisterForClicks("AnyUp")
+                        self:EnableKeyboard(false)
                     </OnLoad>
                     <OnEnter>
-                        self:EnableKeyboard(true)
+                        if motion then
+                            self:EnableKeyboard(true)
+                        end
                     </OnEnter>
                     <OnLeave>
                         self:EnableKeyboard(false)
@@ -323,8 +326,56 @@
             </Frame> <!-- Page 1 - Configuration List -->

              <!-- Page definitions - Edit Page -->
-            <Frame name="$parentPage3" parentKey="page2" hidden="true">
+            <Frame name="$parentPage2" parentKey="page2" hidden="true">
+                <Layers>
+                    <Layer level="OVERLAY">
+                        <FontString name="$parentDesc" parentKey="desc" inherits="GameFontHighlightSmallLeftTop">
+                            <Size x="0" y="200"/>
+                            <Anchors>
+                                <Anchor point="TOPLEFT" x="5" y="-5"/>
+                                <Anchor point="TOPRIGHT" x="-5" y="-5"/>
+                            </Anchors>
+                        </FontString>
+                        <FontString name="$parentBindText" parentKey="bindText" JustifyH="CENTER" inherits="GameFontHighlightSmallLeftTop">
+                            <Size x="200" y="12"/>
+                            <Anchors>
+                                <Anchor point="CENTER" relativeTo="$parent" x="0" y="-24"/>
+                            </Anchors>
+                        </FontString>
+                    </Layer>
+                </Layers>
                 <Frames>
+                    <Button name="$parentButtonBinding" parentKey="button_binding" inherits="UIPanelButtonTemplate2">
+                        <Size x="160" y="22"/>
+                        <Anchors>
+                            <Anchor point="CENTER" relativeTo="$parent" x="0" y="0"/>
+                        </Anchors>
+                        <Scripts>
+                            <OnLoad>
+                                self:RegisterForClicks("AnyUp")
+                                self:EnableKeyboard(false)
+                            </OnLoad>
+                            <OnEnter>
+                                if motion then
+                                    self:EnableKeyboard(true)
+                                end
+                            </OnEnter>
+                            <OnLeave>
+                                self:EnableKeyboard(false)
+                            </OnLeave>
+                            <OnClick>
+                                CliqueConfig:MacroBindingButton_OnClick(self, button)
+                            </OnClick>
+                            <OnKeyDown>
+                                CliqueConfig:MacroBindingButton_OnClick(self, key)
+                            </OnKeyDown>
+                            <OnMouseWheel>
+                                local button = (delta > 0) and "MOUSEWHEELUP" or "MOUSEWHEELDOWN"
+                                CliqueConfig:MacroBindingButton_OnClick(self, key)
+                            </OnMouseWheel>
+                        </Scripts>
+                    </Button>
+
                     <!-- Wrap the scroll frame in a frame that can capture clicks -->
                     <Button name="CliqueClickGrabber" parentKey="clickGrabber">
                         <Size x="320" y="160"/>
@@ -355,7 +406,7 @@
                                 CliqueScrollFrameEditBox:SetFocus()
                             </OnClick>
                         </Scripts>
-                        <Frames>
+                        <Frames>
                             <ScrollFrame name="CliqueScrollFrame" parentKey="scrollFrame" inherits="UIPanelScrollFrameTemplate">
                                 <Size>
                                     <AbsDimension x="288" y="150"/>
@@ -368,7 +419,7 @@
                                     </Anchor>
                                 </Anchors>
                                 <ScrollChild>
-                                    <EditBox name="$parentEditBox" multiLine="true" autoFocus="false" countInvisibleLetters="true">
+                                    <EditBox name="$parentEditBox" parentKey="editbox" multiLine="true" autoFocus="false" countInvisibleLetters="true">
                                         <Size>
                                             <AbsDimension x="288" y="85"/>
                                         </Size>
diff --git a/Utils.lua b/Utils.lua
index d455da9..124ada4 100644
--- a/Utils.lua
+++ b/Utils.lua
@@ -108,6 +108,8 @@ function addon:GetBindingActionText(binding)
             return L["Cast %s (Rank %d)"]:format(binding.spell, binding.rank)
         end
         return L["Cast %s"]:format(binding.spell)
+    elseif btype == "macro" then
+        return L["Run macro '%s'"]:format(tostring(binding.macrotext))
     else
         return L["Unknown binding type '%s'"]:format(tostring(btype))
     end