Skip to content

Commit

Permalink
Added Custom Conditionals support and Config options
Browse files Browse the repository at this point in the history
You can now enter any macro conditions into an editbox in the Config GUI which will feed the state driver. The syntax is not validated, so its your own responsibility to know how macro syntax works!
Example:
[form:1]9;0 -- Page to Bar 9 in Form 1, otherwise don't page at all (id 0)
  • Loading branch information
Nevcairiel committed Sep 28, 2008
1 parent 0b6b233 commit 250f3d8
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 38 deletions.
91 changes: 53 additions & 38 deletions ActionBarStates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local DefaultStanceMap = setmetatable({}, { __index = function(t,k)
}
elseif k == "WARLOCK" then
newT = {
{ id = "metamorphosis", name = GetSpellInfo(59672), index = 2, type = "stance"},
{ id = "metamorphosis", name = GetSpellInfo(59672), index = 2, type = "form"},
}
end
rawset(t, k, newT)
Expand All @@ -55,68 +55,77 @@ Bartender4.StanceMap = DefaultStanceMap
local searchFunc = function(h, n) return (h.match == n or h.match2 == n or h.id == n) end

local stancemap
function ActionBar:UpdateStates()
function ActionBar:UpdateStates(returnOnly)
if not self.buttons then return end
self.statebutton = {}
if not stancemap and DefaultStanceMap[playerclass] then
stancemap = DefaultStanceMap[playerclass]
end

self:ForAll("ClearStateAction")
for i=0,10 do
for i=0,11 do
self:AddButtonStates(i)
end

local statedriver = {}
if self:GetStateOption("possess") then
self:AddButtonStates(11)
table_insert(statedriver, "[bonusbar:5]11")
end
local statedriver

local stateconfig = self.config.states
if self:GetStateOption("enabled") then
-- arguments will be parsed from left to right, so we have a priority here

-- highest priority have our temporary quick-swap keys
for _,v in pairs(modifiers) do
local page = self:GetStateOption(v)
if page and page ~= 0 then
table_insert(statedriver, fmt("[modifier:%s]%s", v, page))
end
if returnOnly or not self:GetStateOption("customEnabled") then
statedriver = {}
if self:GetStateOption("possess") then
table_insert(statedriver, "[bonusbar:5]11")
end

-- second priority the manual changes using the actionbar options
if self:GetStateOption("actionbar") then
for i=2,6 do
table_insert(statedriver, fmt("[actionbar:%s]%s", i, i))
local stateconfig = self.config.states
if self:GetStateOption("enabled") then
-- arguments will be parsed from left to right, so we have a priority here

-- highest priority have our temporary quick-swap keys
for _,v in pairs(modifiers) do
local page = self:GetStateOption(v)
if page and page ~= 0 then
table_insert(statedriver, fmt("[mod:%s]%s", v, page))
end
end
end

-- third priority the stances
if stancemap then
if not stateconfig.stance[playerclass] then stateconfig.stance[playerclass] = {} end
for i,v in pairs(stancemap) do
local state = self:GetStanceState(v)
if state and state ~= 0 and v.index then
if playerclass == "DRUID" and v.id == "cat" then
local prowl = self:GetStanceState("prowl")
if prowl then
table_insert(statedriver, fmt("[bonusbar:%s,stealth:1]%s", v.index, prowl))

-- second priority the manual changes using the actionbar options
if self:GetStateOption("actionbar") then
for i=2,6 do
table_insert(statedriver, fmt("[bar:%s]%s", i, i))
end
end

-- third priority the stances
if stancemap then
if not stateconfig.stance[playerclass] then stateconfig.stance[playerclass] = {} end
for i,v in pairs(stancemap) do
local state = self:GetStanceState(v)
if state and state ~= 0 and v.index then
if playerclass == "DRUID" and v.id == "cat" then
local prowl = self:GetStanceState("prowl")
if prowl then
table_insert(statedriver, fmt("[bonusbar:%s,stealth:1]%s", v.index, prowl))
end
end
table_insert(statedriver, fmt("[%s:%s]%s", v.type or "bonusbar", v.index, state))
end
table_insert(statedriver, fmt("[%s:%s]%s", v.type or "bonusbar", v.index, state))
end
end
end

table_insert(statedriver, tostring(self:GetDefaultState() or 0))
statedriver = table_concat(statedriver, ";")
else
statedriver = self:GetStateOption("custom")
end

self:SetAttribute("_onstate-page", [[
self:SetAttribute("state", newstate)
control:ChildUpdate("state", newstate)
]])

table_insert(statedriver, tostring(self:GetDefaultState() or 0))
RegisterStateDriver(self, "page", table_concat(statedriver, ";"))
if not returnOnly then
RegisterStateDriver(self, "page", statedriver or "")
end

self:SetAttribute("_onstate-assist-help", [[
local state = (newstate ~= "nil") and newstate or nil
Expand All @@ -130,11 +139,13 @@ function ActionBar:UpdateStates()

local pre = ""
if Bartender4.db.profile.selfcastmodifier then
pre = "[mod:"..GetModifiedClick("SELFCAST").."]player;"
pre = "[mod: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")

return statedriver
end

function ActionBar:GetStanceState(stance)
Expand Down Expand Up @@ -210,3 +221,7 @@ function ActionBar:SetConfigAutoAssist(_, value)
end
self:ForAll("RefreshAllStateActions")
end

function ActionBar:SetCopyCustomConditionals()
self.config.states.custom = self:UpdateStates(true)
end
45 changes: 45 additions & 0 deletions Options/ActionBarStates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ do
actionbar = "StateOption",
possess = "StateOption",
autoassist = "ConfigAutoAssist",
customEnabled = "StateOption",
custom = "StateOption",
customCopy = "CopyCustomConditionals",
}
-- retrieves a valid bar object from the modules actionbars table
function getBar(id)
Expand Down Expand Up @@ -196,6 +199,48 @@ function module:GetStateOptionsTable()
},
},
},
customNl = {
order = 48,
type = "description",
name = "\n",
},
customHeader = {
order = 49,
type = "header",
name = L["Custom Conditionals"],
},
customEnabled = {
order = 50,
type = "toggle",
name = L["Use Custom Condition"],
desc = L["Enable the use of a custom condition, disabling all of the above."],
get = optGetter,
set = optSetter,
disabled = disabledFunc,
--width = "double",
},
customCopy = {
order = 51,
type = "execute",
name = "Copy Conditionals",
desc = "Create a copy of the auto-generated conditionals in the custom configuration as a base template",
func = optSetter,
},
customDesc = {
order = 52,
type = "description",
name = L["Note: Enabling Custom Conditionals will disable all of the above settings!"],
},
custom = {
order = 55,
type = "input",
name = L["Custom Conditionals"],
desc = L["You can use any macro conditionals in the custom string, using the number of the bar as target value.\nExample: [form:1]9;0"],
width = "full",
get = optGetter,
set = optSetter,
disabled = disabledFunc,
},
}

do
Expand Down

0 comments on commit 250f3d8

Please sign in to comment.