annotate Modules/DisplayInvested.lua @ 144:03e108d12ef1

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