/Tukui/modules/datatext/gold.lua

http://github.com/Asphyxia/Tukui · Lua · 130 lines · 110 code · 15 blank · 5 comment · 25 complexity · 5ae8aaecdcbbe777597d8320937945a2 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. --------------------------------------------------------------------
  3. -- GOLD
  4. --------------------------------------------------------------------
  5. if C["datatext"].gold and C["datatext"].gold > 0 then
  6. local Stat = CreateFrame("Frame")
  7. Stat:EnableMouse(true)
  8. Stat:SetFrameStrata("BACKGROUND")
  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"].gold, Text)
  13. local COPPER_ICON = "|TInterface\\MONEYFRAME\\UI-CopperIcon:0:0:0:-1|t"
  14. local SILVER_ICON = "|TInterface\\MONEYFRAME\\UI-SilverIcon:0:0:0:-1|t"
  15. local GOLD_ICON = "|TInterface\\MONEYFRAME\\UI-GoldIcon:0:0:0:-1|t"
  16. local Profit = 0
  17. local Spent = 0
  18. local OldMoney = 0
  19. local myPlayerRealm = GetCVar("realmName");
  20. local function formatMoney(money)
  21. local gold = floor(math.abs(money) / 10000)
  22. local silver = mod(floor(math.abs(money) / 100), 100)
  23. local copper = mod(floor(math.abs(money)), 100)
  24. if gold ~= 0 then
  25. return format("%s"..GOLD_ICON.." %s"..SILVER_ICON.." %s"..COPPER_ICON, gold, silver, copper)
  26. elseif silver ~= 0 then
  27. return format("%s"..SILVER_ICON.." %s"..COPPER_ICON, silver, copper)
  28. else
  29. return format("%s"..COPPER_ICON, copper)
  30. end
  31. end
  32. local function FormatTooltipMoney(money)
  33. local gold, silver, copper = abs(money / 10000), abs(mod(money / 100, 100)), abs(mod(money, 100))
  34. local cash = ""
  35. cash = format("%.2d"..GOLD_ICON.." %.2d"..SILVER_ICON.." %.2d"..COPPER_ICON, gold, silver, copper)
  36. return cash
  37. end
  38. local function OnEvent(self, event)
  39. if event == "PLAYER_ENTERING_WORLD" then
  40. OldMoney = GetMoney()
  41. end
  42. local NewMoney = GetMoney()
  43. local Change = NewMoney-OldMoney -- Positive if we gain money
  44. if OldMoney>NewMoney then -- Lost Money
  45. Spent = Spent - Change
  46. else -- Gained Moeny
  47. Profit = Profit + Change
  48. end
  49. Text:SetText(formatMoney(NewMoney))
  50. -- Setup Money Tooltip
  51. self:SetAllPoints(Text)
  52. local myPlayerName = UnitName("player");
  53. if (TukuiData == nil) then TukuiData = {}; end
  54. if (TukuiData.gold == nil) then TukuiData.gold = {}; end
  55. if (TukuiData.gold[myPlayerRealm]==nil) then TukuiData.gold[myPlayerRealm]={}; end
  56. TukuiData.gold[myPlayerRealm][myPlayerName] = GetMoney();
  57. OldMoney = NewMoney
  58. end
  59. Stat:RegisterEvent("PLAYER_MONEY")
  60. Stat:RegisterEvent("SEND_MAIL_MONEY_CHANGED")
  61. Stat:RegisterEvent("SEND_MAIL_COD_CHANGED")
  62. Stat:RegisterEvent("PLAYER_TRADE_MONEY")
  63. Stat:RegisterEvent("TRADE_MONEY_CHANGED")
  64. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  65. Stat:SetScript("OnMouseDown", function() ToggleAllBags() end)
  66. Stat:SetScript("OnEvent", OnEvent)
  67. Stat:SetScript("OnEnter", function(self)
  68. if not InCombatLockdown() then
  69. local anchor, panel, xoff, yoff = T.DataTextTooltipAnchor(Text)
  70. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  71. GameTooltip:ClearLines()
  72. GameTooltip:AddLine(L.datatext_session)
  73. GameTooltip:AddDoubleLine(L.datatext_earned, formatMoney(Profit), 1, 1, 1, 1, 1, 1)
  74. GameTooltip:AddDoubleLine(L.datatext_spent, formatMoney(Spent), 1, 1, 1, 1, 1, 1)
  75. if Profit < Spent then
  76. GameTooltip:AddDoubleLine(L.datatext_deficit, formatMoney(Profit-Spent), 1, 0, 0, 1, 1, 1)
  77. elseif (Profit-Spent)>0 then
  78. GameTooltip:AddDoubleLine(L.datatext_profit, formatMoney(Profit-Spent), 0, 1, 0, 1, 1, 1)
  79. end
  80. GameTooltip:AddLine' '
  81. local totalGold = 0
  82. GameTooltip:AddLine(L.datatext_character)
  83. local thisRealmList = TukuiData.gold[myPlayerRealm];
  84. for k,v in pairs(thisRealmList) do
  85. GameTooltip:AddDoubleLine(k, FormatTooltipMoney(v), 1, 1, 1, 1, 1, 1)
  86. totalGold=totalGold+v;
  87. end
  88. GameTooltip:AddLine' '
  89. GameTooltip:AddLine(L.datatext_server)
  90. GameTooltip:AddDoubleLine(L.datatext_totalgold, FormatTooltipMoney(totalGold), 1, 1, 1, 1, 1, 1)
  91. for i = 1, GetNumWatchedTokens() do
  92. local name, count, extraCurrencyType, icon, itemID = GetBackpackCurrencyInfo(i)
  93. if name and i == 1 then
  94. GameTooltip:AddLine(" ")
  95. GameTooltip:AddLine(CURRENCY)
  96. end
  97. local r, g, b = 1,1,1
  98. if itemID then r, g, b = GetItemQualityColor(select(3, GetItemInfo(itemID))) end
  99. if name and count then GameTooltip:AddDoubleLine(name, count, r, g, b, 1, 1, 1) end
  100. end
  101. GameTooltip:Show()
  102. end
  103. end)
  104. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  105. -- reset gold data
  106. local function RESETGOLD()
  107. local myPlayerRealm = GetCVar("realmName");
  108. local myPlayerName = UnitName("player");
  109. TukuiData.gold = {}
  110. TukuiData.gold[myPlayerRealm]={}
  111. TukuiData.gold[myPlayerRealm][myPlayerName] = GetMoney();
  112. end
  113. SLASH_RESETGOLD1 = "/resetgold"
  114. SlashCmdList["RESETGOLD"] = RESETGOLD
  115. end