Guest User

Untitled

a guest
May 21st, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. local T, C, L = unpack(Tukui)
  2. if T.myclass ~= 'ROGUE' then return nil end
  3.  
  4. local mod = CreateFrame('StatusBar', 'Tukui_RunicPower', UIParent)
  5. mod:SetScript('OnEvent', function(self, event, ...) return self[event](self, ...) end)
  6. mod:RegisterEvent('ADDON_LOADED')
  7.  
  8. function mod:ADDON_LOADED(addon)
  9. if addon == 'Tukui_RunicPower' then
  10. self:UnregisterEvent('ADDON_LOADED')
  11.  
  12. Tukui_RunicPowerDB = Tukui_RunicPowerDB or {
  13. x = 0,
  14. y = 0,
  15. height = 15,
  16. width = 250,
  17. }
  18.  
  19. self.db = Tukui_RunicPowerDB
  20.  
  21. self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', x, y)
  22. self:SetWidth(self.db.width)
  23. self:SetHeight(self.db.height)
  24. self:SetMovable(true)
  25.  
  26. self:SetWidth(self.db.width)
  27. self:SetHeight(self.db.height)
  28. self:SetStatusBarTexture(C.media.normTex)
  29. self:SetTemplate()
  30. self:CreateShadow()
  31.  
  32. self.label = self:CreateFontString(nil, "ARTWORK")
  33. self.label:SetPoint("CENTER")
  34. self.label:SetFont(C.media.uffont, 17, "OUTLINE")
  35. self.label:SetJustifyH("CENTER")
  36.  
  37. self:SetScript('OnMouseDown', self.OnMouseDown)
  38. self:SetScript('OnMouseUp', self.OnMouseUp)
  39.  
  40. self:RegisterEvent('UNIT_POWER')
  41. self:UNIT_POWER('player') -- call this instead of directly calling ResyncValues as a sanity check
  42.  
  43. self.InitializeSavedVariables = nil
  44. self.SetupSlashCommand = nil
  45. self.ADDON_LOADED = nil
  46.  
  47. return true
  48. end
  49. end
  50.  
  51. function mod:UNIT_POWER(unit)
  52. return unit == 'player' and self:ResyncValues()
  53. end
  54.  
  55. function mod:OnMouseDown()
  56. if IsShiftKeyDown() then
  57. self:StartMoving()
  58. self.__moving = true
  59. return true
  60. end
  61. end
  62.  
  63. function mod:OnMouseUp()
  64. if self.__moving then
  65. self:StopMovingOrSizing()
  66. self.__moving = nil
  67.  
  68. self.db.x = self:GetLeft()
  69. self.db.y = self:GetTop()
  70.  
  71. return true
  72. end
  73. end
  74.  
  75. function mod:SetSize(w, h)
  76. w, h = tonumber(w), tonumber(h)
  77.  
  78. self:SetWidth(w)
  79. self:SetHeight(h)
  80.  
  81. self.db.width = w
  82. self.db.height = h
  83.  
  84. return true
  85. end
  86.  
  87. function mod:ResyncValues()
  88. local current, max = UnitPower('player'), UnitPowerMax('player')
  89. self:SetMinMaxValues(0, max)
  90. self:SetValue(current)
  91. self:SetStatusBarColor(1-current/max, 0.3, current/max, 1)
  92. self.label:SetText(current)
  93. return true
  94. end
  95.  
  96. SLASH_TUKUIRP1 = '/tukuirp'
  97. SlashCmdList.TUKUIRP = function(msg)
  98. return mod:SetSize(strsplit('x', msg))
  99. end
Add Comment
Please, Sign In to add comment