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@35
|
12 -- Copied from QuickAuctions
|
Asa@35
|
13 local function validateMoney(value)
|
Asa@35
|
14 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g"))
|
Asa@35
|
15 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s"))
|
Asa@35
|
16 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c"))
|
Asa@35
|
17
|
Asa@35
|
18 if( not gold and not silver and not copper ) then
|
Asa@35
|
19 return false;
|
Asa@35
|
20 -- return L["Invalid monney format entered, should be \"#g#s#c\", \"25g4s50c\" is 25 gold, 4 silver, 50 copper."]
|
Asa@35
|
21 end
|
Asa@35
|
22
|
Asa@35
|
23 return true
|
Asa@35
|
24 end
|
Asa@35
|
25
|
Asa@35
|
26 -- Copied from QuickAuctions
|
Asa@35
|
27 local function parseMoney(value)
|
Asa@35
|
28 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g"))
|
Asa@35
|
29 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s"))
|
Asa@35
|
30 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c"))
|
Asa@35
|
31
|
Asa@35
|
32 -- Convert it all into copper
|
Asa@35
|
33 return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER)
|
Asa@35
|
34
|
Asa@35
|
35 end
|
Asa@35
|
36
|
Asa@35
|
37 local function SaveNewValue(link, type, text)
|
Asa@35
|
38 if not validateMoney(text) then
|
Asa@35
|
39 error("Invalid value")
|
Asa@35
|
40 end
|
Asa@35
|
41 local investedTotal, investedPerItem, numOwned = ItemAuditor:GetItemCost(link)
|
Asa@35
|
42 local newValue=parseMoney(text)
|
Asa@35
|
43
|
Asa@35
|
44 if type == priceTypeEach then
|
Asa@35
|
45 newValue = newValue * numOwned
|
Asa@35
|
46 end
|
Asa@35
|
47
|
Asa@35
|
48 ItemAuditor:SaveValue(link, newValue-investedTotal, 0)
|
Asa@35
|
49 -- ItemAuditor:SaveValue(link, newValue, 0)
|
Asa@35
|
50
|
Asa@35
|
51 promptFrame:Hide()
|
Asa@35
|
52 end
|
Asa@35
|
53
|
Asa@43
|
54 StaticPopupDialogs["ItemAuditor_NewPrice"] = {
|
Asa@43
|
55 text = "New price %s %s",
|
Asa@43
|
56 button1 = SAVE,
|
Asa@43
|
57 button2 = CANCEL,
|
Asa@43
|
58 hasEditBox = 1,
|
Asa@43
|
59 showAlert = 1,
|
Asa@43
|
60 OnAccept = function()
|
Asa@43
|
61 skipCODTracking = true
|
Asa@43
|
62 end,
|
Asa@43
|
63 EditBoxOnEnterPressed = function()
|
Asa@43
|
64 if ( getglobal(this:GetParent():GetName().."Button1"):IsEnabled() == 1 ) then
|
Asa@43
|
65 getglobal(this:GetParent():GetName().."Button1"):Click()
|
Asa@43
|
66 end
|
Asa@43
|
67 end,
|
Asa@43
|
68 EditBoxOnTextChanged = function ()
|
Asa@43
|
69 local parentName = this:GetParent():GetName()
|
Asa@43
|
70 local editBox = getglobal( parentName.."EditBox");
|
Asa@43
|
71 local value = editBox:GetText()
|
Asa@43
|
72 if validateMoney(value) then
|
Asa@43
|
73 getglobal(parentName.."Button1"):Enable();
|
Asa@43
|
74 else
|
Asa@43
|
75 getglobal(parentName.."Button1"):Disable();
|
Asa@43
|
76 end
|
Asa@43
|
77 end,
|
Asa@43
|
78 EditBoxOnEscapePressed = function()
|
Asa@43
|
79 this:GetParent():Hide();
|
Asa@43
|
80 ClearCursor();
|
Asa@43
|
81 end,
|
Asa@43
|
82 timeout = 0,
|
Asa@43
|
83 hideOnEscape = 1,
|
Asa@43
|
84 exclusive = true,
|
Asa@43
|
85 }
|
Asa@35
|
86
|
Asa@35
|
87 local function PromptForNewPrice(link, type)
|
Asa@43
|
88 -- function(widget, event, text) SaveNewValue(link, type, text) end
|
Asa@35
|
89 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
|
Asa@43
|
90
|
Asa@43
|
91 local typeText = "Invested Each"
|
Asa@35
|
92 local price = investedPerItem
|
Asa@43
|
93 if type == priceTypeTotal then
|
Asa@43
|
94 typeText = "Invested Total"
|
Asa@43
|
95 price = investedTotal
|
Asa@43
|
96
|
Asa@43
|
97 end
|
Asa@35
|
98
|
Asa@43
|
99 StaticPopupDialogs["ItemAuditor_NewPrice"].text = format("Update %s: %s|nThe current value is %s", typeText, link, ItemAuditor:FormatMoney(price))
|
Asa@43
|
100
|
Asa@43
|
101 StaticPopupDialogs["ItemAuditor_NewPrice"].OnShow = function (self, data)
|
Asa@43
|
102 self.editBox:SetText(ItemAuditor:FormatMoney(price, '', true))
|
Asa@35
|
103 end
|
Asa@43
|
104
|
Asa@43
|
105 StaticPopupDialogs["ItemAuditor_NewPrice"].OnAccept = function()
|
Asa@43
|
106 local name = this:GetParent():GetName().."EditBox"
|
Asa@43
|
107 local button = getglobal(name)
|
Asa@43
|
108 local newValue = button:GetText()
|
Asa@43
|
109 newValue = parseMoney(newValue)
|
Asa@35
|
110
|
Asa@43
|
111 local investedTotal, investedPerItem, numOwned = ItemAuditor:GetItemCost(link)
|
Asa@43
|
112
|
Asa@43
|
113 if type == priceTypeEach then
|
Asa@43
|
114 newValue = newValue * numOwned
|
Asa@43
|
115 end
|
Asa@43
|
116
|
Asa@43
|
117 ItemAuditor:SaveValue(link, newValue-investedTotal, 0)
|
Asa@35
|
118 end
|
Asa@43
|
119 StaticPopup_Show ("ItemAuditor_NewPrice", link, 'two');
|
Asa@35
|
120 end
|
Asa@35
|
121
|
Asa@35
|
122 local function displayMoney(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...)
|
Asa@35
|
123 if fShow == true then
|
Asa@35
|
124 local money = data[realrow][column]
|
Asa@43
|
125 cellFrame.text:SetText(ItemAuditor:FormatMoney(data[realrow][column]))
|
Asa@35
|
126 end
|
Asa@35
|
127 end
|
Asa@35
|
128
|
Asa@28
|
129 local investedCols = {
|
Asa@43
|
130 { name= "Item", width = 200, defaultsort = "desc",
|
Asa@28
|
131 ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...)
|
Asa@28
|
132 if fShow == true then
|
Asa@28
|
133 local _, link= strsplit("|", data[realrow][column], 2)
|
Asa@28
|
134 cellFrame.text:SetText(link)
|
Asa@28
|
135 end
|
Asa@28
|
136 end,
|
Asa@28
|
137 },
|
Asa@28
|
138 { name= "Invested Total", width = 100, align = "RIGHT",
|
Asa@35
|
139 ['DoCellUpdate'] = displayMoney,
|
Asa@28
|
140 },
|
Asa@35
|
141 { name= "Invested Each", width = 100, align = "RIGHT",
|
Asa@35
|
142 ['DoCellUpdate'] = displayMoney,
|
Asa@28
|
143 },
|
Asa@43
|
144 { name= "# Owned", width = 50, align = "RIGHT", },
|
Asa@28
|
145 }
|
Asa@28
|
146
|
Asa@28
|
147 local investedTable = false
|
Asa@28
|
148 local function ShowInvested(container)
|
Asa@28
|
149 if investedTable == false then
|
Asa@28
|
150 local window = container.frame
|
Asa@28
|
151 investedTable = ScrollingTable:CreateST(investedCols, 23, nil, nil, window)
|
Asa@28
|
152 investedTable.frame:SetPoint("BOTTOMLEFT",window, 10,10)
|
Asa@28
|
153 investedTable.frame:SetPoint("TOP", window, 0, -60)
|
Asa@28
|
154 investedTable.frame:SetPoint("RIGHT", window, -10,0)
|
Asa@28
|
155 investedTable:RegisterEvents({
|
Asa@28
|
156 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
|
Asa@28
|
157 if realrow then
|
Asa@28
|
158 local _, link= strsplit("|", data[realrow][1], 2)
|
Asa@28
|
159
|
Asa@28
|
160 GameTooltip:SetOwner(rowFrame, "ANCHOR_CURSOR")
|
Asa@28
|
161 GameTooltip:SetHyperlink(link)
|
Asa@28
|
162 GameTooltip:Show()
|
Asa@28
|
163 end
|
Asa@28
|
164 end,
|
Asa@28
|
165 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
|
Asa@28
|
166 GameTooltip:Hide()
|
Asa@28
|
167 end,
|
Asa@28
|
168 ["OnClick"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
|
Asa@35
|
169 if realrow ~= nil and (column == 2 or column == 3) then
|
Asa@35
|
170 -- column.text = row:CreateFontString(col:GetName().."text", "OVERLAY", "GameFontHighlightSmall");
|
Asa@35
|
171 local _, link= strsplit("|", data[realrow][1], 2)
|
Asa@35
|
172
|
Asa@35
|
173 local type=priceTypeEach
|
Asa@35
|
174 if column == 2 then
|
Asa@35
|
175 type = priceTypeTotal
|
Asa@35
|
176 end
|
Asa@35
|
177
|
Asa@35
|
178 PromptForNewPrice(link, type)
|
Asa@28
|
179 end
|
Asa@28
|
180 end,
|
Asa@28
|
181 });
|
Asa@28
|
182 end
|
Asa@28
|
183 investedTable:Show()
|
Asa@28
|
184
|
Asa@28
|
185 local width = 80
|
Asa@28
|
186 for i, data in pairs(investedCols) do
|
Asa@28
|
187 width = width + data.width
|
Asa@28
|
188 end
|
Asa@28
|
189 if container.parent then
|
Asa@28
|
190 container.parent:SetWidth(width);
|
Asa@28
|
191 end
|
Asa@28
|
192
|
Asa@28
|
193
|
Asa@28
|
194 UpdateInvestedData()
|
Asa@28
|
195 end
|
Asa@28
|
196
|
Asa@28
|
197
|
Asa@28
|
198 local function switchTab(container, event, group)
|
Asa@28
|
199 container:ReleaseChildren()
|
Asa@28
|
200
|
Asa@28
|
201 if investedTab then investedTab:Hide() end
|
Asa@28
|
202
|
Asa@28
|
203 if group == "tab_invested" then
|
Asa@28
|
204 ShowInvested(container)
|
Asa@28
|
205 end
|
Asa@28
|
206 end
|
Asa@28
|
207
|
Asa@28
|
208
|
Asa@28
|
209
|
Asa@28
|
210 displayFrame = false
|
Asa@28
|
211 local function CreateFrames()
|
Asa@28
|
212 if not displayFrame then
|
Asa@28
|
213 -- Create the frame container
|
Asa@28
|
214 displayFrame = AceGUI:Create("Frame")
|
Asa@38
|
215 ItemAuditor:RegisterFrame(displayFrame)
|
Asa@28
|
216 local window = displayFrame.frame;
|
Asa@43
|
217 -- I have no idea why AceGUI insists on using FULLSCREEN_DIALOG by default.
|
Asa@43
|
218 window:SetFrameStrata("MEDIUM")
|
Asa@28
|
219 displayFrame:SetTitle("ItemAuditor")
|
Asa@28
|
220 displayFrame:SetStatusText("")
|
Asa@28
|
221
|
Asa@28
|
222 displayFrame:SetLayout("Fill")
|
Asa@28
|
223
|
Asa@28
|
224 window:SetHeight(500);
|
Asa@28
|
225
|
Asa@28
|
226 local width = 80
|
Asa@28
|
227 for i, data in pairs(investedCols) do
|
Asa@28
|
228 width = width + data.width
|
Asa@28
|
229 end
|
Asa@28
|
230 window:SetWidth(width);
|
Asa@28
|
231
|
Asa@28
|
232 local tab = AceGUI:Create("TabGroup")
|
Asa@28
|
233 tab:SetLayout("Flow")
|
Asa@28
|
234 tab:SetTabs({{text="Invested", value="tab_invested"}})
|
Asa@28
|
235 tab:SetCallback("OnGroupSelected", switchTab)
|
Asa@28
|
236 tab:SelectTab("tab_invested")
|
Asa@28
|
237
|
Asa@28
|
238 displayFrame:AddChild(tab)
|
Asa@28
|
239 end
|
Asa@28
|
240 displayFrame:Show()
|
Asa@28
|
241 end
|
Asa@28
|
242
|
Asa@28
|
243
|
Asa@28
|
244
|
Asa@28
|
245
|
Asa@28
|
246
|
Asa@28
|
247 function UpdateInvestedData()
|
Asa@28
|
248 if investedTable then
|
Asa@28
|
249 tableData = {} --reset
|
Asa@28
|
250 local totalInvested = 0
|
Asa@28
|
251
|
Asa@28
|
252 local i = 1
|
Asa@28
|
253 local data
|
Asa@35
|
254 local items = ItemAuditor.db.factionrealm.items
|
Asa@35
|
255 local includedItems = {}
|
Asa@35
|
256 for safeLink in pairs(items) do
|
Asa@35
|
257 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(safeLink)
|
Asa@35
|
258 local itemName, link = GetItemInfo(safeLink)
|
Asa@35
|
259 if investedTotal > 0 and link ~= nil then
|
Asa@28
|
260 tableData[i] = {
|
Asa@28
|
261 itemName.."|"..link,
|
Asa@28
|
262 investedTotal,
|
Asa@28
|
263 investedPerItem,
|
Asa@28
|
264 count,
|
Asa@28
|
265 }
|
Asa@28
|
266
|
Asa@28
|
267 totalInvested = totalInvested + investedTotal
|
Asa@28
|
268
|
Asa@28
|
269 i = i + 1
|
Asa@35
|
270 includedItems[safeLink] = true
|
Asa@35
|
271 end
|
Asa@35
|
272 end
|
Asa@35
|
273
|
Asa@35
|
274 local inventory = ItemAuditor:GetCurrentInventory()
|
Asa@35
|
275
|
Asa@35
|
276 for link, count in pairs(inventory.items) do
|
Asa@35
|
277 if includedItems[link] == nil then
|
Asa@35
|
278 local count = Altoholic:GetItemCount(ItemAuditor:GetIDFromLink(link))
|
Asa@35
|
279 local itemName, link = GetItemInfo(link)
|
Asa@35
|
280 tableData[i] = {
|
Asa@35
|
281 itemName.."|"..link,
|
Asa@35
|
282 0,
|
Asa@35
|
283 0,
|
Asa@35
|
284 count,
|
Asa@35
|
285 }
|
Asa@35
|
286
|
Asa@35
|
287 -- totalInvested = totalInvested + investedTotal
|
Asa@35
|
288
|
Asa@35
|
289 i = i + 1
|
Asa@28
|
290 end
|
Asa@28
|
291 end
|
Asa@28
|
292
|
Asa@28
|
293 if investedTable.frame:IsShown() then
|
Asa@28
|
294 displayFrame:SetStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested))
|
Asa@28
|
295 end
|
Asa@28
|
296
|
Asa@28
|
297 investedTable:SetData(tableData, true)
|
Asa@28
|
298 end
|
Asa@28
|
299 end
|
Asa@28
|
300
|
Asa@28
|
301 function ItemAuditor:CreateFrames()
|
Asa@28
|
302 CreateFrames()
|
Asa@28
|
303 end
|
Asa@28
|
304
|