/Tukui/modules/datatext/durability.lua

http://github.com/Asphyxia/Tukui · Lua · 62 lines · 52 code · 6 blank · 4 comment · 11 complexity · 3167db630e6a4b801b1c1d551d3e1423 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. --------------------------------------------------------------------
  3. -- DURABILITY
  4. --------------------------------------------------------------------
  5. if C["datatext"].dur and C["datatext"].dur > 0 then
  6. local Stat = CreateFrame("Frame")
  7. Stat:EnableMouse(true)
  8. Stat:SetFrameStrata("HIGH")
  9. Stat:SetFrameLevel(3)
  10. local Text = TukuiInfoLeft:CreateFontString(nil, "OVERLAY")
  11. Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  12. T.PP(C["datatext"].dur, Text)
  13. local Total = 0
  14. local current, max
  15. local function OnEvent(self)
  16. for i = 1, 11 do
  17. if GetInventoryItemLink("player", L.Slots[i][1]) ~= nil then
  18. current, max = GetInventoryItemDurability(L.Slots[i][1])
  19. if current then
  20. L.Slots[i][3] = current/max
  21. Total = Total + 1
  22. end
  23. end
  24. end
  25. table.sort(L.Slots, function(a, b) return a[3] < b[3] end)
  26. if Total > 0 then
  27. Text:SetText(DURABILITY..": "..T.datacolor..floor(L.Slots[1][3]*100).."% ")
  28. else
  29. Text:SetText(DURABILITY..": "..T.datacolor.."100% ")
  30. end
  31. -- Setup Durability Tooltip
  32. self:SetAllPoints(Text)
  33. Total = 0
  34. end
  35. Stat:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
  36. Stat:RegisterEvent("MERCHANT_SHOW")
  37. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  38. Stat:SetScript("OnMouseDown", function() ToggleCharacter("PaperDollFrame") end)
  39. Stat:SetScript("OnEvent", OnEvent)
  40. Stat:SetScript("OnEnter", function(self)
  41. if not InCombatLockdown() then
  42. local anchor, panel, xoff, yoff = T.DataTextTooltipAnchor(Text)
  43. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  44. GameTooltip:ClearLines()
  45. for i = 1, 11 do
  46. if L.Slots[i][3] ~= 1000 then
  47. green = L.Slots[i][3]*2
  48. red = 1 - green
  49. GameTooltip:AddDoubleLine(L.Slots[i][2], floor(L.Slots[i][3]*100).."%",1 ,1 , 1, red + 1, green, 0)
  50. end
  51. end
  52. GameTooltip:Show()
  53. end
  54. end)
  55. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  56. end