Asa@28: local addonName, addonTable = ...; Asa@28: local ItemAuditor = _G[addonName] Asa@28: 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@35: -- Copied from QuickAuctions Asa@35: local function validateMoney(value) Asa@35: local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) Asa@35: local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) Asa@35: local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) Asa@35: Asa@35: if( not gold and not silver and not copper ) then Asa@35: return false; Asa@35: -- return L["Invalid monney format entered, should be \"#g#s#c\", \"25g4s50c\" is 25 gold, 4 silver, 50 copper."] Asa@35: end Asa@35: Asa@35: return true Asa@35: end Asa@35: Asa@35: -- Copied from QuickAuctions Asa@35: local function parseMoney(value) Asa@35: local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) Asa@35: local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) Asa@35: local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) Asa@35: Asa@35: -- Convert it all into copper Asa@35: return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) Asa@35: Asa@35: end Asa@35: Asa@35: local function SaveNewValue(link, type, text) Asa@35: if not validateMoney(text) then Asa@35: error("Invalid value") Asa@35: end Asa@35: local investedTotal, investedPerItem, numOwned = ItemAuditor:GetItemCost(link) Asa@35: local newValue=parseMoney(text) Asa@35: Asa@35: if type == priceTypeEach then Asa@35: newValue = newValue * numOwned Asa@35: end Asa@35: Asa@35: ItemAuditor:SaveValue(link, newValue-investedTotal, 0) Asa@35: -- ItemAuditor:SaveValue(link, newValue, 0) Asa@35: Asa@35: promptFrame:Hide() Asa@35: end 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@43: EditBoxOnEnterPressed = function() Asa@43: if ( getglobal(this:GetParent():GetName().."Button1"):IsEnabled() == 1 ) then Asa@43: getglobal(this:GetParent():GetName().."Button1"):Click() Asa@43: end Asa@43: end, Asa@43: EditBoxOnTextChanged = function () Asa@43: local parentName = this:GetParent():GetName() Asa@43: local editBox = getglobal( parentName.."EditBox"); Asa@43: local value = editBox:GetText() Asa@43: if validateMoney(value) then Asa@43: getglobal(parentName.."Button1"):Enable(); Asa@43: else Asa@43: getglobal(parentName.."Button1"):Disable(); Asa@43: end Asa@43: end, Asa@43: EditBoxOnEscapePressed = function() Asa@43: this:GetParent():Hide(); Asa@43: ClearCursor(); 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@43: -- function(widget, event, text) SaveNewValue(link, type, text) end 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@43: StaticPopupDialogs["ItemAuditor_NewPrice"].OnAccept = function() Asa@43: local name = this:GetParent():GetName().."EditBox" Asa@43: local button = getglobal(name) Asa@43: local newValue = button: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@43: StaticPopup_Show ("ItemAuditor_NewPrice", link, 'two'); 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@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@28: end Asa@28: Asa@28: Asa@28: local function switchTab(container, event, group) Asa@28: container:ReleaseChildren() Asa@28: Asa@28: if investedTab then investedTab:Hide() end Asa@28: Asa@28: if group == "tab_invested" then Asa@28: ShowInvested(container) Asa@28: end Asa@28: end Asa@28: Asa@28: Asa@28: Asa@28: displayFrame = false Asa@28: local function CreateFrames() Asa@28: if not displayFrame then Asa@28: -- Create the frame container Asa@28: displayFrame = AceGUI:Create("Frame") Asa@38: ItemAuditor:RegisterFrame(displayFrame) Asa@28: local window = displayFrame.frame; Asa@43: -- I have no idea why AceGUI insists on using FULLSCREEN_DIALOG by default. Asa@43: window:SetFrameStrata("MEDIUM") Asa@28: displayFrame:SetTitle("ItemAuditor") Asa@28: displayFrame:SetStatusText("") Asa@28: Asa@28: displayFrame:SetLayout("Fill") Asa@28: Asa@28: window:SetHeight(500); 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: window:SetWidth(width); Asa@28: Asa@28: local tab = AceGUI:Create("TabGroup") Asa@28: tab:SetLayout("Flow") Asa@28: tab:SetTabs({{text="Invested", value="tab_invested"}}) Asa@28: tab:SetCallback("OnGroupSelected", switchTab) Asa@28: tab:SelectTab("tab_invested") Asa@28: Asa@28: displayFrame:AddChild(tab) Asa@28: end Asa@28: displayFrame:Show() Asa@28: end Asa@28: Asa@28: Asa@28: Asa@28: 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@28: Asa@28: totalInvested = totalInvested + investedTotal Asa@28: Asa@28: i = i + 1 Asa@35: includedItems[safeLink] = true Asa@35: end Asa@35: end Asa@35: Asa@35: local inventory = ItemAuditor:GetCurrentInventory() Asa@35: Asa@35: for link, count in pairs(inventory.items) do Asa@35: if includedItems[link] == nil then Asa@35: local count = Altoholic:GetItemCount(ItemAuditor:GetIDFromLink(link)) Asa@35: local itemName, link = GetItemInfo(link) 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@28: displayFrame:SetStatusText("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: function ItemAuditor:CreateFrames() Asa@28: CreateFrames() Asa@28: end Asa@28: