annotate Modules/DisplayInvested.lua @ 59:4ec321eb0dfe

Adding a crafing tab to the ItemAuditor window.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sun, 25 Jul 2010 15:51:13 -0700
parents bdf3aba93aa9
children e7d287cc3b02
rev   line source
Asa@28 1 local addonName, addonTable = ...;
Asa@28 2 local ItemAuditor = _G[addonName]
Asa@28 3
Asa@28 4 local AceGUI = LibStub("AceGUI-3.0")
Asa@28 5 local ScrollingTable = LibStub("ScrollingTable")
Asa@28 6
Asa@35 7 local priceTypeEach = 1
Asa@35 8 local priceTypeTotal = 2
Asa@35 9
Asa@35 10 local promptFrame = false
Asa@35 11
Asa@58 12 local validateMoney = ItemAuditor.validateMoney
Asa@59 13 local parseMoney = ItemAuditor.parseMoney
Asa@35 14
Asa@35 15
Asa@43 16 StaticPopupDialogs["ItemAuditor_NewPrice"] = {
Asa@43 17 text = "New price %s %s",
Asa@43 18 button1 = SAVE,
Asa@43 19 button2 = CANCEL,
Asa@43 20 hasEditBox = 1,
Asa@43 21 showAlert = 1,
Asa@43 22 OnAccept = function()
Asa@43 23 skipCODTracking = true
Asa@43 24 end,
Asa@43 25 EditBoxOnEnterPressed = function()
Asa@43 26 if ( getglobal(this:GetParent():GetName().."Button1"):IsEnabled() == 1 ) then
Asa@43 27 getglobal(this:GetParent():GetName().."Button1"):Click()
Asa@43 28 end
Asa@43 29 end,
Asa@43 30 EditBoxOnTextChanged = function ()
Asa@43 31 local parentName = this:GetParent():GetName()
Asa@43 32 local editBox = getglobal( parentName.."EditBox");
Asa@43 33 local value = editBox:GetText()
Asa@43 34 if validateMoney(value) then
Asa@43 35 getglobal(parentName.."Button1"):Enable();
Asa@43 36 else
Asa@43 37 getglobal(parentName.."Button1"):Disable();
Asa@43 38 end
Asa@43 39 end,
Asa@43 40 EditBoxOnEscapePressed = function()
Asa@43 41 this:GetParent():Hide();
Asa@43 42 ClearCursor();
Asa@43 43 end,
Asa@43 44 timeout = 0,
Asa@43 45 hideOnEscape = 1,
Asa@43 46 exclusive = true,
Asa@43 47 }
Asa@35 48
Asa@35 49 local function PromptForNewPrice(link, type)
Asa@35 50 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
Asa@43 51
Asa@43 52 local typeText = "Invested Each"
Asa@35 53 local price = investedPerItem
Asa@43 54 if type == priceTypeTotal then
Asa@43 55 typeText = "Invested Total"
Asa@43 56 price = investedTotal
Asa@43 57
Asa@43 58 end
Asa@35 59
Asa@43 60 StaticPopupDialogs["ItemAuditor_NewPrice"].text = format("Update %s: %s|nThe current value is %s", typeText, link, ItemAuditor:FormatMoney(price))
Asa@43 61
Asa@43 62 StaticPopupDialogs["ItemAuditor_NewPrice"].OnShow = function (self, data)
Asa@43 63 self.editBox:SetText(ItemAuditor:FormatMoney(price, '', true))
Asa@35 64 end
Asa@43 65
Asa@43 66 StaticPopupDialogs["ItemAuditor_NewPrice"].OnAccept = function()
Asa@43 67 local name = this:GetParent():GetName().."EditBox"
Asa@43 68 local button = getglobal(name)
Asa@43 69 local newValue = button:GetText()
Asa@43 70 newValue = parseMoney(newValue)
Asa@35 71
Asa@43 72 local investedTotal, investedPerItem, numOwned = ItemAuditor:GetItemCost(link)
Asa@43 73
Asa@43 74 if type == priceTypeEach then
Asa@43 75 newValue = newValue * numOwned
Asa@43 76 end
Asa@43 77
Asa@43 78 ItemAuditor:SaveValue(link, newValue-investedTotal, 0)
Asa@35 79 end
Asa@46 80 StaticPopup_Show ("ItemAuditor_NewPrice");
Asa@35 81 end
Asa@35 82
Asa@35 83 local function displayMoney(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...)
Asa@35 84 if fShow == true then
Asa@35 85 local money = data[realrow][column]
Asa@43 86 cellFrame.text:SetText(ItemAuditor:FormatMoney(data[realrow][column]))
Asa@35 87 end
Asa@35 88 end
Asa@35 89
Asa@28 90 local investedCols = {
Asa@43 91 { name= "Item", width = 200, defaultsort = "desc",
Asa@28 92 ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...)
Asa@28 93 if fShow == true then
Asa@28 94 local _, link= strsplit("|", data[realrow][column], 2)
Asa@28 95 cellFrame.text:SetText(link)
Asa@28 96 end
Asa@28 97 end,
Asa@28 98 },
Asa@28 99 { name= "Invested Total", width = 100, align = "RIGHT",
Asa@35 100 ['DoCellUpdate'] = displayMoney,
Asa@28 101 },
Asa@35 102 { name= "Invested Each", width = 100, align = "RIGHT",
Asa@35 103 ['DoCellUpdate'] = displayMoney,
Asa@28 104 },
Asa@43 105 { name= "# Owned", width = 50, align = "RIGHT", },
Asa@28 106 }
Asa@28 107
Asa@28 108 local investedTable = false
Asa@28 109 local function ShowInvested(container)
Asa@28 110 if investedTable == false then
Asa@28 111 local window = container.frame
Asa@28 112 investedTable = ScrollingTable:CreateST(investedCols, 23, nil, nil, window)
Asa@58 113
Asa@58 114
Asa@58 115
Asa@28 116 investedTable.frame:SetPoint("BOTTOMLEFT",window, 10,10)
Asa@28 117 investedTable.frame:SetPoint("TOP", window, 0, -60)
Asa@28 118 investedTable.frame:SetPoint("RIGHT", window, -10,0)
Asa@28 119 investedTable:RegisterEvents({
Asa@28 120 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Asa@28 121 if realrow then
Asa@28 122 local _, link= strsplit("|", data[realrow][1], 2)
Asa@28 123
Asa@28 124 GameTooltip:SetOwner(rowFrame, "ANCHOR_CURSOR")
Asa@28 125 GameTooltip:SetHyperlink(link)
Asa@28 126 GameTooltip:Show()
Asa@28 127 end
Asa@28 128 end,
Asa@28 129 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Asa@28 130 GameTooltip:Hide()
Asa@28 131 end,
Asa@28 132 ["OnClick"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
Asa@35 133 if realrow ~= nil and (column == 2 or column == 3) then
Asa@35 134 -- column.text = row:CreateFontString(col:GetName().."text", "OVERLAY", "GameFontHighlightSmall");
Asa@35 135 local _, link= strsplit("|", data[realrow][1], 2)
Asa@35 136
Asa@35 137 local type=priceTypeEach
Asa@35 138 if column == 2 then
Asa@35 139 type = priceTypeTotal
Asa@35 140 end
Asa@35 141
Asa@35 142 PromptForNewPrice(link, type)
Asa@28 143 end
Asa@28 144 end,
Asa@28 145 });
Asa@28 146 end
Asa@28 147 investedTable:Show()
Asa@28 148
Asa@28 149 local width = 80
Asa@28 150 for i, data in pairs(investedCols) do
Asa@28 151 width = width + data.width
Asa@28 152 end
Asa@28 153 if container.parent then
Asa@28 154 container.parent:SetWidth(width);
Asa@28 155 end
Asa@28 156
Asa@28 157
Asa@28 158 UpdateInvestedData()
Asa@58 159
Asa@58 160 return investedTable
Asa@28 161 end
Asa@28 162
Asa@59 163 ItemAuditor:RegisterTab("Invested", 'tab_invested', ShowInvested)
Asa@58 164 function ItemAuditor:DisplayInvested()
Asa@59 165 self:CreateFrame('tab_invested')
Asa@28 166 end
Asa@28 167
Asa@28 168 function UpdateInvestedData()
Asa@28 169 if investedTable then
Asa@28 170 tableData = {} --reset
Asa@28 171 local totalInvested = 0
Asa@28 172
Asa@28 173 local i = 1
Asa@28 174 local data
Asa@35 175 local items = ItemAuditor.db.factionrealm.items
Asa@35 176 local includedItems = {}
Asa@35 177 for safeLink in pairs(items) do
Asa@35 178 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(safeLink)
Asa@35 179 local itemName, link = GetItemInfo(safeLink)
Asa@35 180 if investedTotal > 0 and link ~= nil then
Asa@28 181 tableData[i] = {
Asa@28 182 itemName.."|"..link,
Asa@28 183 investedTotal,
Asa@28 184 investedPerItem,
Asa@28 185 count,
Asa@28 186 }
Asa@28 187
Asa@28 188 totalInvested = totalInvested + investedTotal
Asa@28 189
Asa@28 190 i = i + 1
Asa@35 191 includedItems[safeLink] = true
Asa@35 192 end
Asa@35 193 end
Asa@35 194
Asa@35 195 local inventory = ItemAuditor:GetCurrentInventory()
Asa@35 196
Asa@35 197 for link, count in pairs(inventory.items) do
Asa@35 198 if includedItems[link] == nil then
Asa@35 199 local count = Altoholic:GetItemCount(ItemAuditor:GetIDFromLink(link))
Asa@35 200 local itemName, link = GetItemInfo(link)
Asa@35 201 tableData[i] = {
Asa@35 202 itemName.."|"..link,
Asa@35 203 0,
Asa@35 204 0,
Asa@35 205 count,
Asa@35 206 }
Asa@35 207
Asa@35 208 -- totalInvested = totalInvested + investedTotal
Asa@35 209
Asa@35 210 i = i + 1
Asa@28 211 end
Asa@28 212 end
Asa@28 213
Asa@28 214 if investedTable.frame:IsShown() then
Asa@58 215 ItemAuditor:UpdateStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested))
Asa@28 216 end
Asa@28 217
Asa@28 218 investedTable:SetData(tableData, true)
Asa@28 219 end
Asa@28 220 end
Asa@28 221
Asa@28 222