View Single Post
10-06-14, 03:47 AM   #28
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Genius idea. I love that.

I would add one exception to the setpoint function though. A function that checks if the plate is shown before you apply the new setpoint. Because otherwise you might show a plate that is not visible.

Btw there is another thing that I read about. NamePlates change index on every /reloadui. But one could check the worldframe children on every OnUpdate until the first one pops up.

After that one just checks for nameplates per index instead of parsing the children all the time.

Here is the adapted code:
Lua Code:
  1. local newPlates, namePlateIndex, _G, string = {}, nil, _G, string
  2.  
  3. WorldFrame:HookScript('OnUpdate', function(self)
  4.   if not namePlateIndex then
  5.     for _, blizzPlate in pairs({self:GetChildren()}) do
  6.       local name = blizzPlate:GetName()
  7.       if name and string.match(name, '^NamePlate%d+$') then
  8.         namePlateIndex = string.gsub(name,'NamePlate','')
  9.         break
  10.       end
  11.     end
  12.   else
  13.     local blizzPlate = _G["NamePlate"..namePlateIndex]
  14.     if not blizzPlate then return end
  15.     if not newPlates[blizzPlate] then
  16.       local newPlate = CreateFrame('Frame', nil, WorldFrame)
  17.       newPlates[blizzPlate] = newPlate
  18.       print(namePlateIndex)
  19.       namePlateIndex = namePlateIndex+1
  20.       newPlate:SetSize(1, 1)      
  21.       for i = 1, 500 do -- Make a bunch of regions for a stress test
  22.         local fs = newPlate:CreateFontString(nil, nil, 'GameFontNormalHuge')
  23.         fs:SetText(namePlateIndex)
  24.         fs:SetPoint('CENTER', newPlate, math.random(-50,50), math.random(-12,12))
  25.       end      
  26.       -- Attach a frame to the nameblizzPlate which will fire OnSizeChanged when it moves
  27.       local sizer = CreateFrame('Frame', nil, newPlate)
  28.       sizer:SetPoint('BOTTOMLEFT', WorldFrame)
  29.       sizer:SetPoint('TOPRIGHT', blizzPlate, 'CENTER')
  30.       sizer:SetScript('OnSizeChanged', function(self, x, y)
  31.         if blizzPlate:IsShown() then
  32.           newPlate:Hide() -- Important, never move the frame while it's visible
  33.           newPlate:SetPoint('CENTER', WorldFrame, 'BOTTOMLEFT', x, y) -- Immediately reposition frame
  34.           newPlate:Show()
  35.         end
  36.       end)    
  37.       blizzPlate:HookScript('OnHide', function() newPlate:Hide() end)
  38.       blizzPlate:HookScript('OnShow', function() newPlate:Show() end)
  39.     end
  40.   end  
  41. end)
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 10-06-14 at 04:56 AM.
  Reply With Quote