rewrite auto-assist feature using new secure state driver rather then ugly macrotext
This commit is contained in:
+17
-2
@@ -115,8 +115,23 @@ function ActionBar:UpdateStates()
|
|||||||
table_insert(statedriver, tostring(self:GetDefaultState() or 0))
|
table_insert(statedriver, tostring(self:GetDefaultState() or 0))
|
||||||
RegisterStateDriver(self, "page", table_concat(statedriver, ";"))
|
RegisterStateDriver(self, "page", table_concat(statedriver, ";"))
|
||||||
|
|
||||||
--local newState = self:GetAttribute("state-page")
|
self:SetAttribute("_onstate-assist-help", [[
|
||||||
--self:SetAttribute("state", newState)
|
local state = (newstate ~= "nil") and newstate or nil
|
||||||
|
control:ChildUpdate("assist-help", state)
|
||||||
|
]])
|
||||||
|
|
||||||
|
self:SetAttribute("_onstate-assist-harm", [[
|
||||||
|
local state = (newstate ~= "nil") and newstate or nil
|
||||||
|
control:ChildUpdate("assist-harm", state)
|
||||||
|
]])
|
||||||
|
|
||||||
|
local pre = ""
|
||||||
|
if Bartender4.db.profile.selfcastmodifier then
|
||||||
|
pre = "[mod:"..GetModifiedClick("SELFCAST").."]player;"
|
||||||
|
end
|
||||||
|
-- TODO: fix rightclick selfcast
|
||||||
|
RegisterStateDriver(self, "assist-help", ("%s[help]nil; [target=targettarget, help]targettarget; nil"):format(pre))
|
||||||
|
RegisterStateDriver(self, "assist-harm", "[harm]nil; [target=targettarget, harm]targettarget; nil")
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionBar:GetStanceState(stance)
|
function ActionBar:GetStanceState(stance)
|
||||||
|
|||||||
+36
-29
@@ -87,19 +87,43 @@ function Bartender4.Button:Create(id, parent)
|
|||||||
|
|
||||||
button:SetAttribute("type", "action")
|
button:SetAttribute("type", "action")
|
||||||
button:SetAttribute("action", absid)
|
button:SetAttribute("action", absid)
|
||||||
|
button:SetAttribute("checkselfcast", true)
|
||||||
|
|
||||||
button:SetAttribute("useparent-unit", true)
|
--button:SetAttribute("useparent-unit", true)
|
||||||
--button:SetAttribute("hidestates", "-1")
|
|
||||||
|
|
||||||
parent:SetAttribute('_adopt', button)
|
parent:SetAttribute('_adopt', button)
|
||||||
button:SetAttribute('_childupdate-state', [[
|
button:SetAttribute('_childupdate-state', [[
|
||||||
self:SetAttribute("state", message)
|
self:SetAttribute("state", message)
|
||||||
local type = self:GetAttribute("type--" .. message)
|
local type = self:GetAttribute("type-" .. message)
|
||||||
if type == "macro" then
|
if type == "special" then
|
||||||
self:SetAttribute("macrotext", self:GetAttribute("macrotext--" .. message))
|
-- TODO
|
||||||
end
|
end
|
||||||
self:SetAttribute("type", type)
|
self:SetAttribute("type", type)
|
||||||
self:SetAttribute("action", self:GetAttribute("action--" .. message))
|
self:SetAttribute("action", self:GetAttribute("action-" .. message))
|
||||||
|
|
||||||
|
-- fix unit on state change
|
||||||
|
if self:GetAttribute("assisttype-"..message) == 1 then
|
||||||
|
self:SetAttribute("unit", G_assist_help)
|
||||||
|
elseif self:GetAttribute("assisttype-"..message) == 2 then
|
||||||
|
self:SetAttribute("unit", G_assist_harm)
|
||||||
|
else
|
||||||
|
self:SetAttribute("unit", nil)
|
||||||
|
end
|
||||||
|
G_state = message
|
||||||
|
]])
|
||||||
|
|
||||||
|
button:SetAttribute('_childupdate-assist-help', [[
|
||||||
|
if self:GetAttribute("assisttype-"..G_state) == 1 then
|
||||||
|
self:SetAttribute("unit", message)
|
||||||
|
end
|
||||||
|
G_assist_help = message
|
||||||
|
]])
|
||||||
|
|
||||||
|
button:SetAttribute('_childupdate-assist-harm', [[
|
||||||
|
if self:GetAttribute("assisttype"..G_state) == 2 then
|
||||||
|
self:SetAttribute("unit", message)
|
||||||
|
end
|
||||||
|
G_assist_harm = message
|
||||||
]])
|
]])
|
||||||
|
|
||||||
button:RegisterForDrag("LeftButton", "RightButton")
|
button:RegisterForDrag("LeftButton", "RightButton")
|
||||||
@@ -224,35 +248,18 @@ end
|
|||||||
function Button:RefreshStateAction(state)
|
function Button:RefreshStateAction(state)
|
||||||
local state = tonumber(state or self:GetAttribute("state") or 0)
|
local state = tonumber(state or self:GetAttribute("state") or 0)
|
||||||
local action = self.stateactions[state]
|
local action = self.stateactions[state]
|
||||||
self:SetAttribute("type--" .. state, "action")
|
self:SetAttribute("type-" .. state, "action")
|
||||||
self:SetAttribute("action--" .. state, action)
|
self:SetAttribute("action-" .. state, action)
|
||||||
|
|
||||||
|
self:SetAttribute("assisttype", nil)
|
||||||
|
self:SetAttribute("unit", nil)
|
||||||
if self.parent.config.autoassist then
|
if self.parent.config.autoassist then
|
||||||
local type, id, subtype = GetActionInfo(action)
|
local type, id, subtype = GetActionInfo(action)
|
||||||
if type == "spell" and id > 0 then
|
if type == "spell" and id > 0 then
|
||||||
local spellName, spellRank = GetSpellInfo(id, subtype)
|
|
||||||
|
|
||||||
local macroText
|
|
||||||
if IsHelpfulSpell(id, subtype) then
|
if IsHelpfulSpell(id, subtype) then
|
||||||
macroText = "/cast %s[help] [target=targettarget, help] [target=none]"
|
self:SetAttribute("assisttype-"..state, 1)
|
||||||
|
|
||||||
-- Hack to get Selfcast working with macrotext syntax
|
|
||||||
local selfcast = ""
|
|
||||||
if Bartender4.db.profile.selfcastrightclick then
|
|
||||||
selfcast = selfcast .. "[button:2, target=player]"
|
|
||||||
end
|
|
||||||
if Bartender4.db.profile.selfcastmodifier then
|
|
||||||
selfcast = selfcast .. "[modifier:".. GetModifiedClick("SELFCAST").. ", target=player]"
|
|
||||||
end
|
|
||||||
macroText = macroText:format(selfcast)
|
|
||||||
elseif IsHarmfulSpell(id, subtype) then
|
elseif IsHarmfulSpell(id, subtype) then
|
||||||
macroText = "/cast [harm] [target=targettarget, harm] [target=none]"
|
self:SetAttribute("assisttype-"..state, 2)
|
||||||
end
|
|
||||||
|
|
||||||
if macroText then
|
|
||||||
self:SetAttribute("type--" .. state, "macro")
|
|
||||||
local macrotext = ("%s%s(%s)"):format(macroText, spellName, spellRank)
|
|
||||||
self:SetAttribute("macrotext--" .. state, macrotext)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user