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