PHP код:
local importants,NameToFrame = {},{}
local function UpdateIcon(self)
local tex = importants[self._lastName]
if tex then
if tex~=self._lasttex then
self._icon:SetTexture(tex)
self._icon:Show()
self._lasttex = tex
end
else
self._icon:Hide()
end
end
local HookNameplate
do
local function NamePlate_OnShow(self)
local name = self._namereg:GetText()
self._lastName = name
NameToFrame[name] = self
if importants[name] then
UpdateIcon(self)
end
end
local function NamePlate_OnHide(self)
self._icon:Hide()
NameToFrame[self._lastName],self._lastName,self._lasttex = nil
end
local function NamePlate_OnUpdate(self)
if self._namereg:GetText()~=self._lastName then
NamePlate_OnHide(self)
NamePlate_OnShow(self)
self._lastName = self._namereg:GetText()
end
end
function HookNameplate(frame)
frame._icon = frame:CreateTexture(nil,"BACKGROUND")
frame._icon:SetSize(40,40)
frame._icon:SetPoint("CENTER",frame,0,36)
local _,_,_,_,_,_,name = frame:GetRegions()
frame._namereg = name
NamePlate_OnShow(frame)
frame:HookScript("OnShow",NamePlate_OnShow)
frame:HookScript("OnHide",NamePlate_OnHide)
frame:HookScript("OnUpdate",NamePlate_OnUpdate)
end
end
local function IsNamePlate(obj)
if obj:GetName() then return end
if obj.GetRegions then
local reg = obj:GetRegions()
if reg and reg.GetTexture then
return reg:GetTexture()==[[Interface\TargetingFrame\UI-TargetingFrame-Flash]]
end
end
end
local WorldFrame = WorldFrame
local lastNumChildren = 1
CreateFrame("frame"):SetScript("OnUpdate",function()
if lastNumChildren~=WorldFrame:GetNumChildren() then
local tbl = {WorldFrame:GetChildren()}
for i = lastNumChildren,#tbl do
if IsNamePlate(tbl[i]) then
HookNameplate(tbl[i])
end
end
lastNumChildren = WorldFrame:GetNumChildren()
end
end)
function SetStamp(name,texture)
importants[name] = texture
if NameToFrame[name] then
UpdateIcon(NameToFrame[name])
end
end