comparison Modules/DisplayInvested.lua @ 58:bdf3aba93aa9

Refactored the way the window for /ia invested works so I can add more tabs.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sun, 25 Jul 2010 15:51:00 -0700
parents 5e981c1df761
children 4ec321eb0dfe
comparison
equal deleted inserted replaced
57:9cb0bc93ed11 58:bdf3aba93aa9
7 local priceTypeEach = 1 7 local priceTypeEach = 1
8 local priceTypeTotal = 2 8 local priceTypeTotal = 2
9 9
10 local promptFrame = false 10 local promptFrame = false
11 11
12 -- Copied from QuickAuctions 12 local validateMoney = ItemAuditor.validateMoney
13 local function validateMoney(value) 13 local parseMoney = parseMoney
14 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) 14
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 15
37 StaticPopupDialogs["ItemAuditor_NewPrice"] = { 16 StaticPopupDialogs["ItemAuditor_NewPrice"] = {
38 text = "New price %s %s", 17 text = "New price %s %s",
39 button1 = SAVE, 18 button1 = SAVE,
40 button2 = CANCEL, 19 button2 = CANCEL,
129 local investedTable = false 108 local investedTable = false
130 local function ShowInvested(container) 109 local function ShowInvested(container)
131 if investedTable == false then 110 if investedTable == false then
132 local window = container.frame 111 local window = container.frame
133 investedTable = ScrollingTable:CreateST(investedCols, 23, nil, nil, window) 112 investedTable = ScrollingTable:CreateST(investedCols, 23, nil, nil, window)
113
114
115
134 investedTable.frame:SetPoint("BOTTOMLEFT",window, 10,10) 116 investedTable.frame:SetPoint("BOTTOMLEFT",window, 10,10)
135 investedTable.frame:SetPoint("TOP", window, 0, -60) 117 investedTable.frame:SetPoint("TOP", window, 0, -60)
136 investedTable.frame:SetPoint("RIGHT", window, -10,0) 118 investedTable.frame:SetPoint("RIGHT", window, -10,0)
137 investedTable:RegisterEvents({ 119 investedTable:RegisterEvents({
138 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) 120 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
172 container.parent:SetWidth(width); 154 container.parent:SetWidth(width);
173 end 155 end
174 156
175 157
176 UpdateInvestedData() 158 UpdateInvestedData()
177 end 159
178 160 return investedTable
179 161 end
180 local function switchTab(container, event, group) 162
181 container:ReleaseChildren() 163 local function getinvestedColsWidth()
182 164 local width = 0
183 if investedTab then investedTab:Hide() end 165 for i, data in pairs(investedCols) do
184 166 width = width + data.width
185 if group == "tab_invested" then 167 end
186 ShowInvested(container) 168 return width
187 end 169 end
188 end 170
189 171 local tabName = 'tab_invested'
190 172 ItemAuditor:RegisterTab("Invested", tabName, getinvestedColsWidth(), ShowInvested)
191 173 function ItemAuditor:DisplayInvested()
192 displayFrame = false 174 self:CreateFrame(tabName)
193 local function CreateFrames() 175 end
194 if not displayFrame then
195 -- Create the frame container
196 displayFrame = AceGUI:Create("Frame")
197 ItemAuditor:RegisterFrame(displayFrame)
198 local window = displayFrame.frame;
199 -- I have no idea why AceGUI insists on using FULLSCREEN_DIALOG by default.
200 window:SetFrameStrata("MEDIUM")
201 displayFrame:SetTitle("ItemAuditor")
202 displayFrame:SetStatusText("")
203
204 displayFrame:SetLayout("Fill")
205
206 window:SetHeight(500);
207
208 local width = 80
209 for i, data in pairs(investedCols) do
210 width = width + data.width
211 end
212 window:SetWidth(width);
213
214 local tab = AceGUI:Create("TabGroup")
215 tab:SetLayout("Flow")
216 tab:SetTabs({{text="Invested", value="tab_invested"}})
217 tab:SetCallback("OnGroupSelected", switchTab)
218 tab:SelectTab("tab_invested")
219
220 displayFrame:AddChild(tab)
221 end
222 displayFrame:Show()
223 end
224
225
226
227
228 176
229 function UpdateInvestedData() 177 function UpdateInvestedData()
230 if investedTable then 178 if investedTable then
231 tableData = {} --reset 179 tableData = {} --reset
232 local totalInvested = 0 180 local totalInvested = 0
271 i = i + 1 219 i = i + 1
272 end 220 end
273 end 221 end
274 222
275 if investedTable.frame:IsShown() then 223 if investedTable.frame:IsShown() then
276 displayFrame:SetStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested)) 224 ItemAuditor:UpdateStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested))
277 end 225 end
278 226
279 investedTable:SetData(tableData, true) 227 investedTable:SetData(tableData, true)
280 end 228 end
281 end 229 end
282 230
283 function ItemAuditor:CreateFrames() 231
284 CreateFrames()
285 end
286