From bfa04a2f3e27945cc7b8491e6b7a8e1807124179 Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Sat, 9 Oct 2010 14:15:03 +0100 Subject: [PATCH] Added support for harm/help click-sets --- Clique.lua | 33 +++++++++++++++++++-------------- Utils.lua | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Clique.lua b/Clique.lua index 6c0dab1..9b01f2e 100755 --- a/Clique.lua +++ b/Clique.lua @@ -188,19 +188,21 @@ function addon:GetClickAttributes(global) for idx, entry in ipairs(self.profile.binds) do if self:ShouldSetBinding(entry, global) then - local prefix, suffix = entry.key:match("^(.-)([^%-]+)$") - if prefix:sub(-1, -1) == "-" then - prefix = prefix:sub(1, -2) - end - - prefix = prefix:lower() - - local button = suffix:match("^BUTTON(%d+)$") - if button then - suffix = button - else - suffix = "cliquebutton" .. idx - prefix = "" + local prefix, suffix = addon:GetBindingPrefixSuffix(entry) + + -- Set up help/harm bindings. The button value will be either a number, + -- in the case of mouse buttons, otherwise it will be a string of + -- characters. Harmbuttons work alongside modifiers, so we need to include + -- then in the remapping. + + if entry.sets.friend then + local newbutton = "friend" .. suffix + bits[#bits + 1] = ATTR(prefix, "helpbutton", suffix, newbutton) + suffix = newbutton + elseif entry.sets.enemy then + local newbutton = "enemy" .. suffix + bits[#bits + 1] = ATTR(prefix, "harmbutton", suffix, newbutton) + suffix = newbutton end -- Build any needed SetAttribute() calls @@ -241,7 +243,10 @@ function addon:GetBindingAttributes(global) if self:ShouldSetBinding(entry, global) then if not entry.key:match("BUTTON%d+$") then -- This is a key binding, so we need a binding for it - set[#set + 1] = B_SET:format(entry.key, "cliquebutton" .. idx) + + local prefix, suffix = addon:GetBindingPrefixSuffix(entry) + + set[#set + 1] = B_SET:format(entry.key, suffix) clr[#clr + 1] = B_CLR:format(entry.key) end end diff --git a/Utils.lua b/Utils.lua index 81a3fbb..8823973 100644 --- a/Utils.lua +++ b/Utils.lua @@ -198,6 +198,27 @@ function addon:GetBindingInfoText(binding) end end +function addon:GetBindingPrefixSuffix(binding) + local prefix, suffix = binding.key:match("^(.-)([^%-]+)$") + if prefix:sub(-1, -1) == "-" then + prefix = prefix:sub(1, -2) + end + + prefix = prefix:lower() + + local button = suffix:match("^BUTTON(%d+)$") + if button then + suffix = button + else + local mbid = (prefix .. suffix):gsub("[^A-Za-z0-9]", "") + suffix = "cliquebutton" .. mbid + prefix = "" + end + + return prefix, suffix +end + + -- This function examines the current state of the game function addon:ShouldSetBinding(binding, global) local apply = false @@ -209,6 +230,10 @@ function addon:ShouldSetBinding(binding, global) apply = false end + if binding.sets.enemy or binding.sets.friend and not binding.sets.global then + apply = true + end + if binding.sets.ooc then if UnitAffectingCombat("player") then apply = false -- 1.7.9.5