diff --git a/.luacheckrc b/.luacheckrc index c4326ace5a..8f0e26aec2 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -102,6 +102,7 @@ globals = { "STATICPOPUP_NUMDIALOGS", "StaticPopup_Show", "StaticPopupDialogs", + "TableHasAnyEntries", "tIndexOf", "UISpecialFrames", diff --git a/WeakAuras/Init.lua b/WeakAuras/Init.lua index 78fd1a2fb3..bb75d6737a 100644 --- a/WeakAuras/Init.lua +++ b/WeakAuras/Init.lua @@ -36,6 +36,7 @@ Private.frames = {} --- @field ContainsCustomPlaceHolder fun(input: string): boolean --- @field ContainsAnyPlaceHolders fun(input: string): boolean --- @field ContainsPlaceHolders fun(input: string, placeholders: string, checkDoublePercent?: boolean): boolean +--- @field CreateSubscribableObject fun(): SubscribableObject --- @field clones table> --- @field customActionsFunctions table> --- @field DebugLog debugLog diff --git a/WeakAuras/RegionTypes/AuraBar.lua b/WeakAuras/RegionTypes/AuraBar.lua index 7883f61636..4769476d39 100644 --- a/WeakAuras/RegionTypes/AuraBar.lua +++ b/WeakAuras/RegionTypes/AuraBar.lua @@ -1296,6 +1296,7 @@ local function modify(parent, region, data) return region.currentMin or 0, region.currentMax or 0 end + region.TimerTick = nil function region:Update() local state = region.state region:UpdateMinMax() @@ -1307,7 +1308,7 @@ local function modify(parent, region, data) end if region.TimerTick then region.TimerTick = nil - region:UpdateRegionHasTimerTick() + region.subRegionEvents:RemoveSubscriber("TimerTick", self) end expirationTime = GetTime() + (state.remaining or 0) else @@ -1316,7 +1317,7 @@ local function modify(parent, region, data) end if not region.TimerTick then region.TimerTick = TimerTick - region:UpdateRegionHasTimerTick() + region.subRegionEvents:AddSubscriber("TimerTick", self, true) end expirationTime = state.expirationTime and state.expirationTime > 0 and state.expirationTime or math.huge; end @@ -1333,7 +1334,7 @@ local function modify(parent, region, data) region:SetValue(value - region.currentMin, region.currentMax - region.currentMin); if region.TimerTick then region.TimerTick = nil - region:UpdateRegionHasTimerTick() + region.subRegionEvents:RemoveSubscriber("TimerTick", region) end else if region.paused then @@ -1342,7 +1343,7 @@ local function modify(parent, region, data) region:SetTime(0, math.huge) if region.TimerTick then region.TimerTick = nil - region:UpdateRegionHasTimerTick() + region.subRegionEvents:RemoveSubscriber("TimerTick", region) end end diff --git a/WeakAuras/RegionTypes/ProgressTexture.lua b/WeakAuras/RegionTypes/ProgressTexture.lua index 5f91217c1c..e940f19b1a 100644 --- a/WeakAuras/RegionTypes/ProgressTexture.lua +++ b/WeakAuras/RegionTypes/ProgressTexture.lua @@ -1308,6 +1308,7 @@ local function modify(parent, region, data) region.PreShow = nil end + region.TimerTick = nil function region:Update() local state = region.state @@ -1320,7 +1321,7 @@ local function modify(parent, region, data) end if region.TimerTick then region.TimerTick = nil - region:UpdateRegionHasTimerTick() + region.subRegionEvents:RemoveSubscriber("TimerTick", region) end expirationTime = GetTime() + (state.remaining or 0) else @@ -1329,7 +1330,7 @@ local function modify(parent, region, data) end if not region.TimerTick then region.TimerTick = TimerTick - region:UpdateRegionHasTimerTick() + region.subRegionEvents:AddSubscriber("TimerTick", region, true) end expirationTime = state.expirationTime and state.expirationTime > 0 and state.expirationTime or math.huge; end @@ -1375,7 +1376,7 @@ local function modify(parent, region, data) region:SetValue(value - adjustMin, max - adjustMin); if region.TimerTick then region.TimerTick = nil - region:UpdateRegionHasTimerTick() + region.subRegionEvents:RemoveSubscriber("TimerTick", region) end else if region.paused then @@ -1384,7 +1385,7 @@ local function modify(parent, region, data) region:SetTime(0, math.huge) if region.TimerTick then region.TimerTick = nil - region:UpdateRegionHasTimerTick() + region.subRegionEvents:RemoveSubscriber("TimerTick", region) end end diff --git a/WeakAuras/RegionTypes/RegionPrototype.lua b/WeakAuras/RegionTypes/RegionPrototype.lua index 362bd1a2d4..f3e622aef3 100644 --- a/WeakAuras/RegionTypes/RegionPrototype.lua +++ b/WeakAuras/RegionTypes/RegionPrototype.lua @@ -8,45 +8,6 @@ local GetAtlasInfo = C_Texture and C_Texture.GetAtlasInfo or GetAtlasInfo WeakAuras.regionPrototype = {}; - -local SubRegionEventSystem = -{ - ClearSubscribers = function(self) - self.events = {} - end, - - AddSubscriber = function(self, event, subRegion) - if not subRegion[event] then - print("Can't register subregion for ", event, " ", subRegion.type) - return - end - - self.events[event] = self.events[event] or {} - tinsert(self.events[event], subRegion) - end, - - RemoveSubscriber = function(self, event, subRegion) - tremove(self.events[event], tIndexOf(self.events[event], subRegion)) - end, - - Notify = function(self, event, ...) - if self.events[event] then - for _, subRegion in ipairs(self.events[event]) do - subRegion[event](subRegion, ...) - end - end - end -} - -local function CreateSubRegionEventSystem() - local system = {} - for f, func in pairs(SubRegionEventSystem) do - system[f] = func - system.events = {} - end - return system -end - -- Alpha function WeakAuras.regionPrototype.AddAlphaToDefault(default) default.alpha = 1.0; @@ -407,37 +368,16 @@ local function SetTriggerProvidesTimer(self, timerTick) self:UpdateTimerTick() end -local function UpdateRegionHasTimerTick(self) - local hasTimerTick = false - if self.TimerTick then - hasTimerTick = true - elseif (self.subRegions) then - for index, subRegion in pairs(self.subRegions) do - if subRegion.TimerTick then - hasTimerTick = true - break; - end - end - end - - self.regionHasTimer = hasTimerTick - self:UpdateTimerTick() -end - local function TimerTickForRegion(region) Private.StartProfileSystem("timer tick") Private.StartProfileAura(region.id); - if region.TimerTick then - region:TimerTick(); - end - region.subRegionEvents:Notify("TimerTick") Private.StopProfileAura(region.id); Private.StopProfileSystem("timer tick") end local function UpdateTimerTick(self) - if self.triggerProvidesTimer and self.regionHasTimer and self.toShow then + if self.triggerProvidesTimer and self.subRegionEvents:HasSubscribers("TimerTick") and self.toShow then if not self:GetScript("OnUpdate") then self:SetScript("OnUpdate", function() TimerTickForRegion(self) @@ -450,6 +390,20 @@ local function UpdateTimerTick(self) end end +local function UpdateFrameTick(self) + if self.subRegionEvents:HasSubscribers("FrameTick") and self.toShow then + Private.FrameTick:AddSubscriber("FrameTick", self) + else + Private.FrameTick:RemoveSubscriber("FrameTick", self) + end +end + +local function FrameTick(self) + Private.StartProfileAura(self.id) + self.subRegionEvents:Notify("FrameTick") + Private.StopProfileAura(self.id) +end + local function AnchorSubRegion(self, subRegion, anchorType, selfPoint, anchorPoint, anchorXOffset, anchorYOffset) subRegion:ClearAllPoints() @@ -503,10 +457,11 @@ function WeakAuras.regionPrototype.create(region) region.SetAnimAlpha = SetAnimAlpha; region.SetTriggerProvidesTimer = SetTriggerProvidesTimer - region.UpdateRegionHasTimerTick = UpdateRegionHasTimerTick region.UpdateTimerTick = UpdateTimerTick + region.UpdateFrameTick = UpdateFrameTick + region.FrameTick = FrameTick - region.subRegionEvents = CreateSubRegionEventSystem() + region.subRegionEvents = Private.CreateSubscribableObject() region.AnchorSubRegion = AnchorSubRegion region.values = {} -- For SubText @@ -519,6 +474,8 @@ function WeakAuras.regionPrototype.modify(parent, region, data) region.state = nil region.states = nil region.subRegionEvents:ClearSubscribers() + region.subRegionEvents:ClearCallbacks() + Private.FrameTick:RemoveSubscriber("FrameTick", region) local defaultsForRegion = Private.regionTypes[data.regionType] and Private.regionTypes[data.regionType].default; @@ -598,7 +555,6 @@ function WeakAuras.regionPrototype.modify(parent, region, data) end return data.actions.finish[fullKey] end, true) - end function WeakAuras.regionPrototype.modifyFinish(parent, region, data) @@ -629,7 +585,15 @@ function WeakAuras.regionPrototype.modifyFinish(parent, region, data) end end - region:UpdateRegionHasTimerTick() + region.subRegionEvents:SetOnSubscriptionStatusChanged("TimerTick", function() + region:UpdateTimerTick() + end) + region:UpdateTimerTick() + + region.subRegionEvents:SetOnSubscriptionStatusChanged("FrameTick", function() + region:UpdateFrameTick() + end) + region:UpdateFrameTick() Private.ApplyFrameLevel(region) end @@ -644,55 +608,25 @@ end local regionsForFrameTick = {} local frameForFrameTick = CreateFrame("Frame"); - Private.frames["Frame Tick Frame"] = frameForFrameTick -local function FrameTick() +Private.FrameTick = Private.CreateSubscribableObject() +Private.FrameTick.OnUpdateHandler = function() if WeakAuras.IsOptionsOpen() then return end Private.StartProfileSystem("frame tick") - for region in pairs(regionsForFrameTick) do - Private.StartProfileAura(region.id); - if region.FrameTick then - region.FrameTick() - end - region.subRegionEvents:Notify("FrameTick") - Private.StopProfileAura(region.id); - end + Private.FrameTick:Notify("FrameTick") Private.StopProfileSystem("frame tick") end -local function RegisterForFrameTick(region) - -- Check for a Frame Tick function - local hasFrameTick = region.FrameTick - if not hasFrameTick then - if (region.subRegions) then - for index, subRegion in pairs(region.subRegions) do - if subRegion.FrameTick then - hasFrameTick = true - break - end - end - end - end - - if not hasFrameTick then - return - end - - regionsForFrameTick[region] = true - if not frameForFrameTick:GetScript("OnUpdate") then - frameForFrameTick:SetScript("OnUpdate", FrameTick); - end -end - -local function UnRegisterForFrameTick(region) - regionsForFrameTick[region] = nil - if not next(regionsForFrameTick) then +Private.FrameTick:SetOnSubscriptionStatusChanged("FrameTick", function() + if Private.FrameTick:HasSubscribers("FrameTick") then + frameForFrameTick:SetScript("OnUpdate", Private.FrameTick.OnUpdateHandler); + else frameForFrameTick:SetScript("OnUpdate", nil) end -end +end) local function TimerTickForSetDuration(self) local duration = self.duration @@ -724,13 +658,13 @@ function WeakAuras.regionPrototype.AddSetDurationInfo(region) if customValue then SetProgressValue(region, duration, expirationTime); region.TimerTick = nil - region:UpdateRegionHasTimerTick() + region.subRegionEvents:RemoveSubscriber("TimerTick", self) else local adjustMin = region.adjustedMin or 0; region:SetTime((duration ~= 0 and region.adjustedMax or duration) - adjustMin, expirationTime - adjustMin, inverse); region.TimerTick = TimerTickForSetDuration - region:UpdateRegionHasTimerTick() + region.subRegionEvents:AddSubscriber("TimerTick", self, true) end end elseif (region.generatedSetDurationInfo) then @@ -844,7 +778,7 @@ function WeakAuras.regionPrototype.AddExpandFunction(data, region, cloneId, pare region:SoundRepeatStop(); end - UnRegisterForFrameTick(region) + region:UpdateFrameTick() region:UpdateTimerTick() end function region:Expand() @@ -880,7 +814,7 @@ function WeakAuras.regionPrototype.AddExpandFunction(data, region, cloneId, pare end parent:ActivateChild(data.id, cloneId); - RegisterForFrameTick(region) + region:UpdateFrameTick() region:UpdateTimerTick() end elseif not(data.controlledChildren) then @@ -903,7 +837,7 @@ function WeakAuras.regionPrototype.AddExpandFunction(data, region, cloneId, pare region:SoundRepeatStop(); end - UnRegisterForFrameTick(region) + region:UpdateFrameTick() region:UpdateTimerTick() end function region:Expand() @@ -951,7 +885,7 @@ function WeakAuras.regionPrototype.AddExpandFunction(data, region, cloneId, pare parent:UpdateBorder(region); end - RegisterForFrameTick(region) + region:UpdateFrameTick() region:UpdateTimerTick() end end diff --git a/WeakAuras/RegionTypes/StopMotion.lua b/WeakAuras/RegionTypes/StopMotion.lua index 6d8fdb2fae..db675f190e 100644 --- a/WeakAuras/RegionTypes/StopMotion.lua +++ b/WeakAuras/RegionTypes/StopMotion.lua @@ -452,6 +452,9 @@ local function modify(parent, region, data) end; region.FrameTick = onUpdate; + if region.FrameTick then + region.subRegionEvents:AddSubscriber("FrameTick", region, true) + end function region:Update() if region.state.paused then diff --git a/WeakAuras/RegionTypes/Text.lua b/WeakAuras/RegionTypes/Text.lua index 3e8bf73b6b..97bb0ed85f 100644 --- a/WeakAuras/RegionTypes/Text.lua +++ b/WeakAuras/RegionTypes/Text.lua @@ -223,6 +223,11 @@ local function modify(parent, region, data) region.Update = Update region.FrameTick = FrameTick region.TimerTick = TimerTick + if TimerTick then + region.subRegionEvents:AddSubscriber("TimerTick", region, true) + else + region.subRegionEvents:RemoveSubscriber("TimerTick", region) + end if not UpdateText then local textStr = data.displayText diff --git a/WeakAuras/SubRegionTypes/SubText.lua b/WeakAuras/SubRegionTypes/SubText.lua index d6da1ba6d7..2330f85c6f 100644 --- a/WeakAuras/SubRegionTypes/SubText.lua +++ b/WeakAuras/SubRegionTypes/SubText.lua @@ -309,18 +309,6 @@ local function modify(parent, region, parentData, data, first) region.FrameTick = FrameTick region.TimerTick = TimerTick - if Update then - parent.subRegionEvents:AddSubscriber("Update", region) - end - - if FrameTick then - parent.subRegionEvents:AddSubscriber("FrameTick", region) - end - - if TimerTick then - parent.subRegionEvents:AddSubscriber("TimerTick", region) - end - if not UpdateText then if text:GetFont() then local textStr = data.text_text @@ -357,7 +345,29 @@ local function modify(parent, region, parentData, data, first) function region:SetVisible(visible) if visible then self:Show() + if self.Update then + parent.subRegionEvents:AddSubscriber("Update", region) + end + + if self.FrameTick then + parent.subRegionEvents:AddSubscriber("FrameTick", region) + end + + if self.TimerTick then + parent.subRegionEvents:AddSubscriber("TimerTick", region) + end else + if self.Update then + parent.subRegionEvents:RemoveSubscriber("Update", region) + end + + if self.FrameTick then + parent.subRegionEvents:RemoveSubscriber("FrameTick", region) + end + + if self.TimerTick then + parent.subRegionEvents:RemoveSubscriber("TimerTick", region) + end self:Hide() end end diff --git a/WeakAuras/SubRegionTypes/Tick.lua b/WeakAuras/SubRegionTypes/Tick.lua index 626e2a6ed2..5abd834a02 100644 --- a/WeakAuras/SubRegionTypes/Tick.lua +++ b/WeakAuras/SubRegionTypes/Tick.lua @@ -199,13 +199,11 @@ local funcs = { then if not self.TimerTick then self.TimerTick = self.UpdateTickPlacement - self.parent:UpdateRegionHasTimerTick() self.parent.subRegionEvents:AddSubscriber("TimerTick", self) end else if self.TimerTick then self.TimerTick = nil - self.parent:UpdateRegionHasTimerTick() self.parent.subRegionEvents:RemoveSubscriber("TimerTick", self) end end diff --git a/WeakAuras/SubscribableObject.lua b/WeakAuras/SubscribableObject.lua new file mode 100644 index 0000000000..70c989d2d0 --- /dev/null +++ b/WeakAuras/SubscribableObject.lua @@ -0,0 +1,90 @@ +if not WeakAuras.IsLibsOK() then return end +--- @type string, Private +local AddonName, Private = ... + +local WeakAuras = WeakAuras +local L = WeakAuras.L + +--- @class SubscribableObject +--- @field events table +--- @field callback table +--- @field ClearSubscribers fun(self: SubscribableObject) +--- @field ClearCallbacks fun(self: SubscribableObject) +--- @field AddSubscriber fun(self: SubscribableObject, event: string, subscriber: frame, highPriority: boolean?) +--- @field RemoveSubscriber fun(self: SubscribableObject, event: string, subscriber: frame) +--- @field SetOnSubscriptionStatusChanged fun(self: SubscribableObject, event: string, cb: fun()) +--- @field Notify fun(self: SubscribableObject, event: type, ...: any) +--- @field HasSubscribers fun(self: SubscribableObject, event: string): boolean +--- @type SubscribableObject +local SubscribableObject = +{ + --- @type fun(self: SubscribableObject) + ClearSubscribers = function(self) + self.events = {} + end, + + --- @type fun(self: SubscribableObject) + ClearCallbacks = function(self) + self.callbacks = {} + end, + + --- @type fun(self: SubscribableObject, event: string, subscriber: frame, highPriority: boolean?) + AddSubscriber = function(self, event, subscriber, highPriority) + if not subscriber[event] then + print("Can't register for ", event, " ", subscriber, subscriber.type) + return + end + + self.events[event] = self.events[event] or {} + local pos = highPriority and 1 or (#self.events[event] + 1) + if TableHasAnyEntries(self.events[event]) then + tinsert(self.events[event], pos, subscriber) + else + tinsert(self.events[event], pos, subscriber) + if self.callbacks[event] then + self.callbacks[event]() + end + end + end, + + --- @type fun(self: SubscribableObject, event: string, subscriber: frame) + RemoveSubscriber = function(self, event, subscriber) + if self.events[event] then + tremove(self.events[event], tIndexOf(self.events[event], subscriber)) + if not TableHasAnyEntries(self.events[event]) then + if self.callbacks[event] then + self.callbacks[event]() + end + end + end + end, + + --- @type fun(self: SubscribableObject, event: string, cb: fun()) + SetOnSubscriptionStatusChanged = function(self, event, cb) + self.callbacks[event] = cb + end, + + --- @type fun(self: SubscribableObject, event: type, ...: any) + Notify = function(self, event, ...) + if self.events[event] then + for _, subscriber in ipairs(self.events[event]) do + subscriber[event](subscriber, ...) + end + end + end, + + --- @type fun(self: SubscribableObject, event: string): boolean + HasSubscribers = function(self, event) + return self.events[event] and TableHasAnyEntries(self.events[event]) + end +} + +function Private.CreateSubscribableObject() + local system = {} + for f, func in pairs(SubscribableObject) do + system[f] = func + system.events = {} + system.callbacks = {} + end + return system +end diff --git a/WeakAuras/Types.lua b/WeakAuras/Types.lua index cc00d53617..7bc79b9492 100644 --- a/WeakAuras/Types.lua +++ b/WeakAuras/Types.lua @@ -2657,8 +2657,11 @@ Private.sound_types = { [" KitID"] = " " .. L["Sound by Kit ID"] } +Private.sound_file_types = {} + for name, path in next, LSM:HashTable("sound") do Private.sound_types[path] = name + Private.sound_file_types[path] = name end LSM.RegisterCallback(WeakAuras, "LibSharedMedia_Registered", function(_, mediatype, key) @@ -2666,6 +2669,7 @@ LSM.RegisterCallback(WeakAuras, "LibSharedMedia_Registered", function(_, mediaty local path = LSM:Fetch(mediatype, key) if path then Private.sound_types[path] = key + Private.sound_file_types[path] = key end end end) @@ -3052,6 +3056,7 @@ Private.author_option_classes = { range = "simple", color = "simple", select = "simple", + media = "simple", multiselect = "simple", description = "noninteractive", space = "noninteractive", @@ -3069,6 +3074,7 @@ Private.author_option_types = { select = L["Dropdown Menu"], space = L["Space"], multiselect = L["Toggle List"], + media = L["Media"], header = L["Separator"], group = L["Option Group"], } @@ -3119,6 +3125,10 @@ Private.author_option_fields = { useHeight = false, height = 1, }, + media = { + mediaType = "sound", + media = "Interface\\AddOns\\WeakAuras\\Media\\Sounds\\AirHorn.ogg" + }, multiselect = { default = {true}, values = {"val1"}, @@ -3142,6 +3152,27 @@ Private.author_option_fields = { } } +Private.shared_media_types = { + sound = L["Sound"], + font = L["Font"], + border = L["Border"], + background = L["Background"], + statusbar = L["Status Bar"] +} + +Private.author_option_media_defaults = { + sound = "Interface\\AddOns\\WeakAuras\\Media\\Sounds\\AirHorn.ogg", + font = "Friz Quadrata TT", + border = "1 Pixel", + background = "None", + statusbar = "Blizzard", +} +Private.author_option_media_controls = { + statusbar = "LSM30_Statusbar", + border = "LSM30_Border", + background = "LSM30_Background", + font = "LSM30_Font" +} Private.array_entry_name_types = { [-1] = L["Fixed Names"], [0] = L["Entry Order"], diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index b41b9a1c4a..13a5a39891 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -2618,7 +2618,12 @@ local function validateUserConfig(data, options, config) local optionClass = Private.author_option_classes[option.type] if optionClass ~= "group" then local option = options[authorOptionKeys[key]] - if type(value) ~= type(option.default) then + if option.type == "media" then + -- sounds can be number or string, other kinds of media can only be string + if type(value) ~= "string" and (type(value) ~= "number" or option.mediaType ~= "sound") then + config[key] = option.default + end + elseif type(value) ~= type(option.default) then -- if type mismatch then we know that it can't be right if type(option.default) ~= "table" then config[key] = option.default diff --git a/WeakAuras/WeakAuras.toc b/WeakAuras/WeakAuras.toc index 95072eee76..cb03c638c7 100644 --- a/WeakAuras/WeakAuras.toc +++ b/WeakAuras/WeakAuras.toc @@ -54,6 +54,7 @@ AuraEnvironment.lua AuraEnvironmentWrappedSystems.lua DebugLog.lua Dragonriding.lua +SubscribableObject.lua # Region support RegionTypes\RegionPrototype.lua diff --git a/WeakAuras/WeakAuras_TBC.toc b/WeakAuras/WeakAuras_TBC.toc index 928e0f97ad..79fb77cab2 100644 --- a/WeakAuras/WeakAuras_TBC.toc +++ b/WeakAuras/WeakAuras_TBC.toc @@ -49,6 +49,7 @@ AuraWarnings.lua AuraEnvironment.lua AuraEnvironmentWrappedSystems.lua DebugLog.lua +SubscribableObject.lua # Region support RegionTypes\RegionPrototype.lua diff --git a/WeakAuras/WeakAuras_Vanilla.toc b/WeakAuras/WeakAuras_Vanilla.toc index edf15b1287..a6b6a13f50 100644 --- a/WeakAuras/WeakAuras_Vanilla.toc +++ b/WeakAuras/WeakAuras_Vanilla.toc @@ -54,6 +54,7 @@ AuraWarnings.lua AuraEnvironment.lua AuraEnvironmentWrappedSystems.lua DebugLog.lua +SubscribableObject.lua # Region support RegionTypes\RegionPrototype.lua diff --git a/WeakAuras/WeakAuras_Wrath.toc b/WeakAuras/WeakAuras_Wrath.toc index 695a72547e..f430ea2682 100644 --- a/WeakAuras/WeakAuras_Wrath.toc +++ b/WeakAuras/WeakAuras_Wrath.toc @@ -49,6 +49,7 @@ AuraWarnings.lua AuraEnvironment.lua AuraEnvironmentWrappedSystems.lua DebugLog.lua +SubscribableObject.lua # Region support RegionTypes\RegionPrototype.lua diff --git a/WeakAurasOptions/AuthorOptions.lua b/WeakAurasOptions/AuthorOptions.lua index f05fb87c46..c93035f151 100644 --- a/WeakAurasOptions/AuthorOptions.lua +++ b/WeakAurasOptions/AuthorOptions.lua @@ -975,6 +975,64 @@ typeControlAdders = { step = 1 } end, + media = function(options, args, data, order, prefix, i) + local option = options[i] + args[prefix .. "mediaType"] = { + type = "select", + width = WeakAuras.normalWidth, + name = name(option, "mediaType", L["Media Type"]), + desc = desc(option, "mediaType"), + values = OptionsPrivate.Private.shared_media_types, + order = order(), + get = get(option, "mediaType"), + set = function(_, value) + for _, optionData in pairs(option.references) do + local childOption = optionData.options[optionData.index] + local childData = optionData.data + childOption.mediaType = value + childOption.default = OptionsPrivate.Private.author_option_media_defaults[value] + WeakAuras.Add(childData) + end + WeakAuras.ClearAndUpdateOptions(data.id, true) + end + } + args[prefix .. "default"] = { + type = "select", + width = WeakAuras.doubleWidth, + name = name(option, "default", L["Default"]), + desc = desc(option, "default"), + values = function() + if option.mediaType == "sound" then + return OptionsPrivate.Private.sound_file_types + else + return AceGUIWidgetLSMlists[option.mediaType] + end + end, + sorting = function() + if option.mediaType == "sound" then + return OptionsPrivate.Private.SortOrderForValues(OptionsPrivate.Private.sound_file_types) + else + return nil + end + end, + dialogControl = OptionsPrivate.Private.author_option_media_controls[option.mediaType], + order = order(), + get = get(option, "default"), + set = function(_, value) + if option.mediaType == "sound" then + -- do this outside the deref loop, so we don't play the sound a million times + PlaySoundFile(value, "Master") + end + for _, optionData in pairs(option.references) do + local childOption = optionData.options[optionData.index] + local childData = optionData.data + childOption.default = value + WeakAuras.Add(childData) + end + WeakAuras.ClearAndUpdateOptions(data.id, true) + end + } + end, multiselect = function(options, args, data, order, prefix, i) local option = options[i] local values = getValues(option) @@ -2283,6 +2341,29 @@ local function addUserModeOption(options, args, data, order, prefix, i) end WeakAuras.ClearAndUpdateOptions(data.id, true) end + elseif optionType == "media" then + userOption.type = "select" + userOption.dialogControl = OptionsPrivate.Private.author_option_media_controls[option.mediaType] + userOption.values = function() + if option.mediaType == "sound" then + return OptionsPrivate.Private.sound_file_types + else + return AceGUIWidgetLSMlists[option.mediaType] + end + end + + userOption.set = function(_, value) + if option.mediaType == "sound" then + PlaySoundFile(value, "Master") + end + for _, optionData in pairs(option.references) do + local childData = optionData.data + local childConfig = optionData.config + childConfig[option.key] = value + WeakAuras.Add(childData) + end + WeakAuras.ClearAndUpdateOptions(data.id, true) + end end elseif optionClass == "noninteractive" then if optionType == "header" then @@ -2361,6 +2442,7 @@ local significantFieldsForMerge = { groupType = true, limitType = true, size = true, + mediaType = true, } -- these fields are special cases, generally reserved for when the UI displays something based on the merged options