Guest User

Untitled

a guest
Oct 15th, 2020
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.86 KB | None | 0 0
  1. SimplePowerBar = LibStub("AceAddon-3.0"):NewAddon("SimplePowerBar", "AceConsole-3.0");
  2. local PPBA = PlayerPowerBarAlt
  3. local Addon = GetAddOnMetadata("SimplePowerBar", "Title");
  4. local Media = LibStub("LibSharedMedia-3.0");
  5. local db, unit, spb, mover;
  6. local RAID_CLASS_COLORS = _G.RAID_CLASS_COLORS
  7. unit = "player"
  8. local _,Class = UnitClass(unit)
  9.  
  10. local path = "INTERFACE\\UNITPOWERBARALT\\"
  11. local blizzColors = {
  12. [path.."STONEGUARDAMETHYST_HORIZONTAL_FILL.BLP"] = {
  13. r = 0.50,
  14. g = 0.45,
  15. b = 0.75,
  16. },
  17. [path.."STONEGUARDCOBALT_HORIZONTAL_FILL.BLP"] = {
  18. r = 0.35,
  19. g = 0.66,
  20. b = 0.78,
  21. },
  22. [path.."STONEGUARDJADE_HORIZONTAL_FILL.BLP"] = {
  23. r = 0.48,
  24. g = 0.75,
  25. b = 0.47,
  26. },
  27. [path.."STONEGUARDJASPER_HORIZONTAL_FILL.BLP"] = {
  28. r = 0.72,
  29. g = 0.48,
  30. b = 0.48,
  31. }
  32. }
  33.  
  34.  
  35. -- Tester Frame --
  36. SimplePowerBar.tester = CreateFrame("Frame", BackdropTemplateMixin and 'BackdropTemplate')
  37. SimplePowerBar.tester.interval = 1
  38. SimplePowerBar.tester.enabled = false
  39. SimplePowerBar.tester.Enable = function()
  40. SimplePowerBar.tester.enabled = true
  41. SimplePowerBar.tester:SetScript("OnUpdate", function(self,elapsed)
  42. SimplePowerBar.tester.interval = SimplePowerBar.tester.interval - elapsed
  43. if SimplePowerBar.tester.interval < 0 then
  44. SimplePowerBar:Update()
  45. SimplePowerBar.tester.interval = 1
  46. end
  47. end)
  48. end
  49. SimplePowerBar.tester.Disable = function()
  50. SimplePowerBar.tester:SetScript("OnUpdate", nil)
  51. SimplePowerBar.tester.interval = 1
  52. SimplePowerBar.tester.enabled = false
  53. SimplePowerBar:Update()
  54. end
  55.  
  56. function SimplePowerBar:OnInitialize()
  57. local defaults = {
  58. profile = {
  59. -- Looks
  60. StatusTex = "ChiselLight",
  61. Orientation = "HORIZONTAL",
  62. border = "Pixel",
  63. bg = "Solid",
  64. tile = false,
  65. tileSize = 0,
  66. borderSize = 1,
  67. borderInset = 1,
  68. frameStrata = "BACKGROUND",
  69. frameLevel = 1,
  70. anchor = "CENTER",
  71. alpha = 1,
  72. width = 128,
  73. height = 24,
  74. x = 0,
  75. y = -220,
  76. -- Settings
  77. amount = true,
  78. level = true,
  79. percent = true,
  80. label = true,
  81. locked = false,
  82. test = false,
  83. useBlizz = false,
  84. debug = false,
  85. -- Coloring config
  86. statusClass = false,
  87. statusBlizz = true,
  88. backdropClass = false,
  89. borderClass = false,
  90. sbbgMaxEnabled = false,
  91. sbMaxEnabled = false,
  92. sbtMaxEnabled = false,
  93. sbbMaxEnabled = false,
  94. ltMaxEnabled = false,
  95. fade = true,
  96. StatusBarText = {
  97. font = "Arial Narrow",
  98. size = 8,
  99. align = "CENTER",
  100. anchor = "CENTER",
  101. style = "NONE",
  102. colorClass = false,
  103. color = {
  104. r = 1,
  105. g = 1,
  106. b = 1,
  107. a = 1,
  108. },
  109. shadow = {
  110. r = 0,
  111. g = 0,
  112. b = 0,
  113. a = 1,
  114. },
  115. shadowOffset = 1,
  116. ofx = 0,
  117. ofy = 0,
  118. MaxColor = {
  119. r = 1,
  120. g = 0,
  121. b = 0,
  122. },
  123. },
  124. LabelText = {
  125. font = "Arial Narrow",
  126. size = 8,
  127. align = "BOTTOM",
  128. anchor = "TOP",
  129. style = "NONE",
  130. colorClass = false,
  131. color = {
  132. r = 1,
  133. g = 1,
  134. b = 1,
  135. a = 1,
  136. },
  137. shadow = {
  138. r = 0,
  139. g = 0,
  140. b = 0,
  141. a = 1,
  142. },
  143. shadowOffset = 1,
  144. ofx = 0,
  145. ofy = 2,
  146. MaxColor = {
  147. r = 1,
  148. g = 0,
  149. b = 0,
  150. },
  151. },
  152. StatusColor = {
  153. r = 0.4,
  154. g = 0.4,
  155. b = 0.4,
  156. a = 1,
  157. MaxColor = {
  158. r = 1,
  159. g = 0,
  160. b = 0,
  161. },
  162. },
  163. StatusLow = {
  164. r = 1,
  165. g = 0,
  166. b = 0,
  167. },
  168. StatusHigh = {
  169. r = 0,
  170. g = 1,
  171. b = 0,
  172. },
  173. BorderColor = {
  174. r = 0,
  175. g = 0,
  176. b = 0,
  177. a = 1,
  178. MaxColor = {
  179. r = 1,
  180. g = 0,
  181. b = 0,
  182. },
  183. },
  184. BackgroundColor = {
  185. r = 0.2,
  186. g = 0.2,
  187. b = 0.2,
  188. a = 0.5,
  189. MaxColor = {
  190. r = 1,
  191. g = 0,
  192. b = 0,
  193. },
  194. },
  195. }
  196. }
  197. db = LibStub("AceDB-3.0"):New("SimpPB_DB",defaults,"Default")
  198. self.db = db
  199. local RegisterCallback = db.RegisterCallback
  200. RegisterCallback(self, "OnProfileChanged", "FullUpdate")
  201. RegisterCallback(self, "OnProfileCopied", "FullUpdate")
  202. RegisterCallback(self, "OnProfileReset", "FullUpdate")
  203.  
  204. db = self.db.profile
  205.  
  206. self:CreatePowerBar()
  207. self:CreateBlizzMover()
  208. self:SetUpInitialOptions()
  209. self:FullUpdate()
  210.  
  211. local commands = {}
  212. commands.lock = function()
  213. db.locked = not db.locked
  214. if db.locked then
  215. print(Addon..": Locked")
  216. else
  217. print(Addon..": Unlocked")
  218. end
  219. end
  220.  
  221. commands.fade = function()
  222. db.fade = not db.fade
  223. if db.fade then
  224. print(Addon..": Color fade enabled.")
  225. else
  226. print(Addon..": Color fade disabled.")
  227. end
  228. end
  229. commands.test = function()
  230. db.test = not db.test
  231. if db.test then
  232. self.tester:Enable()
  233. print(Addon..": Test mode enabled.")
  234.  
  235. else
  236. self.tester:Disable()
  237. print(Addon..": Test mode disabled.")
  238. end
  239. end
  240. commands.blizz = function()
  241. db.useBlizz = not db.useBlizz
  242. if db.useBlizz then
  243. print(Addon..": Blizzard frames enabled.")
  244. else
  245. print(Addon..": Blizzard frames disabled.")
  246. end
  247. end
  248. commands.debug = function()
  249. db.debug = not db.debug
  250. if db.debug then
  251. print(Addon..": Debugging enabled.")
  252. else
  253. print(Addon..": Debugging disabled.")
  254. end
  255. end
  256.  
  257. commands.help = function()
  258. print(Addon.." Commands available:")
  259. print("'/spb lock' -- Allows you to drag the frame and place it with the mouse or lock it in place.")
  260. print("'/spb fade' -- Allows the color to fade according to amount of power.")
  261. print("'/spb blizz' -- Allows the usage of the default Blizzard frames.")
  262. print("'/spb test' -- Allows you to test the bar and its looks.")
  263. print("'/spb debug' -- Allows the debugging mode to be enabled or disabled.")
  264. print("'/spb about' -- Shows additional information about the addon.")
  265. end
  266.  
  267. commands.about = function()
  268. print(Addon..": Created by Suicidal Katt, based off of '|cffC495DDSmelly|r Power Bar' by Smelly.")
  269. end
  270.  
  271. local function slashHandler(arg)
  272. local arg1, arg2, arg3 = strsplit(" ", arg, 3)
  273. if arg1 then
  274. if type(commands[arg1]) == "function" then
  275. commands[arg1](arg2)
  276. SimplePowerBar:FullUpdate()
  277. else
  278. print(Addon..": Type '/spb help' for a list of commands.")
  279. SimplePowerBar:OpenOptions()
  280. end
  281. end
  282. end
  283. SLASH_SIMPPB1 = "/spb"
  284. SlashCmdList["SIMPPB"] = slashHandler
  285. end
  286.  
  287. -- Create Statusbar Frame
  288. function SimplePowerBar:CreatePowerBar()
  289. db = self.db.profile
  290.  
  291. spb = CreateFrame("Frame", "SPB_APB", UIParent, BackdropTemplateMixin and 'BackdropTemplate')
  292.  
  293. spb:SetBackdrop({
  294. bgFile = Media:Fetch("background",db.bg),
  295. edgeFile = Media:Fetch("border",db.border),
  296. tile = db.tile, tileSize = db.tileSize, edgeSize = db.borderSize,
  297. insets = { left = db.borderInset, right = db.borderInset, top = db.borderInset, bottom = db.borderInset}
  298. })
  299. spb:SetHeight(db.height)
  300. spb:SetWidth(db.width)
  301. spb:SetPoint("CENTER",UIParent,"CENTER", db.x, db.y)
  302.  
  303. spb:SetFrameStrata(db.frameStrata)
  304. spb:SetFrameLevel(db.frameLevel)
  305.  
  306. spb:SetMovable(true)
  307. spb:SetClampedToScreen(true)
  308. spb:SetUserPlaced(true)
  309.  
  310. spb.lock = spb:CreateTexture(nil,"OVERLAY")
  311. spb.lock:SetTexture("Interface\\GLUES\\CharacterSelect\\Glues-AddOn-Icons")
  312. spb.lock:SetWidth(8)
  313. spb.lock:SetHeight(8)
  314. spb.lock:SetTexCoord(0.25,0.48,0,1)
  315. spb.lock:SetPoint("CENTER", spb, "TOPRIGHT")
  316.  
  317. spb.Unlock = function()
  318. spb:Show()
  319. spb.lock:Show()
  320. spb:EnableMouse(true)
  321. spb:RegisterForDrag("LeftButton")
  322. spb:SetScript("OnDragStart", spb.StartMoving)
  323. spb:SetScript("OnDragStop", function()
  324. spb:StopMovingOrSizing()
  325. db.anchor,_,_,db.x,db.y = spb:GetPoint()
  326. self:FullUpdate()
  327. end)
  328. end
  329.  
  330. spb.Lock = function ()
  331. spb:EnableMouse(false)
  332. spb.lock:Hide()
  333. spb:SetScript("OnDragStart", nil)
  334. spb:SetScript("OnDragStop", nil)
  335. end
  336.  
  337.  
  338. spb.power = spb:CreateFontString(nil, "OVERLAY")
  339. spb.power:SetFont(Media:Fetch("font", db.StatusBarText.font), db.StatusBarText.size, db.StatusBarText.style)
  340.  
  341. spb.label = spb:CreateFontString(nil, "OVERLAY")
  342. spb.label:SetFont(Media:Fetch("font", db.LabelText.font), db.LabelText.size, db.LabelText.style)
  343.  
  344. spb.bar = CreateFrame("StatusBar", nil, spb, BackdropTemplateMixin and 'BackdropTemplate')
  345. spb.bar:SetPoint("TOPLEFT", spb, "TOPLEFT", db.borderInset, -db.borderInset)
  346. spb.bar:SetPoint("BOTTOMRIGHT", spb, "BOTTOMRIGHT", -db.borderInset, db.borderInset)
  347. spb.bar:SetFrameStrata(spb:GetFrameStrata())
  348. spb.bar:SetFrameLevel(spb:GetFrameLevel())
  349.  
  350. spb.max = false -- Used for 'if max then' coloring.
  351. end
  352.  
  353. -- Create Blizzard Mover
  354.  
  355. function SimplePowerBar:CreateBlizzMover()
  356. db = self.db.profile
  357.  
  358. mover = CreateFrame("Frame", "SPB_MOVER", UIParent, BackdropTemplateMixin and 'BackdropTemplate')
  359. mover:SetSize(128, 20)
  360. mover:SetPoint("CENTER",UIParent,"CENTER", db.x, db.y)
  361. mover:SetFrameStrata("BACKGROUND")
  362. mover:SetMovable(true)
  363. mover:SetClampedToScreen(true)
  364. mover:SetUserPlaced(true)
  365.  
  366. local overlay = CreateFrame("Frame",nil,mover, BackdropTemplateMixin and 'BackdropTemplate')
  367. overlay:SetPoint("CENTER",mover,"CENTER")
  368. overlay:SetSize(mover:GetSize())
  369. overlay:SetFrameStrata("HIGH")
  370. overlay:SetFrameLevel(5)
  371.  
  372. overlay.bg = overlay:CreateTexture(nil,"HIGH")
  373. overlay.bg:SetTexture(0.36,0.7,1,1)
  374. overlay.bg:SetAllPoints(overlay)
  375.  
  376. overlay.texture = overlay:CreateTexture(nil,"OVERLAY")
  377. overlay.texture:SetTexture("Interface\\AddOns\\SimplePowerBar\\Textures\\Statusbar")
  378. overlay.texture:SetVertexColor(0.3,0.3,0.3,1)
  379. overlay.texture:SetPoint("TOPLEFT", overlay, "TOPLEFT", 1, -1)
  380. overlay.texture:SetPoint("BOTTOMRIGHT", overlay, "BOTTOMRIGHT", -1, 1)
  381.  
  382. overlay.text = overlay:CreateFontString(nil,"OVERLAY")
  383. overlay.text:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
  384. overlay.text:SetPoint("CENTER",overlay.texture,"CENTER")
  385. overlay.text:SetText("Drag me!")
  386.  
  387. mover.Unlock = function()
  388. mover:Show()
  389. overlay:Show()
  390. mover:EnableMouse(true)
  391. mover:RegisterForDrag("LeftButton")
  392. mover:SetScript("OnDragStart", mover.StartMoving)
  393. mover:SetScript("OnDragStop", function()
  394. mover:StopMovingOrSizing()
  395. db.anchor,_,_,db.x,db.y = mover:GetPoint()
  396. self:FullUpdate()
  397. end)
  398. end
  399. mover.Lock = function()
  400. overlay:Hide()
  401. mover:EnableMouse(false)
  402. mover:SetScript("OnDragStart", nil)
  403. mover:SetScript("OnDragStop", nil)
  404. end
  405.  
  406. PPBA:ClearAllPoints()
  407. PPBA:SetPoint("CENTER", mover, "CENTER")
  408. PPBA:SetParent(mover)
  409. PPBA:EnableMouse(false)
  410. local hook = function()
  411. PPBA:SetPoint("CENTER", mover, "CENTER")
  412. end
  413. PPBA.ignoreFramePositionManager = true
  414. end
  415. -- Locking
  416. function SimplePowerBar:Unlock()
  417. db = self.db.profile
  418. if db.useBlizz then
  419. mover:Unlock()
  420. else
  421. spb:Unlock()
  422. end
  423. end
  424.  
  425. function SimplePowerBar:Lock()
  426. db = self.db.profile
  427. if db.useBlizz then
  428. mover:Lock()
  429. else
  430. spb:Lock()
  431. end
  432. if not unit or unit ~= PPBA.unit then
  433. unit = PPBA.unit
  434. end
  435. if not GetUnitPowerBarInfo(unit) then mover:Hide();spb:Hide() end
  436. end
  437. -- Updaters
  438. function SimplePowerBar:Update()
  439. db = self.db.profile
  440. if not PPBA:IsShown() then PPBA:Show() end -- Here we're going to make sure the frame is properly parented to the mover
  441.  
  442. if not unit or unit ~= PPBA.unit then
  443. unit = PPBA.unit
  444. end
  445. if GetUnitPowerBarInfo(unit) then -- If no power watched hide, if still unlocked the unlock function will reshow the correct frame.
  446. if db.useBlizz then
  447. if spb:IsShown() then spb:Hide(); end
  448. if not mover:IsShown() then mover:Show(); end
  449. else
  450. if not spb:IsShown() then spb:Show(); end
  451. if mover:IsShown() then mover:Hide(); end
  452. end
  453. else
  454. spb:Hide();
  455. mover:Hide();
  456. end
  457. if db.test then
  458. if not SimplePowerBar.tester.enabled then SimplePowerBar.tester:Enable() end
  459. self.label = "Test Mode Enabled!"
  460. self.power = random(35,100)
  461. self.mpower = 100
  462. else
  463. if SimplePowerBar.tester.enabled then SimplePowerBar.tester:Disable() end
  464. self.label = select(10,GetUnitPowerBarInfo(unit)) or ""
  465. self.power, self.mpower = UnitPower(unit, ALTERNATE_POWER_INDEX), UnitPowerMax(unit, ALTERNATE_POWER_INDEX)
  466. end
  467. if self.power == self.mpower then
  468. self.max = true
  469. else
  470. self.max = false
  471. end
  472. self:LabelTextUpdate(self.label)
  473. self:ValueTextUpdate(self.power,self.mpower)
  474. self:StatusBarUpdate(self.power,self.mpower)
  475. -- Reshow unlocked frame.
  476. if db.locked then
  477. self:Lock()
  478. else
  479. self:Unlock()
  480. end
  481. end
  482.  
  483. function SimplePowerBar:FullUpdate()
  484. db = self.db.profile
  485. -- Update for lock changes
  486. self:Update()
  487. -- SPB
  488. spb:SetBackdrop({
  489. bgFile = Media:Fetch("background",db.bg),
  490. edgeFile = Media:Fetch("border",db.border),
  491. tile = db.tile, tileSize = db.tileSize, edgeSize = db.borderSize,
  492. insets = { left = db.borderInset, right = db.borderInset, top = db.borderInset, bottom = db.borderInset}
  493. })
  494. if db.backdropClass then
  495. local color = RAID_CLASS_COLORS[Class]
  496. spb:SetBackdropColor(color.r,color.g,color.b,db.BackgroundColor.a)
  497. else
  498. spb:SetBackdropColor(db.BackgroundColor.r,db.BackgroundColor.g,db.BackgroundColor.b,db.BackgroundColor.a)
  499. end
  500. if db.borderClass then
  501. local color = RAID_CLASS_COLORS[Class]
  502. spb:SetBackdropBorderColor(color.r,color.g,color.b,db.BorderColor.a)
  503. else
  504. spb:SetBackdropBorderColor(db.BorderColor.r,db.BorderColor.g,db.BorderColor.b,db.BorderColor.a)
  505. end
  506. spb:SetHeight(db.height)
  507. spb:SetWidth(db.width)
  508. spb:ClearAllPoints()
  509. spb:SetPoint(db.anchor,UIParent,db.anchor, db.x, db.y)
  510. spb:SetFrameStrata(db.frameStrata)
  511. spb:SetFrameLevel(db.frameLevel)
  512. -- Mover
  513. mover:ClearAllPoints()
  514. mover:SetPoint(db.anchor,UIParent,db.anchor, db.x, db.y)
  515. -- StatusBar
  516. spb.bar:SetStatusBarTexture(Media:Fetch("statusbar",db.StatusTex))
  517. spb.bar:SetPoint("TOPLEFT", spb, "TOPLEFT", db.borderInset, -db.borderInset)
  518. spb.bar:SetPoint("BOTTOMRIGHT", spb, "BOTTOMRIGHT", -db.borderInset, db.borderInset)
  519. spb.bar:SetOrientation(db.Orientation)
  520. spb.bar:SetFrameStrata(spb:GetFrameStrata())
  521. spb.bar:SetFrameLevel(spb:GetFrameLevel())
  522. -- BarText
  523. spb.power:SetFont(Media:Fetch("font", db.StatusBarText.font), db.StatusBarText.size, db.StatusBarText.style)
  524. spb.power:ClearAllPoints()
  525. spb.power:SetPoint(db.StatusBarText.align, spb, db.StatusBarText.anchor, db.StatusBarText.ofx, db.StatusBarText.ofy)
  526. spb.power:SetShadowColor(db.StatusBarText.shadow.r,db.StatusBarText.shadow.g,db.StatusBarText.shadow.b,db.StatusBarText.shadow.a)
  527. if db.StatusBarText.colorClass then
  528. local color = RAID_CLASS_COLORS[Class]
  529. spb.power:SetTextColor(color.r,color.g,color.b,db.StatusBarText.color.a)
  530. else
  531. spb.power:SetTextColor(db.StatusBarText.color.r,db.StatusBarText.color.g,db.StatusBarText.color.b,db.StatusBarText.color.a)
  532. end
  533. spb.power:SetShadowOffset(db.StatusBarText.shadowOffset,-(db.StatusBarText.shadowOffset))
  534. -- Label
  535. spb.label:SetFont(Media:Fetch("font", db.LabelText.font), db.LabelText.size, db.LabelText.style)
  536. spb.label:ClearAllPoints()
  537. spb.label:SetPoint(db.LabelText.align, spb, db.LabelText.anchor, db.LabelText.ofx, db.LabelText.ofy)
  538. spb.label:SetShadowColor(db.LabelText.shadow.r,db.LabelText.shadow.g,db.LabelText.shadow.b,db.LabelText.shadow.a)
  539. if db.LabelText.colorClass then
  540. local color = RAID_CLASS_COLORS[Class]
  541. spb.label:SetTextColor(color.r,color.g,color.b,db.LabelText.color.a)
  542. else
  543. spb.label:SetTextColor(db.LabelText.color.r,db.LabelText.color.g,db.LabelText.color.b,db.LabelText.color.a)
  544. end
  545. -- Coloring
  546. if self.max then
  547.  
  548. else
  549.  
  550. end
  551. spb.label:SetShadowOffset(db.LabelText.shadowOffset,-(db.LabelText.shadowOffset))
  552. end
  553.  
  554. local CS = CreateFrame("ColorSelect", BackdropTemplateMixin and 'BackdropTemplate')
  555. function CS:GetSmudgeColorRGB(colorA, colorB, perc)
  556. self:SetColorRGB(colorA.r,colorA.g,colorA.b)
  557. local h1, s1, v1 = self:GetColorHSV()
  558. self:SetColorRGB(colorB.r,colorB.g,colorB.b)
  559. local h2, s2, v2 = self:GetColorHSV()
  560. local h3 = floor(h1-(h1-h2)*perc)
  561. if abs(h1-h2) > 180 then
  562. local radius = (360-abs(h1-h2))*perc/100
  563. if h1 < h2 then
  564. h3 = floor(h1-radius)
  565. if h3 < 0 then
  566. h3 = 360+h3
  567. end
  568. else
  569. h3 = floor(h1+radius)
  570. if h3 > 360 then
  571. h3 = h3-360
  572. end
  573. end
  574. end
  575. local s3 = s1-(s1-s2)*perc
  576. local v3 = v1-(v1-v2)*perc
  577. self:SetColorHSV(h3, s3, v3)
  578. local r,g,b = self:GetColorRGB()
  579. return r,g,b
  580. end
  581.  
  582. function SimplePowerBar:StatusBarUpdate(power,mpower)
  583. local r,g,b,a
  584. db = self.db.profile
  585. spb.bar:SetMinMaxValues(0, mpower)
  586. spb.bar:SetValue(power)
  587. local perc = mpower > 0 and power/mpower or 0
  588. if power == mpower and db.sbMaxEnabled then
  589. local s = db.StatusColor.MaxColor
  590. r,g,b = s.r,s.g,s.b
  591. else
  592. if db.fade then
  593. r,g,b = CS:GetSmudgeColorRGB(db.StatusLow,db.StatusHigh,perc)
  594. else
  595. local c = {}
  596. if db.statusClass then
  597. c = RAID_CLASS_COLORS[Class]
  598. elseif not db.statusClass and db.statusBlizz then
  599. local texture, r, g, b = UnitAlternatePowerTextureInfo(unit,2,0) -- 0 Here indicates the current displayed bar.
  600. if blizzColors[texture] then
  601. c = blizzColors[texture]
  602. else
  603. c.r,c.g,c.b = r,g,b
  604. end
  605. else
  606. c = db.StatusColor
  607. end
  608. r,g,b = c.r,c.g,c.b
  609. end
  610. end
  611. a = db.StatusColor.a
  612. spb.bar:SetStatusBarColor(r,g,b,a)
  613. end
  614.  
  615. function SimplePowerBar:LabelTextUpdate(text)
  616. db = self.db.profile
  617. if text and db.label then
  618. spb.label:SetText(text)
  619. else
  620. spb.label:SetText("")
  621. end
  622. end
  623.  
  624. function SimplePowerBar:ValueTextUpdate(power,mpower)
  625. db = self.db.profile
  626. local text, level, percent
  627. local perc = mpower > 0 and floor(power/mpower*100) or 0
  628. if db.amount then
  629. if db.level then
  630. level = power.."/"..mpower
  631. else
  632. level = ""
  633. end
  634. if db.percent and mpower > 0 then
  635. if db.level then
  636. percent = " - "..perc.."%"
  637. else
  638. percent = perc.."%"
  639. end
  640. else
  641. percent = ""
  642. end
  643. text = format("%s%s",level,percent)
  644. else
  645. text = ""
  646. end
  647. spb.power:SetText(text)
  648. end
  649.  
  650. -- Event Handling
  651.  
  652. local EventHandler = CreateFrame("frame")
  653. EventHandler:RegisterEvent("ADDON_LOADED")
  654. EventHandler:SetScript("OnEvent", function(self,event,...)
  655. local arg1,arg2,arg3,arg4 = ...
  656. db = SimplePowerBar.db.profile
  657. if event == "ADDON_LOADED" and arg1 == "SimplePowerBar" then
  658. self:UnregisterEvent("ADDON_LOADED")
  659. self:RegisterEvent("UNIT_POWER_BAR_TIMER_UPDATE")
  660. self:RegisterEvent("UNIT_POWER_BAR_SHOW")
  661. self:RegisterEvent("UNIT_POWER_BAR_HIDE")
  662. self:RegisterEvent("UNIT_POWER_UPDATE")
  663. self:RegisterEvent("UNIT_MAXPOWER")
  664. self:RegisterEvent("PLAYER_REGEN_DISABLED")
  665. self:RegisterEvent("PLAYER_REGEN_ENABLED")
  666. elseif (event == "UNIT_POWER_UPDATE" or event == "UNIT_MAXPOWER") and arg2 == "ALTERNATE" then
  667. if not unit or unit ~= PPBA.unit then
  668. unit = PPBA.unit
  669. end
  670. if unit == arg1 then
  671. SimplePowerBar:Update()
  672. end
  673. elseif event == "UNIT_POWER_BAR_SHOW" then
  674. self:RegisterEvent("UNIT_POWER_UPDATE")
  675. self:RegisterEvent("UNIT_MAXPOWER")
  676.  
  677. SimplePowerBar:Update()
  678.  
  679. elseif event == "UNIT_POWER_BAR_HIDE" then
  680. self:UnregisterEvent("UNIT_POWER_UPDATE")
  681. self:UnregisterEvent("UNIT_MAXPOWER")
  682.  
  683. SimplePowerBar:Update()
  684.  
  685. elseif event == "UNIT_POWER_BAR_TIMER_UPDATE" then
  686. --[[if arg1 == "player" then
  687. local index = 1
  688. local duration, expiration, barID, auraID = UnitPowerBarTimerInfo("player", index);
  689. while barID do
  690. local barType, minPower, startInset, endInset, smooth, hideFromOthers, showOnRaid, opaqueSpark, opaqueFlash, powerName, powerTooltip, costString = GetAlternatePowerInfoByID(barID);
  691. if barType and barType ~= 4 then
  692. print("BarID: "..barID.." BarType: "..barType.." AuraID: "..auraID)
  693. end
  694. index = index + 1
  695. duration, expiration, barID, auraID = UnitPowerBarTimerInfo("player", index);
  696. end
  697. end]]--
  698. elseif event == "PLAYER_REGEN_DISABLED" or event == "PLAYER_REGEN_ENABLED" then
  699.  
  700. SimplePowerBar:Update()
  701.  
  702. end
  703. if db.debug then
  704. if arg2 then
  705. print(event.." "..arg1.." "..arg2)
  706. elseif arg1 and not arg2 then
  707. print(event.." "..arg1)
  708. elseif not arg1 and not arg2 then
  709. print(event)
  710. end
  711. end
  712. end)
  713. SimplePowerBar.EventHandler = EventHandler
Advertisement
Add Comment
Please, Sign In to add comment