-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.lua
1303 lines (1065 loc) · 38.8 KB
/
core.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[Author: Christian Vogt
License: GPL v3
Contact: polarkreis@web.de
Fork of Mail Outbox by DieenDieen, released as PUBLIC DOMAIN
-- global lookup
]]
local folder, core = ...
MO = core --global table
-- local
title = "Mail Bookkeeper"
version = GetAddOnMetadata(folder, "X-Curse-Packaged-Version") or ""
titleFull = title.." "..version
packedtitle = "MailBookKeeper";
local outgoingmail = {};
local outgoingmailitems = {};
local outgoingmailmoney = 0;
local outgoingmailCOD = 0;
MailBookKeeperHistory = {};
local MailBookKeeperHistoryAvaiable = false;
local icon = "Icon\\MailBookKeeper";
local CurrentHistoryVersion=4;
local ActiveTrade={Debit = 0;Credit = 0};
ActiveTrade.PlayerItems={};
ActiveTrade.TargetItems={};
local MoneyTracking=nil;
local exportFrame = false;
local exporteditbox = false;
mooptions = {};
-- Isolate the environment
local _G = getfenv(0)
setmetatable(MO, {__index = _G})
setfenv(1, MO)
core = LibStub("AceAddon-3.0"):NewAddon(packedtitle, "AceConsole-3.0", "AceHook-3.0", "AceEvent-3.0","AceSerializer-3.0")
local ldb=LibStub("LibDataBroker-1.1",true)
local dataobj = {};
if ldb then
dataobj=ldb:NewDataObject("MailBookKeeper", {
icon = "Icon\\MailBookKeeper",
iconWidth = 32,
label = "Mail Bookkeeper",
text = "--",
type = "launcher"
});
end;
local AceGUI = LibStub("AceGUI-3.0")
local MOScrollingTable = LibStub("ScrollingTable")
moconfig = {
name = packedtitle,
handler = core,
type = 'group',
args = {
COD = {
type = 'group',
name = 'COD settings',
args = {
Zero={
type = 'toggle',
name = 'Zero COD gold visible',
desc = 'Enables showing of zero COD gold in outgoing mail report',
set = 'SetOption',
get = 'GetOption',
},
Graphics={
type = 'toggle',
name = 'Use graphics',
desc = 'Uses graphics for showing outgoing COD gold',
set = 'SetOption',
get = 'GetOption',
},
}
},
Gold = {
type = 'group',
name = 'Gold settings',
args = {
Zero={
type = 'toggle',
name = 'Zero gold visible',
desc = 'Enables showing of zero gold in outgoing mail report',
set = 'SetOption',
get = 'GetOption',
},
Graphics={
type = 'toggle',
name = 'Use graphics',
desc = 'Uses graphics for showing outgoing gold',
set = 'SetOption',
get = 'GetOption',
},
},
},
History = {
type = 'group',
name = 'History setting',
args = {
Enabled={
type = 'toggle',
name = 'Tracking enabled',
desc = 'Enables storing history of outgoing mails',
set = 'SetOption',
get = 'GetOption',
},
},
},
Cash = {
type = 'group',
name = 'Cash flow tracking',
args = {
Enabled={
type = 'toggle',
name = 'Tracking enabled',
desc = 'Enables tracking of some cash flow events (ah,vendor..)',
set = 'SetOption',
get = 'GetOption',
},
Zero={
type = 'toggle',
name = 'Zero gold visible',
desc = 'Enables showing of zero gold transactions',
set = 'SetOption',
get = 'GetOption',
},
},
},
},
}
modefaultoptions = {
version = 1,
["COD"] = {
["Zero"] = false,
["Graphics"] = true,
},
["Gold"] = {
["Zero"] = false,
["Graphics"] = true,
},
["History"] = {
["Enabled"] = true,
},
["Delete"] = {
["Enabled"] = true,
},
["Cash"] = {
["Enabled"] = true,
},
}
local regEvents = {
"ADDON_LOADED",
"MAIL_SEND_INFO_UPDATE",
"SEND_MAIL_COD_CHANGED",
"MAIL_SEND_SUCCESS",
"SEND_MAIL_MONEY_CHANGED",
"MAIL_SHOW",
"MAIL_CLOSED",
"TRADE_ACCEPT_UPDATE",
"TRADE_TARGET_ITEM_CHANGED",
"TRADE_PLAYER_ITEM_CHANGED",
"TRADE_REQUEST_CANCEL",
"TRADE_CLOSED",
"TRADE_SHOW",
"MAIL_INBOX_UPDATE",
"UI_INFO_MESSAGE",
"AUCTION_HOUSE_SHOW",
"AUCTION_HOUSE_CLOSED",
"MERCHANT_SHOW",
"MERCHANT_CLOSED",
"PLAYER_LOGOUT",
"PLAYER_MONEY",
"PLAYER_ENTERING_WORLD",
}
function core:OnInitialize()
--print "---MailBookKeeper init";
self:RegisterChatCommand("MailBookKeeper", "MySlashProcessorFunc");
self:RegisterChatCommand("mbk", "MySlashProcessorFunc");
local config=LibStub("AceConfig-3.0");
local dialog = LibStub("AceConfigDialog-3.0");
config:RegisterOptionsTable(packedtitle, moconfig);
coreOpts = dialog:AddToBlizOptions(packedtitle, title);
end
local active_action={};
function core:OnEnable()
--print "---MailBookKeeper OnEnable";
for i, event in pairs (regEvents) do
self:RegisterEvent(event)
end
end
function core:MAIL_SHOW(event, ...)
local action= start_action ("mailbox");
action.location=GetZoneText();
if GetSubZoneText() then action.location=action.location.."-"..GetSubZoneText(); end;
action.info="mailbox in "..action.location;
action.show_zero = false;
end;
function core:MAIL_CLOSED(event, ...)
mailOpen = 0
finish_action ("mailbox",false);
end
local function GetItemListString(aMail)
local ItemList="";
for index=1,#aMail.Items do
local anItem=aMail.Items [index];
ItemList = ItemList.." "..(anItem.Link or anItem.Name or "(???)").."x"..(anItem.Count or "0");
end
return ItemList;
end;
local function GetItemListNameString(aMail)
local ItemList="";
for index=1,#aMail.Items do
local anItem=aMail.Items [index];
ItemList = ItemList.." ["..(anItem.Name or "(???)").."]x"..(anItem.Count or "0");
end
return ItemList;
end;
local lastgold,goldgained,goldlost=0,0,0;
local addon_initialized=false;
function core:ADDON_LOADED(event, ...)
if not addon_initialized then
addon_initialized=true;
--print "--ADDON_LOADED event";
if MailBookKeeperHistory==nil then
MailBookKeeperHistory = {};
end;
MailBookKeeperHistoryAvaiable = true;
lastgold =GetMoney();
if MailBookKeeperHistory.Serialized then
local result;
result,MailBookKeeperHistory=core:Deserialize(MailBookKeeperHistory.Serialized);
end;
--upgrade history data
for index,sentmail in pairs(MailBookKeeperHistory) do
if sentmail.Version == nil then sentmail.Version = 1; end;
if sentmail.Version == 1 then sentmail.Version = 2; sentmail.Channel = "mail"; end;
if sentmail.Version == 2 then sentmail.Version = 3; sentmail.InOut = "out"; end;
if sentmail.Version == 3 then sentmail.Version = 4; sentmail.Location = "unknown"; end;
if sentmail.From==nil then sentmail.From="";end;
if sentmail.Subject==nil then sentmail.Subject="";end;
if sentmail.Channel == nil then sentmail.Channel ="";end;
if sentmail.InOut == nil then sentmail.InOut="";end;
if sentmail.Location == nil then sentmail.Location ="";end;
if sentmail.Recipient == nil then sentmail.Recipient = "";end;
end;
if mooptions.version == nil then
mooptions.version = modefaultoptions.version;
mooptions.COD = modefaultoptions.COD;
mooptions.Gold = modefaultoptions.Gold;
--print "default options loaded";
end;
if mooptions.History == nil then mooptions.History = modefaultoptions.History; end;
if mooptions.Cash == nil then mooptions.Cash = modefaultoptions.Cash; end;
end;
end
local function AggregateIntoTable (aTable,anItem)
local ItemAlreadyInList = false;
for index=1,#aTable do
if aTable[index].Link == anItem.Link then
aTable[index].Count = aTable[index].Count + anItem.Count;
ItemAlreadyInList = true;
end;
end;
if not ItemAlreadyInList then table.insert(aTable, anItem);end;
end;
local function FormatMoneyTostring(ammount,category)
local outstring="";
ammount = tonumber(ammount) or 0;
if (ammount>=0) or (mooptions[category].Zero) then
if mooptions[category].Graphics then
outstring=GetCoinTextureString (ammount+0.0001);
else
outstring=tostring((ammount+0.0001)/10000).."g";
end;
end;
return outstring;
end;
local OldGetInboxText=nil;
local InboxItemsSentOn={};
local function ProcessInboxMail(index)
local Transaction = {};
Transaction.Valid = false;
Transaction.Version = CurrentHistoryVersion;
local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemCount, wasRead, wasReturned, textCreated, canReply, isGM, itemQuantity = GetInboxHeaderInfo(index);
local bodyText, texture, isTakeable, isInvoice = OldGetInboxText(index);
Transaction.Subject = subject;
Transaction.Body = bodyText;
Transaction.Cost = 0;
Transaction.COD = CODAmount;
Transaction.Money = money;
Transaction.Channel = "mail";
Transaction.InOut = "in";
Transaction.Location = GetRealZoneText();
Transaction.From = sender or 'unknown';
Transaction.Recipient = GetUnitName ("player");
--Transaction.Timestamp = date("%Y/%m/%d %H:%M:%S",InboxItemsSentOn[index]);
Transaction.Timestamp = date("%Y/%m/%d %H:%M:%S");
if type(itemCount)~="number" then itemCount = 0;end;
Transaction.Items = {};
for i=1,itemCount do
local Name, itemId, itemTexture, Count, quality, canUse = GetInboxItem(index, i);
if Name then
local NewItem= {};
NewItem.Name=Name;
NewItem.Count=Count;
NewItem.Link=GetInboxItemLink(index, i) or '';
AggregateIntoTable (Transaction.Items,NewItem);
end;
end;
Transaction.Valid = true;
table.insert(MailBookKeeperHistory, Transaction);
end;
function CheckMailRecipient (...)
--DEFAULT_CHAT_FRAME:AddMessage ("CheckMailRecipient called");
local EditBox = ...;
local hist= MailBookKeeperHistory;
local foundcnt,rcpt=0,EditBox:GetText();
if C_FriendList.IsIgnored(rcpt) then
EditBox:SetTextColor(1, 0.4, 0.4);
else
for index,sentmail in pairs(hist) do
if sentmail and sentmail.Channel == "mail" and sentmail.Recipient and sentmail.Recipient==rcpt then foundcnt=foundcnt+1;end;
end
--DEFAULT_CHAT_FRAME:AddMessage ("Found "..tostring(foundcnt).." for "..tostring(rcpt));
if foundcnt>5 then
EditBox:SetTextColor(0.2, 1, 0.2);
else
EditBox:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
end
end;
end
function MyGetInboxText(...)
local index = ...;
--print ("---Processing mail at index ",index);
-- cvt
if mooptions.History == nil then mooptions.History = modefaultoptions.History; end;
if mooptions.History.Enabled and type(index)=="number" and index >= 1 and index <= GetInboxNumItems() then
local _, _, _, _, _, _, _, _, wasRead, _, _, _, _, _ = GetInboxHeaderInfo(index);
if not wasRead then
--print ("---Processing new mail at index ",index);
ProcessInboxMail(index);
end;
end;
return OldGetInboxText(...);
end;
local function CleanupHistoryTable(days)
print(string.format("MailBookKeeper: Deleting all mails older than %d %s", days, " days in history"))
local currentTimeStamp = C_DateAndTime.GetCurrentCalendarTime()
print(string.format("Current date: %4d-%02d-%02d", currentTimeStamp.year, currentTimeStamp.month, currentTimeStamp.monthDay))
local tresholdTimeStamp = C_DateAndTime.AdjustTimeByDays(currentTimeStamp, -days -1)
print(string.format("Deleting older than: %4d-%02d-%02d", tresholdTimeStamp.year, tresholdTimeStamp.month, tresholdTimeStamp.monthDay))
local maxIndex = 0
for index, value in pairs(MailBookKeeperHistory) do
maxIndex = maxIndex + 1;
local timestamp = string.sub(value.Timestamp, 1, 10)
local year, month, day = timestamp:match("(%d+)/(%d+)/(%d+)")
local calendarTimeObject = {
hour = 0,
minute = 0,
month = tonumber(month),
monthDay = tonumber(day),
weekday = 1,
year = tonumber(year)
}
local isLower = C_DateAndTime.CompareCalendarTime(calendarTimeObject, tresholdTimeStamp)
if (isLower == -1) then
print(string.format("deleting until date: %4d-%02d-%02d", calendarTimeObject.year, calendarTimeObject.month, calendarTimeObject.monthDay))
print(string.format("Index count is %d", maxIndex))
break
end
end
for i=1, maxIndex do
table.remove(MailBookKeeperHistory, 1)
end
print(string.format("MailBookKeeper: Deleted!"))
end
local function DeleteHistory()
local frame = AceGUI:Create("Frame")
frame:SetCallback("OnClose",function(widget)
frame:Hide();
frame:ClearAllPoints();
AceGUI:Release(frame);
end)
frame:SetTitle("MailBookKeeper DELETE history page");
frame:SetStatusText("Deletion is permanent and can not be reverted!!!")
frame:SetLayout("Flow")
frame:SetPoint("CENTER", -200, -250);
frame:SetWidth(500);
frame:SetHeight(200);
local labelMsg = AceGUI:Create("Label")
labelMsg:SetText("Waiting for input ...")
local labelHint = AceGUI:Create("Label")
labelHint:SetText("After deletion you have to relog!!! Tables are only stored due logout of a char!")
local editbox = AceGUI:Create("EditBox")
editbox:SetLabel("Enter days mails to be preserved: ")
editbox:SetWidth(300)
editbox:SetFocus()
editbox:SetMaxLetters(4)
editbox:SetCallback("OnEnterPressed", function(widget, event, text)
local days = tonumber(text)
if days then
labelMsg:SetText(string.format("Deleting all mails older than %d %s", days, " days in history"))
CleanupHistoryTable(days)
else
labelMsg:SetText("Not a number, please enter ciphers only!")
end
end)
frame:AddChild(editbox)
frame:AddChild(labelMsg)
frame:AddChild(labelHint)
end;
local function ShowHistory()
--table.sort(MailBookKeeperHistory, function (a, b) return a.Timestamp < b.Timestamp end)
-- Create a container frame
local f = AceGUI:Create("Frame")
f:SetCallback("OnClose",function(widget)
local f=widget.ScrollTable.frame;
f:Hide();
widget.ScrollTable:SetData({});
f:UnregisterAllEvents();
f:ClearAllPoints();
widget.ScrollTable = nil;
AceGUI:Release(widget)
end)
f:SetTitle("MailBookKeeper history page");
f:SetStatusText("List of sent and/or received mails and items")
f:SetLayout("Fill")
--f.frame:SetResizable(false);
local mailhistorycols = {
{ name= "Date/time", width = 140, defaultsort = "dsc", },
{ name= "Channel", width = 60, defaultsort = "dsc", },
{ name= "From", width = 100, defaultsort = "dsc",},
{ name= "Recipient", width = 100, defaultsort = "dsc", },
{ name= "Subject", width = 200, defaultsort = "dsc", },
{ name= "Money", width = 100, defaultsort = "dsc",
DoCellUpdate = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, self, ...)
if fShow then
local cellData = data[realrow].cols[column];
cellFrame.text:SetText(FormatMoneyTostring(cellData.value,"Gold"));
end
end
},
{ name= "COD", width = 100, defaultsort = "dsc",
DoCellUpdate = function(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, self, ...)
if fShow then
local cellData = data[realrow].cols[column];
cellFrame.text:SetText(FormatMoneyTostring(cellData.value,"COD"));
end
end},
{ name= "#items", width = 40, defaultsort = "dsc",},
{ name= "List", width = 200, defaultsort = "dsc",},
{ name= "Body", width = 200, defaultsort = "dsc",},
};
local window = f.frame
local mailhistoryST = MOScrollingTable:CreateST(mailhistorycols, 10, 16, nil, window)
mailhistoryST.frame:SetPoint("BOTTOMLEFT",window, 10,10)
mailhistoryST.frame:SetPoint("TOP", window, 0, -60)
mailhistoryST.frame:SetPoint("RIGHT", window, -10,0)
-- mailhistoryST.frame:RegisterEvent("OnEnter",
-- function (rowframe, cellframe, data, cols, row, realrow, column, scrollingtable, ...)
-- local celldata = data[realrow].cols[column];
-- --gametooltip:show(celldata);
-- end
-- );
f.ScrollTable=mailhistoryST;
mailhistoryST.Fire=function(...)return true;end;
mailhistoryST.userdata={};
--fixit: sort table descending
mailhistoryST.QuickFilterRule="";
if MailBookKeeperHistoryAvaiable then
local testdata={};
local i=0;
for index,sentmail in pairs(MailBookKeeperHistory) do
if sentmail.Valid then
local Itemlist= GetItemListString(sentmail);
tinsert(testdata, {cols = {
{value = sentmail.Timestamp},
{value = sentmail.Channel.."/"..tostring(sentmail.InOut)},
{value = sentmail.From},
{value = sentmail.Recipient},
{value = sentmail.Subject},
{value = sentmail.Money},
{value = sentmail.COD},
{value = #sentmail.Items},
{value = Itemlist},
{value = sentmail.Body}
}});
end
end;
-- cvt
--[[
tinsert(testdata, {cols = {
{value = ""},
{value = ""},
{value = ""},
{value = ""},
{value = ""},
{value = ""},
{value = ""},
{value = ""},
{value = ""},
{value = ""}
}});
]]
mailhistoryST:SetData(testdata);
local STFilter=function (self, row)
if self.QuickFilterRule == nil then return true; end;
for index,col in pairs(row.cols) do
if string.find (strlower(col.value),strlower(self.QuickFilterRule))>0 then return true;end;
end;
return false;
end;
--mailhistoryST.SetFilter(STFilter);
end
local width = 100
for i, data in pairs(mailhistorycols) do
width = width + data.width
end
f:SetWidth(width);
mailhistoryST:SetDisplayRows((f.content.height / 16)-2, 16);
--mailhistoryST:Show()
end;
function core:GetOption(info)
local opt = mooptions[info[#info]];
local optname=info[#info];
if #info > 1 then
if mooptions[info[#info-1]] == nil then
mooptions[info[#info-1]]={};
end;
opt = mooptions[info[#info-1]] [info[#info]];
optname=info[#info-1].."."..info[#info];
end;
--print("The " .. tostring(optname) .. " returned as: " .. tostring(opt) );
return opt;
end
function core:SetOption(info, value)
if #info > 1 then
if mooptions [info[#info-1]] == nil then
mooptions [info[#info-1]]={};
end;
mooptions [info[#info-1]] [info[#info]] = value;
--print("The " .. info[#info-1].."."..info[#info] .. " was set to: " .. tostring(value) );
else
mooptions [info[#info]] = value;
--print("The " .. info[#info] .. " was set to: " .. tostring(value) );
end;
end
local function ResetSendMailInfo()
outgoingmail = {};
outgoingmail.Valid = false;
outgoingmailitems = {};
outgoingmailCOD = 0;
outgoingmailmoney = 0;
end;
local function reportMailInfo()
if outgoingmail.Valid then
outgoingmail.Timestamp = date("%Y/%m/%d %H:%M:%S");
local countableitems = (#outgoingmail.Items).." item";
if (#outgoingmail.Items > 1) then
countableitems = countableitems.."s";
elseif (#outgoingmail.Items == 0) then
countableitems = "no items";
end;
--GetCoinTextureString(10001));
local outmoney="";
if (outgoingmail.Money>0) or (mooptions.Gold.Zero) then
if mooptions.Gold.Graphics then
outmoney=GetCoinTextureString (outgoingmail.Money);
else
outmoney=tostring(outgoingmail.Money/10000).."g";
end;
end;
local outCOD="";
if (outgoingmail.COD>0) or (mooptions.COD.Zero) then
if mooptions.COD.Graphics then
outCOD="COD"..GetCoinTextureString (outgoingmail.COD);
else
outCOD="COD"..tostring(outgoingmail.COD/10000).."g";
end;
end;
ChatFrame1:AddMessage (outgoingmail.Timestamp..":(to:"..outgoingmail.Recipient..", "..countableitems..", "..outmoney.." "..outCOD..") '"..outgoingmail.Subject.."'");
local ItemList=GetItemListString(outgoingmail);
if (0<#outgoingmail.Items) then
ChatFrame1:AddMessage (ItemList);
end;
outgoingmail.Version = CurrentHistoryVersion;
outgoingmail.Channel = "mail";
outgoingmail.InOut = "out";
if mooptions.History.Enabled then
MailBookKeeperHistory [#MailBookKeeperHistory+1] = outgoingmail;
end;
ResetSendMailInfo();
end;
end;
local function UpdateSendMailInfo()
--[[
print "------";
print (SendMailSubjectEditBox:GetText());
print (SendMailNameEditBox:GetText());
print (SendMailBodyEditBox:GetText());
print (SendMailMoneyText:GetText());
print (MoneyInputFrame_GetCopper(SendMailMoney));
]]
outgoingmail = nil;
outgoingmail = {};
outgoingmail.From = GetUnitName ("player");
outgoingmail.Recipient = SendMailNameEditBox:GetText();
outgoingmail.Subject = SendMailSubjectEditBox:GetText();
outgoingmail.Body = SendMailBodyEditBox:GetText();
outgoingmail.Cost = GetSendMailPrice();
outgoingmail.Items = outgoingmailitems;
outgoingmail.COD = outgoingmailCOD;
outgoingmail.Money = outgoingmailmoney;
outgoingmail.Location = GetRealZoneText();
outgoingmail.Valid = true;
end;
local function UpdateSendMailitemsInfo()
outgoingmailitems = {};
for index=1, 12 do
local Name, itemId, Texture, Count, Quality = GetSendMailItem (index);
if Name then
local ItemAlreadyInList = false;
for inindex=1,#outgoingmailitems do
if outgoingmailitems[inindex].Name == Name then
outgoingmailitems[inindex].Count = outgoingmailitems[inindex].Count + Count;
ItemAlreadyInList = true;
end;
end;
if not ItemAlreadyInList then
local NewItem= {};
NewItem.Name=Name;
NewItem.Count=Count;
NewItem.Link=GetSendMailItemLink (index);
outgoingmailitems [1+#outgoingmailitems] =NewItem;
ItemAlreadyInList = true;
end;
end
end
UpdateSendMailInfo();
end;
local function ResetActiveTrade()
ActiveTrade={};
ActiveTrade.InProgress=false;
ActiveTrade.Debit = 0;
ActiveTrade.Credit = 0;
ActiveTrade.PlayerItems={};
ActiveTrade.TargetItems={};
end;
local currencylist=false;
function get_currencylist ()
if currencylist then return currencylist;end;
local currencyname, currencyamount, texturePath, earnedThisWeek, weeklyMax, totalMax, isDiscovered,currencyID;
currencylist={};
for currencyID=1,2500 do
currencyname, currencyamount, texturePath, earnedThisWeek, weeklyMax, totalMax, isDiscovered = C_CurrencyInfo.GetCurrencyInfo(currencyID);
if currencyamount~=0 or isDiscovered or #string.trim(currencyname)>0 then
currencylist [currencyID]={};
currencylist [currencyID].name=currencyname;
currencylist [currencyID].texturePath=texturePath;
currencylist [currencyID].link=C_CurrencyInfo.GetCurrencyLink(currencyID, 0);
end;
end;
return currencylist;
end;
local factionlist=false;
function get_factionlist ()
if factionlist then return factionlist;end;
local factionname, factiondescription, standingID, barMin, barMax, barValue, atWarWith, canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild,factionID;
factionlist={};
for factionID=1,2500 do
factionname, factiondescription, standingID, barMin, barMax, barValue, atWarWith, canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild = GetFactionInfoByID(factionID);
if standingID and factionname and #string.trim(factionname)>0 then
factionlist [factionID]={};
factionlist [factionID].name=factionname;
factionlist [factionID].standingID=standingID;
factionlist [factionID].reputation=barValue;
end;
end;
return factionlist;
end;
function core:TRADE_CLOSED(event, ...)
end;
function core:UI_INFO_MESSAGE(event, ...)
local arg1 = ...;
if arg1==ERR_TRADE_CANCELLED then
--print ("ERR_TRADE_CANCELLED");
ResetActiveTrade();
elseif arg1==ERR_TRADE_COMPLETE then
--print ("ERR_TRADE_COMPLETE");
--print ("player money");
--print (ActiveTrade.Debit);
--print ("Trade money");
--print (ActiveTrade.Credit);
--print ("Items");
--print (#ActiveTrade.PlayerItems.."/"..#ActiveTrade.TargetItems);
ActiveTrade.Timestamp = date("%Y/%m/%d %H:%M:%S");
if mooptions.History.Enabled then
local Transaction = {};
Transaction.Subject = "";
Transaction.Body = "";
Transaction.Cost = 0;
Transaction.COD = 0;
Transaction.Valid = false;
Transaction.Version = CurrentHistoryVersion;
Transaction.Channel = "trade";
Transaction.Location = GetRealZoneText();
Transaction.From = GetUnitName ("player");
Transaction.Recipient = ActiveTrade.Recipient;
Transaction.Timestamp = ActiveTrade.Timestamp;
if (ActiveTrade.Debit > 0) or (#ActiveTrade.PlayerItems>0) then
Transaction.Items = ActiveTrade.PlayerItems;
Transaction.Money = ActiveTrade.Debit;
Transaction.InOut = "out";
Transaction.Valid = true;
table.insert(MailBookKeeperHistory, Transaction);
end;
Transaction = nil;
Transaction = {};
Transaction.Subject = "";
Transaction.Body = "";
Transaction.Cost = 0;
Transaction.COD = 0;
Transaction.Valid = false;
Transaction.Version = CurrentHistoryVersion;
Transaction.Channel = "trade";
Transaction.Location = GetRealZoneText();
Transaction.From = GetUnitName ("player");
Transaction.Recipient = ActiveTrade.Recipient;
Transaction.Timestamp = ActiveTrade.Timestamp;
if (ActiveTrade.Credit > 0) or (#ActiveTrade.TargetItems>0) then
Transaction.Items = ActiveTrade.TargetItems;
Transaction.Money = ActiveTrade.Credit;
Transaction.InOut = "in";
Transaction.Valid = true;
table.insert(MailBookKeeperHistory, Transaction);
end;
end;
end; --successful trade
end;
function core:TRADE_REQUEST_CANCEL(event, ...)
ResetActiveTrade();
end;
function core:TRADE_SHOW(event, ...)
ResetActiveTrade();
ActiveTrade.InProgress=true;
ActiveTrade.Recipient=GetUnitName("NPC", true);
end;
local function UpdateTradeMoney()
if ActiveTrade.InProgress then
ActiveTrade.Debit = GetPlayerTradeMoney();
ActiveTrade.Credit = GetTargetTradeMoney();
--print ("money update:"..ActiveTrade.Debit.."/"..ActiveTrade.Credit);
end;
end
function core:TRADE_TARGET_ITEM_CHANGED(event, ...)
---print ("Target items changed");
UpdateTradeMoney();
ActiveTrade.TargetItems = {};
for index=1,MAX_TRADABLE_ITEMS do
local Name, Texture, Count, Quality, isUsable, enchantment = GetTradeTargetItemInfo(index);
if Name then
--print (index..":"..Name.." x"..Count);
local NewItem= {};
NewItem.Name=Name;
NewItem.Count=Count;
NewItem.Link=GetTradeTargetItemLink(index);
AggregateIntoTable (ActiveTrade.TargetItems,NewItem);
else
end;
end;
end;
function core:TRADE_PLAYER_ITEM_CHANGED(event, ...)
--print ("Player items changed");
UpdateTradeMoney();
ActiveTrade.PlayerItems = {};
for index=1,MAX_TRADABLE_ITEMS do
local Name, Texture, Count, Quality, isUsable, enchantment = GetTradePlayerItemInfo(index);
if Name then
--print (index..":"..Name.." x"..Count);
local NewItem= {};
NewItem.Name=Name;
NewItem.Count=Count;
NewItem.Link=GetTradePlayerItemLink(index);
AggregateIntoTable (ActiveTrade.PlayerItems,NewItem);
--print (#ActiveTrade.PlayerItems);
else
end;
end;
end;
function core:TRADE_ACCEPT_UPDATE(event, player, target)
ActiveTrade.PlayerAccepted = player;
ActiveTrade.TargetAccepted = target;
UpdateTradeMoney();
end;
local OldOnTextChanged,OldOnTextChangedHooked=nil,false;
local normalmailduration=30;
function core:MAIL_INBOX_UPDATE(event)
--print ("---Processing mail inbox update",event);
if OldGetInboxText==nil then
--print ("hooking");
OldGetInboxText=_G["GetInboxText"];
_G["GetInboxText"]=MyGetInboxText;
end;
if OldOnTextChangedHooked==false then
OldOnTextChanged = SendMailNameEditBox:GetScript("OnTextChanged");
SendMailNameEditBox:SetScript("OnTextChanged",CheckMailRecipient );
OldOnTextChangedHooked=true;
end;
end;
function core:MAIL_SEND_SUCCESS(event, ...)
-- print "------mail send succes";
outgoingmailmoney = 0;
outgoingmailCOD = 0;
reportMailInfo();
-- print (outgoingmail.Money);
-- print (outgoingmail.COD);
end
function core:PLAYER_LOGOUT(event, ...)
--MailBookKeeperHistory={serialized=core:Serialize(MailBookKeeperHistory)};
end
function core:SEND_MAIL_MONEY_CHANGED(event, ...)
-- print "------SEND_MAIL_MONEY_CHANGED";
if GetSendMailMoney()~=0 then
outgoingmailmoney = GetSendMailMoney();
end;