Thread Tools Display Modes
04-11-14, 09:48 PM   #1
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Add Comma's To My Gold Format

I have a gold tracking stat in my datapanal, it shows my gold for all my toons on the current realm.

As you all know im not a programmer so below is a screen shot of what im talking about and i added the code for the stat.

What I'm trying to do is add a thousand place comma so it looks better.

Thanks
Coke


Screenshot:

Code:
Lua Code:
  1. if db.datapanel.bags and db.datapanel.bags > 0 then
  2.         local Stat = CreateFrame('Frame')
  3.         Stat:EnableMouse(true)
  4.         Stat:SetFrameStrata('BACKGROUND')
  5.         Stat:SetFrameLevel(3)
  6.  
  7.         local Text  = DataPanel:CreateFontString(nil, 'OVERLAY')
  8.         Text:SetFont(db.media.fontNormal, db.media.fontSize,'THINOUTLINE')
  9.         PP(db.datapanel.bags, Text)
  10.  
  11.         local Profit    = 0
  12.         local Spent     = 0
  13.         local OldMoney  = 0
  14.         local myPlayerRealm = GetRealmName();
  15.        
  16.        
  17.         local function formatMoney(c)
  18.             local str = ""
  19.             if not c or c < 0 then
  20.                 return str
  21.             end
  22.            
  23.             if c >= 10000 then
  24.                 local g = math.floor(c/10000)
  25.                 c = c - g*10000
  26.                 str = str..g.."|cFFFFD800g|r "
  27.             end
  28.             if c >= 100 then
  29.                 local s = math.floor(c/100)
  30.                 c = c - s*100
  31.                 str = str..s.."|cFFC7C7C7s|r "
  32.             end
  33.             if c >= 0 then
  34.                 str = str..c.."|cFFEEA55Fc|r"
  35.             end
  36.            
  37.             return str
  38.         end
  39.        
  40.         local function FormatTooltipMoney(c)
  41.             if not c then return end
  42.             local str = ""
  43.             if not c or c < 0 then
  44.                 return str
  45.             end
  46.            
  47.             if c >= 10000 then
  48.                 local g = math.floor(c/10000)
  49.                 c = c - g*10000
  50.                 str = str..g.."|cFFFFD800g|r "
  51.             end
  52.             if c >= 100 then
  53.                 local s = math.floor(c/100)
  54.                 c = c - s*100
  55.                 str = str..s.."|cFFC7C7C7s|r "
  56.             end
  57.             if c >= 0 then
  58.                 str = str..c.."|cFFEEA55Fc|r"
  59.             end
  60.            
  61.             return str
  62.         end
  63.         local function OnEvent(self, event)
  64.             local totalSlots, freeSlots = 0, 0
  65.             local itemLink, subtype, isBag
  66.             for i = 0,NUM_BAG_SLOTS do
  67.                 isBag = true
  68.                 if i > 0 then
  69.                     itemLink = GetInventoryItemLink('player', ContainerIDToInventoryID(i))
  70.                     if itemLink then
  71.                         subtype = select(7, GetItemInfo(itemLink))
  72.                         if (subtype == 'Mining Bag') or (subtype == 'Gem Bag') or (subtype == 'Engineering Bag') or (subtype == 'Enchanting Bag') or (subtype == 'Herb Bag') or (subtype == 'Inscription Bag') or (subtype == 'Leatherworking Bag') or (subtype == 'Fishing Bag')then
  73.                             isBag = false
  74.                         end
  75.                     end
  76.                 end
  77.                 if isBag then
  78.                     totalSlots = totalSlots + GetContainerNumSlots(i)
  79.                     freeSlots = freeSlots + GetContainerNumFreeSlots(i)
  80.                 end
  81.                 Text:SetText(hexa.."Bags: "..hexb.. freeSlots.. '/' ..totalSlots)
  82.                     if freeSlots < 6 then
  83.                         Text:SetTextColor(1,0,0)
  84.                     elseif freeSlots < 10 then
  85.                         Text:SetTextColor(1,0,0)
  86.                     elseif freeSlots > 10 then
  87.                         Text:SetTextColor(1,1,1)
  88.                     end
  89.                 self:SetAllPoints(Text)
  90.                
  91.             end
  92.             if event == "PLAYER_ENTERING_WORLD" then
  93.                 OldMoney = GetMoney()
  94.             end
  95.            
  96.             local NewMoney  = GetMoney()
  97.             local Change = NewMoney-OldMoney -- Positive if we gain money
  98.            
  99.             if OldMoney>NewMoney then       -- Lost Money
  100.                 Spent = Spent - Change
  101.             else                            -- Gained Money
  102.                 Profit = Profit + Change
  103.             end
  104.            
  105.             --Text:SetText(formatMoney(NewMoney))
  106.             -- Setup Money Tooltip
  107.             self:SetAllPoints(Text)
  108.  
  109.             local myPlayerName  = UnitName("player")               
  110.             if not BasicDB then BasicDB = {} end
  111.             if not BasicDB.gold then BasicDB.gold = {} end
  112.             if not BasicDB.gold[myPlayerRealm] then BasicDB.gold[myPlayerRealm]={} end
  113.             BasicDB.gold[myPlayerRealm][myPlayerName] = GetMoney()     
  114.                
  115.             OldMoney = NewMoney
  116.                
  117.         end
  118.  
  119.         Stat:RegisterEvent("PLAYER_MONEY")
  120.         Stat:RegisterEvent("SEND_MAIL_MONEY_CHANGED")
  121.         Stat:RegisterEvent("SEND_MAIL_COD_CHANGED")
  122.         Stat:RegisterEvent("PLAYER_TRADE_MONEY")
  123.         Stat:RegisterEvent("TRADE_MONEY_CHANGED")
  124.         Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  125.         Stat:SetScript('OnMouseDown',
  126.             function()
  127.                 if db.datapanel.bag ~= true then
  128.                     ToggleAllBags()
  129.                 else
  130.                     ToggleBag(0)
  131.                 end
  132.             end
  133.         )
  134.         Stat:SetScript('OnEvent', OnEvent) 
  135.         Stat:SetScript("OnEnter", function(self)
  136.             if not InCombatLockdown() then
  137.                 local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
  138.                 GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  139.                 GameTooltip:ClearLines()
  140.                 GameTooltip:AddLine(hexa..myname.."'s"..hexb.." Gold")
  141.                 --GameTooltip:AddLine(" " .. formatMoney(OldMoney), 1, 1, 1, 1, 1, 1)
  142.                 GameTooltip:AddLine' '         
  143.                 GameTooltip:AddLine("This Session: ")              
  144.                 GameTooltip:AddDoubleLine("Earned:", formatMoney(Profit), 1, 1, 1, 1, 1, 1)
  145.                 GameTooltip:AddDoubleLine("Spent:", formatMoney(Spent), 1, 1, 1, 1, 1, 1)
  146.                 if Profit < Spent then
  147.                     GameTooltip:AddDoubleLine("Deficit:", formatMoney(Profit-Spent), 1, 0, 0, 1, 1, 1)
  148.                 elseif (Profit-Spent)>0 then
  149.                     GameTooltip:AddDoubleLine("Profit:", formatMoney(Profit-Spent), 0, 1, 0, 1, 1, 1)
  150.                 end            
  151.                 GameTooltip:AddLine'---------------------------------'
  152.                 GameTooltip:AddDoubleLine("Total:", formatMoney(OldMoney), 1, 1, 1, 1, 1, 1)
  153.                 GameTooltip:AddLine' '
  154.                
  155.                 local totalGold = 0            
  156.                 GameTooltip:AddLine("Character's On This Server: ")        
  157.                 local thisRealmList = BasicDB.gold[myPlayerRealm];
  158.                 for k,v in pairs(thisRealmList) do
  159.                     GameTooltip:AddDoubleLine(k, FormatTooltipMoney(v), 1, 1, 1, 1, 1, 1)
  160.                     totalGold=totalGold+v;
  161.                 end  
  162.                 GameTooltip:AddLine' '
  163.                 GameTooltip:AddLine("Server: ")
  164.                 GameTooltip:AddDoubleLine("Total: ", FormatTooltipMoney(totalGold), 1, 1, 1, 1, 1, 1)
  165.  
  166.                 for i = 1, GetNumWatchedTokens() do
  167.                     local name, count, extraCurrencyType, icon, itemID = GetBackpackCurrencyInfo(i)
  168.                     if name and i == 1 then
  169.                         GameTooltip:AddLine(" ")
  170.                         GameTooltip:AddLine(CURRENCY..":")
  171.                     end
  172.                     local r, g, b = 1,1,1
  173.                     if itemID then r, g, b = GetItemQualityColor(select(3, GetItemInfo(itemID))) end
  174.                     if name and count then GameTooltip:AddDoubleLine(name, count, r, g, b, 1, 1, 1) end
  175.                 end
  176.                 GameTooltip:AddLine' '
  177.                 GameTooltip:AddLine("|cffeda55fClick|r to Open Bags")          
  178.                 GameTooltip:Show()
  179.             end
  180.         end)
  181.        
  182.         Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)           
  183.         -- reset gold data
  184.         local function RESETGOLD()
  185.             local myPlayerRealm = GetRealmName();
  186.             local myPlayerName  = UnitName("player");
  187.            
  188.             BasicDB.gold = {}
  189.             BasicDB.gold[myPlayerRealm]={}
  190.             BasicDB.gold[myPlayerRealm][myPlayerName] = GetMoney();
  191.         end
  192.         SLASH_RESETGOLD1 = "/resetgold"
  193.         SlashCmdList["RESETGOLD"] = RESETGOLD  
  194.  
  195.     end

