From 250f3d8a5be347e1d4ec242379f3a152f192d26f Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Sun, 28 Sep 2008 14:32:38 +0200 Subject: [PATCH] Added Custom Conditionals support and Config options 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) --- ActionBarStates.lua | 91 +++++++++++++++++++++---------------- Options/ActionBarStates.lua | 45 ++++++++++++++++++ 2 files changed, 98 insertions(+), 38 deletions(-) diff --git a/ActionBarStates.lua b/ActionBarStates.lua index ab3942e..ad819cb 100644 --- a/ActionBarStates.lua +++ b/ActionBarStates.lua @@ -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) @@ -55,7 +55,7 @@ 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 @@ -63,51 +63,59 @@ function ActionBar:UpdateStates() 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", [[ @@ -115,8 +123,9 @@ function ActionBar:UpdateStates() 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 @@ -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) @@ -210,3 +221,7 @@ function ActionBar:SetConfigAutoAssist(_, value) end self:ForAll("RefreshAllStateActions") end + +function ActionBar:SetCopyCustomConditionals() + self.config.states.custom = self:UpdateStates(true) +end diff --git a/Options/ActionBarStates.lua b/Options/ActionBarStates.lua index 11ff77b..355cb0b 100644 --- a/Options/ActionBarStates.lua +++ b/Options/ActionBarStates.lua @@ -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) @@ -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