diff --git a/TradeSkillMaster_Accounting/Locale/enUS.lua b/TradeSkillMaster_Accounting/Locale/enUS.lua index 936afab..34325eb 100644 --- a/TradeSkillMaster_Accounting/Locale/enUS.lua +++ b/TradeSkillMaster_Accounting/Locale/enUS.lua @@ -145,6 +145,12 @@ L["Total Sale Price"] = true L["Total Spent:"] = true L["Total Value"] = true L["Total:"] = true +L["Player Wealth"] = true +L["Not Available"] = true +L["Bags:"] = true +L["Bank:"] = true +L["Auctions:"] = true +L["Coin on Hand"] = true L["Track sales/purchases via trade"] = true L["Type"] = true L["Use smart average for purchase price"] = true diff --git a/TradeSkillMaster_Accounting/Modules/data.lua b/TradeSkillMaster_Accounting/Modules/data.lua index a36e7f8..4162b2d 100644 --- a/TradeSkillMaster_Accounting/Modules/data.lua +++ b/TradeSkillMaster_Accounting/Modules/data.lua @@ -1251,7 +1251,12 @@ function Data:LogGold() TSM.db.realm.goldLog[player] = TSM.db.realm.goldLog[player] or {} local goldLog = TSM.db.realm.goldLog[player] - local currentGold = TSM:Round(GetMoney(), COPPER_PER_GOLD * 1000) + local currentMoney = GetMoney() + local resolution = COPPER_PER_GOLD + if currentMoney >= (COPPER_PER_GOLD * 1000) then + resolution = COPPER_PER_GOLD * 1000 + end + local currentGold = TSM:Round(currentMoney, resolution) if #goldLog > 0 and currentGold == goldLog[#goldLog].copper then goldLog[#goldLog].endMinute = currentMinute else diff --git a/TradeSkillMaster_Accounting/Modules/gui.lua b/TradeSkillMaster_Accounting/Modules/gui.lua index d021b59..c1a8626 100644 --- a/TradeSkillMaster_Accounting/Modules/gui.lua +++ b/TradeSkillMaster_Accounting/Modules/gui.lua @@ -884,63 +884,100 @@ function private:GetGoldGraphSumData() return private:GetGoldGraphPoints(temp) end -function GUI:DrawGoldGraph(container) - TSM.db.realm.goldGraphCharacter = TSM.db.realm.goldGraphCharacter or UnitName("player") - local player = TSM.db.realm.goldGraphCharacter - local data, minX, maxX, minY, maxY +function private:GetWealthPrice(itemString) + local avgSell = TSM:GetAvgSellPrice(itemString) + local marketValue = TSMAPI:GetItemValue(itemString, "DBMarket") + if avgSell and marketValue then + return (avgSell + marketValue) / 2 + end + return avgSell or marketValue +end + +function private:GetWealthTotals(player) + local totals = { + bags = 0, + bank = 0, + auctions = 0, + } + local hasData = false + + local function AddTotals(itemData, key) + if not itemData then return end + hasData = true + for itemString, quantity in pairs(itemData) do + if quantity > 0 then + local price = private:GetWealthPrice(itemString) + if price then + totals[key] = totals[key] + (price * quantity) + end + end + end + end + if player == "" then - data, minX, maxX, minY, maxY = private:GetGoldGraphSumData() + local players = TSMAPI:ModuleAPI("ItemTracker", "playerlist") or {} + for _, playerName in ipairs(players) do + AddTotals(TSMAPI:ModuleAPI("ItemTracker", "playerbags", playerName), "bags") + AddTotals(TSMAPI:ModuleAPI("ItemTracker", "playerbank", playerName), "bank") + AddTotals(TSMAPI:ModuleAPI("ItemTracker", "playerauctions", playerName), "auctions") + end else - data, minX, maxX, minY, maxY = private:GetGoldGraphPoints(TSM.db.realm.goldLog[player]) + AddTotals(TSMAPI:ModuleAPI("ItemTracker", "playerbags", player), "bags") + AddTotals(TSMAPI:ModuleAPI("ItemTracker", "playerbank", player), "bank") + AddTotals(TSMAPI:ModuleAPI("ItemTracker", "playerauctions", player), "auctions") + end + + if not hasData then return end + return totals +end + +function private:GetLatestGold(player) + local function GetLogGold(log) + if not log or #log == 0 then return end + return log[#log].copper + end + + if player == "" then + local total = 0 + local hasData = false + for name, log in pairs(TSM.db.realm.goldLog) do + local gold = GetLogGold(log) + if gold then + total = total + gold + hasData = true + end + end + if not hasData then return end + return total end + + return GetLogGold(TSM.db.realm.goldLog[player]) +end + +function GUI:DrawGoldGraph(container) + TSM.db.realm.goldGraphCharacter = TSM.db.realm.goldGraphCharacter or UnitName("player") + local player = TSM.db.realm.goldGraphCharacter local dropdownList = {[""]="Sum of All Characters"} for player in pairs(TSM.db.realm.goldLog) do dropdownList[player] = player end - - if not data then - local page = { - { - type = "SimpleGroup", - layout = "Flow", - children = { - { - type = "Label", - text = L["Accounting has not yet collected enough information for this tab. This is likely due to not having recorded enough data points or not seeing any significant fluctuations in your gold on hand."], - relativeWidth = 1, - }, - { - type = "Spacer", - }, - { - type = "Dropdown", - label = "Character to Graph", - settingInfo = {TSM.db.realm, "goldGraphCharacter"}, - relativeWidth = 0.5, - list = dropdownList, - callback = function() container:ReloadTab() end, - tooltip = "", - }, - }, - }, - } - TSMAPI:BuildPage(container, page) - return - end - local startDate, endDate - if TSM.db.realm.timeFormat == "eudate" then - startDate = date("%d/%m/%y %H:%M", minX * 60) - endDate = date("%d/%m/%y %H:%M", maxX * 60) - elseif TSM.db.realm.timeFormat == "aidate" then - startDate = date("%y/%m/%d %H:%M", minX * 60) - endDate = date("%y/%m/%d %H:%M", maxX * 60) - else - startDate = date("%m/%d/%y %H:%M", minX * 60) - endDate = date("%m/%d/%y %H:%M", maxX * 60) + local wealthTotals = private:GetWealthTotals(player) + local wealthTotalText = L["Not Available"] + local wealthBagsText = L["Not Available"] + local wealthBankText = L["Not Available"] + local wealthAuctionsText = L["Not Available"] + if wealthTotals then + wealthTotalText = TSMAPI:FormatTextMoney(wealthTotals.bags + wealthTotals.bank + wealthTotals.auctions) or "---" + wealthBagsText = TSMAPI:FormatTextMoney(wealthTotals.bags) or "---" + wealthBankText = TSMAPI:FormatTextMoney(wealthTotals.bank) or "---" + wealthAuctionsText = TSMAPI:FormatTextMoney(wealthTotals.auctions) or "---" end + local coinTotal = private:GetLatestGold(player) + local coinTotalText = coinTotal and TSMAPI:FormatTextMoney(coinTotal) or L["Not Available"] + local page = { { type = "SimpleGroup", @@ -948,7 +985,7 @@ function GUI:DrawGoldGraph(container) children = { { type = "Label", - text = format(L["Below is a graph of the your character's gold on hand over time.\n\nThe x-axis is time and goes from %s to %s\nThe y-axis is gold."], startDate, endDate), + text = L["Player Gold"], relativeWidth = 1, }, -- { @@ -962,48 +999,52 @@ function GUI:DrawGoldGraph(container) list = dropdownList, callback = function() container:ReloadTab() end, }, - -- { - -- type = "HeadingLine" - -- }, { - type = "Spacer", + type = "InlineGroup", + layout = "Flow", + title = L["Player Wealth"], + backdrop = true, + children = { + { + type = "Label", + text = L["Total:"] .. " " .. wealthTotalText, + relativeWidth = 1, + }, + { + type = "Label", + text = L["Bags:"] .. " " .. wealthBagsText, + relativeWidth = 0.33, + }, + { + type = "Label", + text = L["Bank:"] .. " " .. wealthBankText, + relativeWidth = 0.33, + }, + { + type = "Label", + text = L["Auctions:"] .. " " .. wealthAuctionsText, + relativeWidth = 0.33, + }, + }, }, { - type = "ScrollFrame", - fullHeight = false, --true - layout = "flow" + type = "InlineGroup", + layout = "Flow", + title = L["Coin on Hand"], + backdrop = true, + children = { + { + type = "Label", + text = L["Total:"] .. " " .. coinTotalText, + relativeWidth = 1, + }, + }, }, }, }, } TSMAPI:BuildPage(container, page) - - local parent = container.children[1].children[#container.children[1].children].frame - - parent:SetWidth(container.frame:GetWidth() - 80) - parent:SetHeight(container.frame:GetHeight() - 140) - - --if not GUI.lineGraph then - local graph = LibStub("LibGraph-2.0"):CreateGraphLine(nil, parent, "CENTER", nil, nil, nil, parent:GetWidth(), parent:GetHeight()) - graph:SetGridColor({ 0.8, 0.8, 0.8, 0.6 }) - graph:SetYLabels(true) - GUI.lineGraph = graph - --end - GUI.lineGraph:Show() - GUI.lineGraph:SetParent(parent) - GUI.lineGraph:ClearAllPoints() - GUI.lineGraph:SetAllPoints(parent) - - GUI.lineGraph:ResetData() - local ySpacing = max(ceil((maxY - minY) / 20), 0.5) - GUI.lineGraph:SetGridSpacing(nil, ySpacing) - local xBuffer = (maxX-minX)*0.05 - local yBuffer = (maxY-minY)*0.03 - GUI.lineGraph:SetXAxis(minX-xBuffer, maxX) - GUI.lineGraph:SetYAxis(minY-yBuffer, maxY+yBuffer) - GUI.lineGraph:AddDataSeries(data, {1, 0.83, 0, 1}) - GUI.lineGraph:RefreshGraph() end function GUI:DrawOptions(container)