Quantcast

Add an option to call /stopcasting before each spellcast

James Whitehead II [12-24-11 - 14:50]
Add an option to call /stopcasting before each spellcast
Filename
Clique.lua
DatabaseDefaults.lua
OptionsPanel.lua
diff --git a/Clique.lua b/Clique.lua
index e0a12cf..f9dfea3 100755
--- a/Clique.lua
+++ b/Clique.lua
@@ -68,6 +68,12 @@ function addon:Initialize()
     ]])
     RegisterAttributeDriver(self.header, "hasunit", "[@mouseover, exists] true; false")

+	-- Create a secure action button that's sole purpose is to cancel a
+	-- pending spellcast (the targeting hand)
+	self.stopbutton = CreateFrame("Button", addonName .. "StopButton", nil, "SecureActionButtonTemplate")
+	self.stopbutton.name = self.stopbutton:GetName()
+	self.stopbutton:SetAttribute("type", "stop")
+
     -- Create a secure action button that can be used for 'hovercast' and 'global'
     self.globutton = CreateFrame("Button", addonName .. "SABButton", UIParent, "SecureActionButtonTemplate, SecureHandlerBaseTemplate")

@@ -479,7 +485,14 @@ function addon:GetClickAttributes(global)
             if entry.type == "target" or entry.type == "menu" then
                 bits[#bits + 1] = ATTR(indent, prefix, "type", suffix, entry.type)
                 rembits[#rembits + 1] = REMATTR(prefix, "type", suffix)
-            elseif entry.type == "spell" then
+			elseif entry.type == "spell" and self.settings.stopcastingfix then
+				-- Implementation of the 'stop casting' fix
+				local macrotext = string.format("/click %s\n/cast %s", self.stopbutton.name, entry.spell)
+                bits[#bits + 1] = ATTR(indent, prefix, "type", suffix, "macro")
+                bits[#bits + 1] = ATTR(indent, prefix, "macrotext", suffix, macrotext)
+                rembits[#rembits + 1] = REMATTR(prefix, "type", suffix)
+                rembits[#rembits + 1] = REMATTR(prefix, "macrotext", suffix)
+           elseif entry.type == "spell" then
                 bits[#bits + 1] = ATTR(indent, prefix, "type", suffix, entry.type)
                 bits[#bits + 1] = ATTR(indent, prefix, "spell", suffix, entry.spell)
                 rembits[#rembits + 1] = REMATTR(prefix, "type", suffix)
diff --git a/DatabaseDefaults.lua b/DatabaseDefaults.lua
index 3eb0917..f0d3648 100644
--- a/DatabaseDefaults.lua
+++ b/DatabaseDefaults.lua
@@ -17,6 +17,7 @@ addon.defaults = {
             compactparty = true,
             boss = true,
         },
+		stopcastingfix = false,
     },
     profile = {
         bindings = {
diff --git a/OptionsPanel.lua b/OptionsPanel.lua
index 73019ab..695bb80 100644
--- a/OptionsPanel.lua
+++ b/OptionsPanel.lua
@@ -89,9 +89,14 @@ function panel:CreateOptions()
     self.profiledd = make_dropdown("CliqueOptionsProfileMgmt", self)
     UIDropDownMenu_SetWidth(self.profiledd, 200)

+	self.stopcastingfix = make_checkbox("CliqueOptionsStopCastingFix", self)
+    self.stopcastingfix.text:SetText(L["Attempt to fix the issue introduced in 4.3 with casting on dead targets"])
+
+
     -- Collect and anchor the bits together
     table.insert(bits, self.updown)
     table.insert(bits, self.fastooc)
+	table.insert(bits, self.stopcastingfix)
     table.insert(bits, self.specswap)
     table.insert(bits, self.prispeclabel)
     table.insert(bits, self.prispec)
@@ -370,6 +375,7 @@ function panel.refresh()

     panel.updown:SetChecked(settings.downclick)
     panel.fastooc:SetChecked(settings.fastooc)
+	panel.stopcastingfix:SetChecked(settings.stopcastingfix)
     panel.specswap:SetChecked(settings.specswap)
     panel.specswap.EnableDisable()
 end
@@ -378,8 +384,11 @@ function panel.okay()
     local settings = addon.settings
     local currentProfile = addon.db:GetCurrentProfile()

+	local changed = (not not panel.stopcastingfix:GetChecked()) ~= settings.stopcastingfix
+
     -- Update the saved variables
     settings.downclick = not not panel.updown:GetChecked()
+	settings.stopcastingfix = not not panel.stopcastingfix:GetChecked()
     settings.fastooc = not not panel.fastooc:GetChecked()
     settings.specswap = not not panel.specswap:GetChecked()
     settings.pri_profileKey = UIDropDownMenu_GetSelectedValue(panel.prispec)
@@ -389,6 +398,10 @@ function panel.okay()
         addon.db:SetProfile(newProfile)
     end
     addon:UpdateCombatWatch()
+
+	if changed then
+		addon:FireMessage("BINDINGS_CHANGED")
+	end
 end

 panel.cancel = panel.refresh