Mercurial > wow > itemauditor
comparison Modules/DisplayInvested.lua @ 35:aaa716c93fb2 v0.1.1
Added the ability to change the price of an item. You can click the Total Invested or the Invested Each to change the value.
| author | Asa Ayers <Asa.Ayers@Gmail.com> |
|---|---|
| date | Sun, 18 Jul 2010 16:43:03 -0700 |
| parents | e6ddeb9f9994 |
| children | e27d13095b49 |
comparison
equal
deleted
inserted
replaced
| 34:d21d202f3b3d | 35:aaa716c93fb2 |
|---|---|
| 1 local addonName, addonTable = ...; | 1 local addonName, addonTable = ...; |
| 2 local ItemAuditor = _G[addonName] | 2 local ItemAuditor = _G[addonName] |
| 3 | 3 |
| 4 local AceGUI = LibStub("AceGUI-3.0") | 4 local AceGUI = LibStub("AceGUI-3.0") |
| 5 local ScrollingTable = LibStub("ScrollingTable") | 5 local ScrollingTable = LibStub("ScrollingTable") |
| 6 | |
| 7 local priceTypeEach = 1 | |
| 8 local priceTypeTotal = 2 | |
| 9 | |
| 10 local promptFrame = false | |
| 11 | |
| 12 -- Copied from QuickAuctions | |
| 13 local function validateMoney(value) | |
| 14 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) | |
| 15 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) | |
| 16 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) | |
| 17 | |
| 18 if( not gold and not silver and not copper ) then | |
| 19 return false; | |
| 20 -- return L["Invalid monney format entered, should be \"#g#s#c\", \"25g4s50c\" is 25 gold, 4 silver, 50 copper."] | |
| 21 end | |
| 22 | |
| 23 return true | |
| 24 end | |
| 25 | |
| 26 -- Copied from QuickAuctions | |
| 27 local function parseMoney(value) | |
| 28 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) | |
| 29 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) | |
| 30 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) | |
| 31 | |
| 32 -- Convert it all into copper | |
| 33 return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) | |
| 34 | |
| 35 end | |
| 36 | |
| 37 local function SaveNewValue(link, type, text) | |
| 38 if not validateMoney(text) then | |
| 39 error("Invalid value") | |
| 40 end | |
| 41 local investedTotal, investedPerItem, numOwned = ItemAuditor:GetItemCost(link) | |
| 42 local newValue=parseMoney(text) | |
| 43 | |
| 44 if type == priceTypeEach then | |
| 45 newValue = newValue * numOwned | |
| 46 end | |
| 47 | |
| 48 ItemAuditor:SaveValue(link, newValue-investedTotal, 0) | |
| 49 -- ItemAuditor:SaveValue(link, newValue, 0) | |
| 50 | |
| 51 promptFrame:Hide() | |
| 52 end | |
| 53 | |
| 54 | |
| 55 local function PromptForNewPrice(link, type) | |
| 56 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link) | |
| 57 local itemName, displayLink = GetItemInfo(link) | |
| 58 local priceDesc = " Invested Each:" | |
| 59 local price = investedPerItem | |
| 60 | |
| 61 if type == priceTypeTotal then | |
| 62 priceDesc = " Invested Total:" | |
| 63 price = investedTotal | |
| 64 end | |
| 65 | |
| 66 if not promptFrame then | |
| 67 promptFrame = AceGUI:Create("Frame") | |
| 68 | |
| 69 local window = promptFrame.frame; | |
| 70 local width = 345 | |
| 71 local height = 115 | |
| 72 window:SetWidth(width ) | |
| 73 window:SetHeight(height ) | |
| 74 window:SetMinResize(width, height) | |
| 75 window:SetMaxResize(width, height) | |
| 76 | |
| 77 promptFrame:SetTitle("ItemAuditor") | |
| 78 promptFrame:SetStatusText("Status Here") | |
| 79 promptFrame:SetCallback("OnClose", function(widget) AceGUI:Release(widget); promptFrame = false end) | |
| 80 promptFrame:SetLayout("Flow") | |
| 81 | |
| 82 promptFrame.editbox = AceGUI:Create("EditBox") | |
| 83 promptFrame.editbox:SetWidth(300) | |
| 84 promptFrame:AddChild(promptFrame.editbox) | |
| 85 end | |
| 86 promptFrame.editbox:SetCallback("OnEnterPressed", function(widget, event, text) SaveNewValue(link, type, text) end) | |
| 87 promptFrame:SetStatusText("Current Price: "..ItemAuditor:FormatMoney(price)) | |
| 88 promptFrame.editbox:SetLabel(displayLink..priceDesc) | |
| 89 promptFrame.editbox:SetText(ItemAuditor:FormatMoney(price, "", true)) | |
| 90 | |
| 91 promptFrame:Show() | |
| 92 editBox = promptFrame.editbox | |
| 93 end | |
| 94 | |
| 95 local function displayMoney(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) | |
| 96 if fShow == true then | |
| 97 local money = data[realrow][column] | |
| 98 if money == nil then | |
| 99 cellFrame.text:SetText("None") | |
| 100 else | |
| 101 cellFrame.text:SetText(ItemAuditor:FormatMoney(data[realrow][column])) | |
| 102 end | |
| 103 end | |
| 104 end | |
| 6 | 105 |
| 7 local investedCols = { | 106 local investedCols = { |
| 8 { name= "Item", width = 200, | 107 { name= "Item", width = 200, |
| 9 ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) | 108 ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) |
| 10 if fShow == true then | 109 if fShow == true then |
| 12 cellFrame.text:SetText(link) | 111 cellFrame.text:SetText(link) |
| 13 end | 112 end |
| 14 end, | 113 end, |
| 15 }, | 114 }, |
| 16 { name= "Invested Total", width = 100, align = "RIGHT", | 115 { name= "Invested Total", width = 100, align = "RIGHT", |
| 17 ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) | 116 ['DoCellUpdate'] = displayMoney, |
| 18 if fShow == true then | |
| 19 cellFrame.text:SetText(ItemAuditor:FormatMoney(data[realrow][column])) | |
| 20 end | |
| 21 end, | |
| 22 }, | 117 }, |
| 23 { name= "Invested each", width = 100, align = "RIGHT", | 118 { name= "Invested Each", width = 100, align = "RIGHT", |
| 24 ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) | 119 ['DoCellUpdate'] = displayMoney, |
| 25 if fShow == true then | |
| 26 cellFrame.text:SetText(ItemAuditor:FormatMoney(data[realrow][column])) | |
| 27 end | |
| 28 end, | |
| 29 }, | 120 }, |
| 30 { name= "# owned", width = 50, align = "RIGHT", defaultsort = "asc", }, | 121 { name= "# Owned", width = 50, align = "RIGHT", defaultsort = "asc", }, |
| 31 } | 122 } |
| 32 | 123 |
| 33 local investedTable = false | 124 local investedTable = false |
| 34 local function ShowInvested(container) | 125 local function ShowInvested(container) |
| 35 if investedTable == false then | 126 if investedTable == false then |
| 50 end, | 141 end, |
| 51 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | 142 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) |
| 52 GameTooltip:Hide() | 143 GameTooltip:Hide() |
| 53 end, | 144 end, |
| 54 ["OnClick"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | 145 ["OnClick"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) |
| 55 if column == 3 then | 146 if realrow ~= nil and (column == 2 or column == 3) then |
| 56 GameTooltip:Hide() | 147 -- column.text = row:CreateFontString(col:GetName().."text", "OVERLAY", "GameFontHighlightSmall"); |
| 148 local _, link= strsplit("|", data[realrow][1], 2) | |
| 149 | |
| 150 local type=priceTypeEach | |
| 151 if column == 2 then | |
| 152 type = priceTypeTotal | |
| 153 end | |
| 154 | |
| 155 PromptForNewPrice(link, type) | |
| 57 end | 156 end |
| 58 end, | 157 end, |
| 59 }); | 158 }); |
| 60 end | 159 end |
| 61 investedTable:Show() | 160 investedTable:Show() |
| 124 tableData = {} --reset | 223 tableData = {} --reset |
| 125 local totalInvested = 0 | 224 local totalInvested = 0 |
| 126 | 225 |
| 127 local i = 1 | 226 local i = 1 |
| 128 local data | 227 local data |
| 129 for link in pairs(ItemAuditor.db.factionrealm.items) do | 228 local items = ItemAuditor.db.factionrealm.items |
| 130 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link) | 229 local includedItems = {} |
| 131 local itemName, link = GetItemInfo(link) | 230 for safeLink in pairs(items) do |
| 132 if investedTotal > 0 then | 231 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(safeLink) |
| 232 local itemName, link = GetItemInfo(safeLink) | |
| 233 if investedTotal > 0 and link ~= nil then | |
| 133 tableData[i] = { | 234 tableData[i] = { |
| 134 itemName.."|"..link, | 235 itemName.."|"..link, |
| 135 investedTotal, | 236 investedTotal, |
| 136 investedPerItem, | 237 investedPerItem, |
| 137 count, | 238 count, |
| 138 } | 239 } |
| 139 | 240 |
| 140 totalInvested = totalInvested + investedTotal | 241 totalInvested = totalInvested + investedTotal |
| 141 | 242 |
| 142 i = i + 1 | 243 i = i + 1 |
| 244 includedItems[safeLink] = true | |
| 245 end | |
| 246 end | |
| 247 | |
| 248 local inventory = ItemAuditor:GetCurrentInventory() | |
| 249 | |
| 250 for link, count in pairs(inventory.items) do | |
| 251 if includedItems[link] == nil then | |
| 252 local count = Altoholic:GetItemCount(ItemAuditor:GetIDFromLink(link)) | |
| 253 local itemName, link = GetItemInfo(link) | |
| 254 tableData[i] = { | |
| 255 itemName.."|"..link, | |
| 256 0, | |
| 257 0, | |
| 258 count, | |
| 259 } | |
| 260 | |
| 261 -- totalInvested = totalInvested + investedTotal | |
| 262 | |
| 263 i = i + 1 | |
| 143 end | 264 end |
| 144 end | 265 end |
| 145 | 266 |
| 146 if investedTable.frame:IsShown() then | 267 if investedTable.frame:IsShown() then |
| 147 displayFrame:SetStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested)) | 268 displayFrame:SetStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested)) |
