Mercurial > wow > itemauditor
comparison Modules/DisplayInvested.lua @ 28:34daa46b644a
Added an interface to view how much you have invested in each item.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Fri, 16 Jul 2010 01:32:08 -0700 |
parents | |
children | e6ddeb9f9994 |
comparison
equal
deleted
inserted
replaced
27:5da5d85cd714 | 28:34daa46b644a |
---|---|
1 local addonName, addonTable = ...; | |
2 local ItemAuditor = _G[addonName] | |
3 | |
4 local AceGUI = LibStub("AceGUI-3.0") | |
5 local ScrollingTable = LibStub("ScrollingTable") | |
6 | |
7 local investedCols = { | |
8 { name= "Item", width = 200, | |
9 ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) | |
10 if fShow == true then | |
11 local _, link= strsplit("|", data[realrow][column], 2) | |
12 cellFrame.text:SetText(link) | |
13 end | |
14 end, | |
15 }, | |
16 { name= "Invested Total", width = 100, align = "RIGHT", | |
17 ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) | |
18 if fShow == true then | |
19 cellFrame.text:SetText(ItemAuditor:FormatMoney(data[realrow][column])) | |
20 end | |
21 end, | |
22 }, | |
23 { name= "Invested each", width = 100, align = "RIGHT", | |
24 ['DoCellUpdate'] = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) | |
25 if fShow == true then | |
26 cellFrame.text:SetText(ItemAuditor:FormatMoney(data[realrow][column])) | |
27 end | |
28 end, | |
29 }, | |
30 { name= "Count", width = 50, defaultsort = "asc", }, | |
31 } | |
32 | |
33 local investedTable = false | |
34 local function ShowInvested(container) | |
35 if investedTable == false then | |
36 local window = container.frame | |
37 investedTable = ScrollingTable:CreateST(investedCols, 23, nil, nil, window) | |
38 investedTable.frame:SetPoint("BOTTOMLEFT",window, 10,10) | |
39 investedTable.frame:SetPoint("TOP", window, 0, -60) | |
40 investedTable.frame:SetPoint("RIGHT", window, -10,0) | |
41 investedTable:RegisterEvents({ | |
42 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | |
43 if realrow then | |
44 local _, link= strsplit("|", data[realrow][1], 2) | |
45 | |
46 GameTooltip:SetOwner(rowFrame, "ANCHOR_CURSOR") | |
47 GameTooltip:SetHyperlink(link) | |
48 GameTooltip:Show() | |
49 end | |
50 end, | |
51 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | |
52 GameTooltip:Hide() | |
53 end, | |
54 ["OnClick"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | |
55 if column == 3 then | |
56 GameTooltip:Hide() | |
57 end | |
58 end, | |
59 }); | |
60 end | |
61 investedTable:Show() | |
62 | |
63 local width = 80 | |
64 for i, data in pairs(investedCols) do | |
65 width = width + data.width | |
66 end | |
67 if container.parent then | |
68 container.parent:SetWidth(width); | |
69 end | |
70 | |
71 | |
72 UpdateInvestedData() | |
73 end | |
74 | |
75 | |
76 local function switchTab(container, event, group) | |
77 container:ReleaseChildren() | |
78 | |
79 if investedTab then investedTab:Hide() end | |
80 | |
81 if group == "tab_invested" then | |
82 ShowInvested(container) | |
83 end | |
84 end | |
85 | |
86 | |
87 | |
88 displayFrame = false | |
89 local function CreateFrames() | |
90 if not displayFrame then | |
91 -- Create the frame container | |
92 displayFrame = AceGUI:Create("Frame") | |
93 local window = displayFrame.frame; | |
94 displayFrame:SetTitle("ItemAuditor") | |
95 displayFrame:SetStatusText("") | |
96 | |
97 displayFrame:SetLayout("Fill") | |
98 | |
99 window:SetHeight(500); | |
100 | |
101 local width = 80 | |
102 for i, data in pairs(investedCols) do | |
103 width = width + data.width | |
104 end | |
105 window:SetWidth(width); | |
106 | |
107 local tab = AceGUI:Create("TabGroup") | |
108 tab:SetLayout("Flow") | |
109 tab:SetTabs({{text="Invested", value="tab_invested"}}) | |
110 tab:SetCallback("OnGroupSelected", switchTab) | |
111 tab:SelectTab("tab_invested") | |
112 | |
113 displayFrame:AddChild(tab) | |
114 end | |
115 displayFrame:Show() | |
116 end | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 function UpdateInvestedData() | |
123 if investedTable then | |
124 tableData = {} --reset | |
125 local totalInvested = 0 | |
126 | |
127 local i = 1 | |
128 local data | |
129 for link in pairs(ItemAuditor.db.factionrealm.items) do | |
130 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link) | |
131 local itemName, link = GetItemInfo(link) | |
132 if investedTotal > 0 then | |
133 tableData[i] = { | |
134 itemName.."|"..link, | |
135 investedTotal, | |
136 investedPerItem, | |
137 count, | |
138 } | |
139 | |
140 totalInvested = totalInvested + investedTotal | |
141 | |
142 i = i + 1 | |
143 end | |
144 end | |
145 | |
146 if investedTable.frame:IsShown() then | |
147 displayFrame:SetStatusText("Total Invested: "..ItemAuditor:FormatMoney(totalInvested)) | |
148 end | |
149 | |
150 investedTable:SetData(tableData, true) | |
151 end | |
152 end | |
153 | |
154 function ItemAuditor:CreateFrames() | |
155 CreateFrames() | |
156 end | |
157 |