Advertisement
Guest User

custom PlateBuff style

a guest
Oct 22nd, 2012
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.41 KB | None | 0 0
  1. local folder, core = ...
  2.  
  3. if not core.LibNameplate then
  4. return
  5. end
  6.  
  7. --~ local LBF = LibStub("LibButtonFacade", true)
  8.  
  9.  
  10. local L = core.L or LibStub("AceLocale-3.0"):GetLocale(folder, true)
  11. local _G = _G
  12. local pairs = pairs
  13. local GetTime = GetTime
  14. local CreateFrame = CreateFrame
  15. local table_remove = table.remove
  16. local table_sort = table.sort
  17. local type = type
  18. local table_getn = table.getn
  19. local Debug = core.Debug
  20. local table_getn = table.getn
  21. local DebuffTypeColor = DebuffTypeColor
  22. local select = select
  23. local string_gsub = string.gsub
  24.  
  25. local P = {}
  26. local LibNameplate = core.LibNameplate
  27. local nametoGUIDs = core.nametoGUIDs
  28. local buffBars = core.buffBars
  29. local buffFrames = core.buffFrames
  30. local guidBuffs = core.guidBuffs
  31.  
  32. core.unknownIcon = "Inv_misc_questionmark"
  33.  
  34.  
  35. local defaultSettings = core.defaultSettings
  36. defaultSettings.profile.skin_SkinID = "Blizzard"
  37. defaultSettings.profile.skin_Gloss = false
  38. defaultSettings.profile.skin_Backdrop = false
  39. defaultSettings.profile.skin_Colors = {}
  40.  
  41. do
  42. local OnEnable = core.OnEnable
  43. function core:OnEnable()
  44. if OnEnable then OnEnable(self) end
  45.  
  46. --~ Debug("OnEnable", "frames", self.db.profile)
  47. P = self.db.profile --this can change on profile change.
  48.  
  49. --[[
  50. if LBF then
  51. LBF:RegisterSkinCallback(folder, self.SkinCallback, self)
  52.  
  53. LBF:Group(self.name):Skin(self.db.profile.skin_SkinID, self.db.profile.skin_Gloss, self.db.profile.skin_Backdrop, self.db.profile.skin_Colors)
  54. end]]
  55. end
  56. end
  57.  
  58. function core:UpdateTexterSkins()
  59. --~ local Group = LBF:Group(folder, "Buffs")
  60. --~ Group:Skin(P.skin_SkinID, P.skin_Gloss, P.skin_Backdrop, P.skin_Colors)
  61.  
  62. --~ for i=1, NUM_ACTIONBAR_BUTTONS do
  63. --~ local button = format("ActionButton%d", i)
  64. --~ if _G[button] then
  65. --~ Group:AddButton(_G[button])
  66. --~ _G[button]:SetFrameStrata("HIGH")
  67. --~ end
  68. --~ end
  69.  
  70. end
  71.  
  72. function core:SkinCallback(SkinID, Gloss, Backdrop, Group, Button, Colors)
  73. Debug("SkinCallback", SkinID, Gloss, Backdrop, Group, Button, Colors)
  74. end
  75.  
  76. ----------------------------------------------------------
  77. local function UpdateBuffSize(frame, size) --
  78. -- Update a spell frame's texture size. --
  79. ----------------------------------------------------------
  80. frame.icon:SetWidth(size)
  81. frame.icon:SetHeight(size*0.8)
  82.  
  83. frame:SetWidth(size)
  84.  
  85. if P.showCooldown == true then
  86. frame:SetHeight(size + frame.cd:GetStringHeight())
  87. else
  88. frame:SetHeight(size)
  89. end
  90. end
  91.  
  92. ------------------------------------------------------
  93. local function UpdateBuffCDSize(buffFrame, size) --
  94. -- Set cooldown text size. --
  95. ------------------------------------------------------
  96. buffFrame.cd:SetFont("Interface\\AddOns\\dMedia\\Infinity Gears.ttf", size, "THINOUTLINE")
  97. buffFrame.cdbg:SetHeight(buffFrame.cd:GetStringHeight())
  98. --~ iconOnShow(buffFrame) --lazy way to hide/show cooldown.
  99. end
  100.  
  101. --------------------------------------------------
  102. local function SetStackSize(buffFrame, size) --
  103. -- Set the stack text size. --
  104. --------------------------------------------------
  105. buffFrame.stack:SetFont("Interface\\AddOns\\dMedia\\Infinity Gears.ttf", size, "THINOUTLINE")
  106. end
  107.  
  108. ------------------------------------------
  109. local function iconOnShow(self) --
  110. -- Called when spell frames are shown. --
  111. ------------------------------------------
  112. self:SetAlpha(1)
  113.  
  114. self.cdbg:Hide()
  115. self.cd:Hide()
  116. self.cdtexture:Hide()
  117. self.stack:Hide()
  118. self.border:Hide()
  119. --~ self.skin:Hide()
  120.  
  121. if P.showCooldown == true and self.expirationTime > 0 then
  122. self.cdbg:Show()
  123. self.cd:Show()
  124. end
  125. if P.showCooldownTexture == true then
  126. self.cdtexture:Show()
  127. local cdtexturetimer = self.startTime or GetTime()
  128. self.cdtexture:SetCooldown(cdtexturetimer, self.duration, true);
  129. else
  130. self.cdtexture:Hide()
  131. end
  132.  
  133. local iconSize = P.iconSize
  134. local cooldownSize = P.cooldownSize
  135. local stackSize = P.stackSize
  136.  
  137. --~ if not self.spellName then
  138. --~ Debug("iconOnShow", "no spell name?")
  139. --~ end
  140.  
  141. local spellName = self.spellName or "X"
  142.  
  143. local spellOpts = core:HaveSpellOpts(spellName)
  144.  
  145. if spellOpts then
  146. iconSize = spellOpts.iconSize or iconSize
  147. cooldownSize = spellOpts.cooldownSize or cooldownSize
  148. stackSize = spellOpts.stackSize or stackSize
  149. end
  150.  
  151. UpdateBuffCDSize(self, cooldownSize)
  152.  
  153. if self.stackCount and self.stackCount > 1 then
  154. self.stack:SetText(self.stackCount)
  155.  
  156. self.stack:Show()
  157. SetStackSize(self, stackSize)
  158. end
  159.  
  160. if self.isDebuff then
  161. local colour = DebuffTypeColor[self.debuffType or ""]
  162. if colour then
  163. self.border:SetVertexColor(colour.r, colour.g, colour.b)
  164. self.border:Show()
  165.  
  166. --~ self.skin:SetVertexColor(colour.r, colour.g, colour.b)
  167. --~ self.skin:Show()
  168. end
  169.  
  170. end
  171.  
  172. if self.playerCast and P.biggerSelfSpells == true then
  173. UpdateBuffSize(self, iconSize * 1.2)
  174. else
  175. UpdateBuffSize(self, iconSize)
  176. end
  177. end
  178.  
  179. ------------------------------------------
  180. local function iconOnHide(self) --
  181. -- Called when spell frames are shown. --
  182. ------------------------------------------
  183. self.stack:Hide()
  184. self.cdbg:Hide()
  185. self.cd:Hide()
  186. self.border:Hide()
  187. --~ self.skin:Hide()
  188. self.cdtexture:Hide()
  189. self:SetAlpha(1)
  190.  
  191. UpdateBuffSize(self, P.iconSize)
  192. end
  193.  
  194. ----------------------------------------------
  195. local function iconOnUpdate(self, elapsed) --
  196. -- Fires for spell frames. --
  197. ----------------------------------------------
  198. self.lastUpdate = self.lastUpdate + elapsed
  199. if self.lastUpdate > 0.1 then --abit fast for cooldown flash.
  200. self.lastUpdate = 0
  201.  
  202. --~ if self.stackCount > 0 then
  203. --~ self.stack:SetText(self.stackCount)
  204. --~ end
  205.  
  206. if self.expirationTime > 0 then
  207. local rawTimeLeft = self.expirationTime - GetTime()
  208. local timeLeft
  209. if rawTimeLeft < 10 then
  210. timeLeft = core:Round(rawTimeLeft, 1)
  211. else
  212. timeLeft = core:Round(rawTimeLeft)
  213. end
  214.  
  215. if P.showCooldown == true then
  216. self.cd:SetText(core:SecondsToString(timeLeft, 1))
  217. self.cd:SetTextColor(core:RedToGreen(timeLeft, self.duration))
  218. self.cdbg:SetWidth(self.cd:GetStringWidth())
  219. end
  220.  
  221. if (timeLeft / (self.duration + 0.01) ) < P.blinkTimeleft and timeLeft < 60 then --buff only has 20% timeleft and is less then 60 seconds.
  222. local f = GetTime() % 1
  223. if f > 0.5 then
  224. f = 1 - f
  225. end
  226.  
  227. self:SetAlpha(f * 3)
  228. end
  229.  
  230. if GetTime() > self.expirationTime then
  231. self:Hide()
  232.  
  233. local GUID = LibNameplate:GetGUID(self.realPlate)
  234. if GUID then
  235. core:RemoveOldSpells(GUID)
  236. core:AddBuffsToPlate(self.realPlate, GUID)
  237. else
  238. local plateName = LibNameplate:GetName(self.realPlate)
  239. if plateName and nametoGUIDs[plateName] then
  240. core:RemoveOldSpells(nametoGUIDs[plateName])
  241. core:AddBuffsToPlate(self.realPlate, nametoGUIDs[plateName])
  242. end
  243. end
  244. end
  245. end
  246.  
  247. end
  248. end
  249.  
  250.  
  251. function core:RemoveOldSpells(GUID)
  252. for i=(P.numBars * P.iconsPerBar), 1, -1 do
  253. if guidBuffs[GUID] and guidBuffs[GUID][i] then
  254. if guidBuffs[GUID][i].expirationTime and guidBuffs[GUID][i].expirationTime > 0 and GetTime() > guidBuffs[GUID][i].expirationTime then
  255. --~ Debug("RemoveOldSpells", GUID, i, guidBuffs[GUID][i].name)
  256. table_remove(guidBuffs[GUID], i)
  257. end
  258. end
  259. end
  260. end
  261.  
  262.  
  263. local function SetBarSize(barFrame, width, height)
  264. barFrame:SetWidth(width)
  265. barFrame:SetHeight(height)
  266. end
  267.  
  268. local function CreateBuffFrame(parentFrame, realPlate)
  269. local f = CreateFrame("Frame", nil, parentFrame) --
  270. f.realPlate = realPlate
  271. f:SetFrameStrata("BACKGROUND")
  272.  
  273. f.icon = CreateFrame("Frame", nil, f)
  274. f.icon:SetPoint("TOP", f)
  275.  
  276. f.texture = f.icon:CreateTexture(nil,"BACKGROUND")
  277. f.texture:SetAllPoints(f.icon)
  278.  
  279. local cd = f:CreateFontString(nil, "ARTWORK", "ChatFontNormal")
  280. cd:SetText("0")
  281. cd:SetPoint("TOP", f.icon, "BOTTOM")
  282. f.cd = cd
  283.  
  284. --Make the text easier to see.
  285. f.cdbg = f:CreateTexture(nil,"BACKGROUND")
  286. --f.cdbg:SetTexture(0,0,0,.75)
  287. --f.cdbg:SetPoint("CENTER", cd)
  288.  
  289. -- clock cooldown texture
  290. -- f.cdtextureP = CreateFrame("Frame", nil, f)
  291. -- f.cdtextureP:SetPoint("TOP", f)
  292.  
  293. f.cdtexture = CreateFrame("Cooldown", nil , f.icon)
  294. f.cdtexture:SetAllPoints(true)
  295. f.cdtexture:SetReverse(true)
  296.  
  297. -- f.cdtexture:SetDrawEdge(true)
  298. -- f.cdtexture:SetPoint("CENTER", f.icon, 0, -1)
  299. -- f.cdtexture:SetAllPoints(f.icon)
  300. -- f.cdtexture:SetFrameLevel(core.db.profile.frameLevel + 1)
  301.  
  302. core:SetFrameLevel(f)
  303.  
  304. f.stack = f.icon:CreateFontString(nil, "OVERLAY", "ChatFontNormal")
  305. f.stack:SetText("0")
  306. f.stack:SetPoint("BOTTOMRIGHT", f.icon, "BOTTOMRIGHT", -1, 3)
  307.  
  308. f.border = f.icon:CreateTexture(nil, "BORDER")
  309. --~ f.border:SetPoint("CENTER", f.icon)
  310. f.border:SetAllPoints(true)
  311. --f.border:SetTexture("Interface\\Buttons\\UI-Debuff-Overlays") --Interface\\Buttons\\UI-Debuff-Overlays
  312. --f.border:SetTexCoord(0.296875,0.5703125,0,0.515625)
  313.  
  314. -- 1px icon border
  315. local oSet = UIParent:GetScale() / f:GetEffectiveScale()
  316. local blankTex = "Interface\\Buttons\\WHITE8x8"
  317. local backdrop = {edgeFile = blankTex, edgeSize = oSet}
  318. f.border2 = CreateFrame("Frame", nil, f)
  319. f.border2:SetPoint("TOPLEFT", f.icon, "TOPLEFT", -oSet, oSet)
  320. f.border2:SetPoint("BOTTOMRIGHT", f.icon, "BOTTOMRIGHT", oSet, -oSet)
  321. f.border2:SetBackdrop(backdrop)
  322. f.border2:SetBackdropBorderColor(0,0,0)
  323. f.border2:SetFrameLevel(3)
  324.  
  325. f.lastUpdate = 0
  326. f.expirationTime = 0
  327. f:SetScript("OnShow", iconOnShow)
  328. f:SetScript("OnHide", iconOnHide)
  329.  
  330.  
  331. f:SetScript("OnUpdate", iconOnUpdate)
  332. f.stackCount = 0
  333.  
  334. f.cdbg:Hide()
  335. f.cd:Hide()
  336. f.border:Hide()
  337. f.cdtexture:Hide()
  338. f.stack:Hide()
  339.  
  340. --[===[@debug@
  341. --~ f:EnableMouse(true)
  342. --~ f:SetScript("OnEnter", function(frame)
  343. --~ Debug("OnEnter!",
  344. --~ frame.spellName,
  345. --~ frame.expirationTime,
  346. --~ (frame.expirationTime or 0) - GetTime(),
  347. --~ frame.cd:IsShown()
  348. --~ )
  349. --~ end)
  350. --@end-debug@]===]
  351.  
  352. --[[
  353. if LBF then
  354. local Group = LBF:Group(folder)
  355. local skinID = Group.SkinID
  356.  
  357. local SkinData = LBF:GetSkins()
  358. Debug("Create", skinID, SkinData[skinID].Border.Texture)
  359.  
  360. f.skin = f.icon:CreateTexture(nil,"OVERLAY")
  361. f.skin:SetAllPoints(true)
  362.  
  363. f.skin:SetTexture(SkinData[skinID].Border.Texture)
  364.  
  365. f.skin:SetTexCoord(0.2,0.8,0.2,0.8)
  366. f.skin:SetBlendMode("ADD")
  367. f.skin:Hide()
  368. end]]
  369.  
  370.  
  371. return f
  372. end
  373.  
  374. --[[
  375. function skinTest()-- /run skinTest()
  376. local Group = LBF:Group(folder)
  377. local skinID = Group.SkinID
  378.  
  379. local SkinData = LBF:GetSkins()
  380. Debug("test", SkinData[skinID].Border.Texture)
  381.  
  382. for skinID, skinData in pairs(SkinData) do
  383.  
  384.  
  385. for a, b in pairs(skinData.Border) do
  386. Debug("skinTest 1", skinID, skinData, a, b)
  387. end
  388.  
  389. end
  390.  
  391. end]]
  392.  
  393. ------------------------------------------
  394. function core:UpdateBarsBackground() --
  395. -- Show/Hide bar background texture. --
  396. ------------------------------------------
  397. for plate in pairs(buffBars) do
  398. for b in pairs(buffBars[plate]) do
  399.  
  400. if P.showBarBackground == true then
  401. buffBars[plate][b].barBG:Show()
  402. else
  403. buffBars[plate][b].barBG:Hide()
  404. end
  405.  
  406. end
  407. end
  408. end
  409. --~ local barSizes = {}
  410.  
  411. ----------------------------------------------------------
  412. local function CreateBarFrame(parentFrame, realPlate) --
  413. -- Create and return a bar frame. --
  414. ----------------------------------------------------------
  415. local f = CreateFrame("frame", nil, parentFrame)
  416. f.realPlate = realPlate
  417.  
  418. f:SetFrameStrata("BACKGROUND")
  419. --~ f:SetFrameLevel(parentFrame:GetFrameLevel())
  420.  
  421.  
  422. f:SetWidth(1)
  423. f:SetHeight(1)
  424.  
  425. --Make the text easier to see.
  426. f.barBG = f:CreateTexture(nil,"BACKGROUND")
  427. f.barBG:SetAllPoints(true)
  428.  
  429. f.barBG:SetTexture(1,1,1,0.3) --uses for testing
  430. if P.showBarBackground == true then
  431. f.barBG:Show()
  432. else
  433. f.barBG:Hide()
  434. end
  435.  
  436. f:Show()
  437. return f
  438. end
  439.  
  440. ----------------------------------------------------------------------
  441. local function BuildPlateBars(plate, visibleFrame) --
  442. -- Build all our bar frames for a plate. --
  443. -- We anchor these to the plate and our spell frames to the bar. --
  444. ----------------------------------------------------------------------
  445. buffBars[plate] = buffBars[plate] or {}
  446.  
  447.  
  448. if not buffBars[plate][1] then
  449. buffBars[plate][1] = CreateBarFrame(visibleFrame, plate)
  450. end
  451. buffBars[plate][1]:ClearAllPoints()
  452. buffBars[plate][1]:SetPoint(P.barAnchorPoint, visibleFrame, P.plateAnchorPoint, P.barOffsetX, P.barOffsetY) -- + GetCooldownHeight(buffFrames[plate][1])
  453. buffBars[plate][1]:SetParent(visibleFrame) --uhuh
  454.  
  455. local barPoint = P.barAnchorPoint
  456. local parentPoint = P.plateAnchorPoint
  457. if P.barGrowth == 1 then --up
  458. barPoint = string_gsub(barPoint, "TOP", "BOTTOM");
  459. parentPoint = string_gsub(parentPoint, "BOTTOM", "TOP");
  460. else
  461. barPoint = string_gsub(barPoint, "BOTTOM,", "TOP");
  462. parentPoint = string_gsub(parentPoint, "TOP", "BOTTOM");
  463. end
  464.  
  465. if P.numBars > 1 then
  466. for r=2, P.numBars do
  467. if not buffBars[plate][r] then
  468. buffBars[plate][r] = CreateBarFrame(visibleFrame, plate)
  469. end
  470. buffBars[plate][r]:ClearAllPoints()
  471.  
  472. buffBars[plate][r]:SetPoint(barPoint, buffBars[plate][r-1], parentPoint, 0, 0)
  473. buffBars[plate][r]:SetParent(visibleFrame) --uhuh
  474. end
  475. end
  476. end
  477.  
  478. local function GetBarChildrenSize(n, ...)
  479. local frame
  480. local totalWidth = 1
  481. local totalHeight = 1
  482. if n > P.iconsPerBar then
  483. n = P.iconsPerBar
  484. end
  485. for i = 1, n do
  486. frame = select(i, ...)
  487. if P.shrinkBar == true then
  488. if frame:IsShown() then
  489. totalWidth = totalWidth + frame:GetWidth()
  490.  
  491. if frame:GetHeight() > totalHeight then
  492. totalHeight = frame:GetHeight()
  493. end
  494. end
  495. else
  496. totalWidth = totalWidth + frame:GetWidth()
  497.  
  498. if frame:GetHeight() > totalHeight then
  499. totalHeight = frame:GetHeight()
  500. end
  501. end
  502. end
  503. return totalWidth, totalHeight
  504. end
  505.  
  506. --------------------------------------------------------------------------------------
  507. local function UpdateBarSize(barFrame) --
  508. -- Update a bar's size taking into account all the spell frame's height and width. --
  509. --------------------------------------------------------------------------------------
  510. if barFrame:GetNumChildren() == 0 then
  511. --~ Debug("Our buff bar lost it's children?")
  512. return
  513. end
  514.  
  515. local totalWidth, totalHeight = GetBarChildrenSize(barFrame:GetNumChildren(), barFrame:GetChildren())
  516.  
  517. barFrame:SetWidth(totalWidth)
  518. barFrame:SetHeight(totalHeight)
  519. end
  520.  
  521. local function UpdateAllBarSizes(plate)
  522. --~ for r=P.numBars, 1, -1 do
  523. for r=1, P.numBars do
  524. UpdateBarSize(buffBars[plate][r])
  525. end
  526. end
  527.  
  528. function core:UpdateAllPlateBarSizes()
  529. for plate in pairs(buffBars) do
  530. UpdateAllBarSizes(plate)
  531. end
  532. end
  533.  
  534.  
  535.  
  536. ----------------------------------------------
  537. function core:AddBuffsToPlate(plate, GUID) --
  538. -- Show spells on a plate linked to a GUID. --
  539. ----------------------------------------------
  540.  
  541. --~ if true then
  542. --~ return
  543. --~ end
  544.  
  545. if not buffFrames[plate] or not buffFrames[plate][P.iconsPerBar] then
  546. self:BuildBuffFrame(plate)
  547. end
  548.  
  549. local t, f
  550. --~ Debug("AddBuffsToPlate 0", GUID)
  551. if guidBuffs[GUID] then
  552. table_sort(guidBuffs[GUID], function(a,b)
  553. if(a and b) then
  554. if a.playerCast ~= b.playerCast then
  555. return (a.playerCast or 0) > (b.playerCast or 0)
  556. elseif a.expirationTime == b.expirationTime then
  557. return a.name < b.name
  558. else
  559. return (a.expirationTime or 0) < (b.expirationTime or 0)
  560. end
  561. end
  562. end)
  563.  
  564.  
  565.  
  566. for i=1, P.numBars * P.iconsPerBar do
  567. if buffFrames[plate][i] then
  568.  
  569.  
  570. if guidBuffs[GUID][i] then --and (not guidBuffs[GUID][i].expirationTime or guidBuffs[GUID][i].expirationTime == 0 or guidBuffs[GUID][i].expirationTime > GetTime()) then
  571. buffFrames[plate][i].spellName = guidBuffs[GUID][i].name or ""
  572. buffFrames[plate][i].expirationTime = guidBuffs[GUID][i].expirationTime or 0
  573. buffFrames[plate][i].duration = guidBuffs[GUID][i].duration or 1
  574. buffFrames[plate][i].startTime = guidBuffs[GUID][i].startTime or GetTime()
  575. buffFrames[plate][i].stackCount = guidBuffs[GUID][i].stackCount or 0
  576. buffFrames[plate][i].isDebuff = guidBuffs[GUID][i].isDebuff
  577. buffFrames[plate][i].debuffType = guidBuffs[GUID][i].debuffType
  578. buffFrames[plate][i].playerCast = guidBuffs[GUID][i].playerCast
  579.  
  580.  
  581. buffFrames[plate][i].texture:SetTexture("Interface\\Icons\\"..guidBuffs[GUID][i].icon)
  582. buffFrames[plate][i].texture:SetTexCoord(.08, .92, .08, .92)
  583.  
  584. --~ if buffFrames[plate][i]:IsShown() then
  585. --~ iconOnShow(buffFrames[plate][i])
  586. --~ else
  587. buffFrames[plate][i]:Show()--make sure OnShow fires.
  588. --~ end
  589.  
  590. --Making sure it does fire. sometimes it doesn't. =/
  591. iconOnShow(buffFrames[plate][i])
  592.  
  593. iconOnUpdate(buffFrames[plate][i], 1) --do a onupdate.
  594. else
  595. buffFrames[plate][i]:Hide()
  596. end
  597. end
  598. end
  599.  
  600. UpdateAllBarSizes(plate)
  601. end
  602.  
  603.  
  604. end
  605.  
  606. ----------------------------------------------------------------------------------
  607. function core:AddUnknownIcon(plate) --
  608. -- Display a question mark icon since we don't know the GUID of the plate/mob. --
  609. ----------------------------------------------------------------------------------
  610. if not buffFrames[plate] then
  611. self:BuildBuffFrame(plate, nil, true)
  612. end
  613.  
  614. local i = 1 --eaiser for me to copy/paste code elsewhere.
  615. buffFrames[plate][i].spellName = false
  616. buffFrames[plate][i].expirationTime = 0
  617. buffFrames[plate][i].duration = 1
  618. buffFrames[plate][i].stackCount = 0
  619. buffFrames[plate][i].isDebuff = false
  620. buffFrames[plate][i].debuffType = false
  621. buffFrames[plate][i].playerCast = false
  622.  
  623.  
  624. buffFrames[plate][i].texture:SetTexture("Interface\\Icons\\"..core.unknownIcon)
  625. buffFrames[plate][i].texture:SetTexCoord(.08, .92, .08, .92)
  626.  
  627. if buffFrames[plate][i]:IsShown() then
  628. buffFrames[plate][i]:Hide()
  629. end
  630. buffFrames[plate][i]:Show()
  631.  
  632.  
  633. UpdateAllBarSizes(plate)
  634.  
  635. end
  636.  
  637. function core:UpdateAllFrameLevel()
  638. for plate in pairs(self.buffFrames) do
  639. for i=1, table_getn(self.buffFrames[plate]) do
  640. self:SetFrameLevel( self.buffFrames[plate][i] )
  641. end
  642. end
  643. end
  644.  
  645. function core:SetFrameLevel(frame)
  646. Debug("SetFrameLevel",frame, self.db.profile.frameLevel)
  647. frame:SetFrameLevel( self.db.profile.frameLevel )
  648. frame.cdtexture:SetFrameLevel(self.db.profile.frameLevel + 1)
  649. end
  650.  
  651. ----------------------------------------------------------
  652. function core:ResetAllPlateIcons() --
  653. -- This will reset all the anchors on the spell frames. --
  654. ----------------------------------------------------------
  655. for plate in pairs(buffFrames) do
  656. core:BuildBuffFrame(plate, true)
  657. end
  658. end
  659.  
  660. ------------------------------------------------------
  661. function core:BuildBuffFrame(plate, reset, onlyOne) --
  662. -- Create our buff frames on a plate. --
  663. ------------------------------------------------------
  664.  
  665. --~ local visibleFrame = LibNameplate:GetVisibleFrame(plate)
  666. local visibleFrame = plate
  667. if not buffBars[plate] then
  668. BuildPlateBars(plate, visibleFrame)
  669. end
  670.  
  671. if not buffBars[plate][P.numBars] then--user increased the size.
  672. BuildPlateBars(plate, visibleFrame)
  673. end
  674.  
  675.  
  676. buffFrames[plate] = buffFrames[plate] or {}
  677.  
  678. if reset then
  679. for i=1, table_getn(buffFrames[plate]) do
  680. buffFrames[plate][i]:Hide() --makesure all frames stop OnUpdating.
  681. end
  682.  
  683. --~ for b in pairs(buffBars[plate]) do
  684. --~ buffBars[plate][b]:Hide()
  685. --~ end
  686. end
  687.  
  688. local total = 1 --total number of spell frames
  689. if not buffFrames[plate][total] then
  690. buffFrames[plate][total] = CreateBuffFrame(buffBars[plate][1], plate)
  691. end
  692. buffFrames[plate][total]:SetParent(buffBars[plate][1])--Doing this seems to make UpdateBarSize() function properly. =/
  693.  
  694. buffFrames[plate][total]:ClearAllPoints()
  695. buffFrames[plate][total]:SetPoint("BOTTOMLEFT", buffBars[plate][1]) -- + GetCooldownHeight(buffFrames[plate][1])
  696.  
  697.  
  698. if onlyOne then
  699.  
  700. --[===[@debug@
  701. -- Used to see why my frames were doubling up. think I fixed this in LibNameplate r56
  702. buffFrames[plate][total]:SetScript("OnShow", function(self)
  703.  
  704. if self.realPlate.extended then
  705. Debug("buffFrames OnShow", "buff frame on show!", self.realPlate.extended)
  706. end
  707. end)
  708. --@end-debug@]===]
  709.  
  710.  
  711. --Save CPU cycles not creating every single frame. Lets wait till they're needed.
  712. --~ UpdateBarSize(buffBars[plate][1])
  713. return
  714. end
  715.  
  716.  
  717.  
  718.  
  719. local prevFrame = buffFrames[plate][total]
  720. for i=2, P.iconsPerBar do
  721. total = total + 1
  722. if not buffFrames[plate][total] then
  723. buffFrames[plate][total] = CreateBuffFrame(buffBars[plate][1], plate)
  724. end
  725. buffFrames[plate][total]:SetParent(buffBars[plate][1])
  726.  
  727. buffFrames[plate][total]:ClearAllPoints()
  728. buffFrames[plate][total]:SetPoint("BOTTOMLEFT", prevFrame, "BOTTOMRIGHT")
  729.  
  730. prevFrame = buffFrames[plate][total]
  731. end
  732. --~ UpdateBarSize(buffBars[plate][1])
  733.  
  734.  
  735. if P.numBars > 1 then
  736. for r=2, P.numBars do
  737. for i=1, P.iconsPerBar do
  738. total = total + 1
  739.  
  740. if not buffFrames[plate][total] then
  741. buffFrames[plate][total] = CreateBuffFrame(buffBars[plate][r], plate)
  742. end
  743. buffFrames[plate][total]:SetParent(buffBars[plate][r])
  744.  
  745.  
  746. buffFrames[plate][total]:ClearAllPoints()
  747. if i == 1 then
  748. buffFrames[plate][total]:SetPoint("BOTTOMLEFT", buffBars[plate][r])
  749. else
  750. buffFrames[plate][total]:SetPoint("BOTTOMLEFT", prevFrame, "BOTTOMRIGHT")
  751. end
  752.  
  753. prevFrame = buffFrames[plate][total]
  754. end
  755.  
  756. --~ UpdateBarSize(buffBars[plate][r])
  757. --~ buffBars[plate][r]:Show() --***
  758.  
  759. end
  760. end
  761.  
  762. if not plate.PlateBuffsIsHooked then
  763. -- ChatFrame7:AddMessage("PlateBuffs.BuildBuffFrame(): hooking")
  764. plate.PlateBuffsIsHooked = true
  765. plate:HookScript("OnSizeChanged",
  766. function(self, w, h)
  767. -- ChatFrame7:AddMessage("PlateBuffs.BuildBuffFrame(): " .. tostring(self))
  768. core:ResetPlateBarPoints(self)
  769. end)
  770. end
  771.  
  772. end
  773.  
  774. --------------------------------------------------------------
  775. function core:ResetBarPoint(barFrame, plate, visibleFrame) --
  776. -- Reset a bar's anchor point. --
  777. --------------------------------------------------------------
  778.  
  779. barFrame:ClearAllPoints()
  780.  
  781. --~ buffFrames[plate][i]:SetPoint(P.barAnchorPoint, plate, P.plateAnchorPoint, P.barOffsetX, P.barOffsetY)
  782. --~ local visibleFrame = visibleFrame or LibNameplate:GetVisibleFrame(plate)
  783. local visibleFrame = plate
  784. barFrame:SetParent(visibleFrame)
  785. barFrame:SetPoint(P.barAnchorPoint, visibleFrame, P.plateAnchorPoint, P.barOffsetX, P.barOffsetY) -- + GetCooldownHeight(barFrame)
  786. end
  787.  
  788. --------------------------------------------------------------
  789. function core:ResetIconSizes() --
  790. -- Reset all icon sizes. Called when user changes settings. --
  791. --------------------------------------------------------------
  792.  
  793. local iconSize
  794.  
  795. local frame
  796. for plate in pairs(self.buffFrames) do
  797. for i=1, table_getn(self.buffFrames[plate]) do
  798. frame = self.buffFrames[plate][i]
  799.  
  800. local spellOpts = self:HaveSpellOpts(frame.name)
  801. if frame:IsShown() and spellOpts then
  802. iconSize = spellOpts.iconSize
  803. else
  804. iconSize = P.iconSize
  805. end
  806.  
  807. --~ if frame:IsShown() and P.spellOpts[frame.name] then
  808. --~ iconSize = P.spellOpts[frame.name].iconSize
  809. --~ else
  810. --~ iconSize = P.iconSize
  811. --~ end
  812.  
  813. --Update the spell texture size.
  814. --~ frame.texture:SetWidth(iconSize)
  815. --~ frame.texture:SetHeight(iconSize)
  816.  
  817. frame.icon:SetWidth(iconSize)
  818. frame.icon:SetHeight(iconSize)
  819.  
  820. --~ frame.cdtextureP:SetWidth(iconSize)
  821. --~ frame.cdtextureP:SetHeight(iconSize)
  822.  
  823. --~ frame.cdtexture:SetPoint("CENTER", frame.texture, 0, -1)
  824.  
  825. --Update the frame as a whole, this takes into account the size of the cooldown size.
  826. frame:SetWidth(iconSize)
  827.  
  828. if P.showCooldown == true then
  829. frame:SetHeight(iconSize + frame.cd:GetStringHeight())
  830. else
  831. frame:SetHeight(iconSize)
  832. end
  833. --~ frame:SetScale(1)
  834. end
  835. end
  836. end
  837.  
  838. ----------------------------------------------------------------------
  839. function core:ResetCooldownSize() --
  840. -- Reset cooldown text sizes. Called when user changes settings. --
  841. ----------------------------------------------------------------------
  842. for plate in pairs(buffFrames) do
  843. for i=1, table_getn(buffFrames[plate]) do
  844. --~ buffFrames[plate][i].cd:SetFontObject(core:GetCooldownFont())
  845. local spellOpts = self:HaveSpellOpts(buffFrames[plate][i].spellName)
  846.  
  847. --~ UpdateBuffCDSize(buffFrames[plate][i], buffFrames[plate][i].spellName and P.spellOpts[buffFrames[plate][i].spellName] and P.spellOpts[buffFrames[plate][i].spellName].cooldownSize or P.cooldownSize)
  848. UpdateBuffCDSize(buffFrames[plate][i], buffFrames[plate][i].spellName and spellOpts and spellOpts.cooldownSize or P.cooldownSize)
  849. end
  850. end
  851. end
  852.  
  853.  
  854.  
  855. ----------------------------------
  856. function core:ResetStackSizes() --
  857. -- Update stack text size. --
  858. ----------------------------------
  859. for plate in pairs(buffFrames) do
  860. for i=1, table_getn(buffFrames[plate]) do
  861. local spellOpts = self:HaveSpellOpts(buffFrames[plate][i].spellName)
  862. --~ SetStackSize(buffFrames[plate][i], buffFrames[plate][i].spellName and P.spellOpts[buffFrames[plate][i].spellName] and P.spellOpts[buffFrames[plate][i].spellName].stackSize or P.stackSize)
  863. SetStackSize(buffFrames[plate][i], buffFrames[plate][i].spellName and spellOpts and spellOpts.stackSize or P.stackSize)
  864.  
  865. --~ buffFrames[plate][i].stack:SetFont("Fonts\\FRIZQT__.TTF", P.stackSize, "OUTLINE")
  866. end
  867. end
  868. end
  869.  
  870. --------------------------------------
  871. function core:ResetAllBarPoints() --
  872. -- Reset all bar anchors. --
  873. --------------------------------------
  874. local barPoint = P.barAnchorPoint
  875. local parentPoint = P.plateAnchorPoint
  876.  
  877. if P.barGrowth == 1 then --up
  878. barPoint = string_gsub(barPoint, "TOP", "BOTTOM");
  879. parentPoint = string_gsub(parentPoint, "BOTTOM", "TOP");
  880. else
  881. barPoint = string_gsub(barPoint, "BOTTOM,", "TOP");
  882. parentPoint = string_gsub(parentPoint, "TOP", "BOTTOM");
  883. end
  884.  
  885. for plate in pairs(buffBars) do
  886. self:ResetPlateBarPoints(plate)
  887. end
  888. end
  889.  
  890. --------------------------------------
  891. function core:ResetPlateBarPoints(plate) --
  892. -- Reset bar anchors for a particular plate. --
  893. --------------------------------------
  894. if buffBars[plate][1] then
  895. self:ResetBarPoint(buffBars[plate][1], plate)
  896. end
  897.  
  898. for r=2, table_getn(buffBars[plate]) do
  899. buffBars[plate][r]:ClearAllPoints()
  900. buffBars[plate][r]:SetPoint(P.barAnchorPoint, buffBars[plate][r-1], P.plateAnchorPoint, 0, 0)
  901. end
  902. end
  903.  
  904. ------------------------------------------------------------------
  905. function core:ShowAllKnownSpells() --
  906. -- When we change number of icons to show we hide all icons. --
  907. -- This will reshow the buffs again in their new locations. --
  908. ------------------------------------------------------------------
  909. local GUID
  910. for plate in pairs(buffFrames) do
  911. local GUID = LibNameplate:GetGUID(plate)
  912. if GUID then
  913. self:AddBuffsToPlate(plate, GUID)
  914. else
  915. local plateName = LibNameplate:GetName(plate)
  916. if plateName and nametoGUIDs[plateName] then
  917. self:AddBuffsToPlate(plate, nametoGUIDs[plateName])
  918. end
  919. end
  920. end
  921. end
  922.  
  923.  
  924. --[===[@debug@
  925. function PB_TestSizes()-- /run PB_TestSizes()
  926. local plate = LibNameplate:GetTargetNameplate()
  927. local frame
  928. Debug("TestSizes", "----")
  929. if plate and buffBars[plate] then
  930. for i=1, table_getn(buffBars[plate]) do
  931. frame = buffBars[plate][i]
  932. Debug("TestSizes", i, frame:GetScale(), frame:GetWidth(), frame:GetHeight())
  933. end
  934. --~
  935. end
  936. end
  937.  
  938. --@end-debug@]===]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement