Skip to content

Commit

Permalink
Improve Cast trigger thumbnail & preview in options
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbuds committed Sep 9, 2023
1 parent a9adc4d commit 4244c6f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
42 changes: 32 additions & 10 deletions WeakAuras/GenericTrigger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,17 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2
ok, returnValue = xpcall(data.triggerFunc, errorHandler, state, event, unitForUnitTrigger, arg1, arg2, ...);
end
if (ok and returnValue) or optionsEvent then
if optionsEvent then
if Private.event_prototypes[data.event].GetNameAndIcon then
local name, icon = Private.event_prototypes[data.event].GetNameAndIcon(data.trigger)
if state.name == nil then
state.name = name
end
if state.icon == nil then
state.icon = icon
end
end
end
if(Private.ActivateEvent(id, triggernum, data, state)) then
updateTriggerState = true;
end
Expand Down Expand Up @@ -3837,11 +3848,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
Expand Down Expand Up @@ -4185,13 +4200,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
Expand Down
30 changes: 30 additions & 0 deletions WeakAuras/Prototypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8730,6 +8730,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"] = {
Expand Down

0 comments on commit 4244c6f

Please sign in to comment.