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