diff --git a/WeakAuras/Conditions.lua b/WeakAuras/Conditions.lua index e2f4f78..a0e71b7 100644 --- a/WeakAuras/Conditions.lua +++ b/WeakAuras/Conditions.lua @@ -56,6 +56,11 @@ local function formatValueForAssignment(vType, value, pathToCustomFunction, path return tostring(value) end return "nil" + elseif (vType == "string") then + if type(value) == "string" then + return string.format("%s", Private.QuotedString(value)) + end + return "nil" elseif(vType == "color") then if (value and type(value) == "table") then return string.format("{%s, %s, %s, %s}", tostring(value[1]), tostring(value[2]), tostring(value[3]), tostring(value[4])); @@ -114,7 +119,7 @@ local function formatValueForAssignment(vType, value, pathToCustomFunction, path end local function formatValueForCall(type, property) - if (type == "bool" or type == "number" or type == "list" or type == "icon") then + if (type == "bool" or type == "number" or type == "list" or type == "icon" or type == "string") then return "propertyChanges['" .. property .. "']"; elseif (type == "color") then local pcp = "propertyChanges['" .. property .. "']"; diff --git a/WeakAuras/GenericTrigger.lua b/WeakAuras/GenericTrigger.lua index 96f82fd..72a63a1 100644 --- a/WeakAuras/GenericTrigger.lua +++ b/WeakAuras/GenericTrigger.lua @@ -3080,7 +3080,7 @@ do bar.icon = icon bar.timerType = timerType bar.spellId = tostring(spellId) - bar.count = msg:match("%((%d+)%)") or "0" + bar.count = msg:match("%((%d+)%)") or msg:match("((%d+))") or "0" bar.dbmType = dbmType local barOptions = DBM.ReleaseRevision >= 20220412000000 and DBT.Options or DBM.Bars.options @@ -3310,7 +3310,7 @@ do bar.bwBackgroundColor = BWColorModule:GetColorTable("barBackground", addon, spellId) local BWEmphasizedModule = BigWigs:GetPlugin("Super Emphasize") bar.emphasized = BWEmphasizedModule:IsSuperEmphasized(addon, spellId) and true or false - bar.count = text:match("%((%d+)%)") or "0" + bar.count = text:match("%((%d+)%)") or text:match("((%d+))") or "0" bar.cast = not(text:match("^[^<]") and true) WeakAuras.ScanEvents("BigWigs_StartBar", text) diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index 3ef6eb2..3f239ed 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -4106,7 +4106,7 @@ Private.event_prototypes = { { name = "count", display = L["Count"], - desc = L["Only if DBM shows it on it's bar"], + desc = L["Occurence of the event, reset when aura is unloaded\nCan be a range of values\nCan have multiple values separated by a comma or a space\n\nExamples:\n2nd 5th and 6th events: 2, 5, 6\n2nd to 6th: 2-6\nevery 2 events: /2\nevery 3 events starting from 2nd: 2/3\nevery 3 events starting from 2nd and ending at 11th: 2-11/3\n\nOnly if DBM shows it on it's bar"], type = "string", conditionType = "string", }, @@ -4341,7 +4341,7 @@ Private.event_prototypes = { { name = "count", display = L["Count"], - desc = L["Only if BigWigs shows it on it's bar"], + desc = L["Occurence of the event, reset when aura is unloaded\nCan be a range of values\nCan have multiple values separated by a comma or a space\n\nExamples:\n2nd 5th and 6th events: 2, 5, 6\n2nd to 6th: 2-6\nevery 2 events: /2\nevery 3 events starting from 2nd: 2/3\nevery 3 events starting from 2nd and ending at 11th: 2-11/3\n\nOnly if BigWigs shows it on it's bar"], type = "string", conditionType = "string", }, diff --git a/WeakAuras/SubRegionTypes/SubText.lua b/WeakAuras/SubRegionTypes/SubText.lua index b4e04ad..a8b4c3b 100644 --- a/WeakAuras/SubRegionTypes/SubText.lua +++ b/WeakAuras/SubRegionTypes/SubText.lua @@ -68,6 +68,11 @@ local properties = { type = "bool", defaultProperty = true }, + text_text = { + display = L["Text"], + setter = "ChangeText", + type = "string" + }, text_color = { display = L["Color"], setter = "Color", @@ -137,11 +142,12 @@ local function modify(parent, region, parentData, data, first) if not text:GetFont() then -- Font invalid, set the font but keep the setting text:SetFont(STANDARD_TEXT_FONT, data.text_fontSize < 33 and data.text_fontSize or 33, data.text_fontType); end - text:SetTextHeight(data.text_fontSize); if text:GetFont() then text:SetText(WeakAuras.ReplaceRaidMarkerSymbols(data.text_text)); end + text:SetTextHeight(data.text_fontSize); + text:SetShadowColor(unpack(data.text_shadowColor)) text:SetShadowOffset(data.text_shadowXOffset, data.text_shadowYOffset) text:SetJustifyH(data.text_justify or "CENTER") @@ -173,6 +179,23 @@ local function modify(parent, region, parentData, data, first) end end + if type(parentData.conditions) == "table" then + for _, condition in ipairs(parentData.conditions) do + if type(condition.changes) == "table" then + for _, change in ipairs(condition.changes) do + if type(change.property) == "string" + and change.property:match("sub%.%d+%.text_text") + and type(change.value) == "string" + and Private.ContainsCustomPlaceHolder(change.value) + then + containsCustomText = true + break + end + end + end + end + end + if containsCustomText and parentData.customText and parentData.customText ~= "" then parent.customTextFunc = WeakAuras.LoadFunction("return "..parentData.customText) else @@ -182,67 +205,127 @@ local function modify(parent, region, parentData, data, first) parent.values.lastCustomTextUpdate = nil end - local UpdateText - if data.text_text and Private.ContainsAnyPlaceHolders(data.text_text) then - local getter = function(key, default) - local fullKey = "text_text_format_" .. key - if data[fullKey] == nil then - data[fullKey] = default + function region:ConfigureTextUpdate() + local UpdateText + if region.text_text and Private.ContainsAnyPlaceHolders(region.text_text) then + local getter = function(key, default) + local fullKey = "text_text_format_" .. key + if data[fullKey] == nil then + data[fullKey] = default + end + return data[fullKey] end - return data[fullKey] - end - local formatters = Private.CreateFormatters(data.text_text, getter) - UpdateText = function() - local textStr = data.text_text or "" - textStr = Private.ReplacePlaceHolders(textStr, parent, nil, false, formatters) + local formatters = Private.CreateFormatters(region.text_text, getter) + UpdateText = function() + local textStr = region.text_text or "" + textStr = Private.ReplacePlaceHolders(textStr, parent, nil, false, formatters) - if text:GetFont() then - text:SetText(WeakAuras.ReplaceRaidMarkerSymbols(textStr)) + if text:GetFont() then + text:SetText(WeakAuras.ReplaceRaidMarkerSymbols(textStr)) + end + region:UpdateAnchor() end end - end - local Update - if parent.customTextFunc and UpdateText then - Update = function() - if parent.values.lastCustomTextUpdate ~= GetTime() then - parent.values.custom = Private.RunCustomTextFunc(parent, parent.customTextFunc) - parent.values.lastCustomTextUpdate = GetTime() - end - UpdateText() - end - else - Update = UpdateText - end - - local TimerTick - if Private.ContainsPlaceHolders(data.text_text, "p") then - TimerTick = UpdateText - end - - local FrameTick - if parent.customTextFunc and parentData.customTextUpdate == "update" then - if Private.ContainsCustomPlaceHolder(data.text_text) then - FrameTick = function() + local Update + if parent.customTextFunc and UpdateText then + Update = function() if parent.values.lastCustomTextUpdate ~= GetTime() then parent.values.custom = Private.RunCustomTextFunc(parent, parent.customTextFunc) parent.values.lastCustomTextUpdate = GetTime() end UpdateText() end + else + Update = UpdateText + end + + local TimerTick + if Private.ContainsPlaceHolders(region.text_text, "p") then + TimerTick = UpdateText + end + + local FrameTick + if parent.customTextFunc and parentData.customTextUpdate == "update" then + if Private.ContainsCustomPlaceHolder(region.text_text) then + FrameTick = function() + if parent.values.lastCustomTextUpdate ~= GetTime() then + parent.values.custom = Private.RunCustomTextFunc(parent, parent.customTextFunc) + parent.values.lastCustomTextUpdate = GetTime() + end + UpdateText() + end + end + end + + region.Update = Update + region.FrameTick = FrameTick + region.TimerTick = TimerTick + + if not UpdateText then + if text:GetFont() then + local textStr = region.text_text + textStr = textStr:gsub("\\n", "\n"); + text:SetText(WeakAuras.ReplaceRaidMarkerSymbols(textStr)) + end end end - region.Update = Update - region.FrameTick = FrameTick - region.TimerTick = TimerTick - - if not UpdateText then - if text:GetFont() then - local textStr = data.text_text - textStr = textStr:gsub("\\n", "\n"); - text:SetText(WeakAuras.ReplaceRaidMarkerSymbols(textStr)) + function region:ConfigureSubscribers() + local visible = self:IsShown() + if self.Update then + if visible then + parent.subRegionEvents:AddSubscriber("Update", region) + end + else + parent.subRegionEvents:RemoveSubscriber("Update", region) end + if self.FrameTick then + if visible then + parent.subRegionEvents:AddSubscriber("FrameTick", region) + end + else + parent.subRegionEvents:RemoveSubscriber("FrameTick", region) + end + if self.TimerTick then + if visible then + parent.subRegionEvents:AddSubscriber("TimerTick", region) + end + else + parent.subRegionEvents:RemoveSubscriber("TimerTick", region) + end + if self.Update and parent.state and visible then + self:Update() + end + end + + function region:ChangeText(msg) + region.text_text = msg + region:ConfigureTextUpdate() + region:ConfigureSubscribers() + end + + region.text_text = data.text_text + region:ConfigureTextUpdate() + + function region:SetTextHeight(size) + local fontPath = SharedMedia:Fetch("font", data.text_font); + if not text:GetFont() then -- Font invalid, set the font but keep the setting + text:SetFont(STANDARD_TEXT_FONT, size < 33 and size or 33, data.text_fontType); + else + region.text:SetFont(fontPath, size < 33 and size or 33, data.text_fontType); + end + region.text:SetTextHeight(size) + region:UpdateAnchor(); + end + + function region:SetVisible(visible) + if visible then + self:Show() + else + self:Hide() + end + region:ConfigureSubscribers() end function region:Color(r, g, b, a) @@ -253,42 +336,8 @@ local function modify(parent, region, parentData, data, first) if (r or g or b) then a = a or 1; end - text:SetTextColor(region.color_anim_r or r, region.color_anim_g or g, region.color_anim_b or b, region.color_anim_a or a); - end - - function region:SetTextHeight(size) - local fontPath = SharedMedia:Fetch("font", data.text_font); - region.text:SetFont(fontPath, size < 33 and size or 33, data.text_fontType); - region.text:SetTextHeight(size) - end - - 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 - if self.Update and parent.state then - self:Update() - 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 + text:SetTextColor(region.color_anim_r or r, region.color_anim_g or g, + region.color_anim_b or b, region.color_anim_a or a) end local selfPoint = data.text_selfPoint @@ -415,4 +464,5 @@ local function supports(regionType) or regionType == "aurabar" end -WeakAuras.RegisterSubRegionType("subtext", L["Text"], supports, create, modify, onAcquire, onRelease, default, addDefaultsForNewAura, properties); +WeakAuras.RegisterSubRegionType("subtext", L["Text"], supports, create, modify, onAcquire, onRelease, + default, addDefaultsForNewAura, properties) diff --git a/WeakAuras/SubscribableObject.lua b/WeakAuras/SubscribableObject.lua index 07b3045..c677286 100644 --- a/WeakAuras/SubscribableObject.lua +++ b/WeakAuras/SubscribableObject.lua @@ -8,6 +8,7 @@ local SubscribableObject = { ClearSubscribers = function(self) self.events = {} + self.subscribers = {} end, ClearCallbacks = function(self) @@ -21,6 +22,12 @@ local SubscribableObject = end self.events[event] = self.events[event] or {} + self.subscribers[event] = self.subscribers[event] or {} + if self.subscribers[event][subscriber] then + -- Already subscribed, just return + return + end + self.subscribers[event][subscriber] = true local pos = highPriority and 1 or (#self.events[event] + 1) if TableHasAnyEntries(self.events[event]) then tinsert(self.events[event], pos, subscriber) @@ -34,6 +41,12 @@ local SubscribableObject = RemoveSubscriber = function(self, event, subscriber) if self.events[event] then + if not self.subscribers[event][subscriber] then + -- Not subscribed + return + end + + self.subscribers[event][subscriber] = nil local index = tIndexOf(self.events[event], subscriber) if index then tremove(self.events[event], index) @@ -68,6 +81,7 @@ function Private.CreateSubscribableObject() for f, func in pairs(SubscribableObject) do system[f] = func system.events = {} + system.subscribers = {} system.callbacks = {} end return system diff --git a/WeakAurasOptions/ConditionOptions.lua b/WeakAurasOptions/ConditionOptions.lua index 489bf0a..6f8bb54 100644 --- a/WeakAurasOptions/ConditionOptions.lua +++ b/WeakAurasOptions/ConditionOptions.lua @@ -466,6 +466,19 @@ local function addControlsForChange(args, order, data, conditionVariable, totalA args["condition" .. i .. "value" .. j].validate = WeakAuras.ValidateNumeric; end end + elseif (propertyType == "string") then + args["condition" .. i .. "value" .. j] = { + type = "input", + width = WeakAuras.normalWidth, + name = blueIfNoValue(data, conditions[i].changes[j], "value", L["Text"]), + desc = descIfNoValue(data, conditions[i].changes[j], "value", propertyType), + order = order, + get = function() + return conditions[i].changes[j].value; + end, + set = setValue + } + order = order + 1; elseif (propertyType == "icon") then args["condition" .. i .. "value" .. j] = { type = "input", diff --git a/WeakAurasOptions/SubRegionOptions/SubText.lua b/WeakAurasOptions/SubRegionOptions/SubText.lua index 765250d..59c467e 100644 --- a/WeakAurasOptions/SubRegionOptions/SubText.lua +++ b/WeakAurasOptions/SubRegionOptions/SubText.lua @@ -394,11 +394,28 @@ local function createOptions(parentData, data, index, subIndex) return true end - for index, subRegion in ipairs(parentData.subRegions) do + for _, subRegion in ipairs(parentData.subRegions) do if subRegion.type == "subtext" and OptionsPrivate.Private.ContainsCustomPlaceHolder(subRegion.text_text) then return false end end + + if type(parentData.conditions) == "table" then + for _, condition in ipairs(parentData.conditions) do + if type(condition.changes) == "table" then + for _, change in ipairs(condition.changes) do + if type(change.property) == "string" + and change.property:match("sub%.%d+%.text_text") + and type(change.value) == "string" + and OptionsPrivate.Private.ContainsCustomPlaceHolder(change.value) + then + return false + end + end + end + end + end + return true end