Quantcast caelNameplates - WoWInterface
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
08-16-16, 04:24 PM   #1
badness
A Cliff Giant
 
badness's Avatar
Join Date: May 2010
Posts: 74
caelNameplates

Hey guys, so since pre-patch as you know nameplates have changed a huge amount so I've decided to finally take on updating it and take over the addon. I'm still learning lua but I can mostly find my way around and I would appreciate some guidance in updating this addon.
Here is the code for the addon:
Lua Code:
  1. local addonName, ns = ...
  2.  
  3. local caelNamePlates = CreateFrame("Frame", nil, UIParent)
  4. caelNamePlates:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
  5.  
  6. --if not IsAddOnLoaded("caelCore") then
  7.     SetCVar("bloattest", 0) -- 1 might make nameplates larger but it fixes the disappearing ones.
  8.     SetCVar("bloatnameplates", 0) -- 1 makes nameplates larger depending on threat percentage.
  9.     SetCVar("bloatthreat", 0) -- 1 makes nameplates resize depending on threat gain/loss. Only active when a mob has multiple units on its threat table.
  10. --end
  11. --[[
  12. local barTexture = caelMedia.files.statusBarC
  13. local iconTexture = caelMedia.files.buttonNormal
  14. local raidIcons = caelMedia.files.raidIcons
  15. local overlayTexture = [=[Interface\Tooltips\Nameplate-Border]=]
  16. local font, fontSize, fontOutline = caelMedia.fonts.CAELNAMEPLATE_FONT, 8
  17. ]]
  18. local barTexture = [=[Interface\AddOns\caelNameplates\media\normtexc]=]
  19. --local iconTexture = [=[Interface\AddOns\caelNameplates\media\buttonnormal]=]
  20. local raidIcons = [=[Interface\AddOns\caelNameplates\media\raidicons]=]
  21. local overlayTexture = [=[Interface\Tooltips\Nameplate-Border]=]
  22. --local font, fontSize, fontOutline = caelMedia.fonts.CAELNAMEPLATE_FONT, 8
  23. local font = STANDARD_TEXT_FONT
  24. local fontSize = 10
  25. local fontOutline = "THINOUTLINE"
  26.  
  27. local backdrop = {
  28.         bgFile   =  [=[Interface\ChatFrame\ChatFrameBackground]=],
  29.         edgeFile =  [=[Interface\AddOns\caelNameplates\media\glowTex3]=],
  30.         edgeSize =  2,
  31.         insets   =  { left = 2, right = 2, top = 2, bottom = 2 },
  32.     }
  33.  
  34. local select = select
  35.  
  36. --local pixelScale = caelLib.scale
  37.  
  38. local UpdateTime = function(self, curValue)
  39.     local minValue, maxValue = self:GetMinMaxValues()
  40.     if self.channeling then
  41.         self.time:SetFormattedText("%.1f ", curValue)
  42.     else
  43.         self.time:SetFormattedText("%.1f ", maxValue - curValue)
  44.     end
  45. end
  46.  
  47. local ThreatUpdate = function(self, elapsed)
  48.     self.elapsed = self.elapsed + elapsed
  49.     if self.elapsed >= 0.2 then
  50.         if not self.oldglow:IsShown() then
  51.             self.healthBar.hpGlow:SetBackdropBorderColor(0, 0, 0)
  52.         else
  53.             local r, g, b = self.oldglow:GetVertexColor()
  54.             if g + b == 0 then
  55.                 self.healthBar.hpGlow:SetBackdropBorderColor(1, 0, 0)
  56.             else
  57.                 self.healthBar.hpGlow:SetBackdropBorderColor(1, 1, 0)
  58.             end
  59.         end
  60.  
  61.         self.healthBar:SetStatusBarColor(self.r, self.g, self.b)
  62.  
  63.         self.elapsed = 0
  64.     end
  65. end
  66.  
  67. local UpdatePlate = function(self)
  68.     local r, g, b = self.healthBar:GetStatusBarColor()
  69.     local newr, newg, newb
  70.     if g + b == 0 then
  71.         -- Hostile unit
  72.         newr, newg, newb = 1, 0.1, 0.1
  73.         self.healthBar:SetStatusBarColor(1, 0.1, 0.1)
  74.     elseif r + b == 0 then
  75.         -- Friendly unit
  76.         newr, newg, newb = 0.1, 1, 0.1
  77.         self.healthBar:SetStatusBarColor(0.1, 1, 0.1)
  78.     elseif r + g == 0 then
  79.         -- Friendly player
  80.         newr, newg, newb = 0.31, 0.45, 0.63
  81.         self.healthBar:SetStatusBarColor(0.31, 0.45, 0.63)
  82.     elseif 2 - (r + g) < 0.05 and b == 0 then
  83.         -- Neutral unit
  84.         newr, newg, newb = 1, 1, 0 --0.86, 0.83, 0.47
  85.         self.healthBar:SetStatusBarColor(1, 1, 0)
  86.     else
  87.         -- Hostile player - class colored.
  88.         newr, newg, newb = r, g, b 
  89.     end
  90.  
  91.     self.r, self.g, self.b = newr, newg, newb
  92.  
  93.     self.healthBar:ClearAllPoints()
  94.     self.healthBar:SetPoint("CENTER", self.healthBar:GetParent())
  95.     self.healthBar:SetHeight(7)
  96.     self.healthBar:SetWidth(100)
  97.  
  98.     self.healthBar.hpBackground:SetVertexColor(self.r * 0.22, self.g * 0.22, self.b * 0.22, 18)
  99.     self.castBar.IconOverlay:SetVertexColor(self.r, self.g, self.b)
  100.  
  101.     self.castBar:ClearAllPoints()
  102.     self.castBar:SetPoint("TOP", self.healthBar, "BOTTOM", 0, -5)
  103.     self.castBar:SetHeight(4)
  104.     self.castBar:SetWidth(100)
  105.  
  106.     self.highlight:ClearAllPoints()
  107.     self.highlight:SetAllPoints(self.healthBar)
  108.  
  109.     local oldName = self.oldname:GetText()
  110.     local newName = (string.len(oldName) > 20) and string.gsub(oldName, "%s?(.[\128-\191]*)%S+%s", "%1. ") or oldName -- "%s?(.)%S+%s"
  111.  
  112.     self.name:SetText(newName)
  113.  
  114.     local level, elite, mylevel = tonumber(self.level:GetText()), self.elite:IsShown(), UnitLevel("player")
  115.     self.level:ClearAllPoints()
  116.     self.level:SetPoint("RIGHT", self.healthBar, "LEFT", -1, 1)
  117.     if self.boss:IsShown() then
  118.         self.level:SetText("B")
  119.         self.level:SetTextColor(0.8, 0.05, 0)
  120.         self.level:Show()
  121.     elseif not elite and level == mylevel then
  122.         self.level:Hide()
  123.     else
  124.         self.level:SetText(level..(elite and "+" or ""))
  125.     end
  126. end
  127.  
  128. local FixCastbar = function(self)
  129.     self.castbarOverlay:Hide()
  130.  
  131.     self:SetHeight(3)
  132.     self:ClearAllPoints()
  133.     self:SetPoint("TOP", self.healthBar, "BOTTOM", 0, -5)
  134. end
  135.  
  136. local ColorCastBar = function(self, shielded)
  137.     if shielded then
  138.         self:SetStatusBarColor(0.8, 0.05, 0)
  139.         self.cbGlow:SetBackdropBorderColor(0.75, 0.75, 0.75)
  140.     else
  141.         self.cbGlow:SetBackdropBorderColor(0, 0, 0)
  142.     end
  143. end
  144.  
  145. local OnSizeChanged = function(self, width, height)
  146.     if floor(height) ~= 3 then
  147.         self.needFix = true
  148.     end
  149. end
  150.  
  151. local OnShow = function(self)
  152.     self.channeling  = UnitChannelInfo("target")
  153.  
  154.     if self.needFix then
  155.         FixCastbar(self)
  156.         if floor(self:GetHeight()) ~= 3 then
  157. --          print("B) wrong size "..floor(self:GetHeight()))
  158.         end
  159.     end
  160.  
  161.     ColorCastBar(self, self.shieldedRegion:IsShown())
  162.     self.IconOverlay:Show()
  163. end
  164.  
  165. local OnValueChanged = function(self, curValue)
  166.     UpdateTime(self, curValue)
  167.  
  168.     if self.needFix then
  169.         FixCastbar(self)
  170.         if floor(self:GetHeight()) ~= 5 then
  171. --          print("C) wrong size "..floor(self:GetHeight()))
  172.         end
  173.         self.needFix = nil
  174.     end
  175. end
  176.  
  177. local OnHide = function(self)
  178.     self.highlight:Hide()
  179.     self.healthBar.hpGlow:SetBackdropBorderColor(0, 0, 0)
  180. end
  181.  
  182. local OnEvent = function(self, event, unit)
  183.     if unit == "target" then
  184.         if self:IsShown() then
  185.             ColorCastBar(self, event == "UNIT_SPELLCAST_NOT_INTERRUPTIBLE")
  186.         end
  187.     end
  188. end
  189.  
  190. local CreatePlate = function(frame)
  191.      
  192.     frame.done = true
  193.    
  194.     frame.barFrame, frame.nameFrame = frame:GetChildren()
  195.     frame.healthBar, frame.absorbBar, frame.castBar = frame.barFrame:GetChildren()
  196.  
  197.     local healthBar, castBar = frame.healthBar, frame.castBar
  198.     local glowRegion, overlayRegion, highlightRegion, levelTextRegion, bossIconRegion, raidIconRegion, stateIconRegion = frame.barFrame:GetRegions()
  199.     local _, castbarOverlay, shieldedRegion, spellIconRegion = castBar:GetRegions()
  200.     local nameTextRegion = frame.nameFrame:GetRegions()
  201.  
  202.     frame.oldname = nameTextRegion
  203.     nameTextRegion:Hide()
  204.  
  205.     local newNameRegion = frame:CreateFontString()
  206.     newNameRegion:SetPoint("CENTER", healthBar, "CENTER", 0, 10)
  207.     newNameRegion:SetFont(font, fontSize, fontOutline)
  208.     newNameRegion:SetTextColor(0.84, 0.75, 0.65)
  209.     newNameRegion:SetShadowOffset(1.25, -1.25)
  210.     frame.name = newNameRegion
  211.  
  212.     frame.level = levelTextRegion
  213.     levelTextRegion:SetFont(font, fontSize, fontOutline)
  214.     levelTextRegion:SetShadowOffset(1.25, -1.25)
  215.  
  216.     healthBar:SetStatusBarTexture(barTexture)
  217.  
  218.     healthBar.hpBackground = healthBar:CreateTexture(nil, "BACKGROUND")
  219.     healthBar.hpBackground:SetAllPoints()
  220.     healthBar.hpBackground:SetTexture(barTexture)
  221.  
  222.     healthBar.hpGlow = CreateFrame("Frame", nil, healthBar)
  223.     healthBar.hpGlow:SetFrameLevel(healthBar:GetFrameLevel() -1 > 0 and healthBar:GetFrameLevel() -1 or 0)
  224.     healthBar.hpGlow:SetPoint("TOPLEFT", healthBar, "TOPLEFT", -2, 2)
  225.     healthBar.hpGlow:SetPoint("BOTTOMRIGHT", healthBar, "BOTTOMRIGHT", 2, -2)
  226.     healthBar.hpGlow:SetBackdrop(backdrop)
  227.     healthBar.hpGlow:SetBackdropColor(0, 0, 0, 0)
  228.     healthBar.hpGlow:SetBackdropBorderColor(0, 0, 0)
  229.  
  230.     castBar.castbarOverlay = castbarOverlay
  231.     castBar.healthBar = healthBar
  232.     castBar.shieldedRegion = shieldedRegion
  233.     castBar:SetStatusBarTexture(barTexture)
  234.  
  235.     castBar:HookScript("OnShow", OnShow)
  236.     castBar:HookScript("OnSizeChanged", OnSizeChanged)
  237.     castBar:HookScript("OnValueChanged", OnValueChanged)
  238.     castBar:HookScript("OnEvent", OnEvent)
  239.     castBar:RegisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE")
  240.     castBar:RegisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE")
  241.  
  242.     castBar.time = castBar:CreateFontString(nil, "ARTWORK")
  243.     castBar.time:SetPoint("RIGHT", castBar, "LEFT", -2, 0)
  244.     castBar.time:SetFont(font, fontSize, fontOutline)
  245.     castBar.time:SetTextColor(0.84, 0.75, 0.65)
  246.     castBar.time:SetShadowOffset(1.25, -1.25)
  247.  
  248.     castBar.cbBackground = castBar:CreateTexture(nil, "BACKGROUND")
  249.     castBar.cbBackground:SetAllPoints()
  250.     castBar.cbBackground:SetTexture(barTexture)
  251.     castBar.cbBackground:SetVertexColor(0.25, 0.25, 0.25, 0.75)
  252.  
  253.     castBar.cbGlow = CreateFrame("Frame", nil, castBar)
  254.     castBar.cbGlow:SetFrameLevel(castBar:GetFrameLevel() -1 > 0 and castBar:GetFrameLevel() -1 or 0)
  255.     castBar.cbGlow:SetPoint("TOPLEFT", castBar, -2, 2)
  256.     castBar.cbGlow:SetPoint("BOTTOMRIGHT", castBar, 2, -2)
  257.     castBar.cbGlow:SetBackdrop(backdrop)
  258.     castBar.cbGlow:SetBackdropColor(0, 0, 0, 0)
  259.     castBar.cbGlow:SetBackdropBorderColor(0, 0, 0)
  260.  
  261.     castBar.HolderA = CreateFrame("Frame", nil, castBar)
  262.     castBar.HolderA:SetFrameLevel(castBar.HolderA:GetFrameLevel() + 1)
  263.     castBar.HolderA:SetAllPoints()
  264.  
  265.     spellIconRegion:ClearAllPoints()
  266.     spellIconRegion:SetParent(castBar.HolderA)
  267.     spellIconRegion:SetPoint("LEFT", castBar, 8, 0)
  268.     spellIconRegion:SetSize(0.1, 0.1)
  269.  
  270.     castBar.HolderB = CreateFrame("Frame", nil, castBar)
  271.     castBar.HolderB:SetFrameLevel(castBar.HolderA:GetFrameLevel() + 2)
  272.     castBar.HolderB:SetAllPoints()
  273.  
  274.     castBar.IconOverlay = castBar.HolderB:CreateTexture(nil, "OVERLAY")
  275.     castBar.IconOverlay:SetPoint("TOPLEFT", spellIconRegion, -1.5, 1.5)
  276.     castBar.IconOverlay:SetPoint("BOTTOMRIGHT", spellIconRegion, 1.5, -1.5)
  277.     castBar.IconOverlay:SetTexture(iconTexture)
  278.  
  279.     highlightRegion:SetTexture(barTexture)
  280.     highlightRegion:SetVertexColor(0.25, 0.25, 0.25)
  281.     frame.highlight = highlightRegion
  282.  
  283.     raidIconRegion:ClearAllPoints()
  284.     raidIconRegion:SetPoint("RIGHT", healthBar, 25, 2)
  285.     raidIconRegion:SetSize(20, 20)
  286.     raidIconRegion:SetTexture(raidIcons)   
  287.  
  288.     frame.oldglow = glowRegion
  289.     frame.elite = stateIconRegion
  290.     frame.boss = bossIconRegion
  291.  
  292.     glowRegion:SetTexture(nil)
  293.     overlayRegion:SetTexture(nil)
  294.     shieldedRegion:SetTexture(nil)
  295.     castbarOverlay:SetTexture(nil)
  296.     stateIconRegion:SetAlpha(0)
  297.     bossIconRegion:SetTexture(nil)
  298.  
  299.     UpdatePlate(frame)
  300.     frame:SetScript("OnShow", UpdatePlate)
  301.     frame:SetScript("OnHide", OnHide)
  302.  
  303.     frame.elapsed = 0
  304.     frame:SetScript("OnUpdate", ThreatUpdate)
  305. end
  306. --[[
  307. local CheckFrames = function(num, ...)
  308.     for i = 1, num do
  309.         local frame = select(i, ...)
  310.         if frame:GetName() and frame:GetName():find("NamePlate%d") and not frame.done then
  311.             CreatePlate(frame)
  312.             frame.done = true
  313.         end
  314.     end
  315. end
  316. ]]
  317. local numKids = 0
  318. local lastUpdate = 0
  319. local index = 1
  320. local OnUpdate = function(self, elapsed)
  321.     lastUpdate = lastUpdate + elapsed
  322.  
  323.     if lastUpdate > 0.1 then
  324.         lastUpdate = 0
  325.  
  326.         local newNumKids = WorldFrame:GetNumChildren()
  327.         if newNumKids ~= numKids then
  328.             numKids = WorldFrame:GetNumChildren()
  329.             for i = index, numKids do
  330.                 local frame = select(i, WorldFrame:GetChildren())
  331.                 local name = frame:GetName()
  332.  
  333.                 if name and name:find("NamePlate") and not frame.done then
  334.                     --StyleFrame(frame)
  335.                     CreatePlate(frame)
  336.                     index = i
  337.                 end
  338.             end
  339.         end
  340.     end
  341. end
  342. caelNamePlates:SetScript("OnUpdate", OnUpdate)
  343. --[[
  344. caelNameplates.eventFrame:SetScript("OnUpdate", function(self, elapsed)
  345.     lastUpdate = lastUpdate + elapsed
  346.  
  347.     if lastUpdate > 0.1 then
  348.         local newNumKids = WorldFrame:GetNumChildren()
  349.  
  350.         if newNumKids ~= numKids then
  351.             CheckFrames(newNumKids, WorldFrame:GetChildren())
  352.  
  353.             for i = numKids + 1, newNumKids do
  354.                 local frame = select(i, WorldFrame:GetChildren())
  355.  
  356.                 if frame:GetName() and frame:GetName():find("NamePlate%d") then
  357.                     CreatePlate(frame)
  358.                 end
  359.             end
  360.  
  361.             numKids = newNumKids
  362.         end
  363.         lastUpdate = 0
  364.     end
  365. end)]]
  366. --[[
  367. caelNameplates.eventFrame:SetScript("OnEvent", function(self, event, ...)
  368.     if type(self[event]) == "function" then
  369.         return self[event](self, event, ...)
  370.     end
  371. end)
  372.  
  373. function caelNameplates.eventFrame:PLAYER_REGEN_ENABLED()
  374.     SetCVar("nameplateShowEnemies", 0)
  375. end
  376.  
  377. function caelNameplates.eventFrame:PLAYER_REGEN_DISABLED()
  378.     SetCVar("nameplateShowEnemies", 1)
  379. end
  380.  
  381. caelNameplates.eventFrame:RegisterEvent("ADDON_LOADED")
  382. function caelNameplates.eventFrame:ADDON_LOADED(event, addon)
  383.     if addon and addon:lower() == "caelnameplates" then
  384.         if not caelNameplatesDB then
  385.             caelNameplatesDB = {autotoggle = true}
  386.         end
  387.        
  388.         caelNameplates.settings = caelNameplatesDB
  389.        
  390.         if caelNameplates.settings.autotoggle then
  391.             self:RegisterEvent("PLAYER_REGEN_ENABLED")
  392.             self:RegisterEvent("PLAYER_REGEN_DISABLED")
  393.         end
  394.     end
  395. end
  396.  
  397. SlashCmdList["caelNameplates"] = function(parameters)
  398.     if parameters == "autotoggle" then
  399.         local newsetting = not caelNameplates.settings.autotoggle
  400.         caelNameplates.settings.autotoggle = newsetting
  401.        
  402.         local func = newsetting and "RegisterEvent" or "UnregisterEvent"
  403.        
  404.         caelNameplates.eventFrame[func](caelNameplates.eventFrame, "PLAYER_REGEN_ENABLED")
  405.         caelNameplates.eventFrame[func](caelNameplates.eventFrame, "PLAYER_REGEN_DISABLED")
  406.         print("Auto toggling of nameplates based on combat state " .. (caelNameplates.settings.autotoggle and "|cff00ff00enabled|r." or "|cffff0000disabled|r."))
  407.     end
  408. end
  409.  
  410. SLASH_caelNameplates1 = "/caelnameplates"
  411. ]]
It isn't showing when enabled and it isn't giving any lua errors, so I assume the first step would be to change all the SetTextures to SetVertexColor but after that I'm pretty much lost. What would be my next step after that?
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » caelNameplates

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off