vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local tablet = AceLibrary("Tablet-2.0") |
2 | local dewdrop = AceLibrary("Dewdrop-2.0") |
||
3 | local metro = AceLibrary("Metrognome-2.0") |
||
4 | local abacus = AceLibrary("Abacus-2.0") |
||
5 | local compost = AceLibrary("Compost-2.0") |
||
6 | local L = AceLibrary("AceLocale-2.0"):new("MoneyFu") |
||
7 | |||
8 | MoneyFu = AceLibrary("AceAddon-2.0"):new("FuBarPlugin-2.0", "AceDB-2.0", "AceEvent-2.0", "AceHook-2.0", "AceConsole-2.0") |
||
9 | MoneyFu.hasIcon = true |
||
10 | MoneyFu:RegisterDB("MoneyFuDB", "MoneyFuCharDB") |
||
11 | MoneyFu:RegisterDefaults('profile', { |
||
12 | style = "GRAPHICAL", |
||
13 | trackByRealm = true, |
||
14 | simpleTooltip = false |
||
15 | }) |
||
16 | MoneyFu:RegisterDefaults('char', { |
||
17 | spent = {}, |
||
18 | gained = {}, |
||
19 | time = {} |
||
20 | }) |
||
21 | MoneyFu:RegisterDefaults('realm', { |
||
22 | chars = {}, |
||
23 | spent = {}, |
||
24 | gained = {}, |
||
25 | time = {} |
||
26 | }) |
||
27 | MoneyFu:RegisterChatCommand(L["COMMANDS"], { |
||
28 | desc = L["DESCRIPTION"], |
||
29 | type = 'group', |
||
30 | args = {}, |
||
31 | }) |
||
32 | MoneyFu.frame = MoneyFu:CreateBasicPluginFrame("MoneyFuFrame") |
||
33 | |||
34 | function MoneyFu:SetStyle(style) |
||
35 | style = string.upper(style) |
||
36 | if style ~= "GRAPHICAL" and style ~= "FULL" and style ~= "SHORT" and style ~= "CONDENSED" then |
||
37 | style = "GRAPHICAL" |
||
38 | end |
||
39 | self.db.profile.style = style |
||
40 | self:UpdateText() |
||
41 | end |
||
42 | |||
43 | function MoneyFu:ResetSession() |
||
44 | self.initialMoney = GetMoney() |
||
45 | self.sessionTime = time() |
||
46 | self.gained = 0 |
||
47 | self.spent = 0 |
||
48 | end |
||
49 | |||
50 | function MoneyFu:OnInitialize() |
||
51 | self.hasIcon = true |
||
52 | self.canHideText = true |
||
53 | local frame = self.frame |
||
54 | local icon = frame:CreateTexture("MoneyFuFrameIcon", "ARTWORK") |
||
55 | icon:SetWidth(16) |
||
56 | icon:SetHeight(16) |
||
57 | icon:SetPoint("LEFT", frame, "LEFT") |
||
58 | self.iconFrame = icon |
||
59 | |||
60 | local text = frame:CreateFontString("MoneyFuFrameText", "OVERLAY") |
||
61 | text:SetJustifyH("RIGHT") |
||
62 | text:SetPoint("RIGHT", frame, "RIGHT", 0, 1) |
||
63 | text:SetFontObject(GameFontNormal) |
||
64 | self.textFrame = text |
||
65 | |||
66 | self:SetIcon(true) |
||
67 | |||
68 | local goldIcon = frame:CreateTexture("MoneyFuFrameGoldIcon", "ARTWORK") |
||
69 | goldIcon:SetWidth(16) |
||
70 | goldIcon:SetHeight(16) |
||
71 | goldIcon:SetTexture("Interface\\MoneyFrame\\UI-MoneyIcons") |
||
72 | goldIcon:SetTexCoord(0, 0.25, 0, 1) |
||
73 | |||
74 | local silverIcon = frame:CreateTexture("MoneyFuFrameSilverIcon", "ARTWORK") |
||
75 | silverIcon:SetWidth(16) |
||
76 | silverIcon:SetHeight(16) |
||
77 | silverIcon:SetTexture("Interface\\MoneyFrame\\UI-MoneyIcons") |
||
78 | silverIcon:SetTexCoord(0.25, 0.5, 0, 1) |
||
79 | |||
80 | local copperIcon = frame:CreateTexture("MoneyFuFrameCopperIcon", "ARTWORK") |
||
81 | copperIcon:SetWidth(16) |
||
82 | copperIcon:SetHeight(16) |
||
83 | copperIcon:SetTexture("Interface\\MoneyFrame\\UI-MoneyIcons") |
||
84 | copperIcon:SetTexCoord(0.5, 0.75, 0, 1) |
||
85 | |||
86 | local goldText = frame:CreateFontString("MoneyFuFrameGoldText", "OVERLAY") |
||
87 | goldText:SetJustifyH("RIGHT") |
||
88 | goldText:SetPoint("RIGHT", goldIcon, "LEFT", 0, 1) |
||
89 | goldText:SetFontObject(GameFontNormal) |
||
90 | |||
91 | local silverText = frame:CreateFontString("MoneyFuFrameSilverText", "OVERLAY") |
||
92 | silverText:SetJustifyH("RIGHT") |
||
93 | silverText:SetPoint("RIGHT", silverIcon, "LEFT", 0, 1) |
||
94 | silverText:SetFontObject(GameFontNormal) |
||
95 | |||
96 | local copperText = frame:CreateFontString("MoneyFuFrameCopperText", "OVERLAY") |
||
97 | copperText:SetJustifyH("RIGHT") |
||
98 | copperText:SetPoint("RIGHT", copperIcon, "LEFT", 0, 1) |
||
99 | copperText:SetFontObject(GameFontNormal) |
||
100 | |||
101 | copperIcon:SetPoint("RIGHT", frame, "RIGHT") |
||
102 | silverIcon:SetPoint("RIGHT", copperText, "LEFT") |
||
103 | goldIcon:SetPoint("RIGHT", silverText, "LEFT") |
||
104 | end |
||
105 | |||
106 | local function GetToday(self) |
||
107 | return floor((time() / 60 / 60 + self:GetServerOffset()) / 24) |
||
108 | end |
||
109 | |||
110 | function MoneyFu:OnEnable() |
||
111 | self.initialMoney = GetMoney() |
||
112 | self.lastMoney = self.initialMoney |
||
113 | self.lastTime = GetToday(self) |
||
114 | local lastWeek = self.lastTime - 6 |
||
115 | for day in pairs(self.db.char.gained) do |
||
116 | if day < lastWeek then |
||
117 | self.db.char.gained[day] = nil |
||
118 | end |
||
119 | end |
||
120 | for day in pairs(self.db.char.spent) do |
||
121 | if day < lastWeek then |
||
122 | self.db.char.spent[day] = nil |
||
123 | end |
||
124 | end |
||
125 | for day in pairs(self.db.char.time) do |
||
126 | if day < lastWeek then |
||
127 | self.db.char.time[day] = nil |
||
128 | end |
||
129 | end |
||
130 | for day in pairs(self.db.realm.gained) do |
||
131 | if day < lastWeek then |
||
132 | self.db.realm.gained[day] = nil |
||
133 | end |
||
134 | end |
||
135 | for day in pairs(self.db.realm.spent) do |
||
136 | if day < lastWeek then |
||
137 | self.db.realm.spent[day] = nil |
||
138 | end |
||
139 | end |
||
140 | for day in pairs(self.db.realm.time) do |
||
141 | if day < lastWeek then |
||
142 | self.db.realm.time[day] = nil |
||
143 | end |
||
144 | end |
||
145 | for i = self.lastTime - 6, self.lastTime do |
||
146 | if not self.db.char.gained[i] then |
||
147 | self.db.char.gained[i] = 0 |
||
148 | end |
||
149 | if not self.db.char.spent[i] then |
||
150 | self.db.char.spent[i] = 0 |
||
151 | end |
||
152 | if not self.db.char.time[i] then |
||
153 | self.db.char.time[i] = 0 |
||
154 | end |
||
155 | if not self.db.realm.gained[i] then |
||
156 | self.db.realm.gained[i] = 0 |
||
157 | end |
||
158 | if not self.db.realm.spent[i] then |
||
159 | self.db.realm.spent[i] = 0 |
||
160 | end |
||
161 | if not self.db.realm.time[i] then |
||
162 | self.db.realm.time[i] = 0 |
||
163 | end |
||
164 | end |
||
165 | self.gained = 0 |
||
166 | self.spent = 0 |
||
167 | self.sessionTime = time() |
||
168 | self.savedTime = time() |
||
169 | |||
170 | if self.db.profile.style == "GRAPHICAL" then |
||
171 | self:HideIcon() |
||
172 | self.iconFrame:Hide() |
||
173 | self.hasIcon = false |
||
174 | end |
||
175 | self:RegisterEvent("PLAYER_MONEY", "Update") |
||
176 | self:RegisterEvent("PLAYER_TRADE_MONEY", "Update") |
||
177 | self:RegisterEvent("TRADE_MONEY_CHANGED", "Update") |
||
178 | self:RegisterEvent("SEND_MAIL_MONEY_CHANGED", "Update") |
||
179 | self:RegisterEvent("SEND_MAIL_COD_CHANGED", "Update") |
||
180 | |||
181 | self:Hook("OpenCoinPickupFrame") |
||
182 | |||
183 | MoneyFuFrameGoldIcon:ClearAllPoints() |
||
184 | MoneyFuFrameGoldIcon:SetPoint("RIGHT", MoneyFuFrameSilverText, "LEFT", 0, -1) |
||
185 | MoneyFuFrameSilverIcon:ClearAllPoints() |
||
186 | MoneyFuFrameSilverIcon:SetPoint("RIGHT", MoneyFuFrameCopperText, "LEFT", 0, -1) |
||
187 | |||
188 | metro:RegisterMetro(self.name, self.UpdateTooltip, 1, self) |
||
189 | metro:StartMetro(self.name) |
||
190 | end |
||
191 | |||
192 | function MoneyFu:OnDisable() |
||
193 | metro:UnregisterMetro(self.name) |
||
194 | end |
||
195 | |||
196 | function MoneyFu:OnMenuRequest(level, value) |
||
197 | if level == 1 then |
||
198 | dewdrop:AddLine( |
||
199 | 'text', L["MENU_RESET_SESSION"], |
||
200 | 'arg1', self, |
||
201 | 'func', "ResetSession", |
||
202 | 'closeWhenClicked', true |
||
203 | ) |
||
204 | |||
205 | dewdrop:AddLine( |
||
206 | 'text', L["MENU_CHARACTER_SPECIFIC_CASHFLOW"], |
||
207 | 'arg1', self, |
||
208 | 'func', function() |
||
209 | self.db.profile.trackByRealm = not self.db.profile.trackByRealm |
||
210 | self:UpdateTooltip() |
||
211 | end, |
||
212 | 'checked', not self.db.profile.trackByRealm |
||
213 | ) |
||
214 | |||
215 | dewdrop:AddLine() |
||
216 | |||
217 | dewdrop:AddLine( |
||
218 | 'text', L["MENU_SHOW_GRAPHICAL"], |
||
219 | 'arg1', self, |
||
220 | 'func', self.db.profile.style ~= "GRAPHICAL" and "SetStyle", |
||
221 | 'arg2', "GRAPHICAL", |
||
222 | 'checked', self.db.profile.style == "GRAPHICAL", |
||
223 | 'isRadio', true |
||
224 | ) |
||
225 | |||
226 | dewdrop:AddLine( |
||
227 | 'text', L["MENU_SHOW_FULL"], |
||
228 | 'arg1', self, |
||
229 | 'func', self.db.profile.style ~= "FULL" and "SetStyle", |
||
230 | 'arg2', "FULL", |
||
231 | 'checked', self.db.profile.style == "FULL", |
||
232 | 'isRadio', true |
||
233 | ) |
||
234 | |||
235 | dewdrop:AddLine( |
||
236 | 'text', L["MENU_SHOW_SHORT"], |
||
237 | 'arg1', self, |
||
238 | 'func', self.db.profile.style ~= "SHORT" and "SetStyle", |
||
239 | 'arg2', "SHORT", |
||
240 | 'checked', self.db.profile.style == "SHORT", |
||
241 | 'isRadio', true |
||
242 | ) |
||
243 | |||
244 | dewdrop:AddLine( |
||
245 | 'text', L["MENU_SHOW_CONDENSED"], |
||
246 | 'arg1', self, |
||
247 | 'func', self.db.profile.style ~= "CONDENSED" and "SetStyle", |
||
248 | 'arg2', "CONDENSED", |
||
249 | 'checked', self.db.profile.style == "CONDENSED", |
||
250 | 'isRadio', true |
||
251 | ) |
||
252 | |||
253 | dewdrop:AddLine( |
||
254 | 'text', L["SIMPLIFIED_TOOLTIP"], |
||
255 | 'arg1', self, |
||
256 | 'func', function() |
||
257 | self.db.profile.simpleTooltip = not self.db.profile.simpleTooltip |
||
258 | self:Update() |
||
259 | end, |
||
260 | 'checked', self.db.profile.simpleTooltip |
||
261 | ) |
||
262 | |||
263 | if next(self.db.realm.chars) ~= UnitName("player") or next(self.db.realm.chars, UnitName("player")) then |
||
264 | dewdrop:AddLine() |
||
265 | |||
266 | dewdrop:AddLine( |
||
267 | 'text', L["MENU_PURGE"], |
||
268 | 'hasArrow', true, |
||
269 | 'value', "purge" |
||
270 | ) |
||
271 | end |
||
272 | elseif level == 2 then |
||
273 | if value == "purge" then |
||
274 | for name in self.db.realm.chars do |
||
275 | if name ~= UnitName("player") then |
||
276 | dewdrop:AddLine( |
||
277 | 'text', name, |
||
278 | 'arg1', name, |
||
279 | 'func', function(name) |
||
280 | self.db.realm.chars[name] = nil |
||
281 | end, |
||
282 | 'closeWhenClicked', true |
||
283 | ) |
||
284 | end |
||
285 | end |
||
286 | end |
||
287 | end |
||
288 | end |
||
289 | |||
290 | function MoneyFu:UpdateData() |
||
291 | local today = GetToday(self) |
||
292 | if not self.lastTime then |
||
293 | self.lastTime = today |
||
294 | end |
||
295 | if today > self.lastTime then |
||
296 | self.db.char.gained[today - 7] = nil |
||
297 | self.db.char.spent[today - 7] = nil |
||
298 | self.db.char.time[today - 7] = nil |
||
299 | self.db.realm.gained[today - 7] = nil |
||
300 | self.db.realm.spent[today - 7] = nil |
||
301 | self.db.realm.time[today - 7] = nil |
||
302 | self.db.char.gained[today] = self.db.char.gained[today] or 0 |
||
303 | self.db.char.spent[today] = self.db.char.spent[today] or 0 |
||
304 | self.db.char.time[today] = self.db.char.time[today] or 0 |
||
305 | self.db.realm.gained[today] = self.db.realm.gained[today] or 0 |
||
306 | self.db.realm.spent[today] = self.db.realm.spent[today] or 0 |
||
307 | self.db.realm.time[today] = self.db.realm.time[today] or 0 |
||
308 | self.lastTime = today |
||
309 | end |
||
310 | local current = GetMoney() |
||
311 | if not self.lastMoney then |
||
312 | self.lastMoney = current |
||
313 | end |
||
314 | if self.lastMoney < current then |
||
315 | self.gained = (self.gained or 0) + current - self.lastMoney |
||
316 | self.db.char.gained[today] = (self.db.char.gained[today] or 0) + current - self.lastMoney |
||
317 | self.db.realm.gained[today] = (self.db.realm.gained[today] or 0) + current - self.lastMoney |
||
318 | elseif self.lastMoney > current then |
||
319 | self.spent = (self.spent or 0) + self.lastMoney - current |
||
320 | self.db.char.spent[today] = (self.db.char.spent[today] or 0) + self.lastMoney - current |
||
321 | self.db.realm.spent[today] = (self.db.realm.spent[today] or 0) + self.lastMoney - current |
||
322 | end |
||
323 | self.lastMoney = current |
||
324 | self.db.realm.chars[UnitName("player")] = current |
||
325 | local now = time() |
||
326 | self.db.char.time[today] = self.db.char.time[today] + now - self.savedTime |
||
327 | self.db.realm.time[today] = self.db.realm.time[today] + now - self.savedTime |
||
328 | self.savedTime = now |
||
329 | end |
||
330 | |||
331 | function MoneyFu:UpdateText() |
||
332 | if self.db.profile == nil then |
||
333 | return |
||
334 | end |
||
335 | if self.db.profile.style == "GRAPHICAL" then |
||
336 | if self:IsIconShown() then |
||
337 | self.db.profile.iconVisible = true |
||
338 | self:HideIcon() |
||
339 | end |
||
340 | self.hasIcon = false |
||
341 | MoneyFuFrameIcon:Hide() |
||
342 | MoneyFuFrameText:Hide() |
||
343 | local copper = GetMoney() |
||
344 | local gold = floor(copper / 10000) |
||
345 | local silver = mod(floor(copper / 100), 100) |
||
346 | copper = mod(copper, 100) |
||
347 | local width = 0 |
||
348 | if gold == 0 then |
||
349 | MoneyFuFrameGoldIcon:Hide() |
||
350 | MoneyFuFrameGoldText:Hide() |
||
351 | else |
||
352 | MoneyFuFrameGoldIcon:Show() |
||
353 | MoneyFuFrameGoldText:Show() |
||
354 | MoneyFuFrameGoldText:SetWidth(0) |
||
355 | MoneyFuFrameGoldText:SetText(gold) |
||
356 | width = width + MoneyFuFrameGoldIcon:GetWidth() + MoneyFuFrameGoldText:GetWidth() |
||
357 | end |
||
358 | if gold == 0 and silver == 0 then |
||
359 | MoneyFuFrameSilverIcon:Hide() |
||
360 | MoneyFuFrameSilverText:Hide() |
||
361 | else |
||
362 | MoneyFuFrameSilverIcon:Show() |
||
363 | MoneyFuFrameSilverText:Show() |
||
364 | MoneyFuFrameSilverText:SetWidth(0) |
||
365 | MoneyFuFrameSilverText:SetText(silver) |
||
366 | width = width + MoneyFuFrameSilverIcon:GetWidth() + MoneyFuFrameSilverText:GetWidth() |
||
367 | end |
||
368 | MoneyFuFrameCopperIcon:Show() |
||
369 | MoneyFuFrameCopperText:Show() |
||
370 | MoneyFuFrameCopperText:SetWidth(0) |
||
371 | MoneyFuFrameCopperText:SetText(copper) |
||
372 | width = width + MoneyFuFrameCopperIcon:GetWidth() + MoneyFuFrameCopperText:GetWidth() |
||
373 | self.frame:SetWidth(width) |
||
374 | else |
||
375 | if not self.hasIcon then |
||
376 | self.hasIcon = true |
||
377 | if self.db.profile.iconVisible then |
||
378 | self:ShowIcon() |
||
379 | end |
||
380 | end |
||
381 | self.db.profile.iconVisible = false |
||
382 | MoneyFuFrameGoldIcon:Hide() |
||
383 | MoneyFuFrameSilverIcon:Hide() |
||
384 | MoneyFuFrameCopperIcon:Hide() |
||
385 | MoneyFuFrameGoldText:Hide() |
||
386 | MoneyFuFrameSilverText:Hide() |
||
387 | MoneyFuFrameCopperText:Hide() |
||
388 | MoneyFuFrameText:Show() |
||
389 | if self.db.profile.style == "CONDENSED" then |
||
390 | self:SetText(abacus:FormatMoneyCondensed(GetMoney(), true)) |
||
391 | elseif self.db.profile.style == "FULL" then |
||
392 | self:SetText(abacus:FormatMoneyFull(GetMoney(), true)) |
||
393 | else |
||
394 | self:SetText(abacus:FormatMoneyShort(GetMoney(), true)) |
||
395 | end |
||
396 | self:CheckWidth(true) |
||
397 | end |
||
398 | end |
||
399 | |||
400 | function MoneyFu:OnTooltipUpdate() |
||
401 | local now = time() |
||
402 | local today = self.lastTime |
||
403 | self.db.char.time[today] = self.db.char.time[today] + now - self.savedTime |
||
404 | self.db.realm.time[today] = self.db.realm.time[today] + now - self.savedTime |
||
405 | self.savedTime = now |
||
406 | local func |
||
407 | if self.db.profile.style == "CONDENSED" then |
||
408 | func = abacus.FormatMoneyCondensed |
||
409 | elseif self.db.profile.style == "SHORT" then |
||
410 | func = abacus.FormatMoneyShort |
||
411 | else |
||
412 | func = abacus.FormatMoneyFull |
||
413 | end |
||
414 | |||
415 | local supercat = tablet:AddCategory( |
||
416 | 'columns', 3, |
||
417 | 'child_text2', L["TEXT_AMOUNT"], |
||
418 | 'child_text3', L["TEXT_PER_HOUR"], |
||
419 | 'child_child_textR', 1, |
||
420 | 'child_child_textG', 1, |
||
421 | 'child_child_textB', 0, |
||
422 | 'child_child_text2R', 1, |
||
423 | 'child_child_text2G', 1, |
||
424 | 'child_child_text2B', 1, |
||
425 | 'child_child_text3R', 1, |
||
426 | 'child_child_text3G', 1, |
||
427 | 'child_child_text3B', 1 |
||
428 | ) |
||
429 | |||
430 | ------------ |
||
431 | if not self.db.profile.simpleTooltip then |
||
432 | local cat = supercat:AddCategory( |
||
433 | 'text', L["TEXT_THIS_SESSION"] |
||
434 | ) |
||
435 | |||
436 | cat:AddLine( |
||
437 | 'text', L["TEXT_GAINED"], |
||
438 | 'text2', func(abacus, self.gained, true), |
||
439 | 'text3', func(abacus, self.gained / (now - self.sessionTime) * 3600, true) |
||
440 | ) |
||
441 | cat:AddLine( |
||
442 | 'text', L["TEXT_SPENT"], |
||
443 | 'text2', func(abacus, self.spent, true), |
||
444 | 'text3', func(abacus, self.spent / (now - self.sessionTime) * 3600, true) |
||
445 | ) |
||
446 | local profit = self.gained - self.spent |
||
447 | cat:AddLine( |
||
448 | 'text', profit >= 0 and L["TEXT_PROFIT"] or L["TEXT_LOSS"], |
||
449 | 'text2', func(abacus, profit, true, true), |
||
450 | 'text3', func(abacus, profit / (now - self.sessionTime) * 3600, true, true) |
||
451 | ) |
||
452 | |||
453 | local t |
||
454 | if self.db.profile.trackByRealm then |
||
455 | t = self.db.realm |
||
456 | else |
||
457 | t = self.db.char |
||
458 | end |
||
459 | local gained = t.gained |
||
460 | local spent = t.spent |
||
461 | local time = t.time |
||
462 | |||
463 | -- ------------ |
||
464 | -- Session totals |
||
465 | -- ------------ |
||
466 | cat = supercat:AddCategory( |
||
467 | 'text', HONOR_THIS_SESSION |
||
468 | ) |
||
469 | |||
470 | cat:AddLine( |
||
471 | 'text', L["TEXT_GAINED"], |
||
472 | 'text2', func(abacus, gained[self.lastTime], true), |
||
473 | 'text3', func(abacus, gained[self.lastTime] / time[self.lastTime] * 3600, true) |
||
474 | ) |
||
475 | cat:AddLine( |
||
476 | 'text', L["TEXT_SPENT"], |
||
477 | 'text2', func(abacus, spent[self.lastTime], true), |
||
478 | 'text3', func(abacus, spent[self.lastTime] / time[self.lastTime] * 3600, true) |
||
479 | ) |
||
480 | local profit = gained[self.lastTime] - spent[self.lastTime] |
||
481 | cat:AddLine( |
||
482 | 'text', profit >= 0 and L["TEXT_PROFIT"] or L["TEXT_LOSS"], |
||
483 | 'text2', func(abacus, profit, true, true), |
||
484 | 'text3', func(abacus, profit / time[self.lastTime] * 3600, true, true) |
||
485 | ) |
||
486 | |||
487 | -- ----------- |
||
488 | -- Yesterday totals |
||
489 | -- ----------- |
||
490 | cat = supercat:AddCategory( |
||
491 | 'text', HONOR_YESTERDAY |
||
492 | ) |
||
493 | |||
494 | cat:AddLine( |
||
495 | 'text', L["TEXT_GAINED"], |
||
496 | 'text2', func(abacus, gained[self.lastTime - 1], true), |
||
497 | 'text3', func(abacus, gained[self.lastTime - 1] / time[self.lastTime - 1] * 3600, true) |
||
498 | ) |
||
499 | cat:AddLine( |
||
500 | 'text', L["TEXT_SPENT"], |
||
501 | 'text2', func(abacus, spent[self.lastTime - 1], true), |
||
502 | 'text3', func(abacus, spent[self.lastTime - 1] / time[self.lastTime - 1] * 3600, true) |
||
503 | ) |
||
504 | local profit = gained[self.lastTime - 1] - spent[self.lastTime - 1] |
||
505 | cat:AddLine( |
||
506 | 'text', profit >= 0 and L["TEXT_PROFIT"] or L["TEXT_LOSS"], |
||
507 | 'text2', func(abacus, profit, true, true), |
||
508 | 'text3', func(abacus, profit / time[self.lastTime - 1] * 3600, true, true) |
||
509 | ) |
||
510 | |||
511 | -- ----------- |
||
512 | -- Week totals |
||
513 | -- ----------- |
||
514 | local weekGained = 0 |
||
515 | local weekSpent = 0 |
||
516 | local weekTime = 0 |
||
517 | for i = self.lastTime - 6, self.lastTime do |
||
518 | weekGained = weekGained + gained[i] |
||
519 | weekSpent = weekSpent + spent[i] |
||
520 | weekTime = weekTime + time[i] |
||
521 | end |
||
522 | cat = supercat:AddCategory( |
||
523 | 'text', HONOR_THISWEEK |
||
524 | ) |
||
525 | |||
526 | cat:AddLine( |
||
527 | 'text', L["TEXT_GAINED"], |
||
528 | 'text2', func(abacus, weekGained, true), |
||
529 | 'text3', func(abacus, weekGained / weekTime * 3600, true) |
||
530 | ) |
||
531 | cat:AddLine( |
||
532 | 'text', L["TEXT_SPENT"], |
||
533 | 'text2', func(abacus, weekSpent, true), |
||
534 | 'text3', func(abacus, weekSpent / weekTime * 3600, true) |
||
535 | ) |
||
536 | local profit = weekGained - weekSpent |
||
537 | cat:AddLine( |
||
538 | 'text', profit >= 0 and L["TEXT_PROFIT"] or L["TEXT_LOSS"], |
||
539 | 'text2', func(abacus, profit, true, true), |
||
540 | 'text3', func(abacus, profit / weekTime * 3600, true, true) |
||
541 | ) |
||
542 | end |
||
543 | -- ------------- |
||
544 | -- Character Totals, we always show this bit. |
||
545 | -- ------------- |
||
546 | local total = 0 |
||
547 | local addedCat = false |
||
548 | if next(self.db.realm.chars) ~= UnitName("player") or next(self.db.realm.chars, UnitName("player")) then |
||
549 | local t = compost:Acquire() |
||
550 | for name in pairs(self.db.realm.chars) do |
||
551 | table.insert(t, name) |
||
552 | end |
||
553 | if not self.sort_func then |
||
554 | self.sort_func = function(alpha, bravo) |
||
555 | return self.db.realm.chars[alpha] < self.db.realm.chars[bravo] |
||
556 | end |
||
557 | end |
||
558 | table.sort(t, self.sort_func) |
||
559 | |||
560 | cat = tablet:AddCategory( |
||
561 | 'columns', 2, |
||
562 | 'text', L["TEXT_CHARACTERS"], |
||
563 | 'text2', "Amount", |
||
564 | 'child_textR', 1, |
||
565 | 'child_textG', 1, |
||
566 | 'child_textB', 0, |
||
567 | 'child_text2R', 1, |
||
568 | 'child_text2G', 1, |
||
569 | 'child_text2B', 1 |
||
570 | ) |
||
571 | for _,name in t do |
||
572 | local value = self.db.realm.chars[name] |
||
573 | cat:AddLine( |
||
574 | 'text', name, |
||
575 | 'text2', func(abacus, value, true) |
||
576 | ) |
||
577 | total = total + value |
||
578 | end |
||
579 | else |
||
580 | total = self.db.realm.chars[UnitName("player")] |
||
581 | end |
||
582 | |||
583 | cat = tablet:AddCategory( |
||
584 | 'columns', 2, |
||
585 | 'child_textR', 1, |
||
586 | 'child_textG', 1, |
||
587 | 'child_textB', 1, |
||
588 | 'child_text2R', 1, |
||
589 | 'child_text2G', 1, |
||
590 | 'child_text2B', 1 |
||
591 | ) |
||
592 | |||
593 | cat:AddLine( |
||
594 | 'text', L["TEXT_TOTAL"], |
||
595 | 'text2', func(abacus, total, true) |
||
596 | ) |
||
597 | |||
598 | tablet:SetHint(L["HINT"]) |
||
599 | end |
||
600 | |||
601 | local function getsecond(_, value) |
||
602 | return value |
||
603 | end |
||
604 | |||
605 | function MoneyFu:OnClick(button) |
||
606 | local money = GetMoney() |
||
607 | if money < 100 then |
||
608 | money = 1 |
||
609 | elseif money < 10000 then |
||
610 | money = 100 |
||
611 | else |
||
612 | money = 10000 |
||
613 | end |
||
614 | self.frame.moneyType = "PLAYER" |
||
615 | OpenCoinPickupFrame(money, GetMoney(), self.frame) |
||
616 | self.frame.hasPickup = 1 |
||
617 | |||
618 | CoinPickupFrame:ClearAllPoints() |
||
619 | local frame = self.frame |
||
620 | if self:IsMinimapAttached() then |
||
621 | frame = self.minimapFrame |
||
622 | end |
||
623 | if frame:GetCenter() < GetScreenWidth()/2 then |
||
624 | if getsecond(frame:GetCenter()) < GetScreenHeight()/2 then |
||
625 | CoinPickupFrame:SetPoint("BOTTOMLEFT", frame, "TOPLEFT") |
||
626 | else |
||
627 | CoinPickupFrame:SetPoint("TOPLEFT", frame, "BOTTOMLEFT") |
||
628 | end |
||
629 | else |
||
630 | if getsecond(frame:GetCenter()) < GetScreenHeight()/2 then |
||
631 | CoinPickupFrame:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT") |
||
632 | else |
||
633 | CoinPickupFrame:SetPoint("TOPRIGHT", frame, "BOTTOMRIGHT") |
||
634 | end |
||
635 | end |
||
636 | end |
||
637 | |||
638 | function MoneyFu:OpenCoinPickupFrame(multiplier, maxMoney, parent) |
||
639 | CoinPickupFrame:ClearAllPoints() |
||
640 | self.hooks.OpenCoinPickupFrame.orig(multiplier, maxMoney, parent) |
||
641 | end |
||
642 | |||
643 | function MoneyFu:SetFontSize(size) |
||
644 | if MoneyFuFrameGoldIcon == nil then |
||
645 | self.fontSize = size |
||
646 | return |
||
647 | end |
||
648 | MoneyFuFrameGoldIcon:SetWidth(size) |
||
649 | MoneyFuFrameGoldIcon:SetHeight(size) |
||
650 | MoneyFuFrameSilverIcon:SetWidth(size) |
||
651 | MoneyFuFrameSilverIcon:SetHeight(size) |
||
652 | MoneyFuFrameCopperIcon:SetWidth(size) |
||
653 | MoneyFuFrameCopperIcon:SetHeight(size) |
||
654 | self.iconFrame:SetWidth(size) |
||
655 | self.iconFrame:SetHeight(size) |
||
656 | local font,_,flags = MoneyFuFrameGoldText:GetFont() |
||
657 | if font ~= nil then |
||
658 | MoneyFuFrameGoldText:SetFont(font, size, flags) |
||
659 | MoneyFuFrameSilverText:SetFont(font, size, flags) |
||
660 | MoneyFuFrameCopperText:SetFont(font, size, flags) |
||
661 | self.textFrame:SetFont(font, size) |
||
662 | end |
||
663 | self:UpdateText() |
||
664 | end |
||
665 | |||
666 | local offset |
||
667 | function MoneyFu:GetServerOffset() |
||
668 | if offset then |
||
669 | return offset |
||
670 | end |
||
671 | local serverHour, serverMinute = GetGameTime() |
||
672 | local utcHour = tonumber(date("!%H")) |
||
673 | local utcMinute = tonumber(date("!%M")) |
||
674 | local ser = serverHour + serverMinute / 60 |
||
675 | local utc = utcHour + utcMinute / 60 |
||
676 | offset = floor((ser - utc) * 2 + 0.5) / 2 |
||
677 | if offset >= 12 then |
||
678 | offset = offset - 24 |
||
679 | elseif offset < -12 then |
||
680 | offset = offset + 24 |
||
681 | end |
||
682 | return offset |
||
683 | end |