Quantcast

Add support for new talent specializations

Jim Whitehead [07-25-16 - 21:18]
Add support for new talent specializations

This new version works a bit differently than the old one in that the
same spell can be bound to multiple talent sets and it should work
correctly. Basically if a talent bind set is selected then the bind will
only be available when that spec is active, but it is no longer an ONLY
bind set.
Filename
BindConfig.lua
Clique.lua
diff --git a/BindConfig.lua b/BindConfig.lua
index d08eb07..3f2d5aa 100755
--- a/BindConfig.lua
+++ b/BindConfig.lua
@@ -48,6 +48,12 @@ function CliqueConfig:OnHide()
 end

 function CliqueConfig:SetupGUI()
+    self.talents = {}
+    for i = 1, GetNumSpecializations() do
+        local id, name = GetSpecializationInfo(i)
+        self.talents[i] = name
+    end
+
     self.rows = {}
     for i = 1, MAX_ROWS do
         self.rows[i] = CreateFrame("Button", "CliqueRow" .. i, self.page1, "CliqueRowTemplate")
@@ -599,23 +605,18 @@ function CliqueConfig:Row_OnClick(frame, button)
         keepShownOnClick = true,
     })

-	table.insert(submenu.menuList, {
-        text = L["Primary talent spec (ONLY)"],
-        checked = function() return binding.sets["pritalent"] end,
-        func = toggleSet(binding, "pritalent"),
-        tooltipTitle = L["Clique: 'pritalent' binding-set"],
-        tooltipText = L["A binding that belongs to the 'pritalent' binding-set is only active when the player is currently using their primary talent spec, regardless of the other binding-sets that this binding belongs to."],
-        keepShownOnClick = true,
-    })
-
-	table.insert(submenu.menuList, {
-        text = L["Secondary talent spec (ONLY)"],
-        checked = function() return binding.sets["sectalent"] end,
-        func = toggleSet(binding, "sectalent"),
-        tooltipTitle = L["Clique: 'sectalent' binding-set"],
-        tooltipText = L["A binding that belongs to the 'sectalent' binding-set is only active when the player is currently using their secondary talent spec, regardless of the other binding-sets that this binding belongs to."],
-        keepShownOnClick = true,
-    })
+    -- Add some buttons for the talent specs
+    for i = 1, #self.talents do
+        local key = "spec" .. i
+        table.insert(submenu.menuList, {
+            text = L["Talents: %s"]:format(self.talents[i]),
+            checked = function() return binding.sets[key] end,
+            func = toggleSet(binding, key),
+            tooltipTitle = L["Clique: talent set %d binding-set"].format(i),
+            tooltipText = L["A binding that belongs to this binding-set is only active when the player has the given talent specialization active"],
+            keepShownOnClick = true,
+        })
+    end

     table.insert(submenu.menuList, {
         text = L["Hovercast bindings (target required)"],
diff --git a/Clique.lua b/Clique.lua
index 25ac060..0b35c00 100755
--- a/Clique.lua
+++ b/Clique.lua
@@ -346,13 +346,22 @@ local function shouldApply(global, entry)
     end
 end

-local function correctSpec(entry, currentSpec)
-	if entry.sets.pritalent and currentSpec ~= 1 then
-		return false
-	elseif entry.sets.sectalent and currentSpec ~= 2 then
-		return false
-	end
-	return true
+local function correctSpec(entry)
+    -- Check to ensure we're on the right spec for this binding
+    local currentSpec = GetSpecialization()
+    if currentSpec and entry.sets["spec" .. tostring(currentSpec)] then
+        return true
+    end
+
+    -- Need to check the other spec sets to ensure this shouldn't be
+    -- deactivated
+    for i = 1, GetNumSpecializations() do
+        if entry.sets["spec" .. tostring(i)] then
+            return false
+        end
+    end
+
+    return true
 end

 local function getEntryString(entry)
@@ -418,7 +427,7 @@ function addon:GetClickAttributes(global)
         -- non-global bindings are only applied on non-global frames. handle
         -- this logic here.

-        if shouldApply(global, entry) and correctSpec(entry, GetActiveSpecGroup()) and entry.key then
+        if shouldApply(global, entry) and correctSpec(entry) and entry.key then
             -- Check to see if this is a 'friend' or an 'enemy' binding, and
             -- check if it would mask an 'ooc' binding with the same key. If
             -- so, we need to add code that prevents this from happening, by
@@ -604,7 +613,7 @@ function addon:GetBindingAttributes(global)

     for idx, entry in ipairs(self.bindings) do
 		if entry.key then
-			if shouldApply(global, entry) and correctSpec(entry, GetActiveSpecGroup()) then
+			if shouldApply(global, entry) and correctSpec(entry) then
 				if global then
 					-- Allow for the re-binding of clicks and keys, except for
 					-- unmodified left/right-click