Quantcast
WoWInterface - View Single Post - caelNameplates
Thread: caelNameplates
View Single Post
08-19-16, 04:18 PM   #9
badness
A Cliff Giant
 
badness's Avatar
Join Date: May 2010
Posts: 74
Lua Code:
  1. --[[    $Id: caelNameplates.lua 2819 2012-11-30 11:03:27Z [email][email protected][/email] $    ]]
  2.  
  3. local addonName, ns = ...
  4.  
  5. local caelNamePlates = CreateFrame("Frame", nil, UIParent)
  6. caelNamePlates:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
  7.  
  8. --[[ if not IsAddOnLoaded("caelCore") then
  9.     --SetCVar("bloattest", 0) -- 1 might make nameplates larger but it fixes the disappearing ones.
  10.     --SetCVar("bloatnameplates", 0) -- 1 makes nameplates larger depending on threat percentage.
  11.     --SetCVar("bloatthreat", 0) -- 1 makes nameplates resize depending on threat gain/loss. Only active when a mob has multiple units on its threat table.
  12. --end
  13.  
  14. local barTexture = caelMedia.files.statusBarC
  15. local iconTexture = caelMedia.files.buttonNormal
  16. local raidIcons = caelMedia.files.raidIcons
  17. local overlayTexture = [=[Interface\Tooltips\Nameplate-Border]=]
  18. local font, fontSize, fontOutline = caelMedia.fonts.CAELNAMEPLATE_FONT, 8
  19. --]]
  20. local barTexture = [=[Interface\AddOns\caelNameplates\media\normtexc]=]
  21. --local iconTexture = [=[Interface\AddOns\caelNameplates\media\buttonnormal]=]
  22. local raidIcons = [=[Interface\AddOns\caelNameplates\media\raidicons]=]
  23. local overlayTexture = [=[Interface\Tooltips\Nameplate-Border]=]
  24. --local font, fontSize, fontOutline = caelMedia.fonts.CAELNAMEPLATE_FONT, 8
  25. local font = STANDARD_TEXT_FONT
  26. local fontSize = 10
  27. local fontOutline = "THINOUTLINE"
  28.  
  29. local backdrop = {
  30.         bgFile   =  [=[Interface\ChatFrame\ChatFrameBackground]=],
  31.         edgeFile =  [=[Interface\AddOns\caelNameplates\media\glowTex3]=],
  32.         edgeSize =  2,
  33.         insets   =  { left = 2, right = 2, top = 2, bottom = 2 },
  34.     }
  35.  
  36. local select = select
  37.  
  38. --local pixelScale = caelLib.scale
  39.  
  40. local UpdateTime = function(self, curValue)
  41.     local minValue, maxValue = self:GetMinMaxValues()
  42.     if self.channeling then
  43.         self.time:SetFormattedText("%.1f ", curValue)
  44.     else
  45.         self.time:SetFormattedText("%.1f ", maxValue - curValue)
  46.     end
  47. end
  48.  
  49. local ThreatUpdate = function(self, elapsed)
  50.     self.elapsed = self.elapsed + elapsed
  51.     if self.elapsed >= 0.2 then
  52.         if not self.oldglow:IsShown() then
  53.             self.healthBar.hpGlow:SetBackdropBorderColor(0, 0, 0)
  54.         else
  55.             local r, g, b = self.oldglow:GetVertexColor()
  56.             if g + b == 0 then
  57.                 self.healthBar.hpGlow:SetBackdropBorderColor(1, 0, 0)
  58.             else
  59.                 self.healthBar.hpGlow:SetBackdropBorderColor(1, 1, 0)
  60.             end
  61.         end
  62.  
  63.         self.healthBar:SetStatusBarColor(self.r, self.g, self.b)
  64.  
  65.         self.elapsed = 0
  66.     end
  67. end
  68.  
  69. local UpdatePlate = function(self)
  70.     local r, g, b = self.healthBar:GetStatusBarColor()
  71.     local newr, newg, newb
  72.     if g + b == 0 then
  73.         -- Hostile unit
  74.         newr, newg, newb = 1, 0.1, 0.1
  75.         self.healthBar:SetStatusBarColor(1, 0.1, 0.1)
  76.     elseif r + b == 0 then
  77.         -- Friendly unit
  78.         newr, newg, newb = 0.1, 1, 0.1
  79.         self.healthBar:SetStatusBarColor(0.1, 1, 0.1)
  80.     elseif r + g == 0 then
  81.         -- Friendly player
  82.         newr, newg, newb = 0.31, 0.45, 0.63
  83.         self.healthBar:SetStatusBarColor(0.31, 0.45, 0.63)
  84.     elseif 2 - (r + g) < 0.05 and b == 0 then
  85.         -- Neutral unit
  86.         newr, newg, newb = 1, 1, 0 --0.86, 0.83, 0.47
  87.         self.healthBar:SetStatusBarColor(1, 1, 0)
  88.     else
  89.         -- Hostile player - class colored.
  90.         newr, newg, newb = r, g, b 
  91.     end
  92.  
  93.     self.r, self.g, self.b = newr, newg, newb
  94.  
  95.     self.healthBar:ClearAllPoints()
  96.     self.healthBar:SetPoint("CENTER", self.healthBar:GetParent())
  97.     self.healthBar:SetHeight(7)
  98.     self.healthBar:SetWidth(100)
  99.  
  100.     self.healthBar.hpBackground:SetVertexColor(self.r * 0.22, self.g * 0.22, self.b * 0.22, 18)
  101.     self.castBar.IconOverlay:SetVertexColor(self.r, self.g, self.b)
  102.  
  103.     self.castBar:ClearAllPoints()
  104.     self.castBar:SetPoint("TOP", self.healthBar, "BOTTOM", 0, -5)
  105.     self.castBar:SetHeight(4)
  106.     self.castBar:SetWidth(100)
  107.  
  108.     self.highlight:ClearAllPoints()
  109.     self.highlight:SetAllPoints(self.healthBar)
  110.  
  111.     local oldName = self.oldname:GetText()
  112.     local newName = (string.len(oldName) > 20) and string.gsub(oldName, "%s?(.[\128-\191]*)%S+%s", "%1. ") or oldName -- "%s?(.)%S+%s"
  113.  
  114.     self.name:SetText(newName)
  115.  
  116.     local level, elite, mylevel = tonumber(self.level:GetText()), self.elite:IsShown(), UnitLevel("player")
  117.     self.level:ClearAllPoints()
  118.     self.level:SetPoint("RIGHT", self.healthBar, "LEFT", -1, 1)
  119.     if self.boss:IsShown() then
  120.         self.level:SetText("B")
  121.         self.level:SetTextColor(0.8, 0.05, 0)
  122.         self.level:Show()
  123.     elseif not elite and level == mylevel then
  124.         self.level:Hide()
  125.     else
  126.         self.level:SetText(level..(elite and "+" or ""))
  127.     end
  128. end
  129.  
  130. local FixCastbar = function(self)
  131.     self.castbarOverlay:Hide()
  132.  
  133.     self:SetHeight(3)
  134.     self:ClearAllPoints()
  135.     self:SetPoint("TOP", self.healthBar, "BOTTOM", 0, -5)
  136. end
  137.  
  138. local ColorCastBar = function(self, shielded)
  139.     if shielded then
  140.         self:SetStatusBarColor(0.8, 0.05, 0)
  141.         self.cbGlow:SetBackdropBorderColor(0.75, 0.75, 0.75)
  142.     else
  143.         self.cbGlow:SetBackdropBorderColor(0, 0, 0)
  144.     end
  145. end
  146.  
  147. local OnSizeChanged = function(self, width, height)
  148.     if floor(height) ~= 3 then
  149.         self.needFix = true
  150.     end
  151. end
  152.  
  153. local OnShow = function(self)
  154.     self.channeling  = UnitChannelInfo("target")
  155.  
  156.     if self.needFix then
  157.         FixCastbar(self)
  158.         if floor(self:GetHeight()) ~= 3 then
  159. --          print("B) wrong size "..floor(self:GetHeight()))
  160.         end
  161.     end
  162.  
  163.     ColorCastBar(self, self.shieldedRegion:IsShown())
  164.     self.IconOverlay:Show()
  165. end
  166.  
  167. local OnValueChanged = function(self, curValue)
  168.     UpdateTime(self, curValue)
  169.  
  170.     if self.needFix then
  171.         FixCastbar(self)
  172.         if floor(self:GetHeight()) ~= 5 then
  173. --          print("C) wrong size "..floor(self:GetHeight()))
  174.         end
  175.         self.needFix = nil
  176.     end
  177. end
  178.  
  179. local OnHide = function(self)
  180.     self.highlight:Hide()
  181.     self.healthBar.hpGlow:SetBackdropBorderColor(0, 0, 0)
  182. end
  183.  
  184. local OnEvent = function(self, event, unit)
  185.     if unit == "target" then
  186.         if self:IsShown() then
  187.             ColorCastBar(self, event == "UNIT_SPELLCAST_NOT_INTERRUPTIBLE")
  188.         end
  189.     end
  190. end
  191.  
  192. local CreatePlate = function(frame)
  193.      
  194.     frame.done = true
  195.     --[[
  196.     frame.barFrame, frame.nameFrame = frame:GetChildren()
  197.     frame.healthBar, frame.absorbBar, frame.castBar = frame.barFrame:GetChildren()
  198.  
  199.     local healthBar, castBar = frame.healthBar, frame.castBar
  200.     local glowRegion, overlayRegion, highlightRegion, levelTextRegion, bossIconRegion, raidIconRegion, stateIconRegion = frame.barFrame:GetRegions()
  201.     local _, castbarOverlay, shieldedRegion, spellIconRegion = castBar:GetRegions()
  202.     local nameTextRegion = frame.nameFrame:GetRegions()
  203. --]]
  204.     frame.oldname = nameTextRegion
  205.     nameTextRegion:Hide()
  206.  
  207.     local newNameRegion = frame:CreateFontString()
  208.     newNameRegion:SetPoint("CENTER", healthBar, "CENTER", 0, 10)
  209.     newNameRegion:SetFont(font, fontSize, fontOutline)
  210.     newNameRegion:SetTextColor(0.84, 0.75, 0.65)
  211.     newNameRegion:SetShadowOffset(1.25, -1.25)
  212.     frame.name = newNameRegion
  213.  
  214.     frame.level = levelTextRegion
  215.     levelTextRegion:SetFont(font, fontSize, fontOutline)
  216.     levelTextRegion:SetShadowOffset(1.25, -1.25)
  217.  
  218.     healthBar:SetStatusBarTexture(barTexture)
  219.  
  220.     healthBar.hpBackground = CreateTexture(nil, "BACKGROUND")
  221.     healthBar.hpBackground:SetAllPoints()
  222.     healthBar.hpBackground:SetTexture(barTexture)
  223.  
  224.     healthBar.hpGlow = CreateFrame("Frame", nil, healthBar)
  225.     healthBar.hpGlow:SetFrameLevel(self:GetFrameLevel() -1 > 0 and self:GetFrameLevel() -1 or 0)
  226.     healthBar.hpGlow:SetPoint("TOPLEFT", healthBar, "TOPLEFT", -2, 2)
  227.     healthBar.hpGlow:SetPoint("BOTTOMRIGHT", healthBar, "BOTTOMRIGHT", 2, -2)
  228.     healthBar.hpGlow:SetBackdrop(backdrop)
  229.     healthBar.hpGlow:SetBackdropColor(0, 0, 0, 0)
  230.     healthBar.hpGlow:SetBackdropBorderColor(0, 0, 0)
  231.  
  232.     castBar.castbarOverlay = castbarOverlay
  233.     castBar.healthBar = healthBar
  234.     castBar.shieldedRegion = shieldedRegion
  235.     castBar:SetStatusBarTexture(barTexture)
  236.  
  237.     castBar:HookScript("OnShow", OnShow)
  238.     castBar:HookScript("OnSizeChanged", OnSizeChanged)
  239.     castBar:HookScript("OnValueChanged", OnValueChanged)
  240.     castBar:HookScript("OnEvent", OnEvent)
  241.     castBar:RegisterEvent("UNIT_SPELLCAST_INTERRUPTIBLE")
  242.     castBar:RegisterEvent("UNIT_SPELLCAST_NOT_INTERRUPTIBLE")
  243.  
  244.     castBar.time = CreateFontString(nil, "ARTWORK")
  245.     castBar.time:SetPoint("RIGHT", castBar, "LEFT", -2, 0)
  246.     castBar.time:SetFont(font, fontSize, fontOutline)
  247.     castBar.time:SetTextColor(0.84, 0.75, 0.65)
  248.     castBar.time:SetShadowOffset(1.25, -1.25)
  249.  
  250.     castBar.cbBackground = CreateTexture(nil, "BACKGROUND")
  251.     castBar.cbBackground:SetAllPoints()
  252.     castBar.cbBackground:SetTexture(barTexture)
  253.     castBar.cbBackground:SetVertexColor(0.25, 0.25, 0.25, 0.75)
  254.  
  255.     castBar.cbGlow = CreateFrame("Frame", nil, castBar)
  256.     castBar.cbGlow:SetFrameLevel(self:GetFrameLevel() -1 > 0 and self:GetFrameLevel() -1 or 0)
  257.     castBar.cbGlow:SetPoint("TOPLEFT", castBar, -2, 2)
  258.     castBar.cbGlow:SetPoint("BOTTOMRIGHT", castBar, 2, -2)
  259.     castBar.cbGlow:SetBackdrop(backdrop)
  260.     castBar.cbGlow:SetBackdropColor(0, 0, 0, 0)
  261.     castBar.cbGlow:SetBackdropBorderColor(0, 0, 0)
  262.  
  263.     castBar.HolderA = CreateFrame("Frame", nil, castBar)
  264.     castBar.HolderA:SetFrameLevel(self:GetFrameLevel() + 1)
  265.     castBar.HolderA:SetAllPoints()
  266.  
  267.     spellIconRegion:ClearAllPoints()
  268.     spellIconRegion:SetParent(HolderA)
  269.     spellIconRegion:SetPoint("LEFT", castBar, 8, 0)
  270.     spellIconRegion:SetSize(0.1, 0.1)
  271.  
  272.     castBar.HolderB = CreateFrame("Frame", nil, castBar)
  273.     castBar.HolderB:SetFrameLevel(self:GetFrameLevel() + 2)
  274.     castBar.HolderB:SetAllPoints()
  275.  
  276.     castBar.IconOverlay = CreateTexture(nil, "OVERLAY")
  277.     castBar.IconOverlay:SetPoint("TOPLEFT", spellIconRegion, -1.5, 1.5)
  278.     castBar.IconOverlay:SetPoint("BOTTOMRIGHT", spellIconRegion, 1.5, -1.5)
  279.     castBar.IconOverlay:SetTexture(iconTexture)
  280.  
  281.     highlightRegion:SetTexture(barTexture)
  282.     highlightRegion:SetVertexColor(0.25, 0.25, 0.25)
  283.     frame.highlight = highlightRegion
  284.  
  285.     raidIconRegion:ClearAllPoints()
  286.     raidIconRegion:SetPoint("RIGHT", healthBar, 25, 2)
  287.     raidIconRegion:SetSize(20, 20)
  288.     raidIconRegion:SetTexture(raidIcons)   
  289.  
  290.     frame.oldglow = glowRegion
  291.     frame.elite = stateIconRegion
  292.     frame.boss = bossIconRegion
  293.  
  294.     glowRegion:SetTexture(nil)
  295.     overlayRegion:SetTexture(nil)
  296.     shieldedRegion:SetTexture(nil)
  297.     castbarOverlay:SetTexture(nil)
  298.     stateIconRegion:SetAlpha(0)
  299.     bossIconRegion:SetTexture(nil)
  300.  
  301.     UpdatePlate(frame)
  302.     frame:SetScript("OnShow", UpdatePlate)
  303.     frame:SetScript("OnHide", OnHide)
  304.  
  305.     frame.elapsed = 0
  306.     frame:SetScript("OnUpdate", ThreatUpdate)
  307. end
  308. hooksecurefunc(NamePlateDriverFrame, "OnNamePlateCreated", function(_, frame)
  309.     CreatePlate(frame.UnitFrame)
  310. end)
  311.  
  312. hooksecurefunc(NamePlateDriverFrame, "ApplyFrameOptions", function(_, frame, unit)
  313.     UpdatePlate(frame.UnitFrame)
  314. end)
what I have currently...I'm kind of struggling
  Reply With Quote