vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --===========================================================================-- |
2 | ---------------------------- LootTracker by PNB ---------------------------- |
||
3 | --===========================================================================-- |
||
4 | -- LootTrackerSettingsUI.lua |
||
5 | -- |
||
6 | -- Code behind the settings UI |
||
7 | --===========================================================================-- |
||
8 | |||
9 | |||
10 | ------------------------------------------------------------------------------ |
||
11 | -- UpdateUI |
||
12 | ------------------------------------------------------------------------------ |
||
13 | |||
14 | function LT_UpdateUI() |
||
15 | |||
16 | -- TODO: Move to LootTrackerSessionChangeUI.lua |
||
17 | LT_OnSessionEditValueChanged(LT_ChangeSessionEditBox:GetText()); |
||
18 | |||
19 | LT_UpdateCurrentSessionText(); |
||
20 | |||
21 | end |
||
22 | |||
23 | |||
24 | ------------------------------------------------------------------------------ |
||
25 | -- UpdateCurrentSessionText |
||
26 | ------------------------------------------------------------------------------ |
||
27 | |||
28 | function LT_UpdateCurrentSessionText() |
||
29 | |||
30 | local settings = LT_GetSettings(); |
||
31 | local sessionName = settings.CurrentSession; |
||
32 | LT_CurrentSessionText:SetText(LT_FormatSessionName(sessionName)); |
||
33 | |||
34 | end |
||
35 | |||
36 | |||
37 | ------------------------------------------------------------------------------ |
||
38 | -- FormatSessionName |
||
39 | ------------------------------------------------------------------------------ |
||
40 | |||
41 | function LT_FormatSessionName(sessionName) |
||
42 | |||
43 | local text = LT_ColorText(sessionName, LT_White); |
||
44 | |||
45 | local session = LT_GetSession(sessionName, false); |
||
46 | if (session ~= nil) then |
||
47 | |||
48 | local sessionBeginTime = session.FirstEventTime; |
||
49 | local sessionEndTime = session.MostRecentEventTime; |
||
50 | if ((sessionBeginTime ~= nil) and (sessionEndTime ~= nil)) then |
||
51 | -- Would use difftime() here, but WoW doesn't include that LUA API. |
||
52 | local elapsedTime = sessionEndTime - sessionBeginTime; |
||
53 | |||
54 | -- If I don't do this I'm getting a time that's offset by 16 hours. |
||
55 | -- I don't exactly understand why, but this seems to clear it up... |
||
56 | local baseTime = {}; |
||
57 | baseTime.year = 1970; |
||
58 | baseTime.month = 1; |
||
59 | baseTime.day = 1; |
||
60 | baseTime.hour = 0; |
||
61 | local offsetTime = time(baseTime); |
||
62 | |||
63 | -- I'm not sure why time() is sometimes returning nil here, but some |
||
64 | -- people are reporting an error there. Pretty harmless to just |
||
65 | -- check for nil and leave off the time display if that's the case. |
||
66 | if (offsetTime ~= nil) then |
||
67 | |||
68 | -- Get the elapsed time for this session. |
||
69 | local elapsedTime = elapsedTime + offsetTime; |
||
70 | |||
71 | local formattedStartTime = date(LT_LABEL_FORMAT_TIMESTART, sessionBeginTime); |
||
72 | local formattedElapsedTime = date(LT_LABEL_FORMAT_TIMEELAPSED, elapsedTime); |
||
73 | text = text .. "\n" .. string.format(LT_LABEL_TIMESUMMARY, formattedStartTime, formattedElapsedTime); |
||
74 | end |
||
75 | end |
||
76 | |||
77 | local totalValue = 0; |
||
78 | local items = session.Items; |
||
79 | if (items ~= nil) then |
||
80 | foreach(items, function(itemName, item) |
||
81 | local itemValue = item.Value; |
||
82 | if (itemValue ~= nil) then |
||
83 | local timesLooted = getn(item.TimesLooted); |
||
84 | totalValue = totalValue + (timesLooted * itemValue); |
||
85 | end |
||
86 | end); |
||
87 | end |
||
88 | |||
89 | if (totalValue > 0) then |
||
90 | text = text .. "\nValue: " .. LT_GetValueString(totalValue, true); |
||
91 | end |
||
92 | end |
||
93 | |||
94 | return text; |
||
95 | |||
96 | end |
||
97 | |||
98 | |||
99 | ------------------------------------------------------------------------------ |
||
100 | -- OnSessionEditValueChanged |
||
101 | ------------------------------------------------------------------------------ |
||
102 | |||
103 | function LT_OnSessionEditValueChanged(value) |
||
104 | |||
105 | local settings = LT_GetSettings(); |
||
106 | local userData = LT_Data[LT_RealmAndPlayer]; |
||
107 | |||
108 | local isCurrentSession = (value == settings.CurrentSession); |
||
109 | local doesSessionExist = LT_TableHasKey(userData, value); |
||
110 | local isValidSessionName = not LT_StrIsNilOrEmpty(value); |
||
111 | |||
112 | if (isCurrentSession) then |
||
113 | LT_SetSessionButton:SetText(LT_BUTTON_CREATE); |
||
114 | LT_SetSessionButton:Disable(); |
||
115 | |||
116 | LT_ResetButton:SetText(LT_BUTTON_RESET); |
||
117 | LT_ResetButton:Enable(); |
||
118 | |||
119 | LT_ExportSessionButton:Disable(); |
||
120 | else |
||
121 | if (isValidSessionName) then |
||
122 | if (doesSessionExist) then |
||
123 | LT_SetSessionButton:SetText(LT_BUTTON_SET); |
||
124 | else |
||
125 | LT_SetSessionButton:SetText(LT_BUTTON_CREATE); |
||
126 | end |
||
127 | LT_SetSessionButton:Enable(); |
||
128 | else |
||
129 | LT_SetSessionButton:SetText(LT_BUTTON_CREATE); |
||
130 | LT_SetSessionButton:Disable(); |
||
131 | end |
||
132 | |||
133 | LT_ResetButton:SetText(LT_BUTTON_DELETE); |
||
134 | if (doesSessionExist) then |
||
135 | LT_ResetButton:Enable(); |
||
136 | else |
||
137 | LT_ResetButton:Disable(); |
||
138 | end |
||
139 | |||
140 | if (isValidSessionName) then |
||
141 | LT_ExportSessionButton:Enable(); |
||
142 | else |
||
143 | LT_ExportSessionButton:Disable(); |
||
144 | end |
||
145 | end |
||
146 | |||
147 | end |
||
148 | |||
149 | |||
150 | ------------------------------------------------------------------------------ |
||
151 | -- UpdateSessionScroll |
||
152 | ------------------------------------------------------------------------------ |
||
153 | |||
154 | LT_SCROLL_SESSIONITEMHEIGHT = 20; |
||
155 | LT_SCROLL_SESSIONVISIBLECOUNT = 5; |
||
156 | |||
157 | function LT_UpdateSessionScroll() |
||
158 | |||
159 | local offset = FauxScrollFrame_GetOffset(LT_SessionScrollFrame); |
||
160 | |||
161 | local validSessions = LT_GetAvailableSessions(); |
||
162 | local numItems = getn(validSessions); |
||
163 | |||
164 | FauxScrollFrame_Update(LT_SessionScrollFrame, numItems, LT_SCROLL_SESSIONVISIBLECOUNT, LT_SCROLL_SESSIONITEMHEIGHT, nil, nil, nil, nil, 165, 100); |
||
165 | |||
166 | -- Fill in the buttons |
||
167 | for i=1, LT_SCROLL_SESSIONVISIBLECOUNT, 1 do |
||
168 | |||
169 | local index = i + offset; |
||
170 | local button = getglobal("LT_SessionButton" .. i); |
||
171 | assert(button ~= nil); |
||
172 | |||
173 | local sessionName = validSessions[index]; |
||
174 | |||
175 | if ((index <= numItems) and (sessionName ~= nil)) then |
||
176 | button:SetText(sessionName); |
||
177 | button:Show(); |
||
178 | else |
||
179 | button:Hide(); |
||
180 | end |
||
181 | |||
182 | end |
||
183 | |||
184 | end |
||
185 | |||
186 | ------------------------------------------------------------------------------ |
||
187 | -- SessionButtonClicked |
||
188 | ------------------------------------------------------------------------------ |
||
189 | |||
190 | function LT_SessionButtonClicked(button) |
||
191 | |||
192 | local text = button:GetText(); |
||
193 | LT_ChangeSessionEditBox:SetText(text); |
||
194 | LT_UpdateCurrentSessionText(); |
||
195 | |||
196 | end |
||
197 | |||
198 | |||
199 | ------------------------------------------------------------------------------ |
||
200 | -- SessionButtonClicked |
||
201 | ------------------------------------------------------------------------------ |
||
202 | |||
203 | function LT_SessionButtonClicked(button) |
||
204 | |||
205 | local text = button:GetText(); |
||
206 | LT_ChangeSessionEditBox:SetText(text); |
||
207 | LT_UpdateCurrentSessionText(); |
||
208 | |||
209 | end |
||
210 | |||
211 | |||
212 | ------------------------------------------------------------------------------ |
||
213 | -- UpdateGenericScroller |
||
214 | ------------------------------------------------------------------------------ |
||
215 | |||
216 | function LT_UpdateGenericScroller(scroller) |
||
217 | |||
218 | if (scroller == nil) then |
||
219 | scroller = this; |
||
220 | end |
||
221 | |||
222 | assert(scroller ~= nil); |
||
223 | |||
224 | if (scroller.Data ~= nil) then |
||
225 | LT_DebugMessage(4, "Data: " .. scroller.Data.Name); |
||
226 | end |
||
227 | |||
228 | |||
229 | local offset = FauxScrollFrame_GetOffset(scroller); |
||
230 | if (offset == nil) then |
||
231 | offset = 0; |
||
232 | end |
||
233 | |||
234 | local numItems = scroller.TotalCountHandler(scroller); |
||
235 | LT_DebugMessage(4, "NumItems: " .. tostring(numItems)); |
||
236 | |||
237 | FauxScrollFrame_Update(scroller, numItems, scroller.VisibleCount, scroller.ItemHeight, nil, nil, nil, nil, scroller:GetWidth(), scroller:GetHeight()); |
||
238 | |||
239 | -- Fill in the buttons |
||
240 | for i=1, scroller.VisibleCount, 1 do |
||
241 | |||
242 | local index = i + offset; |
||
243 | local button = getglobal(scroller.ButtonName .. i); |
||
244 | assert(button ~= nil); |
||
245 | |||
246 | if (index <= numItems) then |
||
247 | |||
248 | local label, data = scroller.ItemLabelHandler(scroller, index); |
||
249 | LT_DebugMessage(4, "Label(" .. index .. "): " .. tostring(label)); |
||
250 | button:Show(); |
||
251 | |||
252 | if (label ~= nil) then |
||
253 | button:SetText(label); |
||
254 | button.Data = data; |
||
255 | |||
256 | local text = getglobal(button:GetName() .. "Text"); |
||
257 | assert(text ~= nil); |
||
258 | text:SetText(label); |
||
259 | end |
||
260 | else |
||
261 | LT_DebugMessage(4, "Label(" .. index .. "): <Hide>"); |
||
262 | button:Hide(); |
||
263 | end |
||
264 | |||
265 | end |
||
266 | |||
267 | end |
||
268 | |||
269 | |||
270 | ------------------------------------------------------------------------------ |
||
271 | -- GetItemLabel |
||
272 | ------------------------------------------------------------------------------ |
||
273 | |||
274 | function LT_GetItemLabel(scroller, t, index, func) |
||
275 | |||
276 | if (t == nil) then |
||
277 | return "Unknown"; |
||
278 | end |
||
279 | |||
280 | local currentIndex = 1; |
||
281 | local label = nil; |
||
282 | local data = nil; |
||
283 | foreach(t, function(k,v) |
||
284 | if (currentIndex == index) then |
||
285 | label, data = func(scroller, k, v); |
||
286 | end |
||
287 | currentIndex = currentIndex + 1; |
||
288 | end); |
||
289 | |||
290 | if (label == nil) then |
||
291 | label = func(scroller, "Unknown", nil); |
||
292 | end |
||
293 | |||
294 | return label, data; |
||
295 | |||
296 | end |
||
297 | |||
298 | ------------------------------------------------------------------------------ |
||
299 | -- Scroller_GetPercentageLabel |
||
300 | ------------------------------------------------------------------------------ |
||
301 | |||
302 | function LT_Scroller_GetPercentageLabel(scroller, k, v) |
||
303 | |||
304 | local name = k; |
||
305 | local count = v; |
||
306 | |||
307 | if (count == nil) then |
||
308 | count = scroller.UnknownCount; |
||
309 | if ((count == nil) or (count == 0)) then |
||
310 | return name, name; |
||
311 | end |
||
312 | end |
||
313 | |||
314 | local percentage = (count / scroller.TotalCount) * 100; |
||
315 | |||
316 | local label = string.format("%s: %d (%.0f%%)", name, count, percentage); |
||
317 | local data = name; |
||
318 | |||
319 | return label, data; |
||
320 | |||
321 | end |
||
322 | |||
323 | |||
324 | ------------------------------------------------------------------------------ |
||
325 | -- Scroller_GetLabel |
||
326 | ------------------------------------------------------------------------------ |
||
327 | |||
328 | function LT_Scroller_GetLabel(scroller, k, v) |
||
329 | |||
330 | return tostring(v), k; |
||
331 | |||
332 | end |