local addon, ns = ...
local cfg = ns.cfg
local unpack = unpack
--------------------------------------------------------------
--if not cfg.show.gold then return end
-------------
-- HELPERS --
-------------
-- copies missing parts of source table to another table
function CopyTable(src, dest)
if type(dest) ~= "table" then
dest = {}
end
for k, v in pairs(src) do
if type(v) == "table" then
dest[k] = CopyTable(v, dest[k])
elseif type(v) ~= type(dest[k]) then
dest[k] = v
end
end
return dest
end
-- removes everything that is present in source table from another table
function DiffTable(src, dest)
if type(dest) ~= "table" then
return {}
end
if type(src) ~= "table" then
return dest
end
for k, v in pairs(dest) do
if type(v) == "table" then
if not next(DiffTable(src[k], v)) then
dest[k] = nil
end
elseif v == src[k] then
dest[k] = nil
end
end
return dest
end
local function ConvertDateToNumber(month, day, year)
month = gsub(month, "(%d)(%d?)", function(d1, d2) return d2 == "" and "0"..d1 or d1..d2 end) -- converts M to MM
day = gsub(day, "(%d)(%d?)", function(d1, d2) return d2 == "" and "0"..d1 or d1..d2 end) -- converts D to DD
return tonumber(year..month..day)
end
--------------
-- DEFAULTS --
--------------
local D = {
["money_related_stuff"] = {}
}
-----------
-- STUFF --
-----------
local function Controller_OnEvent(self, event, arg)
if event == "ADDON_LOADED" and arg == "SXUI_Bottombar" then -- "test" is addon name
local CONFIG = CopyTable(D, TEST_CONFIG)
ns.CONFIG = CONFIG -- makes this table available throughout addon
local playerRealm, playerFaction, playerName = GetRealmName(), UnitFactionGroup("player"), UnitName("player")
if not CONFIG["money_related_stuff"][playerRealm] then
CONFIG["money_related_stuff"][playerRealm] = {} -- creates a table, if it doesn't exist
end
local realmData = CONFIG["money_related_stuff"][playerRealm] -- just an alias
ns.realmData = realmData
if not realmData[playerFaction[playerName]] then
realmData[playerFaction[playerName]] = {} -- creates a table, if it doesn't exist
end
ns.playerData = realmData[playerFaction[playerName]]
self:UnregisterEvent("ADDON_LOADED")
elseif event == "PLAYER_LOGIN" then
local playerData = ns.playerData
local weekday, month, day, year = CalendarGetDate()
local today = ConvertDateToNumber(month, day, year)
local updateData
if playerData.lastLoginDate then
if playerData.lastLoginDate < today then -- is true, if last time player logged in was the day before or even earlier
playerData.lastLoginDate = today
updateData = true
end
else
playerData.lastLoginDate = today
updateData = true
end
if updateData then -- daily updates
if playerData["money_on_first_weekday"] then
if weekday == cfg.core.firstWeekday then -- 1 is Sunday, 2 is Monday, different countries have different first day of the week
playerData["money_on_first_weekday"] = GetMoney()
end
else
playerData["money_on_first_weekday"] = GetMoney()
end
playerData["money_on_first_login_today"] = GetMoney()
end
playerData["money_on_session_start"] = GetMoney() -- this one resets on every single login or UI reload
self:UnregisterEvent("PLAYER_LOGIN")
elseif event == "PLAYER_LOGOUT" then
TEST_CONFIG = DiffTable(D, ns.CONFIG) -- writes data into TEST_CONFIG table
end
end
local Controller = CreateFrame("Frame")
Controller:RegisterEvent("ADDON_LOADED")
Controller:RegisterEvent("PLAYER_LOGIN")
Controller:RegisterEvent("PLAYER_LOGOUT")
Controller:SetScript("OnEvent", Controller_OnEvent)
local goldConverter = function(money)
if money == 1 then
end
local g, s, c = abs(money/10000), abs(mod(money/100, 100)), abs(mod(money, 100))
end
local goldFrame = CreateFrame("BUTTON",nil, cfg.SXUIframe)
goldFrame:SetPoint("RIGHT",-210,0)
goldFrame:SetSize(16, 16)
goldFrame:EnableMouse(true)
goldFrame:RegisterForClicks("AnyUp")
local goldIcon = goldFrame:CreateTexture(nil,"OVERLAY",nil,7)
goldIcon:SetPoint("LEFT")
goldIcon:SetTexture(cfg.mediaFolder.."datatexts\\gold")
goldIcon:SetVertexColor(unpack(cfg.color.normal))
local goldText = goldFrame:CreateFontString(nil, "OVERLAY")
goldText:SetFont(cfg.font, cfg.core.normalFontSize)
goldText:SetPoint("RIGHT", goldFrame,2,0)
goldText:SetTextColor(unpack(cfg.color.normal))
goldFrame:SetScript("OnEnter", function()
if InCombatLockdown() then return end
goldIcon:SetVertexColor(unpack(cfg.color.hover))
GameTooltip:SetOwner(goldFrame, cfg.tooltipPos)
GameTooltip:AddLine("[|cff6699FFGold|r]")
GameTooltip:AddLine(" ")
---------------------------------------------------
local sessionGold = playerData["money_on_session_start"]
local dailyGold = playerData["money_on_first_login_today"]
local weekGold = playerData["money_on_first_weekday"]
local money = GetMoney()
local moneyIcon = GetCoinIcon(money)
local g, s, c = abs(money/10000), abs(mod(money/100, 100)), abs(mod(money, 100))
if ( g < 1 ) then g = "" else g = string.format("|cffffffff%d|cffffd700g|r ", g) end
if ( s < 1 ) then s = "" else s = string.format("|cffffffff%d|cffc7c7cfs|r ", s) end
c = string.format("|cffffffff%d|cffeda55fc|r ", c)
GameTooltip:AddDoubleLine("Current Gold",("%s%s%s"):format(g,s,c))
GameTooltip:AddDoubleLine("Session Gold",sessionGold)
GameTooltip:AddDoubleLine("Daily Gold",dailyGold)
GameTooltip:AddDoubleLine("Week Gold",weekGold)
GameTooltip:Show()
end)
goldFrame:SetScript("OnLeave", function() if ( GameTooltip:IsShown() ) then GameTooltip:Hide() end goldIcon:SetVertexColor(unpack(cfg.color.normal)) end)
goldFrame:SetScript("OnClick", function(self, button, down)
if InCombatLockdown() then return end
if button == "LeftButton" then
OpenAllBags()
elseif button == "RightButton" then
CloseAllBags()
end
end)
local eventframe = CreateFrame("Frame")
eventframe:RegisterEvent("PLAYER_LOGIN")
eventframe:RegisterEvent("PLAYER_ENTERING_WORLD")
eventframe:RegisterEvent("PLAYER_MONEY")
eventframe:RegisterEvent("SEND_MAIL_MONEY_CHANGED")
eventframe:RegisterEvent("SEND_MAIL_COD_CHANGED")
eventframe:RegisterEvent("PLAYER_TRADE_MONEY")
eventframe:RegisterEvent("TRADE_MONEY_CHANGED")
eventframe:RegisterEvent("TRADE_LOGOUT")
eventframe:SetScript("OnEvent", function(self,event, ...)
if event == ("PLAYER_LOGIN") then
local sessionGold = 0
end
local money = GetMoney()
local g, s, c = abs(money/10000), abs(mod(money/100, 100)), abs(mod(money, 100))
if g > 1 then
goldText:SetText(floor(g).."g")
elseif s > 1 then
goldText:SetText(floor(s).."s")
else
goldText:SetText(floor(c).."c")
end
goldFrame:SetSize(goldText:GetStringWidth()+18, 16)
end)