Quantcast

Add 'hovercast' click set, to replace the old 'global'. New 'global' is truly global, with no target specified. These binding sets are mutually exclusive

James Whitehead II [10-14-10 - 13:10]
Add 'hovercast' click set, to replace the old 'global'. New 'global' is truly global, with no target specified. These binding sets are mutually exclusive
Filename
BindConfig.lua
Clique.lua
Utils.lua
diff --git a/BindConfig.lua b/BindConfig.lua
index 4b7e3e2..195fd34 100755
--- a/BindConfig.lua
+++ b/BindConfig.lua
@@ -414,7 +414,13 @@ function CliqueConfig:AcceptSetBinding()
     dialog:Hide()
 end

-local function toggleSet(binding, set)
+local function toggleSet(binding, set, ...)
+    local exclude = {}
+    for i = 1, select("#", ...) do
+        local item = select(i, ...)
+        table.insert(exclude, item)
+    end
+
     return function()
         if not binding.sets then
             binding.sets = {}
@@ -424,6 +430,12 @@ local function toggleSet(binding, set)
         else
             binding.sets[set] = true
         end
+
+        for idx, exclset in ipairs(exclude) do
+            binding.sets[exclset] = nil
+        end
+
+        UIDropDownMenu_Refresh(UIDROPDOWNMENU_OPEN_MENU, nil, UIDROPDOWNMENU_MENU_LEVEL)
         CliqueConfig:UpdateList()
         addon:UpdateAttributes()
         addon:UpdateGlobalAttributes()
@@ -503,11 +515,20 @@ function CliqueConfig:Row_OnClick(frame, button)
     })

     table.insert(submenu.menuList, {
-        text = L["Global bindings"],
+        text = L["Hovercast bindings (target required)"],
+        checked = function() return binding.sets["hovercast"] end,
+        func = toggleSet(binding, "hovercast", "global"),
+        tooltipTitle = L["Clique: 'hovercast' click-set"],
+        tooltipText = L["A binding that belongs to the 'hovercast' click-set is active whenever the mouse is over a unit frame, or a character in the 3D world. This allows you to use 'hovercasting', where you hover over a unit in the world and press a key to cast a spell on them. THese bindings are also active over unit frames."],
+        keepShownOnClick = true,
+    })
+
+    table.insert(submenu.menuList, {
+        text = L["Global bindings (no target)"],
         checked = function() return binding.sets["global"] end,
-        func = toggleSet(binding, "global"),
+        func = toggleSet(binding, "global", "hovercast"),
         tooltipTitle = L["Clique: 'global' click-set"],
-        tooltipText = L["A binding that belongs to the 'global' click-set is always active, regardless of whether the mouse is over a unit frame or not. This click-set allows you to bind spells to keys that can then be used over the 3-D game world, to enable 'hovercasting', where you hover over a unit in the world and press a key to cast a spell on them. These bindings are also active over unit frames."],
+        tooltipText = L["A binding that belongs to the 'global' click-set is always active. If the spell requires a target, you will be given the 'casting hand', otherwise the spell will be cast. If the spell is an AOE spell, then you will be given the ground targeting circle."],
         keepShownOnClick = true,
     })

diff --git a/Clique.lua b/Clique.lua
index b617fb3..abb3849 100755
--- a/Clique.lua
+++ b/Clique.lua
@@ -25,10 +25,11 @@
 --      clicking on is an enemy, i.e. a unit that you can attack.
 --    * friendly - These bindings are ONLY active when the unit you are
 --      clicking on is a friendly unit, i.e. one that you can assist
---    * global - These bindings will be available regardless of where
---      your mouse is on the screen, be it in the 3D world, or over a
---      unit frame. These bindings take up a slot that might otherwise
---      be used in the 'Key Bindings' interface options.
+--    * hovercast - These bindings will be available whenever you are over
+--      a unit frame, or a unit in the 3D world.
+--    * global - These bindings will be always available. They
+--      do not specify a target for the action, so if the action requires
+--      a target, you must specify it after performing the binding.
 --
 --  The click-sets layer on each other, with the 'default' click-set
 --  being at the bottom, and any other click-set being layered on top.
@@ -55,9 +56,8 @@ function addon:Initialize()
     self.header = CreateFrame("Frame", addonName .. "HeaderFrame", UIParent, "SecureHandlerBaseTemplate")
     ClickCastHeader = addon.header

-    -- Create a secure action button that can be used for 'global' bindings
+    -- Create a secure action button that can be used for 'hovercast' and 'global'
     self.globutton = CreateFrame("Button", addonName .. "SABButton", UIParent, "SecureActionButtonTemplate, SecureHandlerBaseTemplate")
-    self.globutton:SetAttribute("unit", "mouseover")

     -- Create a table within the addon header to store the frames
     -- that are registered for click-casting
@@ -285,6 +285,13 @@ function addon:GetClickAttributes(global)
                 suffix = newbutton
             end

+            -- Give globutton the 'mouseover' unit as target when using the 'hovercast'
+            -- binding set, as opposed to the global set.
+            if entry.sets.hovercast then
+                bits[#bits + 1] = ATTR(prefix, "unit", suffix, "mouseover")
+                rembits[#rembits + 1] = REMATTR(prefix, "unit", suffix)
+            end
+
             -- Build any needed SetAttribute() calls
             if entry.type == "target" or entry.type == "menu" then
                 bits[#bits + 1] = ATTR(prefix, "type", suffix, entry.type)
@@ -299,7 +306,6 @@ function addon:GetClickAttributes(global)
                 bits[#bits + 1] = ATTR(prefix, "macrotext", suffix, entry.macrotext)
                 rembits[#rembits + 1] = REMATTR(prefix, "type", suffix)
                 rembits[#rembits + 1] = REMATTR(prefix, "macrotext", suffix)
-
             else
                 error(string.format("Invalid action type: '%s'", entry.type))
             end
diff --git a/Utils.lua b/Utils.lua
index 6178f28..8aefb53 100644
--- a/Utils.lua
+++ b/Utils.lua
@@ -222,7 +222,7 @@ function addon:ShouldSetBinding(binding, global)
     local apply = false

     -- Check for global bindings first in isolation
-    if binding.sets.global then
+    if binding.sets.hovercast or binding.sets.global then
         if global then
             return true
         else