PHP код:
local function formatV(v)
if v > 0 then
if v < 1e3 then
return v
elseif v < 1e6 then
return ("%.1fk"):format(v/1e3)
else
return ("%.1fm"):format(v/1e6)
end
end
end
local function healthbar_valuechanged_cb(self,value)
self.text:SetText(formatV(value))
end
local function healthbar_show_cb(self)
self.text:SetText(formatV(self:GetValue()))
end
local function nameplate_update_cb(self)
self:SetAlpha(1)
end
local function InitNamePlate(frame)
local healthbar = frame:GetChildren()
healthbar.text = healthbar:CreateFontString(nil,"ARTWORK")
healthbar.text:SetFont("Fonts\\FRIZQT__.TTF",11,"OUTLINE")
healthbar.text:SetPoint("CENTER")
healthbar_show_cb(healthbar)
healthbar:SetScript("OnValueChanged",healthbar_valuechanged_cb)
healthbar:SetScript("OnShow",healthbar_show_cb)
frame:SetScript("OnUpdate",nameplate_update_cb)
end
local function IdentifyFrame(self)
if self:GetName() then return end
if self.GetRegions then
local region = self:GetRegions()
if region.GetTexture then
local texturePath = region:GetTexture()
if texturePath == "Interface\\TargetingFrame\\UI-TargetingFrame-Flash" then
return "NamePlate"
elseif texturePath == "Interface\\Tooltips\\ChatBubble-Background" then
return "ChatBubble"
end
end
end
end
local function iterateChildrens(object,...)
if not object then return end
local type = IdentifyFrame(object)
if type == "NamePlate" then
InitNamePlate(object)
elseif type == "ChatBubble" then
--InitChatBubble(object)
end
return iterateChildrens(...)
end
local select,WorldFrame = select,WorldFrame
local lastWorldFrameChildsCount = 0
CreateFrame("frame"):SetScript("OnUpdate",function()
local worldFrameChildsCount = WorldFrame:GetNumChildren()
if worldFrameChildsCount ~= lastWorldFrameChildsCount then
iterateChildrens(select(lastWorldFrameChildsCount+1,WorldFrame:GetChildren()))
lastWorldFrameChildsCount = worldFrameChildsCount
end
end)