PageRenderTime 16ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/Tukui/modules/databars/currency.lua

http://github.com/Asphyxia/Tukui
Lua | 133 lines | 115 code | 17 blank | 1 comment | 12 complexity | 2fc1f3c6ce7b5e777f4bb43ab7619c37 MD5 | raw file
  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. if C["databars"].currency == true then
  3. -- CURRENCY DATA BARS
  4. local CurrencyData = {}
  5. local tokens = {
  6. {61, 250}, -- Dalaran Jewelcrafter's Token
  7. {81, 250}, -- Dalaran Cooking Award
  8. {241, 250}, -- Champion Seal
  9. {361, 200}, -- Illustrious Jewelcrafter's Token
  10. {390, 3000}, -- Conquest Points
  11. {391, 2000}, -- Tol Barad Commendation
  12. {392, 4000}, -- Honor Points
  13. {395, 4000}, -- Justice Points
  14. {396, 4000}, -- Valor Points
  15. {402, 10}, -- Chef's Award
  16. {416, 300}, -- Mark of the World Tree
  17. }
  18. local function updateCurrency()
  19. if CurrencyData[1] then
  20. for i = 1, getn(CurrencyData) do
  21. CurrencyData[i]:Kill()
  22. end
  23. wipe(CurrencyData)
  24. end
  25. for i, v in ipairs(tokens) do
  26. local id, max = unpack(v)
  27. local name, amount, icon = GetCurrencyInfo(id)
  28. local r, g, b = oUFTukui.ColorGradient(amount/max, 0,.8,0,.8,.8,0,.8,0,0)
  29. if name and amount > 0 then
  30. local frame = CreateFrame("Frame", "CurrencyData"..id, UIParent)
  31. frame:CreatePanel("Transparent", 120, 20, "CENTER", UIParent, "CENTER", 0, 0)
  32. frame:EnableMouse(true)
  33. frame:CreateShadow("Default")
  34. frame:Animate(-140, 0, 0.4)
  35. frame:Hide()
  36. frame.Status = CreateFrame("StatusBar", "CurrencyDataStatus"..id, frame)
  37. frame.Status:SetFrameLevel(12)
  38. frame.Status:SetStatusBarTexture((C["media"].raidTex) or (C["media"].normTex))
  39. frame.Status:SetMinMaxValues(0, max)
  40. frame.Status:SetValue(amount)
  41. frame.Status:SetStatusBarColor(r, g, b, 1)
  42. frame.Status:Point("TOPLEFT", frame, "TOPLEFT", 2, -2)
  43. frame.Status:Point("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2)
  44. frame.Text = frame.Status:CreateFontString(nil, "OVERLAY")
  45. frame.Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  46. frame.Text:Point("CENTER", frame, "CENTER", 0, 2)
  47. frame.Text:Width(frame:GetWidth() - 4)
  48. frame.Text:SetShadowColor(0, 0, 0)
  49. frame.Text:SetShadowOffset(1.25, -1.25)
  50. frame.Text:SetText(format("%s / %s", amount, max))
  51. frame.IconBG = CreateFrame("Frame", "CurrencyDataIconBG"..id, frame)
  52. frame.IconBG:CreatePanel(nil, 20, 20, "BOTTOMLEFT", frame, "BOTTOMRIGHT", T.Scale(3), 0)
  53. frame.Icon = frame.IconBG:CreateTexture(nil, "ARTWORK")
  54. frame.Icon:Point("TOPLEFT", frame.IconBG, "TOPLEFT", 4, -2)
  55. frame.Icon:Point("BOTTOMRIGHT", frame.IconBG, "BOTTOMRIGHT", -2, 2)
  56. frame.IconBG:CreateShadow("Default")
  57. frame.Icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
  58. frame.Icon:SetTexture("Interface\\Icons\\"..icon)
  59. frame:SetScript("OnEnter", function(self) frame.Text:SetText(format("%s", name)) end)
  60. frame:SetScript("OnLeave", function(self) frame.Text:SetText(format("%s / %s", amount, max)) end)
  61. tinsert(CurrencyData, frame)
  62. end
  63. end
  64. for key, frame in ipairs(CurrencyData) do
  65. frame:ClearAllPoints()
  66. if key == 1 then
  67. frame:Point("TOPLEFT", UIParent, "TOPLEFT", 3, -30)
  68. else
  69. frame:Point("TOP", CurrencyData[key-1], "BOTTOM", 0, -3)
  70. end
  71. end
  72. end
  73. local function ModifiedBackdrop(self)
  74. local color = RAID_CLASS_COLORS[T.myclass]
  75. self:SetBackdropColor(unpack(C["media"].backdropcolor))
  76. self:SetBackdropBorderColor(color.r, color.g, color.b)
  77. end
  78. local function OriginalBackdrop(self)
  79. self:SetBackdropColor(unpack(C["media"].backdropcolor))
  80. self:SetBackdropBorderColor(unpack(C["media"].bordercolor))
  81. end
  82. local toggle = CreateFrame("Frame", "CurrencyToggle", UIParent)
  83. toggle:CreatePanel("Default", 30, 15, "TOPRIGHT", TukuiChatBackgroundRight, "TOPRIGHT", -2, -84)
  84. toggle:EnableMouse(true)
  85. toggle:SetFrameStrata("MEDIUM")
  86. toggle:SetFrameLevel(2)
  87. toggle:CreateOverlay(toggle)
  88. toggle:CreateShadow("Default")
  89. toggle:SetAlpha(0)
  90. toggle:HookScript("OnEnter", ModifiedBackdrop)
  91. toggle:HookScript("OnLeave", OriginalBackdrop)
  92. toggle:SetScript("OnEnter", function()
  93. if InCombatLockdown() then return end
  94. toggle:FadeIn()
  95. end)
  96. toggle:SetScript("OnLeave", function()
  97. toggle:FadeOut()
  98. end)
  99. toggle.Text = toggle:CreateFontString(nil, "OVERLAY")
  100. toggle.Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  101. toggle.Text:Point("CENTER", toggle, "CENTER", 1.5, 1)
  102. toggle.Text:SetText(T.datacolor.."C")
  103. toggle:SetScript("OnMouseUp", function(self)
  104. for _, frame in pairs(CurrencyData) do
  105. if frame and frame:IsVisible() then
  106. frame:SlideOut()
  107. else
  108. frame:SlideIn()
  109. end
  110. end
  111. end)
  112. local updater = CreateFrame("Frame")
  113. updater:RegisterEvent("PLAYER_HONOR_GAIN")
  114. updater:SetScript("OnEvent", updateCurrency)
  115. hooksecurefunc("BackpackTokenFrame_Update", updateCurrency)
  116. end