diff --git a/WeakAuras/Prototypes.lua b/WeakAuras/Prototypes.lua index 6ec6f07..ba7cbab 100644 --- a/WeakAuras/Prototypes.lua +++ b/WeakAuras/Prototypes.lua @@ -2828,10 +2828,17 @@ Private.event_prototypes = { store = true }, { + name = "extraSpellId", + display = WeakAuras.newFeatureString .. L["Extra Spell Id"], + init = "arg", enable = function(trigger) return trigger.subeventSuffix and (trigger.subeventSuffix == "_INTERRUPT" or trigger.subeventSuffix == "_DISPEL" or trigger.subeventSuffix == "_DISPEL_FAILED" or trigger.subeventSuffix == "_STOLEN" or trigger.subeventSuffix == "_AURA_BROKEN_SPELL") - end - }, -- extraSpellId ignored with SPELL_INTERRUPT + end, + type = "spell", + showExactOption = false, + store = true, + conditionType = "number" + }, { name = "extraSpellName", display = L["Extra Spell Name"], diff --git a/WeakAuras/RegionTypes/Text.lua b/WeakAuras/RegionTypes/Text.lua index 49480a6..7270f61 100644 --- a/WeakAuras/RegionTypes/Text.lua +++ b/WeakAuras/RegionTypes/Text.lua @@ -44,7 +44,12 @@ local properties = { softMax = 72, step = 1, default = 12 - } + }, + displayText = { + display = L["Text"], + setter = "ChangeText", + type = "string" + }, } WeakAuras.regionPrototype.AddProperties(properties, default); @@ -172,8 +177,13 @@ local function modify(parent, region, data) end end - local UpdateText - if Private.ContainsAnyPlaceHolders(data.displayText) then + local containsCustomText = false + if Private.ContainsCustomPlaceHolder(data.displayText) then + containsCustomText = true + end + + local formatters + do local getter = function(key, default) local fullKey = "displayText_format_" .. key if (data[fullKey] == nil) then @@ -181,67 +191,102 @@ local function modify(parent, region, data) end return data[fullKey] end - local formatters = Private.CreateFormatters(data.displayText, getter) - UpdateText = function() - local textStr = data.displayText; - textStr = Private.ReplacePlaceHolders(textStr, region, nil, false, formatters); - if (textStr == nil or textStr == "") then - textStr = " "; - end + local texts = {} + tinsert(texts, data.displayText) + + if type(data.conditions) == "table" then + for _, condition in ipairs(data.conditions) do + if type(condition.changes) == "table" then + for _, change in ipairs(condition.changes) do + if type(change.property) == "string" + and change.property == "displayText" + and type(change.value) == "string" + and Private.ContainsAnyPlaceHolders(change.value) + then + if not containsCustomText and Private.ContainsCustomPlaceHolder(change.value) then + containsCustomText = true + end + tinsert(texts, change.value) + end + end + end + end + end + + formatters = Private.CreateFormatters(texts, getter) + end + + local customTextFunc = nil + if containsCustomText and data.customText and data.customText ~= "" then + customTextFunc = WeakAuras.LoadFunction("return "..data.customText) + end + + function region:ConfigureTextUpdate() + local UpdateText + if self.displayText and Private.ContainsAnyPlaceHolders(self.displayText) then + UpdateText = function() + local textStr = self.displayText; + textStr = Private.ReplacePlaceHolders(textStr, self, nil, false, formatters); + if (textStr == nil or textStr == "") then + textStr = " "; + end + + SetText(textStr) + end + end + + local Update + if customTextFunc and self.displayText and Private.ContainsCustomPlaceHolder(self.displayText) then + Update = function() + self.values.custom = Private.RunCustomTextFunc(self, customTextFunc) + UpdateText() + end + else + Update = UpdateText or function() end + end + + local TimerTick + if Private.ContainsPlaceHolders(self.displayText, "p") then + TimerTick = UpdateText + end + + local FrameTick + if customTextFunc and data.customTextUpdate == "update" then + if Private.ContainsCustomPlaceHolder(self.displayText) then + FrameTick = function() + self.values.custom = Private.RunCustomTextFunc(self, customTextFunc) + UpdateText() + end + end + end + + self.Update = Update + self.FrameTick = FrameTick + self.TimerTick = TimerTick + + if not UpdateText then + local textStr = self.displayText + textStr = textStr:gsub("\\n", "\n"); SetText(textStr) end end - local customTextFunc = nil - if(Private.ContainsCustomPlaceHolder(data.displayText) and data.customText) then - customTextFunc = WeakAuras.LoadFunction("return "..data.customText) - end - - local Update - if customTextFunc then - if UpdateText then - Update = function() - region.values.custom = Private.RunCustomTextFunc(region, customTextFunc) - UpdateText() - end + function region:ConfigureSubscribers() + if self.FrameTick then + self.subRegionEvents:AddSubscriber("FrameTick", self) + else + self.subRegionEvents:RemoveSubscriber("FrameTick", self) end - else - Update = UpdateText or function() end - end - local TimerTick - if Private.ContainsPlaceHolders(data.displayText, "p") then - TimerTick = UpdateText - end - - local FrameTick - if customTextFunc and data.customTextUpdate == "update" then - FrameTick = function() - region.values.custom = Private.RunCustomTextFunc(region, customTextFunc) - UpdateText() + if self.TimerTick then + self.subRegionEvents:AddSubscriber("TimerTick", self, true) + else + self.subRegionEvents:RemoveSubscriber("TimerTick", self) + end + if self.Update and self.state then + self:Update() end - end - - 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 FrameTick then - region.subRegionEvents:AddSubscriber("FrameTick", region) - else - region.subRegionEvents:RemoveSubscriber("FrameTick", region) - end - - if not UpdateText then - local textStr = data.displayText - textStr = textStr:gsub("\\n", "\n"); - SetText(textStr) end function region:Color(r, g, b, a) @@ -279,6 +324,16 @@ local function modify(parent, region, data) region.text:SetTextHeight(size) end + function region:ChangeText(msg) + self.displayText = msg + self:ConfigureTextUpdate() + self:ConfigureSubscribers() + end + + region.displayText = data.displayText + region:ConfigureTextUpdate() + region:ConfigureSubscribers() + WeakAuras.regionPrototype.modifyFinish(parent, region, data); end diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index b1f6f7b..cac4106 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -4561,7 +4561,8 @@ end function Private.CreateFormatters(input, getter, withoutColor) local seenSymbols = {} local formatters = {} - Private.ParseTextStr(input, function(symbol) + + local parseFn = function(symbol) if not seenSymbols[symbol] then local _, sym = string.match(symbol, "(.+)%.(.+)") sym = sym or symbol @@ -4576,7 +4577,15 @@ function Private.CreateFormatters(input, getter, withoutColor) end end seenSymbols[symbol] = true - end) + end + + if type(input) == "string" then + Private.ParseTextStr(input, parseFn) + elseif type(input) == "table" then + for _, v in ipairs(input) do + Private.ParseTextStr(v, parseFn) + end + end return formatters end diff --git a/WeakAurasOptions/RegionOptions/Text.lua b/WeakAurasOptions/RegionOptions/Text.lua index 25cd9f7..bd34bf7 100644 --- a/WeakAurasOptions/RegionOptions/Text.lua +++ b/WeakAurasOptions/RegionOptions/Text.lua @@ -12,6 +12,30 @@ local hiddenFontExtra = function() end local function createOptions(id, data) + local function hideCustomTextOption() + if OptionsPrivate.Private.ContainsCustomPlaceHolder(data.displayText) then + return false + end + + if type(data.conditions) == "table" then + for _, condition in ipairs(data.conditions) do + if type(condition.changes) == "table" then + for _, change in ipairs(condition.changes) do + if type(change.property) == "string" + and change.property == "displayText" + and type(change.value) == "string" + and OptionsPrivate.Private.ContainsCustomPlaceHolder(change.value) + then + return false + end + end + end + end + end + + return true + end + local options = { __title = L["Text Settings"], __order = 1, @@ -38,7 +62,7 @@ local function createOptions(id, data) customTextUpdate = { type = "select", width = WeakAuras.doubleWidth, - hidden = function() return not OptionsPrivate.Private.ContainsCustomPlaceHolder(data.displayText); end, + hidden = hideCustomTextOption, name = L["Update Custom Text On..."], values = OptionsPrivate.Private.text_check_types, order = 36 @@ -267,7 +291,7 @@ local function createOptions(id, data) }; OptionsPrivate.commonOptions.AddCodeOption(options, data, L["Custom Function"], "customText", "https://github.com/WeakAuras/WeakAuras2/wiki/Custom-Code-Blocks#custom-text", - 37, function() return not OptionsPrivate.Private.ContainsCustomPlaceHolder(data.displayText) end, {"customText"}, false); + 37, hideCustomTextOption, {"customText"}, false); -- Add Text Format Options local hidden = function() @@ -299,11 +323,29 @@ local function createOptions(id, data) end for child in OptionsPrivate.Private.TraverseLeafsOrAura(data) do + local texts = {} + if child.displayText ~= "" then + tinsert(texts, child.displayText) + end + for _, condition in ipairs(child.conditions) do + if type(condition.changes) == "table" then + for _, change in ipairs(condition.changes) do + if type(change.property) == "string" + and change.property == "displayText" + and type(change.value) == "string" + and change.value ~= "" + then + tinsert(texts, change.value) + end + end + end + end + local get = function(key) return child["displayText_format_" .. key] end - local input = child.displayText - OptionsPrivate.AddTextFormatOption(input, true, get, addOption, hidden, setHidden, false, index, total) + + OptionsPrivate.AddTextFormatOption(texts, true, get, addOption, hidden, setHidden, false, index, total) index = index + 1 end diff --git a/WeakAurasOptions/WeakAurasOptions.lua b/WeakAurasOptions/WeakAurasOptions.lua index b5b75b3..453861f 100644 --- a/WeakAurasOptions/WeakAurasOptions.lua +++ b/WeakAurasOptions/WeakAurasOptions.lua @@ -1957,7 +1957,7 @@ function OptionsPrivate.AddTextFormatOption(input, withHeader, get, addOption, h local seenSymbols = {} - OptionsPrivate.Private.ParseTextStr(input, function(symbol) + local parseFn = function(symbol) if not seenSymbols[symbol] then local _, sym = string.match(symbol, "(.+)%.(.+)") sym = sym or symbol @@ -1987,7 +1987,15 @@ function OptionsPrivate.AddTextFormatOption(input, withHeader, get, addOption, h seenSymbols[symbol] = true end end - end) + end + + if type(input) == "table" then + for _, txt in ipairs(input) do + OptionsPrivate.Private.ParseTextStr(txt, parseFn) + end + else + OptionsPrivate.Private.ParseTextStr(input, parseFn) + end if withHeader and (not index or index == total) then addOption("header_anchor",