comparison GoldPrice.lua @ 6:4fbf9f182530

- when the player logon it'll show the goild price automatically. - added a slash command '/token onlogin' to disable show on login.
author Tercio
date Thu, 08 Dec 2016 14:51:48 -0200
parents 899a07e4bef9
children
comparison
equal deleted inserted replaced
5:54a27a528450 6:4fbf9f182530
1 do 1 do
2 local f = CreateFrame ("frame", "GoldPriceFrame", UIParent) 2 local f = CreateFrame ("frame", "GoldPriceFrame", UIParent)
3 f:RegisterEvent ("TOKEN_MARKET_PRICE_UPDATED") 3 f:RegisterEvent ("TOKEN_MARKET_PRICE_UPDATED")
4 f:RegisterEvent ("ADDON_LOADED")
4 f:Hide() 5 f:Hide()
6
7 local addonName = ...
5 8
6 function f:comma_value (n) 9 function f:comma_value (n)
7 n = floor (n) 10 n = floor (n)
8 local left,num,right = string.match (n,'^([^%d]*%d)(%d*)(.-)$') 11 local left,num,right = string.match (n,'^([^%d]*%d)(%d*)(.-)$')
9 return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right 12 return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
10 end 13 end
11 14
12 f:SetScript ("OnEvent", function (self, event) 15 f:SetScript ("OnEvent", function (self, event, ...)
13 if (f.canShow) then 16 --GoldPriceGlobalSV
14 local price = C_WowTokenPublic.GetCurrentMarketPrice() 17 if (event == "TOKEN_MARKET_PRICE_UPDATED") then
15 price = floor (price / 10000) 18 if (f.canShow) then
16 print ("|cFFFF9900Token Price|r: ", f:comma_value (price) .. "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t") 19 local price = C_WowTokenPublic.GetCurrentMarketPrice()
17 f.canShow = false 20 price = floor (price / 10000)
21 print ("|c66FFDDDDToken Price|r: ", f:comma_value (price) .. "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t")
22 f.canShow = false
23 end
24 end
25 if (... == addonName) then
26 GoldPriceGlobalSV = GoldPriceGlobalSV or {}
27 if (GoldPriceGlobalSV.ShowOnLogin == nil) then
28 GoldPriceGlobalSV.ShowOnLogin = true
29 end
30
31 if (GoldPriceGlobalSV.ShowOnLogin) then
32 f.ShowGoldPrice()
33 end
18 end 34 end
19 end) 35 end)
36
37 function f.ShowGoldPrice()
38 if (GoldPriceFrame.LastQuerry and GoldPriceFrame.LastQuerry+15 > GetTime()) then
39 local price = C_WowTokenPublic.GetCurrentMarketPrice()
40 if (price) then
41 price = floor (price / 10000)
42 return print ("|c66FFDDDDToken Price|r: ", GoldPriceFrame:comma_value (price) .. "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t")
43 end
44 end
45
46 GoldPriceFrame.canShow = true
47 GoldPriceFrame.LastQuerry = GetTime()
48 C_WowTokenPublic.UpdateMarketPrice()
49 end
50
20 end 51 end
21 52
22 SLASH_GoldPrice1, SLASH_GoldPrice2 = "/gold", "/token" 53 SLASH_GoldPrice1, SLASH_GoldPrice2 = "/gold", "/token"
23 function SlashCmdList.GoldPrice (msg, editbox) 54 function SlashCmdList.GoldPrice (msg, editbox)
24 if (GoldPriceFrame.LastQuerry and GoldPriceFrame.LastQuerry+15 > GetTime()) then 55 print ("|cFFFF9900Token Price Commands")
25 local price = C_WowTokenPublic.GetCurrentMarketPrice() 56 print ("|cFFFF9900/token onlogin|r: disable showing the token price on login.")
26 if (price) then 57
27 price = floor (price / 10000) 58 if (msg == "onlogin") then
28 return print ("|cFFFF9900Token Price|r: ", GoldPriceFrame:comma_value (price) .. "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t") 59 GoldPriceGlobalSV.ShowOnLogin = not GoldPriceGlobalSV.ShowOnLogin
29 end 60 print ("|c66FFDDDDToken Price|r show on login:", GoldPriceGlobalSV.ShowOnLogin)
61 return
30 end 62 end
31 63
32 GoldPriceFrame.canShow = true 64 GoldPriceFrame.ShowGoldPrice()
33 GoldPriceFrame.LastQuerry = GetTime()
34 C_WowTokenPublic.UpdateMarketPrice()
35 end 65 end