From ba4039dae289267a465ef6ba9a712b2ac20216b0 Mon Sep 17 00:00:00 2001 From: NoM0Re Date: Thu, 16 Jan 2025 20:55:38 +0100 Subject: [PATCH] from retail --- WeakAuras/SubRegionTypes/SubText.lua | 71 +++++++++++++------ WeakAurasOptions/SubRegionOptions/SubText.lua | 52 ++++++++------ 2 files changed, 81 insertions(+), 42 deletions(-) diff --git a/WeakAuras/SubRegionTypes/SubText.lua b/WeakAuras/SubRegionTypes/SubText.lua index a8b4c3b..5162133 100644 --- a/WeakAuras/SubRegionTypes/SubText.lua +++ b/WeakAuras/SubRegionTypes/SubText.lua @@ -178,24 +178,22 @@ local function modify(parent, region, parentData, data, first) break 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 + if not containsCustomText then + 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") + then + containsCustomText = true + break + end end end end end end - if containsCustomText and parentData.customText and parentData.customText ~= "" then parent.customTextFunc = WeakAuras.LoadFunction("return "..parentData.customText) else @@ -205,20 +203,49 @@ local function modify(parent, region, parentData, data, first) parent.values.lastCustomTextUpdate = nil end + local texts = {} + local textStr = data.text_text or "" + if textStr ~= "" then + tinsert(texts, textStr) + end + + local subRegionIndex = 1 + for index, subRegion in ipairs(parentData.subRegions) do + if subRegion == data then + subRegionIndex = index + break; + end + end + if type(parentData.conditions) == "table" then + local conditionName = "sub."..subRegionIndex..".text_text" + 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 == conditionName then + if type(change.value ) == "string" and change.value ~= "" then + tinsert(texts, change.value) + end + end + end + end + end + end + + local getter = function(key, default) + local fullKey = "text_text_format_" .. key + if (data[fullKey] == nil) then + data[fullKey] = default + end + return data[fullKey] + end + region.subTextFormatters = Private.CreateFormatters(texts, getter) + 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 - local formatters = Private.CreateFormatters(region.text_text, getter) UpdateText = function() local textStr = region.text_text or "" - textStr = Private.ReplacePlaceHolders(textStr, parent, nil, false, formatters) + textStr = Private.ReplacePlaceHolders(textStr, parent, nil, false, self.subTextFormatters) if text:GetFont() then text:SetText(WeakAuras.ReplaceRaidMarkerSymbols(textStr)) diff --git a/WeakAurasOptions/SubRegionOptions/SubText.lua b/WeakAurasOptions/SubRegionOptions/SubText.lua index 59c467e..613ff2e 100644 --- a/WeakAurasOptions/SubRegionOptions/SubText.lua +++ b/WeakAurasOptions/SubRegionOptions/SubText.lua @@ -465,30 +465,42 @@ local function createOptions(parentData, data, index, subIndex) options["text_text_format_" .. key] = option end - if parentData.controlledChildren then - local list = {} - for child in OptionsPrivate.Private.TraverseLeafs(parentData) do - if child.subRegions then - local childSubRegion = child.subRegions[index] - if childSubRegion then - tinsert(list, childSubRegion) + local list = {} + for child in OptionsPrivate.Private.TraverseLeafsOrAura(parentData) do + if child.subRegions then + local childSubRegion = child.subRegions[index] + if childSubRegion then + tinsert(list, child) + end + end + end + + for listIndex, child in ipairs(list) do + local childSubRegion = child.subRegions[index] + local get = function(key) + return childSubRegion["text_text_format_" .. key] + end + local texts = {} + if type(childSubRegion.text_text) == "string" and childSubRegion.text_text ~= "" then + -- found text of subregion + tinsert(texts, childSubRegion.text_text) + end + + for _, condition in ipairs(child.conditions) do + if type(condition.changes) == "table" then + for _, change in ipairs(condition.changes) do + if change.property == "sub."..index..".text_text" + and type(change.value) == "string" + and change.value ~= "" + then + -- found a condition editing text of that subregion + tinsert(texts, change.value) + end end end end - for listIndex, childSubRegion in ipairs(list) do - local get = function(key) - return childSubRegion["text_text_format_" .. key] - end - local input = childSubRegion["text_text"] - OptionsPrivate.AddTextFormatOption(input, true, get, addOption, hidden, setHidden, false, listIndex, #list) - end - else - local get = function(key) - return data["text_text_format_" .. key] - end - local input = data["text_text"] - OptionsPrivate.AddTextFormatOption(input, true, get, addOption, hidden, setHidden, false) + OptionsPrivate.AddTextFormatOption(texts, true, get, addOption, hidden, setHidden, false, listIndex, #list) end addOption("footer", {