-
Notifications
You must be signed in to change notification settings - Fork 6
/
WIM.lua
1362 lines (1238 loc) · 39 KB
/
WIM.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
WIM_VERSION = "1.3.1";
WIM_Windows = {};
WIM_EditBoxInFocus = nil;
WIM_NewMessageFlag = false;
WIM_NewMessageCount = 0;
WIM_Icon_TheMenu = nil;
WIM_Icon_UpdateInterval = .5;
WIM_CascadeStep = 0;
WIM_MaxMenuCount = 20;
WIM_ClassIcons = {};
WIM_ClassColors = {};
WIM_PlayerCache = {}
WIM_PlayerCacheQueue = {}
WIM_WhisperedTo = {}
WIM_AlreadyCheckedGuildRoster = false;
WIM_GuildList = {}; --[Not saved between sessions: Autopopulates from GUILD_ROSTER_UPDATE event
WIM_FriendList = {}; --[Not saved between sessions: Autopopulates from FRIENDLIST_SHOW & FRIENDLIST_UPDATE event
WIM_Alias = {};
WIM_Filters = nil;
WIM_ToggleWindow_Timer = 0;
WIM_ToggleWindow_Index = 1;
WIM_RecentList = {}; --[Not saved between sessions: Store's list of recent conversations.
WIM_History = {};
WIM_Data_DEFAULTS = {
versionLastLoaded = "",
showChangeLogOnNewVersion = true,
enableWIM = true,
iconPosition=337,
showMiniMap=true,
displayColors = {
wispIn = {r=0.5607843137254902, g=0.03137254901960784, b=0.7607843137254902},
wispOut = {r=1, g=0.07843137254901961, b=0.9882352941176471},
sysMsg = {r=1, g=0.6627450980392157, b=0},
errorMsg = {r=1, g=0, b=0},
webAddress = {r=0, g=0, b=1},
},
fontSize = 12,
windowSize = 1,
windowAlpha = .8,
supressWisps = true,
keepFocus = false,
keepFocusRested = false,
popNew = true,
popUpdate = true,
popOnSend = true,
popCombat = false,
autoFocus = false,
playSoundWisp = true,
showToolTips = true,
sortAlpha = false,
winSize = {
width = 384,
height = 256
},
winLoc = {
left =242 ,
top =775
},
winCascade = {
enabled = true,
direction = "downright"
},
miniFreeMoving = {
enabled = false;
left = 0,
top = 0
},
characterInfo = {
show = true,
classIcon = true,
details = true,
classColor = true
},
showTimeStamps = true,
showShortcutBar = true,
enableAlias = true,
enableFilter = true,
aliasAsComment = true,
enableHistory = true,
historySettings = {
recordEveryone = false,
recordFriends = true,
recordGuild = true,
colorIn = {
r=0.4705882352941176,
g=0.4705882352941176,
b=0.4705882352941176
},
colorOut = {
r=0.7058823529411764,
g=0.7058823529411764,
b=0.7058823529411764
},
popWin = {
enabled = true,
count = 25
},
maxMsg = {
enabled = true,
count = 200
},
autoDelete = {
enabled = true,
days = 7
}
},
showAFK = true,
useEscape = true,
hookWispParse = true,
blockLowLevel = false,
};
--[initialize defualt values
WIM_Data = WIM_Data_DEFAULTS;
WIM_CascadeDirection = {
up = {
left = 0,
top = 25
},
down = {
left = 0,
top = -25
},
left = {
left = -50,
top = 0
},
right = {
left = 50,
top = 0
},
upleft = {
left = -50,
top = 25
},
upright = {
left = 50,
top = 25
},
downleft = {
left = -50,
top = -25
},
downright = {
left = 50,
top = -25
}
};
WIM_IconItems = { };
function WIM_OnLoad()
SlashCmdList["WIM"] = WIM_SlashCommand;
SLASH_WIM1 = "/wim";
end
function WIM_Incoming(event)
--[Events
if(event == "VARIABLES_LOADED") then
if(WIM_Data.enableWIM == nil) then WIM_Data.enableWIM = WIM_Data_DEFAULTS.enableWIM; end;
if(WIM_Data.versionLastLoaded == nil) then WIM_Data.versionLastLoaded = ""; end;
if(WIM_Data.showChangeLogOnNewVersion == nil) then WIM_Data.showChangeLogOnNewVersion = WIM_Data_DEFAULTS.showChangeLogOnNewVersion; end;
if(WIM_Data.displayColors == nil) then WIM_Data.displayColors = WIM_Data_DEFAULTS.displayColors; end;
if(WIM_Data.displayColors.sysMsg == nil) then WIM_Data.displayColors.sysMsg = WIM_Data_DEFAULTS.displayColors.sysMsg; end;
if(WIM_Data.displayColors.errorMsg == nil) then WIM_Data.displayColors.errorMsg = WIM_Data_DEFAULTS.displayColors.errorMsg; end;
if(WIM_Data.fontSize == nil) then WIM_Data.fontSize = WIM_Data_DEFAULTS.fontSize; end;
if(WIM_Data.windowSize == nil) then WIM_Data.windowSize = WIM_Data_DEFAULTS.windowSize; end;
if(WIM_Data.windowAlpha == nil) then WIM_Data.windowAlpha = WIM_Data_DEFAULTS.windowAlpha; end;
if(WIM_Data.supressWisps == nil) then WIM_Data.supressWisps = WIM_Data_DEFAULTS.supressWisps; end;
if(WIM_Data.keepFocus == nil) then WIM_Data.keepFocus = WIM_Data_DEFAULTS.keepFocus; end;
if(WIM_Data.keepFocusRested == nil) then WIM_Data.keepFocusRested = WIM_Data_DEFAULTS.keepFocusRested; end;
if(WIM_Data.popNew == nil) then WIM_Data.popNew = WIM_Data_DEFAULTS.popNew; end;
if(WIM_Data.popUpdate == nil) then WIM_Data.popNew = WIM_Data_DEFAULTS.popUpdate; end;
if(WIM_Data.autoFocus == nil) then WIM_Data.autoFocus = WIM_Data_DEFAULTS.autoFocus; end;
if(WIM_Data.playSoundWisp == nil) then WIM_Data.playSoundWisp = WIM_Data_DEFAULTS.playSoundWisp; end;
if(WIM_Data.showToolTips == nil) then WIM_Data.showToolTips = WIM_Data_DEFAULTS.showToolTips; end;
if(WIM_Data.sortAlpha == nil) then WIM_Data.sortAlpha = WIM_Data_DEFAULTS.sortAlpha; end;
if(WIM_Data.winSize == nil) then WIM_Data.winSize = WIM_Data_DEFAULTS.winSize; end;
if(WIM_Data.miniFreeMoving == nil) then WIM_Data.miniFreeMoving = WIM_Data_DEFAULTS.miniFreeMoving; end;
if(WIM_Data.popCombat == nil) then WIM_Data.popCombat = WIM_Data_DEFAULTS.popCombat; end;
if(WIM_Data.characterInfo == nil) then WIM_Data.characterInfo = WIM_Data_DEFAULTS.characterInfo; end;
if(WIM_Data.showTimeStamps == nil) then WIM_Data.showTimeStamps = WIM_Data_DEFAULTS.showTimeStamps; end;
if(WIM_Data.showShortcutBar == nil) then WIM_Data.showShortcutBar = WIM_Data_DEFAULTS.showShortcutBar; end;
if(WIM_Data.enableAlias == nil) then WIM_Data.enableAlias = WIM_Data_DEFAULTS.enableAlias; end;
if(WIM_Data.enableFilter == nil) then WIM_Data.enableFilter = WIM_Data_DEFAULTS.enableFilter; end;
if(WIM_Data.aliasAsComment == nil) then WIM_Data.aliasAsComment = WIM_Data_DEFAULTS.aliasAsComment; end;
if(WIM_Data.enableHistory == nil) then WIM_Data.enableHistory = WIM_Data_DEFAULTS.enableHistory; end;
if(WIM_Data.historySettings == nil) then WIM_Data.historySettings = WIM_Data_DEFAULTS.historySettings; end;
if(WIM_Data.winLoc == nil) then WIM_Data.winLoc = WIM_Data_DEFAULTS.winLoc; end;
if(WIM_Data.winCascade == nil) then WIM_Data.winCascade = WIM_Data_DEFAULTS.winCascade; end;
if(WIM_Data.popOnSend == nil) then WIM_Data.popOnSend = WIM_Data_DEFAULTS.popOnSend; end;
if(WIM_Data.versionLastLoaded == nil) then WIM_Data.versionLastLoaded = WIM_Data_DEFAULTS.versionLastLoaded; end;
if(WIM_Data.showAFK == nil) then WIM_Data.showAFK = WIM_Data_DEFAULTS.showAFK; end;
if(WIM_Data.useEscape == nil) then WIM_Data.useEscape = WIM_Data_DEFAULTS.useEscape; end;
if(WIM_Data.hookWispParse == nil) then WIM_Data.hookWispParse = WIM_Data_DEFAULTS.hookWispParse; end;
if(WIM_Filters == nil) then
WIM_LoadDefaultFilters();
end
ShowFriends(); --[update friend list
if(IsInGuild()) then GuildRoster(); end; --[update guild roster
ItemRefTooltip:SetFrameStrata("TOOLTIP");
WIM_HistoryPurge();
WIM_InitClassProps();
WIM_SetWIM_Enabled(WIM_Data.enableWIM);
if(WIM_VERSION ~= WIM_Data.versionLastLoaded) then
WIM_Help:Show();
end
WIM_Data.versionLastLoaded = WIM_VERSION;
if(WIM_Data.miniFreeMoving.enabled) then
if(WIM_Data.showMiniMap == false) then
WIM_IconFrame:Hide();
else
WIM_IconFrame:Show();
WIM_IconFrame:SetFrameStrata("HIGH");
WIM_IconFrame:SetPoint("TOPLEFT", "UIParent", "BOTTOMLEFT",WIM_Data.miniFreeMoving.left,WIM_Data.miniFreeMoving.top);
end
else
WIM_Icon_UpdatePosition();
end
elseif(event == "TRADE_SKILL_SHOW" or event == "CRAFT_SHOW") then
--[hook tradeskill window functions
WIM_HookTradeSkill();
elseif(event == "GUILD_ROSTER_UPDATE") then
WIM_LoadGuildList();
WIM_AlreadyCheckedGuildRoster = true;
elseif(event == "FRIENDLIST_SHOW" or event == "FRIENDLIST_UPDATE") then
WIM_LoadFriendList();
elseif(event == "ADDON_LOADED") then
WIM_AddonDetectToHook(arg1);
else
if(WIM_AlreadyCheckedGuildRoster == false) then
if(IsInGuild()) then GuildRoster(); end; --[update guild roster
end
WIM_ChatFrame_OnEvent(event);
end
end
function WIM_PlayerCacheQueueEmpty()
for _, info in WIM_PlayerCacheQueue do
if info.attempts <= 5 then
return false
end
end
return true
end
function WIM_Update()
if not WIM_LastWhoListUpdate or GetTime() - WIM_LastWhoListUpdate > 5 then
for name, info in WIM_PlayerCacheQueue do
if info.attempts <= 5 and not info.last_sent or GetTime() - info.last_sent > ldexp(2, info.attempts) then
SendWho('n-"'..name..'"')
info.last_sent = GetTime()
info.attempts = info.attempts + 1
return
end
end
end
end
function WIM_WhoInfo(name, callback)
if WIM_PlayerCache[name] then
callback(WIM_PlayerCache[name])
else
WIM_WhoScanInProgress = true
SetWhoToUI(1)
WIM_PlayerCacheQueue[name] = WIM_PlayerCacheQueue[name] or { callbacks = {} }
WIM_PlayerCacheQueue[name].attempts = 0
tinsert(WIM_PlayerCacheQueue[name].callbacks, callback)
end
end
local function playerCheck(player, k)
if not WIM_Data.blockLowLevel then
return k()
end
if WIM_WhisperedTo[player] then
return k()
end
for i=1, GetNumFriends() do
name = GetFriendInfo(i)
if name == player then
return k()
end
end
for i=1, GetNumGuildMembers(true) do
name = GetGuildRosterInfo(i)
if name == player then
return k()
end
end
WIM_WhoInfo(player, function(info)
if info.level >= 10 then
return k()
end
end)
end
function WIM_ChatFrame_OnEvent(event)
if( WIM_Data.enableWIM == false) then
return;
end
local msg = "";
if((event == "CHAT_MSG_AFK" or event == "CHAT_MSG_DND") and WIM_Data.showAFK) then
local afkType;
if( event == "CHAT_MSG_AFK" ) then
afkType = "AFK";
else
afkType = "DND";
end
msg = "<"..afkType.."> |Hplayer:"..arg2.."|h"..arg2.."|h: "..arg1;
WIM_PostMessage(arg2, msg, 3);
ChatEdit_SetLastTellTarget(ChatFrameEditBox,arg2);
elseif event == 'CHAT_MSG_WHISPER' then
local content, sender = arg1, arg2
playerCheck(sender, function()
if WIM_FilterResult(content) ~= 1 and WIM_FilterResult(content) ~= 2 then
msg = "[|Hplayer:"..sender.."|h"..WIM_GetAlias(sender, true).."|h]: "..content
WIM_PostMessage(sender, msg, 1, sender, content)
end
ChatEdit_SetLastTellTarget(ChatFrameEditBox, sender)
end)
elseif event == 'CHAT_MSG_WHISPER_INFORM' then
local content, receiver = arg1, arg2
WIM_WhisperedTo[receiver] = true
if WIM_FilterResult(content) ~= 1 and WIM_FilterResult(content) ~= 2 then
msg = "[|Hplayer:"..UnitName("player").."|h"..WIM_GetAlias(UnitName("player"), true).."|h]: "..content
WIM_PostMessage(receiver, msg, 2, UnitName("player"), content)
end
elseif(event == "CHAT_MSG_SYSTEM") then
local tstart,tfinish = string.find(arg1, "\'(%a+)\'");
if(tstart ~= nil and tfinish ~= nil) then
user = string.sub(arg1, tstart+1, tfinish-1);
user = string.gsub(user, "^%l", string.upper)
tstart, tfinish = string.find(arg1, "playing");
if(tstart ~= nil and WIM_Windows[user] ~= nil) then
-- player not playing, can't whisper
msg = "|Hplayer:"..user.."|h"..user.."|h is not currently playing!";
WIM_PostMessage(user, msg, 4);
end
end
end
end
function WIM_ChatFrameSupressor_OnEvent(event)
if(WIM_Data.enableWIM == false) then
return true;
end
local msg = "";
if((event == "CHAT_MSG_AFK" or event == "CHAT_MSG_DND") and WIM_Data.showAFK) then
if(WIM_Data.supressWisps) then
return false; --[ false to supress from chatframe
else
return true;
end
elseif(event == "CHAT_MSG_WHISPER") then
if(WIM_Data.supressWisps) then
if(WIM_FilterResult(arg1) == 1) then
return true;
else
return false; --[ false to supress from chatframe
end
else
if(WIM_FilterResult(arg1) == 2) then
return false;
else
return true;
end
end
elseif(event == "CHAT_MSG_WHISPER_INFORM") then
if(WIM_Data.supressWisps) then
if(WIM_FilterResult(arg1) == 1) then
return true;
else
return false; --[ false to supress from chatframe
end
else
if(WIM_FilterResult(arg1) == 2) then
return false;
else
return true;
end
end
elseif(event == "CHAT_MSG_SYSTEM") then
local tstart,tfinish = string.find(arg1, "\'(%a+)\'");
if(tstart ~= nil and tfinish ~= nil) then
user = string.sub(arg1, tstart+1, tfinish-1);
user = string.gsub(user, "^%l", string.upper)
tstart, tfinish = string.find(arg1, "playing");
if(tstart ~= nil and WIM_Windows[user] ~= nil) then
-- player not playing, can't whisper
if(WIM_Data.supressWisps) then
return false; --[ false to supress from chatframe
else
return true;
end
end
end
return true;
end
return true;
end
function WIM_PostMessage(user, msg, ttype, from, raw_msg, hotkeyFix)
--[[
ttype:
1 - Wisper from someone
2 - Wisper sent
3 - System Message
4 - Error Message
5 - Show window... Do nothing else...
]]--
local f,chatBox
local isNew = false
if not WIM_Windows[user] then
if getglobal('WIM_msgFrame'..user) then
f = getglobal('WIM_msgFrame'..user)
else
f = CreateFrame('Frame', 'WIM_msgFrame'..user,UIParent, 'WIM_msgFrameTemplate')
end
WIM_SetWindowProps(f)
WIM_Windows[user] = {
frame = 'WIM_msgFrame'..user,
newMSG = true,
is_visible = false,
last_msg = time(),
}
f.theUser = user
getglobal('WIM_msgFrame'..user..'From'):SetText(WIM_GetAlias(user))
WIM_Icon_AddUser(user)
isNew = true
WIM_SetWindowLocation(f)
if WIM_Data.characterInfo.show then
if table.getn(WIM_Split(user, '-')) == 2 then
-- WIM_GetBattleWhoInfo(user)
else
WIM_WhoInfo(user, function()
WIM_SetWhoInfo(user)
end)
end
end
WIM_UpdateCascadeStep()
WIM_DisplayHistory(user)
if(WIM_History[user]) then
getglobal(f:GetName()..'HistoryButton'):Show()
end
end
f = getglobal('WIM_msgFrame'..user)
chatBox = getglobal('WIM_msgFrame'..user..'ScrollingMessageFrame')
msg = WIM_ConvertURLtoLinks(msg)
WIM_Windows[user].newMSG = true
WIM_Windows[user].last_msg = time()
if ttype == 1 then
WIM_PlaySoundWisp()
WIM_AddToHistory(user, from, raw_msg, false)
WIM_RecentListAdd(user)
chatBox:AddMessage(WIM_getTimeStamp()..msg, WIM_Data.displayColors.wispIn.r, WIM_Data.displayColors.wispIn.g, WIM_Data.displayColors.wispIn.b)
elseif ttype == 2 then
WIM_AddToHistory(user, from, raw_msg, true)
WIM_RecentListAdd(user)
chatBox:AddMessage(WIM_getTimeStamp()..msg, WIM_Data.displayColors.wispOut.r, WIM_Data.displayColors.wispOut.g, WIM_Data.displayColors.wispOut.b)
elseif ttype == 3 then
chatBox:AddMessage(msg, WIM_Data.displayColors.sysMsg.r, WIM_Data.displayColors.sysMsg.g, WIM_Data.displayColors.sysMsg.b)
elseif ttype == 4 then
chatBox:AddMessage(msg, WIM_Data.displayColors.errorMsg.r, WIM_Data.displayColors.errorMsg.g, WIM_Data.displayColors.errorMsg.b)
end
if WIM_PopOrNot(isNew) or ttype == 2 or ttype == 5 then
WIM_Windows[user].newMSG = false
if ttype == 2 and WIM_Data.popOnSend == false then
--[ do nothing, user prefers not to pop on send
else
f:Show()
if ttype ==5 then
f:Raise()
getglobal(f:GetName()..'MsgBox'):SetFocus()
end
end
end
WIM_UpdateScrollBars(chatBox)
WIM_Icon_DropDown_Update()
if WIM_HistoryFrame:IsVisible() then
WIM_HistoryViewNameScrollBar_Update()
WIM_HistoryViewFiltersScrollBar_Update()
end
if hotkeyFix then
local orig = getglobal(f:GetName()..'MsgBox'):GetScript('OnChar')
getglobal(f:GetName()..'MsgBox'):SetScript('OnChar', function()
getglobal(f:GetName()..'MsgBox'):SetText('')
getglobal(f:GetName()..'MsgBox'):SetScript('OnChar', orig)
end)
end
end
function WIM_SetWindowLocation(theWin)
local CascadeOffset_Left = 0;
local CascadeOffset_Top = 0;
if(WIM_Data.winCascade.enabled) then
CascadeOffset_Left = WIM_CascadeDirection[WIM_Data.winCascade.direction].left;
CascadeOffset_Top = WIM_CascadeDirection[WIM_Data.winCascade.direction].top;
end
theWin:SetPoint(
"TOPLEFT",
"UIParent",
"BOTTOMLEFT",
(WIM_Data.winLoc.left + WIM_CascadeStep*CascadeOffset_Left),
(WIM_Data.winLoc.top + WIM_CascadeStep*CascadeOffset_Top)
);
end
function WIM_PopOrNot(isNew)
if(isNew == true and WIM_Data.popNew == true) then
if(WIM_Data.popCombat and UnitAffectingCombat("player")) then
return false;
else
return true;
end
elseif(WIM_Data.popNew == true and WIM_Data.popUpdate == true) then
if(WIM_Data.popCombat and UnitAffectingCombat("player")) then
return false;
else
return true;
end
else
return false;
end
end
function WIM_UpdateScrollBars(smf)
local parentName = smf:GetParent():GetName();
if(smf:AtTop()) then
getglobal(parentName.."ScrollUp"):Disable();
else
getglobal(parentName.."ScrollUp"):Enable();
end
if(smf:AtBottom()) then
getglobal(parentName.."ScrollDown"):Disable();
else
getglobal(parentName.."ScrollDown"):Enable();
end
end
function WIM_isLinkURL(link)
if (strsub(link, 1, 3) == "url") then
return true;
else
return false;
end
end
function WIM_DisplayURL(link)
local theLink = "";
if (string.len(link) > 4) and (string.sub(link,1,4) == "url:") then
theLink = string.sub(link,5, string.len(link));
end
--show UI to show url so it can be copied
if(theLink) then
WIM_urlCopyUrlBox:SetText(theLink);
WIM_urlCopy:Show();
WIM_urlCopyUrlBox:HighlightText(0);
end
end
function WIM_ConvertURLtoLinks(text)
local preLink, midLink, postLink;
preLink = "|Hurl:";
midLink = "|h|cff"..WIM_RGBtoHex(WIM_Data.displayColors.webAddress.r, WIM_Data.displayColors.webAddress.g, WIM_Data.displayColors.webAddress.b);
postLink = "|h|r";
text = string.gsub(text, "(%a+://[%w_/%.%?%%=~&-]+)", preLink.."%1"..midLink.."%1"..postLink);
return text;
end
function WIM_SlashCommand(msg)
if(msg == "" or msg == nil) then
WIM_Options:Show();
elseif(msg == "reset") then
WIM_Data = WIM_Data_DEFAULTS;
elseif(msg == "clear history") then
WIM_History = {};
elseif(msg == "reset filters") then
WIM_LoadDefaultFilters();
elseif(msg == "history") then
WIM_HistoryFrame:Show();
elseif(msg == "help") then
WIM_Help:Show();
end
end
function WIM_Icon_Move(toDegree)
WIM_Data.iconPosition = toDegree;
WIM_Icon_UpdatePosition();
end
function WIM_Icon_UpdatePosition()
if(WIM_Data.showMiniMap == false) then
WIM_IconFrame:Hide();
else
if(WIM_Data.miniFreeMoving.enabled == false) then
WIM_IconFrame:SetPoint(
"TOPLEFT",
"Minimap",
"TOPLEFT",
54 - (78 * cos(WIM_Data.iconPosition)),
(78 * sin(WIM_Data.iconPosition)) - 55
);
end
WIM_IconFrame:Show();
end
end
function WIM_SetWindowProps(theWin)
if(WIM_Data.showShortcutBar) then
getglobal(theWin:GetName().."ShortcutFrame"):Show();
local tHeight = WIM_Data.winSize.height;
if(tHeight < 240) then
tHeight = 240;
end
theWin:SetHeight(tHeight);
else
getglobal(theWin:GetName().."ShortcutFrame"):Hide();
theWin:SetHeight(WIM_Data.winSize.height);
end
theWin:SetWidth(WIM_Data.winSize.width);
theWin:SetScale(WIM_Data.windowSize);
theWin:SetAlpha(WIM_Data.windowAlpha);
getglobal(theWin:GetName().."ScrollingMessageFrame"):SetFont("Fonts\\FRIZQT__.TTF",WIM_Data.fontSize);
getglobal(theWin:GetName().."ScrollingMessageFrame"):SetAlpha(1);
getglobal(theWin:GetName().."MsgBox"):SetAlpha(1);
getglobal(theWin:GetName().."ShortcutFrame"):SetAlpha(1);
if(WIM_Data.useEscape) then
WIM_AddEscapeWindow(theWin);
else
WIM_RemoveEscapeWindow(theWin);
end
--WIM_SetTabFrameProps();
end
function WIM_AddEscapeWindow(theWin)
for i=1, table.getn(UISpecialFrames) do
if(UISpecialFrames[i] == theWin:GetName()) then
return;
end
end
tinsert(UISpecialFrames,theWin:GetName());
end
function WIM_RemoveEscapeWindow(theWin)
for i=1, table.getn(UISpecialFrames) do
if(UISpecialFrames[i] == theWin:GetName()) then
table.remove(UISpecialFrames, i);
return;
end
end
end
function WIM_SetAllWindowProps()
for key in WIM_Windows do
WIM_SetWindowProps(getglobal(WIM_Windows[key].frame));
end
end
function WIM_Icon_ToggleDropDown()
--ToggleDropDownMenu(1, nil, WIM_Icon_DropDown);
--local tMenu = getglobal("DropDownList"..UIDROPDOWNMENU_MENU_LEVEL);
--tMenu:ClearAllPoints();
--tMenu:SetPoint("TOPRIGHT", "WIM_IconFrameButton", "BOTTOMLEFT", 0, 0);
--WIM_Icon_DropDown:SetWidth(DropDownList1Button1:GetWidth()+50);
--DropDownList1:SetScale(UIParent:GetScale());
if(WIM_ConversationMenu:IsVisible()) then
WIM_ConversationMenu:Hide();
else
WIM_ConversationMenu:ClearAllPoints();
WIM_ConversationMenu:Show();
WIM_ConversationMenu:SetPoint("TOPRIGHT", WIM_IconFrame, "BOTTOMLEFT", 5, 5);
end
end
function WIM_Icon_DropDown_Update()
local tList = {}
local tListActivity = {}
local tCount = 0
for key in WIM_IconItems do
table.insert(tListActivity, key)
tCount = tCount + 1
end
--[first get a sorted list of users by most recent activity
table.sort(tListActivity, WIM_Icon_SortByActivity)
--[account for only the allowable amount of active users
for i=1,table.getn(tListActivity) do
if i <= WIM_MaxMenuCount then
table.insert(tList, tListActivity[i])
end
end
--Initialize Menu
for i=1,20 do
getglobal("WIM_ConversationMenuTellButton"..i.."Close"):Show()
getglobal("WIM_ConversationMenuTellButton"..i):Enable()
getglobal("WIM_ConversationMenuTellButton"..i):Hide()
end
WIM_NewMessageCount = 0;
if tCount == 0 then
info = {}
info.justifyH = "LEFT"
info.text = " - None -"
info.notClickable = 1
info.notCheckable = 1
getglobal("WIM_ConversationMenuTellButton1Close"):Hide()
getglobal("WIM_ConversationMenuTellButton1"):Disable()
getglobal("WIM_ConversationMenuTellButton1"):SetText("|cffffffff - None -")
getglobal("WIM_ConversationMenuTellButton1"):Show()
else
if WIM_Data.sortAlpha then
table.sort(tList)
end
WIM_NewMessageFlag = false
for i=1,table.getn(tList) do
if WIM_Windows[tList[i]].newMSG and WIM_Windows[tList[i]].is_visible == false then
WIM_IconItems[tList[i]].color = "|cff"..WIM_RGBtoHex(77/255, 135/233, 224/255)
WIM_NewMessageFlag = true
WIM_NewMessageCount = WIM_NewMessageCount + 1
else
WIM_IconItems[tList[i]].color = "|cffffffff"
end
getglobal("WIM_ConversationMenuTellButton"..i):SetText(WIM_IconItems[tList[i]].color..WIM_GetAlias(WIM_IconItems[tList[i]].text, true))
getglobal("WIM_ConversationMenuTellButton"..i).theUser = WIM_IconItems[tList[i]].text
getglobal("WIM_ConversationMenuTellButton"..i).value = WIM_IconItems[tList[i]].value
getglobal("WIM_ConversationMenuTellButton"..i):Show()
end
end
--Set Height of Conversation Menu depending on message count
local ConvoMenuHeight = 60
local CMH_Delta = 16 * (table.getn(tList)-1)
if CMH_Delta < 0 then CMH_Delta = 0 end
ConvoMenuHeight = ConvoMenuHeight + CMH_Delta
WIM_ConversationMenu:SetHeight(ConvoMenuHeight)
--Minimap icon
if WIM_Data.enableWIM == true then
if WIM_NewMessageFlag == true then
WIM_IconFrameButton:SetNormalTexture("Interface\\AddOns\\WIM\\Images\\miniEnabled")
else
WIM_IconFrameButton:SetNormalTexture("Interface\\AddOns\\WIM\\Images\\miniDisabled")
end
else
--show wim disabled icon
WIM_IconFrameButton:SetNormalTexture("Interface\\AddOns\\WIM\\Images\\miniOff")
end
end
function WIM_ConversationMenu_OnUpdate(elapsed)
if this.isCounting then
this.timeElapsed = this.timeElapsed + elapsed
if this.timeElapsed > 1 then
this:Hide()
this.timeElapsed = 0
this.isCounting = false
end
end
end
function WIM_Icon_AddUser(theUser)
UIDROPDOWNMENU_INIT_MENU = "WIM_Options_DropDown"
UIDROPDOWNMENU_OPEN_MENU = UIDROPDOWNMENU_INIT_MENU
local info = {}
info.text = theUser;
info.justifyH = "LEFT"
info.isTitle = nil
info.notCheckable = 1
info.value = WIM_Windows[theUser].frame
info.func = WIM_Icon_PlayerClick
WIM_IconItems[theUser] = info
table.sort(WIM_IconItems)
WIM_Icon_DropDown_Update()
end
function WIM_Icon_PlayerClick()
if(this.value ~= nil) then
getglobal(this.value):Show()
--[local user = getglobal(this.value.."From"):GetText();
local user = getglobal(this.value).theUser
WIM_Windows[user].newMSG = false
WIM_Windows[user].is_visible = true
WIM_Icon_DropDown_Update()
end
end
function WIM_Icon_OnUpdate(elapsedTime)
if WIM_NewMessageFlag == false then
this.TimeSinceLastUpdate = 0
if WIM_Icon_NewMessageFlash:IsVisible() then
WIM_Icon_NewMessageFlash:Hide()
end
return
end
this.TimeSinceLastUpdate = this.TimeSinceLastUpdate + elapsedTime
while this.TimeSinceLastUpdate > WIM_Icon_UpdateInterval do
if WIM_Icon_NewMessageFlash:IsVisible() then
WIM_Icon_NewMessageFlash:Hide()
else
WIM_Icon_NewMessageFlash:Show()
end
this.TimeSinceLastUpdate = this.TimeSinceLastUpdate - WIM_Icon_UpdateInterval
end
end
function WIM_UpdateCascadeStep()
WIM_CascadeStep = WIM_CascadeStep + 1
if WIM_CascadeStep > 10 then
WIM_CascadeStep = 0
end
end
function WIM_PlaySoundWisp()
if WIM_Data.playSoundWisp == true then
PlaySoundFile("Interface\\AddOns\\WIM\\Sounds\\wisp.wav")
end
end
function WIM_Icon_SortByActivity(user1, user2)
return WIM_Windows[user1].last_msg > WIM_Windows[user2].last_msg
end
function WIM_RGBtoHex(r,g,b)
return string.format ("%.2x%.2x%.2x",r*255,g*255,b*255)
end
function WIM_Icon_OnEnter()
GameTooltip:SetOwner(this, "ANCHOR_LEFT");
GameTooltip:SetText("WIM v"..WIM_VERSION.." ");
GameTooltip:AddDoubleLine("Conversation Menu", "Left-Click", 1,1,1,1,1,1);
GameTooltip:AddDoubleLine("Show New Messages", "Right-Click", 1,1,1,1,1,1);
GameTooltip:AddDoubleLine("WIM Options", "/wim", 1,1,1,1,1,1);
end
function WIM_ShowNewMessages()
for key in WIM_Windows do
if(WIM_Windows[key].newMSG == true) then
getglobal(WIM_Windows[key].frame):Show();
WIM_Windows[key].newMSG = false;
end
end
WIM_Icon_DropDown_Update();
end
function WIM_ShowAll()
for key in WIM_Windows do
getglobal(WIM_Windows[key].frame):Show();
end
end
function WIM_HideAll()
for key in WIM_Windows do
getglobal(WIM_Windows[key].frame):Hide();
end
end
function WIM_CloseAllConvos()
for key in WIM_Windows do
WIM_CloseConvo(key);
end
end
function WIM_CloseConvo(theUser)
if(WIM_Windows[theUser] == nil) then return; end; --[ fail silently
getglobal(WIM_Windows[theUser].frame):Hide();
getglobal(WIM_Windows[theUser].frame.."ScrollingMessageFrame"):Clear();
getglobal(WIM_Windows[theUser].frame.."ClassIcon"):SetTexture("Interface\\AddOns\\WIM\\Images\\classBLANK");
getglobal(WIM_Windows[theUser].frame.."CharacterDetails"):SetText("");
WIM_Windows[theUser] = nil;
WIM_IconItems[theUser] = nil;
WIM_Icon_DropDown_Update();
end
function WIM_InitClassProps()
WIM_ClassIcons[WIM_LOCALIZED_DRUID] = "Interface\\AddOns\\WIM\\Images\\classDRUID";
WIM_ClassIcons[WIM_LOCALIZED_HUNTER] = "Interface\\AddOns\\WIM\\Images\\classHUNTER";
WIM_ClassIcons[WIM_LOCALIZED_MAGE] = "Interface\\AddOns\\WIM\\Images\\classMAGE";
WIM_ClassIcons[WIM_LOCALIZED_PALADIN] = "Interface\\AddOns\\WIM\\Images\\classPALADIN";
WIM_ClassIcons[WIM_LOCALIZED_PRIEST] = "Interface\\AddOns\\WIM\\Images\\classPRIEST";
WIM_ClassIcons[WIM_LOCALIZED_ROGUE] = "Interface\\AddOns\\WIM\\Images\\classROGUE";
WIM_ClassIcons[WIM_LOCALIZED_SHAMAN] = "Interface\\AddOns\\WIM\\Images\\classSHAMAN";
WIM_ClassIcons[WIM_LOCALIZED_WARLOCK] = "Interface\\AddOns\\WIM\\Images\\classWARLOCK";
WIM_ClassIcons[WIM_LOCALIZED_WARRIOR] = "Interface\\AddOns\\WIM\\Images\\classWARRIOR";
WIM_ClassColors[WIM_LOCALIZED_DRUID] = "ff7d0a";
WIM_ClassColors[WIM_LOCALIZED_HUNTER] = "abd473";
WIM_ClassColors[WIM_LOCALIZED_MAGE] = "69ccf0";
WIM_ClassColors[WIM_LOCALIZED_PALADIN] = "f58cba";
WIM_ClassColors[WIM_LOCALIZED_PRIEST] = "ffffff";
WIM_ClassColors[WIM_LOCALIZED_ROGUE] = "fff569";
WIM_ClassColors[WIM_LOCALIZED_SHAMAN] = "f58cba";
WIM_ClassColors[WIM_LOCALIZED_WARLOCK] = "9482ca";
WIM_ClassColors[WIM_LOCALIZED_WARRIOR] = "c79c6e";
end
function WIM_UserWithClassColor(theUser)
if(WIM_PlayerCache[theUser].class == "") then
return theUser;
else
if(WIM_ClassColors[WIM_PlayerCache[theUser].class]) then
return "|cff"..WIM_ClassColors[WIM_PlayerCache[theUser].class]..WIM_GetAlias(theUser);
else
return WIM_GetAlias(theUser);
end
end
end
function WIM_SetWhoInfo(theUser)
local classIcon = getglobal(WIM_Windows[theUser].frame.."ClassIcon");
if(WIM_Data.characterInfo.classIcon and WIM_ClassIcons[WIM_PlayerCache[theUser].class]) then
classIcon:SetTexture(WIM_ClassIcons[WIM_PlayerCache[theUser].class]);
else
classIcon:SetTexture("Interface\\AddOns\\WIM\\Images\\classBLANK");
end
if(WIM_Data.characterInfo.classColor) then
getglobal(WIM_Windows[theUser].frame.."From"):SetText(WIM_UserWithClassColor(theUser));
end
if(WIM_Data.characterInfo.details) then
local tGuild = "";
if(WIM_PlayerCache[theUser].guild ~= "") then
tGuild = "<"..WIM_PlayerCache[theUser].guild.."> ";
end
getglobal(WIM_Windows[theUser].frame.."CharacterDetails"):SetText("|cffffffff"..tGuild..WIM_PlayerCache[theUser].level.." "..WIM_PlayerCache[theUser].race.." "..WIM_PlayerCache[theUser].class.."|r");
end
end
function WIM_getTimeStamp()
if(WIM_Data.showTimeStamps) then
return "|cff"..WIM_RGBtoHex(WIM_Data.displayColors.sysMsg.r, WIM_Data.displayColors.sysMsg.g, WIM_Data.displayColors.sysMsg.b)..date("%H:%M").."|r ";
else
return "";
end
end
function WIM_Bindings_EnableWIM()
WIM_SetWIM_Enabled(not WIM_Data.enableWIM);
end
function WIM_SetWIM_Enabled(YesOrNo)
WIM_Data.enableWIM = YesOrNo
WIM_Icon_DropDown_Update();
end
function WIM_LoadShortcutFrame()
local tButtons = {
{
icon = "Interface\\Icons\\Ability_Hunter_AimedShot",
cmd = "target",
tooltip = "Target"
},
{
icon = "Interface\\Icons\\Spell_Holy_BlessingOfStrength",
cmd = "invite",
tooltip = "Invite"
},
{
icon = "Interface\\Icons\\INV_Misc_Bag_10_Blue",
cmd = "trade",