api: add GetNoNameObject

This commit is contained in:
Artur Morozov
2019-03-31 14:59:21 +02:00
committed by shagu
parent 3568b8f760
commit 74fa9df790
+54
View File
@@ -941,3 +941,57 @@ function pfUI.api.GetColorGradient(perc)
gradientcolors[perc].b,
gradientcolors[perc].h
end
-- [ GetNoNameObject ] --
-- 'frame' [string] parent frame
-- 'scantype' [string] scanning Region or Children
-- 'objtype' [string]
-- 'layer' [string]
-- 'arg1' [string]
-- return object
-- NOTE: special symbols must be escaped by the SAME symbol!
-- e.g. symbol '\': '\\'
-- symbol '-': '--'
function pfUI.api.GetNoNameObject(frame, objtype, layer, arg1, arg2)
local objects
if objtype == "Texture" or objtype == "FontString" then
objects = {frame:GetRegions()}
else
objects = {frame:GetChildren()}
end
for _, object in ipairs(objects) do
local check = true
if object:GetObjectType() ~= objtype or (layer and object:GetDrawLayer() ~= layer) then check = false end
if check then
if objtype == "Texture" and object.SetTexture and object:GetTexture() ~= "Interface\\BUTTONS\\WHITE8X8" then
if arg1 then
local texture = object:GetTexture()
if texture and not string.find(texture, arg1) then check = false end
end
if check then return object end
elseif objtype == "FontString" and object.SetText then
if arg1 then
local text = object:GetText()
if text and not string.find(text, arg1) then check = false end
end
if check then return object end
elseif objtype == "Button" and object.GetNormalTexture and object:GetNormalTexture() then
if arg1 then
local texture = object:GetNormalTexture():GetTexture()
if texture and not string.find(texture, arg1) then check = false end
end
if arg2 then
local text = object:GetText()
if text and not string.find(text, arg2) then check = false end
end
if check then return object end
end
end
end
end