diff --git a/Bindings.lua b/Bindings.lua index 80899fe..609fb16 100644 --- a/Bindings.lua +++ b/Bindings.lua @@ -97,7 +97,7 @@ function GT:ClearFilters() GT:ClearDisplay() end -function GT:ResetPerHour() +function GT:ResetSession() --resets the per hour displays to current time and values GT.Debug("Reset Per Hour", 1) @@ -107,8 +107,13 @@ function GT:ResetPerHour() itemData.startAmount = {} for senderIndex, value in ipairs(itemData.counts) do itemData.startAmount[senderIndex] = value + itemData.sessionCounts[senderIndex] = 0 end itemData.startTotal = GT:SumTable(itemData.startAmount) end + for senderIndex, senderData in ipairs(GT.sender) do + senderData.sessionData = {} + end GT:RefreshPerHourDisplay(false, true) + GT:RebuildDisplay("Reset Session") end diff --git a/Bindings.xml b/Bindings.xml index 9630a9c..11fa042 100644 --- a/Bindings.xml +++ b/Bindings.xml @@ -14,7 +14,7 @@ GatheringTracker:ClearFilters() - - GatheringTracker:ResetPerHour() + + GatheringTracker:ResetSession() \ No newline at end of file diff --git a/Config.lua b/Config.lua index 33ac785..9b9b425 100644 --- a/Config.lua +++ b/Config.lua @@ -59,6 +59,8 @@ GT.defaults = { goldPerHour = false, collapseDisplay = false, collapseTime = 2, + sessionItems = false, + sessionOnly = false, }, Notifications = { Count = { @@ -528,6 +530,48 @@ local generalOptions = { end, order = 204 }, + header2 = { + type = "header", + name = "Session Display Options", + order = 250 + }, + sessionItems = { + type = "toggle", + name = "Display Session Item Counts", + desc = "If selected session item counts will be displayed in the column to the right of the item count.\n" .. + "Price data (if enabled) is not displayed for session data.\n\n" .. + "|cffff0000Session data not displayed in group mode.|r", + width = 1.70, + get = function() return GT.db.profile.General.sessionItems end, + set = function(_, key) + GT.db.profile.General.sessionItems = key + if not key then + GT.db.profile.General.sessionOnly = false + end + GT:RebuildDisplay("Display Session Item Counts Changed") + end, + order = 251 + }, + sessionOnly = { + type = "toggle", + name = "Only Display Session Data", + desc = "If selected only the session data will be displayed and selected items will only display if collected during the session.\n" .. + "Price data (if enabled) is displayed for the session data.", + width = 1.70, + get = function() return GT.db.profile.General.sessionOnly end, + set = function(_, key) + GT.db.profile.General.sessionOnly = key + GT:RebuildDisplay("Only Display Session Data Changed") + end, + disabled = function() + if not GT.db.profile.General.sessionItems then + return true + else + return false + end + end, + order = 252 + }, itemsPerHour = { type = "toggle", name = "Display Items Per Hour", @@ -536,10 +580,9 @@ local generalOptions = { get = function() return GT.db.profile.General.itemsPerHour end, set = function(_, key) GT.db.profile.General.itemsPerHour = key - GT:RebuildDisplay("tems Per Hour Changed") + GT:RebuildDisplay("Items Per Hour Changed") end, - - order = 205 + order = 255 }, goldPerHour = { type = "toggle", @@ -559,24 +602,25 @@ local generalOptions = { return false end end, - order = 206 + order = 256 }, perHourReset = { type = "execute", - name = "Reset Item and Gold Per Hour", - desc = "Clicking this will reset the Item and Gold Per Hour displays.", + name = "Reset Session Data", + desc = "Clicking this will reset the session data.", width = 1.70, func = function() - GT:ResetPerHour() + GT:ResetSession() end, disabled = function() - if not GT.db.profile.General.itemsPerHour and not GT.db.profile.General.goldPerHour then - return true - else + if GT.db.profile.General.itemsPerHour or GT.db.profile.General.goldPerHour or + GT.db.profile.General.sessionItems then return false + else + return true end end, - order = 207 + order = 257 }, header3 = { type = "header", diff --git a/Constants.lua b/Constants.lua index 9fc3857..f6dc4dd 100644 --- a/Constants.lua +++ b/Constants.lua @@ -1490,7 +1490,6 @@ local ItemData = { Other = { { id = 1, name = "Current Gold", order = 1, icon = 370211, desc = "Displays the current Gold on the character, rounded to the nearest whole number." }, { id = 2, name = "Open Bag Space", order = 2, icon = 975745, desc = "Displays the number of open bag space." }, - { id = 3, name = "Timer", order = 3, icon = 134377, desc = "Displays a timer starting from the first gather after being enabled." }, }, }, } diff --git a/GatheringTracker.lua b/GatheringTracker.lua index 5ec3cdf..484dd53 100644 --- a/GatheringTracker.lua +++ b/GatheringTracker.lua @@ -326,6 +326,7 @@ function GT:RemoveSender(senderIndex) GT.Debug("Remove Sender", 2, senderIndex) for itemID, inventoryData in pairs(GT.InventoryData) do table.remove(inventoryData.counts, senderIndex) + table.remove(inventoryData.sessionCounts, senderIndex) table.remove(inventoryData.startAmount, senderIndex) end table.remove(GT.sender, senderIndex) @@ -544,7 +545,13 @@ function GT:PrepareDataForDisplay(event, wait) if GT.db.profile.General.characterValue and GT:GroupDisplayCheck() and GT.priceSources then local playerPriceTotals = {} for senderIndex, senderData in ipairs(GT.sender) do - local playerTotal, playerPrice = GT:CalculateTotals(senderIndex, true) + local playerTotal, playerPrice = GT:CalculateTotals( + senderIndex, + true, + nil, + nil, + GT.db.profile.General.sessionOnly + ) table.insert(playerPriceTotals, tostring(math.ceil(playerPrice - 0.5)) .. "g") end GT:InitiateFrameProcess( @@ -590,7 +597,7 @@ function GT:SetupItemRows() itemData.counts ) else - local totalItemCount, priceTotalItem = GT:CalculateTotals(nil, nil, itemID, true) + local totalItemCount, priceTotalItem = GT:CalculateTotals(nil, nil, itemID, true, GT.db.profile.General.sessionOnly) local pricePerItem = nil if GT.priceSources then pricePerItem = GT:GetItemPrice(itemID) @@ -598,26 +605,50 @@ function GT:SetupItemRows() local itemsPerHour = GT:CalculateItemsPerHour(itemID) local goldPerHour = itemsPerHour * (pricePerItem or 0) - GT:InitiateFrameProcess( - tonumber(itemID), - GetItemIcon(tonumber(itemID)), - C_TradeSkillUI.GetItemReagentQualityByItemInfo(itemID), - C_Item.GetItemQualityByID(itemID), - itemData.counts, - totalItemCount, - pricePerItem, - priceTotalItem, - itemsPerHour, - goldPerHour - ) + if totalItemCount > 0 or GT.db.profile.General.allFiltered then + GT:InitiateFrameProcess( + tonumber(itemID), + GetItemIcon(tonumber(itemID)), + C_TradeSkillUI.GetItemReagentQualityByItemInfo(itemID), + C_Item.GetItemQualityByID(itemID), + GT:GetItemRowData(itemID), + totalItemCount, + pricePerItem, + priceTotalItem, + itemsPerHour, + goldPerHour + ) + elseif GT.Display.Frames[itemID] then + GT:RemoveDiaplayRow(itemID) + end + end + end +end + +function GT:GetItemRowData(itemID) + GT.Debug("GetItemRowData", 2, itemID) + + if GT.db.profile.General.sessionOnly then + GT.Debug("GetItemRowData", 3, "Session Counts", itemID) + return GT.InventoryData[itemID].sessionCounts + elseif GT.db.profile.General.sessionItems and not IsInGroup() then + local data = {} + for playerIndex, count in ipairs(GT.InventoryData[itemID].counts) do + table.insert(data, count) + table.insert(data, GT.InventoryData[itemID].sessionCounts[playerIndex]) end + GT.Debug("GetItemRowData", 3, "Normal Counts & Session Counts", itemID) + return data + else + GT.Debug("GetItemRowData", 3, "Normal Counts", itemID) + return GT.InventoryData[itemID].counts end end function GT:CalculateItemsPerHour(itemID) if itemID then local itemData = GT.InventoryData[itemID] - local itemDiff = itemData.total - itemData.startTotal + local itemDiff = GT:SumTable(itemData.sessionCounts) local timeDiff = time() - itemData.startTime --divind time diff in Seconds by 3600 to get time diff in hours @@ -632,11 +663,11 @@ function GT:CalculateItemsPerHour(itemID) end function GT:CalculateItemsPerHourTotal(playerTotals) - local startAmount = 0 + local sessionAmount = 0 local pricePerHour = 0 for itemID, itemData in pairs(GT.InventoryData) do if itemID > #GT.ItemData.Other.Other then - startAmount = startAmount + itemData.startTotal + sessionAmount = sessionAmount + GT:SumTable(itemData.sessionCounts) local itemPerHour = GT:CalculateItemsPerHour(itemID) if itemPerHour and GT.priceSources then @@ -644,12 +675,11 @@ function GT:CalculateItemsPerHourTotal(playerTotals) end end end - local amountDiff = playerTotals - startAmount local timeDiff = time() - GT.GlobalStartTime --divind time diff in Seconds by 3600 to get time diff in hours - local itemsPerHour = amountDiff / (timeDiff / 3600) - GT.Debug("CalculateItemsPerHourTotal", 2, itemsPerHour, pricePerHour, playerTotals, startAmount, amountDiff, timeDiff) + local itemsPerHour = sessionAmount / (timeDiff / 3600) + GT.Debug("CalculateItemsPerHourTotal", 2, itemsPerHour, pricePerHour, playerTotals, sessionAmount, timeDiff) if itemsPerHour < 1 then itemsPerHour = 0 end @@ -664,11 +694,15 @@ function GT:SetupTotalsRow() local totalItemCount = 0 for senderIndex, senderData in ipairs(GT.sender) do - local playerTotal, playerPrice = GT:CalculateTotals(senderIndex, true) + local playerTotal, playerPrice = GT:CalculateTotals(senderIndex, true, nil, nil, GT.db.profile.General.sessionOnly) table.insert(playerTotals, playerTotal) + if GT.db.profile.General.sessionItems and not GT.db.profile.General.sessionOnly and not IsInGroup() then + local playerTotalSession, playerPriceSession = GT:CalculateTotals(senderIndex, true, nil, nil, true) + table.insert(playerTotals, playerTotalSession) + end + totalItemCount = totalItemCount + playerTotal priceTotal = priceTotal + playerPrice end - totalItemCount = GT:SumTable(playerTotals) if totalItemCount > 0 or GT.db.profile.General.collapseDisplay then local itemsPerHour, goldPerHour = GT:CalculateItemsPerHourTotal(totalItemCount) @@ -945,6 +979,7 @@ function GT:UpdateSenderTable(sender) local senderTable = { name = sender, inventoryData = {}, + sessionData = {}, } table.insert(GT.sender, senderTable) senderIndex = #GT.sender @@ -978,6 +1013,8 @@ function GT:ItemDataConstructor(itemID, senderIndex) itemData.startTotal = 0 itemData.startAmount = {} itemData.startAmount[senderIndex] = 0 + itemData.sessionCounts = {} + itemData.sessionCounts[senderIndex] = 0 itemData.startTime = time() return itemData @@ -986,14 +1023,21 @@ end function GT:UpdateInventoryData(senderIndex, itemTable) GT.Debug("UpdateInventoryData", 1, senderIndex, itemTable) for itemID, value in pairs(itemTable) do + local value = tonumber(value) if GT:TableFind(GT.IDs, itemID) then GT.InventoryData[itemID] = GT.InventoryData[itemID] or GT:ItemDataConstructor(itemID, senderIndex) - GT.InventoryData[itemID].counts[senderIndex] = tonumber(value) - GT.sender[senderIndex].inventoryData[itemID] = tonumber(value) + GT.InventoryData[itemID].counts[senderIndex] = value + GT.sender[senderIndex].inventoryData[itemID] = value + if not GT.InventoryData[itemID].startAmount[senderIndex] or GT.InventoryData[itemID].startAmount[senderIndex] == 0 then - GT.InventoryData[itemID].startAmount[senderIndex] = tonumber(value) + GT.InventoryData[itemID].startAmount[senderIndex] = value end + + GT.InventoryData[itemID].sessionCounts[senderIndex] = + GT.InventoryData[itemID].counts[senderIndex] - GT.InventoryData[itemID].startAmount[senderIndex] + GT.sender[senderIndex].sessionData[itemID] = + GT.InventoryData[itemID].counts[senderIndex] - GT.InventoryData[itemID].startAmount[senderIndex] GT.InventoryData[itemID].startTotal = GT:CalculateStartTotal(itemID) else --only matters for when getting data from party members @@ -1006,7 +1050,9 @@ function GT:UpdateInventoryData(senderIndex, itemTable) for itemID, data in pairs(GT.InventoryData) do if not itemTable[itemID] then GT.InventoryData[itemID].counts[senderIndex] = 0 + GT.InventoryData[itemID].sessionCounts[senderIndex] = 0 GT.sender[senderIndex].inventoryData[itemID] = 0 + GT.sender[senderIndex].sessionData[itemID] = 0 end end @@ -1029,24 +1075,30 @@ function GT:CalculateStartTotal(itemID) return total end -function GT:CalculateTotals(senderIndex, calcSenderValue, itemID, calcItemValue) - GT.Debug("CalculateTotals", 1, senderIndex, calcSenderValue, itemID, calcItemValue) +function GT:CalculateTotals(senderIndex, calcSenderValue, itemID, calcItemValue, useSessionData) + GT.Debug("CalculateTotals", 1, senderIndex, calcSenderValue, itemID, calcItemValue, useSessionData) if senderIndex then - return GT:CalculatePlayerTotals(senderIndex, calcSenderValue) + return GT:CalculatePlayerTotals(senderIndex, calcSenderValue, useSessionData) end if itemID then - return GT:CalculateItemTotals(itemID, calcItemValue) + return GT:CalculateItemTotals(itemID, calcItemValue, useSessionData) end end -function GT:CalculatePlayerTotals(senderIndex, calcSenderValue) - GT.Debug("CalculatePlayerTotals", 1, senderIndex, calcSenderValue) +function GT:CalculatePlayerTotals(senderIndex, calcSenderValue, useSessionData) + GT.Debug("CalculatePlayerTotals", 1, senderIndex, calcSenderValue, useSessionData) local total = 0 local value = 0 - for itemID, itemCount in pairs(GT.sender[senderIndex].inventoryData) do + local data = {} + if useSessionData then + data = GT.sender[senderIndex].sessionData + else + data = GT.sender[senderIndex].inventoryData + end + for itemID, itemCount in pairs(data) do if itemID > #GT.ItemData.Other.Other and itemCount - GT.db.profile.General.ignoreAmount > 0 then total = total + itemCount if calcSenderValue and GT.priceSources then @@ -1057,12 +1109,18 @@ function GT:CalculatePlayerTotals(senderIndex, calcSenderValue) return total, math.ceil(value - 0.5) --rounds up to whole number end -function GT:CalculateItemTotals(itemID, calcItemValue) - GT.Debug("CalculateItemTotals", 1, itemID, calcItemValue) +function GT:CalculateItemTotals(itemID, calcItemValue, useSessionData) + GT.Debug("CalculateItemTotals", 1, itemID, calcItemValue, useSessionData) local total = 0 local value = 0 - for senderIndex, itemCount in pairs(GT.InventoryData[itemID].counts) do + local data = {} + if useSessionData then + data = GT.InventoryData[itemID].sessionCounts + else + data = GT.InventoryData[itemID].counts + end + for senderIndex, itemCount in pairs(data) do if itemCount - GT.db.profile.General.ignoreAmount > 0 then total = total + itemCount end diff --git a/GatheringTracker.toc b/GatheringTracker.toc index 611463c..fffe6f8 100644 --- a/GatheringTracker.toc +++ b/GatheringTracker.toc @@ -2,7 +2,7 @@ ## Title: Gathering Tracker ## Notes: Addon for tracking gathered items, supports solo players and groups ## Author: Noshei -## Version: 2.5.6 +## Version: 2.6.0 ## OptionalDeps: TradeSkillMaster, RECrystallize, Auctionator ## SavedVariables: GatheringTrackerDB ## AddonCompartmentFunc: GatheringTracker_OnAddonCompartmentClick diff --git a/Utilities.lua b/Utilities.lua index 5e94f2e..d2d0ac9 100644 --- a/Utilities.lua +++ b/Utilities.lua @@ -131,6 +131,11 @@ end function GT:GroupDisplayCheck() GT.Debug("Group Display Check", 2, GT.db.profile.General.groupType) + --Checks if we should display group data + if GT.SimulateGroupRunning then + GT.Debug("Group Display Check Result", 3, "Simulate Group") + return true + end if GT.db.profile.General.groupType == 0 then GT.Debug("Group Display Check Result", 3, "Group Mode Off") return false @@ -165,6 +170,10 @@ end function GT:SetChatType() local soloMode = GT.db.profile.General.groupType == 0 or GT.db.profile.General.groupType == 2 local groupMode = GT.db.profile.General.groupType > 0 + if GT.SimulateGroupRunning then --used to simulate being in a group + GT.groupMode = "PARTY" + return + end if IsInGroup() == false and soloMode then GT.groupMode = "WHISPER" return @@ -184,6 +193,9 @@ function GT:CheckModeStatus() local soloMode = GT.db.profile.General.groupType == 0 local groupMode = GT.db.profile.General.groupType == 1 GT.Debug("Check Mode Status", 2, soloMode, groupMode, IsInGroup()) + if GT.SimulateGroupRunning then --used to simulate being in a group + return true + end if GT.db.profile.General.groupType == 2 then --group mode set to Both return true end @@ -283,3 +295,31 @@ function GT:GetItemPrice(itemID) end return price end + +function GT:SimulateGroup(case) + --[[ + This is for testing purposes only. + It will simulate the effects of another player being in a group with you that also has the addon. + ]] + GT.Debug("Simulate Group", 1) + GT.SimulateGroupRunning = true + + local message = "" + if case == 1 then + GT:GROUP_ROSTER_UPDATE("Simulate Group", false) + message = "1=4824 2=1 2447=452 2449=483 2450=85 2452=10 785=60 " .. + "765=490 2592=10 3685=10 2589=80 7100=40 6663=10 39354=50 171831=45" + elseif case == 2 then + message = "1=4824 2=2 2447=4520 2449=4830 2450=850 2452=10 785=600 " .. + "765=4900 2592=100 3685=10 2589=80 7100=400 6663=10 39354=50 171831=450" + elseif case == 3 then + message = "1=4824 2=3 2447=45200 2449=4830 2450=850 2452=100 785=600 " .. + "765=4900 2592=1000 3685=10 2589=800 7100=400 6663=100 39354=50 171831=450" + end + if case then + GT:DataMessageReceived("GT_Data", message, "GROUP", "SimulatedGroup") + else + GT.SimulateGroupRunning = nil + GT:GROUP_ROSTER_UPDATE("Simulate Group", false) + end +end