if db.datapanel.bags and db.datapanel.bags > 0 then
local Stat = CreateFrame('Frame')
Stat:EnableMouse(true)
Stat:SetFrameStrata('BACKGROUND')
Stat:SetFrameLevel(3)
local Text = DataPanel:CreateFontString(nil, 'OVERLAY')
Text:SetFont(db.media.fontNormal, db.media.fontSize,'THINOUTLINE')
PP(db.datapanel.bags, Text)
local Profit = 0
local Spent = 0
local OldMoney = 0
local myPlayerRealm = GetRealmName();
local function formatMoney(c)
local str = ""
if not c or c < 0 then
return str
end
if c >= 10000 then
local g = math.floor(c/10000)
c = c - g*10000
str = str..g.."|cFFFFD800g|r "
end
if c >= 100 then
local s = math.floor(c/100)
c = c - s*100
str = str..s.."|cFFC7C7C7s|r "
end
if c >= 0 then
str = str..c.."|cFFEEA55Fc|r"
end
return str
end
local function FormatTooltipMoney(c)
if not c then return end
local str = ""
if not c or c < 0 then
return str
end
if c >= 10000 then
local g = math.floor(c/10000)
c = c - g*10000
str = str..g.."|cFFFFD800g|r "
end
if c >= 100 then
local s = math.floor(c/100)
c = c - s*100
str = str..s.."|cFFC7C7C7s|r "
end
if c >= 0 then
str = str..c.."|cFFEEA55Fc|r"
end
return str
end
local function OnEvent(self, event)
local totalSlots, freeSlots = 0, 0
local itemLink, subtype, isBag
for i = 0,NUM_BAG_SLOTS do
isBag = true
if i > 0 then
itemLink = GetInventoryItemLink('player', ContainerIDToInventoryID(i))
if itemLink then
subtype = select(7, GetItemInfo(itemLink))
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
isBag = false
end
end
end
if isBag then
totalSlots = totalSlots + GetContainerNumSlots(i)
freeSlots = freeSlots + GetContainerNumFreeSlots(i)
end
Text:SetText(hexa.."Bags: "..hexb.. freeSlots.. '/' ..totalSlots)
if freeSlots < 6 then
Text:SetTextColor(1,0,0)
elseif freeSlots < 10 then
Text:SetTextColor(1,0,0)
elseif freeSlots > 10 then
Text:SetTextColor(1,1,1)
end
self:SetAllPoints(Text)
end
if event == "PLAYER_ENTERING_WORLD" then
OldMoney = GetMoney()
end
local NewMoney = GetMoney()
local Change = NewMoney-OldMoney -- Positive if we gain money
if OldMoney>NewMoney then -- Lost Money
Spent = Spent - Change
else -- Gained Money
Profit = Profit + Change
end
--Text:SetText(formatMoney(NewMoney))
-- Setup Money Tooltip
self:SetAllPoints(Text)
local myPlayerName = UnitName("player")
if not BasicDB then BasicDB = {} end
if not BasicDB.gold then BasicDB.gold = {} end
if not BasicDB.gold[myPlayerRealm] then BasicDB.gold[myPlayerRealm]={} end
BasicDB.gold[myPlayerRealm][myPlayerName] = GetMoney()
OldMoney = NewMoney
end
Stat:RegisterEvent("PLAYER_MONEY")
Stat:RegisterEvent("SEND_MAIL_MONEY_CHANGED")
Stat:RegisterEvent("SEND_MAIL_COD_CHANGED")
Stat:RegisterEvent("PLAYER_TRADE_MONEY")
Stat:RegisterEvent("TRADE_MONEY_CHANGED")
Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
Stat:SetScript('OnMouseDown',
function()
if db.datapanel.bag ~= true then
ToggleAllBags()
else
ToggleBag(0)
end
end
)
Stat:SetScript('OnEvent', OnEvent)
Stat:SetScript("OnEnter", function(self)
if not InCombatLockdown() then
local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
GameTooltip:SetOwner(panel, anchor, xoff, yoff)
GameTooltip:ClearLines()
GameTooltip:AddLine(hexa..myname.."'s"..hexb.." Gold")
--GameTooltip:AddLine(" " .. formatMoney(OldMoney), 1, 1, 1, 1, 1, 1)
GameTooltip:AddLine' '
GameTooltip:AddLine("This Session: ")
GameTooltip:AddDoubleLine("Earned:", formatMoney(Profit), 1, 1, 1, 1, 1, 1)
GameTooltip:AddDoubleLine("Spent:", formatMoney(Spent), 1, 1, 1, 1, 1, 1)
if Profit < Spent then
GameTooltip:AddDoubleLine("Deficit:", formatMoney(Profit-Spent), 1, 0, 0, 1, 1, 1)
elseif (Profit-Spent)>0 then
GameTooltip:AddDoubleLine("Profit:", formatMoney(Profit-Spent), 0, 1, 0, 1, 1, 1)
end
GameTooltip:AddLine'---------------------------------'
GameTooltip:AddDoubleLine("Total:", formatMoney(OldMoney), 1, 1, 1, 1, 1, 1)
GameTooltip:AddLine' '
local totalGold = 0
GameTooltip:AddLine("Character's On This Server: ")
local thisRealmList = BasicDB.gold[myPlayerRealm];
for k,v in pairs(thisRealmList) do
GameTooltip:AddDoubleLine(k, FormatTooltipMoney(v), 1, 1, 1, 1, 1, 1)
totalGold=totalGold+v;
end
GameTooltip:AddLine' '
GameTooltip:AddLine("Server: ")
GameTooltip:AddDoubleLine("Total: ", FormatTooltipMoney(totalGold), 1, 1, 1, 1, 1, 1)
for i = 1, GetNumWatchedTokens() do
local name, count, extraCurrencyType, icon, itemID = GetBackpackCurrencyInfo(i)
if name and i == 1 then
GameTooltip:AddLine(" ")
GameTooltip:AddLine(CURRENCY..":")
end
local r, g, b = 1,1,1
if itemID then r, g, b = GetItemQualityColor(select(3, GetItemInfo(itemID))) end
if name and count then GameTooltip:AddDoubleLine(name, count, r, g, b, 1, 1, 1) end
end
GameTooltip:AddLine' '
GameTooltip:AddLine("|cffeda55fClick|r to Open Bags")
GameTooltip:Show()
end
end)
Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
-- reset gold data
local function RESETGOLD()
local myPlayerRealm = GetRealmName();
local myPlayerName = UnitName("player");
BasicDB.gold = {}
BasicDB.gold[myPlayerRealm]={}
BasicDB.gold[myPlayerRealm][myPlayerName] = GetMoney();
end
SLASH_RESETGOLD1 = "/resetgold"
SlashCmdList["RESETGOLD"] = RESETGOLD
end