Mercurial > wow > token-price
diff 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 |
line wrap: on
line diff
--- a/GoldPrice.lua Tue Oct 25 16:35:41 2016 -0200 +++ b/GoldPrice.lua Thu Dec 08 14:51:48 2016 -0200 @@ -1,7 +1,10 @@ do local f = CreateFrame ("frame", "GoldPriceFrame", UIParent) f:RegisterEvent ("TOKEN_MARKET_PRICE_UPDATED") + f:RegisterEvent ("ADDON_LOADED") f:Hide() + + local addonName = ... function f:comma_value (n) n = floor (n) @@ -9,27 +12,54 @@ return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right end - f:SetScript ("OnEvent", function (self, event) - if (f.canShow) then - local price = C_WowTokenPublic.GetCurrentMarketPrice() - price = floor (price / 10000) - print ("|cFFFF9900Token Price|r: ", f:comma_value (price) .. "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t") - f.canShow = false + f:SetScript ("OnEvent", function (self, event, ...) + --GoldPriceGlobalSV + if (event == "TOKEN_MARKET_PRICE_UPDATED") then + if (f.canShow) then + local price = C_WowTokenPublic.GetCurrentMarketPrice() + price = floor (price / 10000) + print ("|c66FFDDDDToken Price|r: ", f:comma_value (price) .. "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t") + f.canShow = false + end + end + if (... == addonName) then + GoldPriceGlobalSV = GoldPriceGlobalSV or {} + if (GoldPriceGlobalSV.ShowOnLogin == nil) then + GoldPriceGlobalSV.ShowOnLogin = true + end + + if (GoldPriceGlobalSV.ShowOnLogin) then + f.ShowGoldPrice() + end end end) + + function f.ShowGoldPrice() + if (GoldPriceFrame.LastQuerry and GoldPriceFrame.LastQuerry+15 > GetTime()) then + local price = C_WowTokenPublic.GetCurrentMarketPrice() + if (price) then + price = floor (price / 10000) + return print ("|c66FFDDDDToken Price|r: ", GoldPriceFrame:comma_value (price) .. "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t") + end + end + + GoldPriceFrame.canShow = true + GoldPriceFrame.LastQuerry = GetTime() + C_WowTokenPublic.UpdateMarketPrice() + end + end SLASH_GoldPrice1, SLASH_GoldPrice2 = "/gold", "/token" -function SlashCmdList.GoldPrice (msg, editbox) - if (GoldPriceFrame.LastQuerry and GoldPriceFrame.LastQuerry+15 > GetTime()) then - local price = C_WowTokenPublic.GetCurrentMarketPrice() - if (price) then - price = floor (price / 10000) - return print ("|cFFFF9900Token Price|r: ", GoldPriceFrame:comma_value (price) .. "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t") - end +function SlashCmdList.GoldPrice (msg, editbox) + print ("|cFFFF9900Token Price Commands") + print ("|cFFFF9900/token onlogin|r: disable showing the token price on login.") + + if (msg == "onlogin") then + GoldPriceGlobalSV.ShowOnLogin = not GoldPriceGlobalSV.ShowOnLogin + print ("|c66FFDDDDToken Price|r show on login:", GoldPriceGlobalSV.ShowOnLogin) + return end - - GoldPriceFrame.canShow = true - GoldPriceFrame.LastQuerry = GetTime() - C_WowTokenPublic.UpdateMarketPrice() + + GoldPriceFrame.ShowGoldPrice() end \ No newline at end of file