from retail

This commit is contained in:
NoM0Re
2025-01-16 20:39:25 +01:00
parent fcd2d11478
commit e924932d63
5 changed files with 187 additions and 66 deletions
+111 -56
View File
@@ -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