Let me add that this stat does 2 things, it keeps track of how many free bags slots I have and the tooltip show the gold tracker.
Attached Thumbnails
Click image for larger version

Name:	Gold 1.png
Views:	266
Size:	113.7 KB
ID:	8057  
  Reply With Quote
04-12-14, 05:09 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Easiest method:
Code:
local displayString = BreakUpLargeNumbers(someHugeNumber)
Example:
Code:
print(BreakUpLargeNumbers(12345678)) => 12,345,678
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-12-14, 06:21 PM   #3
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Phanx View Post
Easiest method:
Code:
local displayString = BreakUpLargeNumbers(someHugeNumber)
Example:
Code:
print(BreakUpLargeNumbers(12345678)) => 12,345,678
Thank you got it figured out.
Lua Code:
  1. local function formatMoney(c)
  2.             local str = ""
  3.             if not c or c < 0 then
  4.                 return str
  5.             end
  6.            
  7.             if c >= 10000 then
  8.                 local g = math.floor(c/10000)
  9.                 c = c - g*10000
  10.                 str = str..BreakUpLargeNumbers(g).."|cFFFFD800g|r "
  11.             end
  12.             if c >= 100 then
  13.                 local s = math.floor(c/100)
  14.                 c = c - s*100
  15.                 str = str..s.."|cFFC7C7C7s|r "
  16.             end
  17.             if c >= 0 then
  18.                 str = str..c.."|cFFEEA55Fc|r"
  19.             end
  20.            
  21.             return str
  22.         end

Now I have all my comma's.

Coke
Attached Thumbnails
Click image for larger version

Name:	Gold 2.png
Views:	236
Size:	112.6 KB
ID:	8060  
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Add Comma's To My Gold Format


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off