diff --git a/WeakAuras/GenericTrigger.lua b/WeakAuras/GenericTrigger.lua index 907251741b..570f845b62 100644 --- a/WeakAuras/GenericTrigger.lua +++ b/WeakAuras/GenericTrigger.lua @@ -670,13 +670,6 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2 untriggerCheck = true; end elseif (data.statesParameter == "unit") then - if optionsEvent then - if Private.multiUnitUnits[data.trigger.unit] then - arg1 = next(Private.multiUnitUnits[data.trigger.unit]) - else - arg1 = data.trigger.unit - end - end if arg1 then if Private.multiUnitUnits[data.trigger.unit] then unitForUnitTrigger = arg1 @@ -956,7 +949,12 @@ function Private.ScanEventsWatchedTrigger(id, watchedTriggernums) Private.ActivateAuraEnvironment(nil) end -local function AddFakeTime(state) +local function AddFakeInformation(state, eventData) + state.autoHide = false + local canHaveDuration = eventData.prototype and eventData.prototype.canHaveDuration == "timed" + if canHaveDuration and state.expirationTime == nil then + state.progressType = "timed" + end if state.progressType == "timed" then if state.expirationTime and state.expirationTime ~= math.huge and state.expirationTime > GetTime() then return @@ -965,38 +963,52 @@ local function AddFakeTime(state) state.expirationTime = GetTime() + 7 state.duration = 7 end + if eventData.prototype and eventData.prototype.GetNameAndIcon then + local name, icon = Private.event_prototypes[eventData.event].GetNameAndIcon(eventData.trigger) + if state.name == nil then + state.name = name + end + if state.icon == nil then + state.icon = icon + end + end end function GenericTrigger.CreateFakeStates(id, triggernum) local data = WeakAuras.GetData(id) + local eventData = events[id][triggernum] Private.ActivateAuraEnvironment(id); 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 arg1 + if eventData.statesParameter == "unit" then + local unit = eventData.trigger.unit + if Private.multiUnitUnits[unit] then + arg1 = next(Private.multiUnitUnits[unit]) + else + arg1 = unit + end + end + + RunTriggerFunc(allStates, eventData, id, triggernum, "OPTIONS", arg1) 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) + + AddFakeInformation(state, eventData) end if shown == 0 then local state = {} GenericTrigger.CreateFallbackState(data, triggernum, state) allStates[""] = state - state.autoHide = false - if canHaveDuration and state.expirationTime == nil then - state.progressType = "timed" - end - AddFakeTime(state) + + AddFakeInformation(state, eventData) end Private.ActivateAuraEnvironment(nil); @@ -3856,11 +3868,15 @@ function GenericTrigger.GetNameAndIcon(data, triggernum) local icon, name if (Private.category_event_prototype[trigger.type]) then if(trigger.event and Private.event_prototypes[trigger.event]) then - if(Private.event_prototypes[trigger.event].iconFunc) then - icon = Private.event_prototypes[trigger.event].iconFunc(trigger); - end - if(Private.event_prototypes[trigger.event].nameFunc) then - name = Private.event_prototypes[trigger.event].nameFunc(trigger); + if (Private.event_prototypes[trigger.event].GetNameAndIcon) then + return Private.event_prototypes[trigger.event].GetNameAndIcon(trigger) + else + if(Private.event_prototypes[trigger.event].iconFunc) then + icon = Private.event_prototypes[trigger.event].iconFunc(trigger); + end + if(Private.event_prototypes[trigger.event].nameFunc) then + name = Private.event_prototypes[trigger.event].nameFunc(trigger); + end end end end @@ -4204,13 +4220,20 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state) Private.ActivateAuraEnvironment(data.id, "", state); local trigger = data.triggers[triggernum].trigger - if (event.nameFunc) then - local ok, name = xpcall(event.nameFunc, Private.GetErrorHandlerUid(data.uid, L["Name Function (fallback state)"]), trigger); + + if event.GetNameAndIcon then + local ok, name, icon = xpcall(event.GetNameAndIcon, Private.GetErrorHandlerUid(data.uid, L["GetNameAndIcon Function (fallback state)"]), trigger); state.name = ok and name or nil; - end - if (event.iconFunc) then - local ok, icon = xpcall(event.iconFunc, Private.GetErrorHandlerUid(data.uid, L["Icon Function (fallback state)"]), trigger); state.icon = ok and icon or nil; + else + if (event.nameFunc) then + local ok, name = xpcall(event.nameFunc, Private.GetErrorHandlerUid(data.uid, L["Name Function (fallback state)"]), trigger); + state.name = ok and name or nil; + end + if (event.iconFunc) then + local ok, icon = xpcall(event.iconFunc, Private.GetErrorHandlerUid(data.uid, L["Icon Function (fallback state)"]), trigger); + state.icon = ok and icon or nil; + end end if (event.textureFunc ) then diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index 8804918504..3d37c5aa02 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -8766,6 +8766,36 @@ Private.event_prototypes = { end } }, + GetNameAndIcon = function(trigger) + local name, icon, spellId, _ + if trigger.use_spellNames and type(trigger.spellNames == "table") then + for _, spellName in ipairs(trigger.spellNames) do + spellId = WeakAuras.SafeToNumber(spellName) + if spellId then + name, _, icon = GetSpellInfo(spellName) + if name and icon then + return name, icon + end + elseif not tonumber(spellName) then + name, _, icon = GetSpellInfo(spellName) + if name and icon then + return name, icon + end + end + end + end + if trigger.use_spellIds and type(trigger.spellIds == "table") then + for _, spellIdString in ipairs(trigger.spellIds) do + spellId = WeakAuras.SafeToNumber(spellIdString) + if spellId then + name, _, icon = GetSpellInfo(spellIdString) + if name and icon then + return name, icon + end + end + end + end + end, automaticrequired = true, }, ["Character Stats"] = {