Skip to content

Commit

Permalink
UI+++ (#4592)
Browse files Browse the repository at this point in the history
* Improve Cast trigger thumbnail & preview in options
  • Loading branch information
mrbuds authored Sep 17, 2023
1 parent a21a47f commit 43b78a1
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 30 deletions.
83 changes: 53 additions & 30 deletions WeakAuras/GenericTrigger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions WeakAuras/Prototypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = {
Expand Down

0 comments on commit 43b78a1

Please sign in to comment.