diff --git a/WeakAuras/GenericTrigger.lua b/WeakAuras/GenericTrigger.lua index 74f96c6..6b4b0de 100644 --- a/WeakAuras/GenericTrigger.lua +++ b/WeakAuras/GenericTrigger.lua @@ -780,12 +780,17 @@ function GenericTrigger.CreateFakeStates(id, triggernum) local allStates = WeakAuras.GetTriggerStateForTrigger(id, triggernum); RunTriggerFunc(allStates, events[id][triggernum], id, triggernum, "OPTIONS") + local canHaveDuration = events[id][triggernum].prototype and events[id][triggernum].prototype.canHaveDuration == "timed" + local shown = 0 for id, state in pairs(allStates) do if state.show then shown = shown + 1 end state.autoHide = false + if canHaveDuration and state.expirationTime == nil then + state.progressType = "timed" + end AddFakeTime(state) end @@ -794,6 +799,9 @@ function GenericTrigger.CreateFakeStates(id, triggernum) GenericTrigger.CreateFallbackState(data, triggernum, state) allStates[""] = state state.autoHide = false + if canHaveDuration and state.expirationTime == nil then + state.progressType = "timed" + end AddFakeTime(state) end @@ -1135,6 +1143,7 @@ function GenericTrigger.Add(data, region) local force_events = false; local durationFunc, overlayFuncs, nameFunc, iconFunc, textureFunc, stacksFunc, loadFunc; local tsuConditionVariables; + local prototype = nil if(triggerType == "status" or triggerType == "event") then if not(trigger.event) then error("Improper arguments to WeakAuras.Add - trigger type is \"event\" but event is not defined"); @@ -1157,24 +1166,25 @@ function GenericTrigger.Add(data, region) end end - triggerFuncStr = ConstructFunction(event_prototypes[trigger.event], trigger); + prototype = event_prototypes[trigger.event] + triggerFuncStr = ConstructFunction(prototype, trigger); - statesParameter = event_prototypes[trigger.event].statesParameter; + statesParameter = prototype.statesParameter; WeakAuras.debug(id.." - "..triggernum.." - Trigger", 1); WeakAuras.debug(triggerFuncStr); triggerFunc = WeakAuras.LoadFunction(triggerFuncStr, id); - durationFunc = event_prototypes[trigger.event].durationFunc; - nameFunc = event_prototypes[trigger.event].nameFunc; - iconFunc = event_prototypes[trigger.event].iconFunc; - textureFunc = event_prototypes[trigger.event].textureFunc; - stacksFunc = event_prototypes[trigger.event].stacksFunc; - loadFunc = event_prototypes[trigger.event].loadFunc; + durationFunc = prototype.durationFunc; + nameFunc = prototype.nameFunc; + iconFunc = prototype.iconFunc; + textureFunc = prototype.textureFunc; + stacksFunc = prototype.stacksFunc; + loadFunc = prototype.loadFunc; - if (event_prototypes[trigger.event].overlayFuncs) then + if (prototype.overlayFuncs) then overlayFuncs = {}; local dest = 1; - for i, v in ipairs(event_prototypes[trigger.event].overlayFuncs) do + for i, v in ipairs(prototype.overlayFuncs) do if (v.enable(trigger)) then overlayFuncs[dest] = v.func; dest = dest + 1; @@ -1182,11 +1192,11 @@ function GenericTrigger.Add(data, region) end end - if (event_prototypes[trigger.event].automaticrequired) then + if (prototype.automaticrequired) then trigger.unevent = "auto"; - elseif event_prototypes[trigger.event].timedrequired then - if type(event_prototypes[trigger.event].timedrequired) == "function" then - if event_prototypes[trigger.event].timedrequired(trigger) then + elseif prototype.timedrequired then + if type(prototype.timedrequired) == "function" then + if prototype.timedrequired(trigger) then trigger.unevent = "timed" else if not(WeakAuras.eventend_types[trigger.unevent]) then @@ -1196,7 +1206,7 @@ function GenericTrigger.Add(data, region) else trigger.unevent = "timed" end - elseif event_prototypes[trigger.event].automatic then + elseif prototype.automatic then if not(WeakAuras.autoeventend_types[trigger.unevent]) then trigger.unevent = "auto" end @@ -1208,9 +1218,9 @@ function GenericTrigger.Add(data, region) trigger.duration = trigger.duration or "1" if(trigger.unevent == "custom") then - untriggerFuncStr = ConstructFunction(event_prototypes[trigger.event], untrigger); + untriggerFuncStr = ConstructFunction(prototype, untrigger); elseif(trigger.unevent == "auto") then - untriggerFuncStr = ConstructFunction(event_prototypes[trigger.event], trigger, true); + untriggerFuncStr = ConstructFunction(prototype, trigger, true); end if(untriggerFuncStr) then @@ -1219,7 +1229,7 @@ function GenericTrigger.Add(data, region) untriggerFunc = WeakAuras.LoadFunction(untriggerFuncStr, id); end - local prototype = event_prototypes[trigger.event]; + if(prototype) then local trigger_all_events = prototype.events; internal_events = prototype.internal_events; @@ -1380,7 +1390,8 @@ function GenericTrigger.Add(data, region) loadFunc = loadFunc, duration = duration, automaticAutoHide = automaticAutoHide, - tsuConditionVariables = tsuConditionVariables + tsuConditionVariables = tsuConditionVariables, + prototype = prototype }; end end diff --git a/WeakAurasOptions/CommonOptions.lua b/WeakAurasOptions/CommonOptions.lua index dd37831..204b657 100644 --- a/WeakAurasOptions/CommonOptions.lua +++ b/WeakAurasOptions/CommonOptions.lua @@ -370,7 +370,7 @@ local function CreateDisabledAll(subOption) end end -local function disabeldOrHiddenChild(childOptionTable, info) +local function disabledOrHiddenChild(childOptionTable, info) return hiddenChild(childOptionTable, info) or disabledChild(childOptionTable, info); end @@ -404,7 +404,7 @@ local function replaceNameDescFuncs(intable, data, subOption) childOptionTable[i] = options; end - if (hiddenChild(childOptionTable, info)) then + if (disabledOrHiddenChild(childOptionTable, info)) then return nil; end @@ -776,12 +776,54 @@ local function replaceValuesFuncs(intable, data, subOption) recurse(intable); end +local getHelper = { + first = true, + combinedValues = {}, + same = true, + Set = function(self, values) + if self.same == false then + return false + end + if(self.first) then + self.combinedValues = values; + self.first = false; + return true + else + if(#self.combinedValues == #values) then + for j=1,#self.combinedValues do + if(type(self.combinedValues[j]) == "number" and type(values[j]) == "number") then + if((math.floor(self.combinedValues[j] * 100) / 100) ~= (math.floor(values[j] * 100) / 100)) then + self.same = false; + break; + end + else + if(self.combinedValues[j] ~= values[j]) then + self.same = false; + break; + end + end + end + else + self.same = false; + end + return self.same + end + end, + Get = function(self) + return self.combinedValues + end, + HasValue = function(self) + return not self.first + end +} + local function CreateGetAll(subOption) return function(data, info, ...) - local combinedValues = {}; - local first = true; - local debug = false; local isToggle = nil + + local allChildren = CopyTable(getHelper) + local enabledChildren = CopyTable(getHelper) + for index, childId in ipairs(data.controlledChildren) do if isToggle == nil then local childData = WeakAuras.GetData(childId) @@ -800,38 +842,19 @@ local function CreateGetAll(subOption) childOptionTable[i] = childOption; end - if (childOption and not hiddenChild(childOptionTable, info)) then + if (childOption and not disabledOrHiddenChild(childOptionTable, info)) then for i=#childOptionTable,0,-1 do if(childOptionTable[i].get) then local values = {childOptionTable[i].get(info, ...)}; if isToggle and values[1] == nil then values[1] = false end - if(first) then - combinedValues = values; - first = false; - else - local same = true; - if(#combinedValues == #values) then - for j=1,#combinedValues do - if(type(combinedValues[j]) == "number" and type(values[j]) == "number") then - if((math.floor(combinedValues[j] * 100) / 100) ~= (math.floor(values[j] * 100) / 100)) then - same = false; - break; - end - else - if(combinedValues[j] ~= values[j]) then - same = false; - break; - end - end - end - else - same = false; - end - if not(same) then - return nil; - end + + local sameAllChildren = allChildren:Set(values) + local sameEnabledChildren = enabledChildren:Set(values) + + if not sameAllChildren and not sameEnabledChildren then + return nil; end break; end @@ -839,7 +862,13 @@ local function CreateGetAll(subOption) end end end - return unpack(combinedValues); + + if enabledChildren:HasValue() then + return unpack(enabledChildren:Get()) + else + -- This can happen if all children are disabled + return unpack(allChildren:Get()) + end end end @@ -859,7 +888,7 @@ local function CreateSetAll(subOption, getAll) childOptionTable[i] = childOption; end - if (childOption and not disabeldOrHiddenChild(childOptionTable, info)) then + if (childOption and not disabledOrHiddenChild(childOptionTable, info)) then for i=#childOptionTable,0,-1 do if(childOptionTable[i].set) then if (childOptionTable[i].type == "multiselect") then @@ -896,7 +925,7 @@ local function CreateExecuteAll(subOption) childOptionTable[i] = childOption; end - if (childOption and not disabeldOrHiddenChild(childOptionTable, info)) then + if (childOption and not disabledOrHiddenChild(childOptionTable, info)) then -- Some functions, that is the expand/collapse functions need to be -- effectively called only once. Passing in the secondCall parameter allows -- them to distinguish between the first and every other call diff --git a/WeakAurasOptions/GenericTrigger.lua b/WeakAurasOptions/GenericTrigger.lua index 5247f86..4923316 100644 --- a/WeakAurasOptions/GenericTrigger.lua +++ b/WeakAurasOptions/GenericTrigger.lua @@ -225,6 +225,8 @@ local function GetCustomTriggerOptions(data, triggernum) end, set = function(info, v) trigger.duration = v + WeakAuras.Add(data) + WeakAuras.ClearAndUpdateOptions(data.id) end }, addOverlayFunction = { @@ -256,7 +258,6 @@ local function GetCustomTriggerOptions(data, triggernum) end WeakAuras.Add(data); WeakAuras.ClearAndUpdateOptions(data.id) - WeakAuras.FillOptions() end } }; @@ -316,6 +317,7 @@ local function GetCustomTriggerOptions(data, triggernum) end WeakAuras.Add(data); WeakAuras.ClearAndUpdateOptions(data.id) + WeakAuras.FillOptions() end local extraFunctions = { diff --git a/WeakAurasOptions/TriggerOptions.lua b/WeakAurasOptions/TriggerOptions.lua index e1a2a82..18716ca 100644 --- a/WeakAurasOptions/TriggerOptions.lua +++ b/WeakAurasOptions/TriggerOptions.lua @@ -104,6 +104,13 @@ local function AddOptions(allOptions, data) local triggerSystemOptionsFunction = trigger.trigger.type and WeakAuras.triggerTypesOptions[trigger.trigger.type] if (triggerSystemOptionsFunction) then triggerOptions = union(triggerOptions, triggerSystemOptionsFunction(data, index)) + else + local options = {}; + WeakAuras.commonOptions.AddCommonTriggerOptions(options, data, index) + WeakAuras.AddTriggerMetaFunctions(options, data, index) + triggerOptions = union(triggerOptions, { + ["trigger." .. index .. ".unknown"] = options + }) end end