Asa@63: local ItemAuditor = select(2, ...) Asa@63: local DisplayInvested = ItemAuditor:NewModule("DisplayInvested") Asa@28: Asa@64: Asa@28: local AceGUI = LibStub("AceGUI-3.0") Asa@28: local ScrollingTable = LibStub("ScrollingTable") Asa@28: Asa@35: local priceTypeEach = 1 Asa@35: local priceTypeTotal = 2 Asa@35: Asa@35: local promptFrame = false Asa@35: Asa@58: local validateMoney = ItemAuditor.validateMoney Asa@59: local parseMoney = ItemAuditor.parseMoney Asa@35: Asa@35: Asa@43: StaticPopupDialogs["ItemAuditor_NewPrice"] = { Asa@43: text = "New price %s %s", Asa@43: button1 = SAVE, Asa@43: button2 = CANCEL, Asa@43: hasEditBox = 1, Asa@43: showAlert = 1, Asa@43: OnAccept = function() Asa@43: skipCODTracking = true Asa@43: end, Asa@148: EditBoxOnEnterPressed = function(self) Asa@148: if ( self:GetParent().button1:IsEnabled() == 1 ) then Asa@148: self:GetParent().button1:Click() Asa@43: end Asa@43: end, Asa@148: EditBoxOnTextChanged = function (self) Asa@148: if validateMoney(self:GetText()) then Asa@148: self:GetParent().button1:Enable() Asa@43: else Asa@148: self:GetParent().button1:Disable(); Asa@43: end Asa@148: Asa@43: end, Asa@148: EditBoxOnEscapePressed = function(self) Asa@148: self:GetParent().button2:Click() Asa@43: end, Asa@43: timeout = 0, Asa@43: hideOnEscape = 1, Asa@43: exclusive = true, Asa@43: } Asa@35: Asa@35: local function PromptForNewPrice(link, type) Asa@35: local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link) Asa@43: Asa@43: local typeText = "Invested Each" Asa@35: local price = investedPerItem Asa@43: if type == priceTypeTotal then Asa@43: typeText = "Invested Total" Asa@43: price = investedTotal Asa@43: Asa@43: end Asa@35: Asa@43: StaticPopupDialogs["ItemAuditor_NewPrice"].text = format("Update %s: %s|nThe current value is %s", typeText, link, ItemAuditor:FormatMoney(price)) Asa@43: Asa@43: StaticPopupDialogs["ItemAuditor_NewPrice"].OnShow = function (self, data) Asa@43: self.editBox:SetText(ItemAuditor:FormatMoney(price, '', true)) Asa@35: end Asa@43: Asa@148: StaticPopupDialogs["ItemAuditor_NewPrice"].OnAccept = function(self) Asa@148: local newValue = self.editBox:GetText() Asa@43: newValue = parseMoney(newValue) Asa@35: Asa@43: local investedTotal, investedPerItem, numOwned = ItemAuditor:GetItemCost(link) Asa@43: Asa@43: if type == priceTypeEach then Asa@43: newValue = newValue * numOwned Asa@43: end Asa@43: Asa@43: ItemAuditor:SaveValue(link, newValue-investedTotal, 0) Asa@35: end Asa@46: StaticPopup_Show ("ItemAuditor_NewPrice"); Asa@35: end Asa@35: Asa@35: local function displayMoney(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) Asa@35: if fShow == true then Asa@35: local money = data[realrow][column] Asa@43: cellFrame.text:SetText(ItemAuditor:FormatMoney(data[realrow][column])) Asa@35: end Asa@35: end Asa@35: Asa@28: local investedCols = { Asa@43: { name= "Item", width = 200, defaultsort = "desc", Asa@28: ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) Asa@28: if fShow == true then Asa@28: local _, link= strsplit("|", data[realrow][column], 2) Asa@28: cellFrame.text:SetText(link) Asa@28: end Asa@28: end, Asa@28: }, Asa@28: { name= "Invested Total", width = 100, align = "RIGHT", Asa@35: ['DoCellUpdate'] = displayMoney, Asa@28: }, Asa@35: { name= "Invested Each", width = 100, align = "RIGHT", Asa@35: ['DoCellUpdate'] = displayMoney, Asa@28: }, Asa@43: { name= "# Owned", width = 50, align = "RIGHT", }, Asa@28: } Asa@28: Asa@28: local investedTable = false Asa@28: local function ShowInvested(container) Asa@28: if investedTable == false then Asa@28: local window = container.frame Asa@28: investedTable = ScrollingTable:CreateST(investedCols, 23, nil, nil, window) Asa@58: Asa@58: Asa@58: Asa@28: investedTable.frame:SetPoint("BOTTOMLEFT",window, 10,10) Asa@28: investedTable.frame:SetPoint("TOP", window, 0, -60) Asa@28: investedTable.frame:SetPoint("RIGHT", window, -10,0) Asa@28: investedTable:RegisterEvents({ Asa@28: ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) Asa@28: if realrow then Asa@28: local _, link= strsplit("|", data[realrow][1], 2) Asa@28: Asa@28: GameTooltip:SetOwner(rowFrame, "ANCHOR_CURSOR") Asa@28: GameTooltip:SetHyperlink(link) Asa@28: GameTooltip:Show() Asa@28: end Asa@28: end, Asa@28: ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) Asa@28: GameTooltip:Hide() Asa@28: end, Asa@28: ["OnClick"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) Asa@35: if realrow ~= nil and (column == 2 or column == 3) then Asa@35: -- column.text = row:CreateFontString(col:GetName().."text", "OVERLAY", "GameFontHighlightSmall"); Asa@35: local _, link= strsplit("|", data[realrow][1], 2) Asa@35: Asa@35: local type=priceTypeEach Asa@35: if column == 2 then Asa@35: type = priceTypeTotal Asa@35: end Asa@35: Asa@35: PromptForNewPrice(link, type) Asa@28: end Asa@28: end, Asa@28: }); Asa@28: end Asa@28: investedTable:Show() Asa@28: Asa@28: local width = 80 Asa@28: for i, data in pairs(investedCols) do Asa@28: width = width + data.width Asa@28: end Asa@28: if container.parent then Asa@28: container.parent:SetWidth(width); Asa@28: end Asa@28: Asa@28: Asa@28: UpdateInvestedData() Asa@58: Asa@58: return investedTable Asa@28: end Asa@28: Asa@59: ItemAuditor:RegisterTab("Invested", 'tab_invested', ShowInvested) Asa@58: function ItemAuditor:DisplayInvested() Asa@59: self:CreateFrame('tab_invested') Asa@28: end Asa@28: Asa@28: function UpdateInvestedData() Asa@28: if investedTable then Asa@28: tableData = {} --reset Asa@28: local totalInvested = 0 Asa@28: Asa@28: local i = 1 Asa@28: local data Asa@35: local items = ItemAuditor.db.factionrealm.items Asa@35: local includedItems = {} Asa@35: for safeLink in pairs(items) do Asa@35: local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(safeLink) Asa@35: local itemName, link = GetItemInfo(safeLink) Asa@35: if investedTotal > 0 and link ~= nil then Asa@28: tableData[i] = { Asa@28: itemName.."|"..link, Asa@28: investedTotal, Asa@28: investedPerItem, Asa@28: count, Asa@28: } Asa@138: Asa@28: totalInvested = totalInvested + investedTotal Asa@138: Asa@28: i = i + 1 Asa@138: includedItems[ItemAuditor:GetIDFromLink(safeLink)] = true Asa@35: end Asa@35: end Asa@35: Asa@35: local inventory = ItemAuditor:GetCurrentInventory() Asa@35: Asa@138: for itemID, count in pairs(inventory.items) do Asa@138: if includedItems[itemID] == nil then Asa@138: local itemName, link = GetItemInfo(itemID) Asa@138: local count = ItemAuditor:GetItemCount(itemID) Asa@35: tableData[i] = { Asa@35: itemName.."|"..link, Asa@35: 0, Asa@35: 0, Asa@35: count, Asa@35: } Asa@35: Asa@35: -- totalInvested = totalInvested + investedTotal Asa@35: Asa@35: i = i + 1 Asa@28: end Asa@28: end Asa@28: Asa@28: if investedTable.frame:IsShown() then Asa@58: ItemAuditor:UpdateStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested)) Asa@28: end Asa@28: Asa@28: investedTable:SetData(tableData, true) Asa@28: end Asa@28: end Asa@28: Asa@28: Asa@67: ItemAuditor.Options.args.invested = { Asa@67: type = "execute", Asa@67: name = "invested", Asa@67: desc = "Shows what you have invested in", Asa@67: func = "DisplayInvested", Asa@67: guiHidden = false, Asa@67: }