-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathFloatingChatFrame.lua
2518 lines (2160 loc) · 78.3 KB
/
FloatingChatFrame.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
-- CHAT PROTOTYPE STUFF
SELECTED_DOCK_FRAME = nil;
DOCKED_CHAT_FRAMES = {};
DOCK_COPY = {};
MOVING_CHATFRAME = nil;
CHAT_TAB_SHOW_DELAY = 0.2;
CHAT_TAB_HIDE_DELAY = 1;
CHAT_FRAME_FADE_TIME = 0.15;
CHAT_FRAME_FADE_OUT_TIME = 2.0;
CHAT_FRAME_BUTTON_FRAME_MIN_ALPHA = 0.2;
CHAT_FRAME_TAB_SELECTED_MOUSEOVER_ALPHA = 1.0;
CHAT_FRAME_TAB_SELECTED_NOMOUSE_ALPHA = 0.4;
CHAT_FRAME_TAB_ALERTING_MOUSEOVER_ALPHA = 1.0;
CHAT_FRAME_TAB_ALERTING_NOMOUSE_ALPHA = 1.0;
CHAT_FRAME_TAB_NORMAL_MOUSEOVER_ALPHA = 0.6;
CHAT_FRAME_TAB_NORMAL_NOMOUSE_ALPHA = 0.2;
DEFAULT_CHATFRAME_ALPHA = 0.25;
DEFAULT_CHATFRAME_COLOR = {r = 0, g = 0, b = 0};
CHAT_FRAME_NORMAL_MIN_HEIGHT = 120;
CHAT_FRAME_BIGGER_MIN_HEIGHT = 147;
CHAT_FRAME_MIN_WIDTH = 296;
CURRENT_CHAT_FRAME_ID = nil;
CHAT_FRAME_TEXTURES = {
"Background",
"TopLeftTexture",
"BottomLeftTexture",
"TopRightTexture",
"BottomRightTexture",
"LeftTexture",
"RightTexture",
"BottomTexture",
"TopTexture",
--"ResizeButton",
"ButtonFrameBackground",
"ButtonFrameTopLeftTexture",
"ButtonFrameBottomLeftTexture",
"ButtonFrameTopRightTexture",
"ButtonFrameBottomRightTexture",
"ButtonFrameLeftTexture",
"ButtonFrameRightTexture",
"ButtonFrameBottomTexture",
"ButtonFrameTopTexture",
}
CHAT_FRAMES = {};
function FloatingChatFrame_OnLoad(self)
--IMPORTANT NOTE: This function isn't run by ChatFrame1.
tinsert(CHAT_FRAMES, self:GetName());
FCF_SetTabPosition(self, 0);
FloatingChatFrame_Update(self:GetID());
FCFTab_UpdateColors(_G[self:GetName().."Tab"], true);
self:SetClampRectInsets(-35, 35, 26, -50);
local chatTab = _G[self:GetName().."Tab"];
chatTab.mouseOverAlpha = CHAT_FRAME_TAB_SELECTED_MOUSEOVER_ALPHA;
chatTab.noMouseAlpha = CHAT_FRAME_TAB_SELECTED_NOMOUSE_ALPHA;
end
function FloatingChatFrame_OnEvent(self, event, ...)
if ( (event == "UPDATE_CHAT_WINDOWS") or (event == "UPDATE_FLOATING_CHAT_WINDOWS") ) then
FloatingChatFrame_Update(self:GetID(), 1);
self.isInitialized = 1;
elseif ( event == "UPDATE_CHAT_COLOR" ) then
local chatType, r, g, b = ...;
if ( self.isTemporary and self.chatType == chatType ) then
local tab = _G[self:GetName().."Tab"];
tab.selectedColorTable.r, tab.selectedColorTable.g, tab.selectedColorTable.b = r, g, b;
FCFTab_UpdateColors(tab, not self.isDocked or self == FCFDock_GetSelectedWindow(GENERAL_CHAT_DOCK));
end
end
end
function FloatingChatFrame_OnMouseScroll(self, delta)
if ( delta > 0 ) then
self:ScrollUp();
else
self:ScrollDown();
end
end
function FCF_GetChatWindowInfo(id)
if ( id > NUM_CHAT_WINDOWS ) then
local frame = _G["ChatFrame"..id];
local tab = _G["ChatFrame"..id.."Tab"];
local background = _G["ChatFrame"..id.."Background"];
if ( frame and tab and background ) then
local r, g, b, a = background:GetVertexColor();
return tab:GetText(), select(2, frame:GetFont()), r, g, b, a, frame:IsShown(), frame.isLocked, frame.isDocked, frame.isUninteractable;
--This is a temporary chat window. Pass this to whatever handles those options.
end
else
return GetChatWindowInfo(id);
end
end
function FCF_CopyChatSettings(copyTo, copyFrom)
local name, fontSize, r, g, b, a, shown, locked, docked, uninteractable = FCF_GetChatWindowInfo(copyFrom:GetID());
FCF_SetWindowColor(copyTo, r, g, b, 1);
FCF_SetWindowAlpha(copyTo, a, 1);
--If we're copying to a docked window, we don't want to copy locked.
if ( not copyTo.isDocked ) then
FCF_SetLocked(copyTo, locked);
end
FCF_SetUninteractable(copyTo, uninteractable);
FCF_SetChatWindowFontSize(nil, copyTo, fontSize);
end
function FloatingChatFrame_Update(id, onUpdateEvent)
local chatFrame = _G["ChatFrame"..id];
local chatTab = _G["ChatFrame"..id.."Tab"];
local name, fontSize, r, g, b, a, shown, locked, docked, uninteractable = FCF_GetChatWindowInfo(id);
-- Set Tab Name
FCF_SetWindowName(chatFrame, name, 1)
if ( onUpdateEvent ) then
-- Set Frame Color and Alpha
FCF_SetWindowColor(chatFrame, r, g, b, 1);
FCF_SetWindowAlpha(chatFrame, a, 1);
FCF_SetLocked(chatFrame, locked);
FCF_SetUninteractable(chatFrame, uninteractable);
end
if ( shown ) then
if ( not chatFrame.minimized ) then
chatFrame:Show();
end
FCF_SetTabPosition(chatFrame, 0);
else
if ( not chatFrame.isDocked ) then
chatFrame:Hide();
chatTab:Hide();
end
end
if ( docked ) then
FCF_DockFrame(chatFrame, docked, (id == 1));
else
if ( shown ) then
FCF_UnDockFrame(chatFrame);
if ( not chatFrame.minimized ) then
chatTab:Show();
end
else
FCF_Close(chatFrame);
end
end
if ( not chatFrame.isTemporary and (chatFrame == DEFAULT_CHAT_FRAME or not chatFrame.isDocked)) then
FCF_RestorePositionAndDimensions(chatFrame);
end
FCF_UpdateButtonSide(chatFrame);
end
-- Channel Dropdown
function FCFOptionsDropDown_OnLoad(self)
CURRENT_CHAT_FRAME_ID = self:GetParent():GetID();
UIDropDownMenu_Initialize(self, FCFOptionsDropDown_Initialize, "MENU");
UIDropDownMenu_SetButtonWidth(self, 50);
UIDropDownMenu_SetWidth(self, 50);
end
function FCFOptionsDropDown_Initialize(dropDown)
-- Window preferences
local name, fontSize, r, g, b, a, shown = FCF_GetChatWindowInfo(FCF_GetCurrentChatFrameID());
local info;
local chatFrame = FCF_GetCurrentChatFrame();
local isTemporary = chatFrame and chatFrame.isTemporary;
-- If level 2
if ( UIDROPDOWNMENU_MENU_LEVEL == 2 ) then
-- If this is the font size menu then create dropdown
if ( UIDROPDOWNMENU_MENU_VALUE == FONT_SIZE ) then
-- Add the font heights from the font height table
local value;
for i=1, #CHAT_FONT_HEIGHTS do
value = CHAT_FONT_HEIGHTS[i];
info = UIDropDownMenu_CreateInfo();
info.text = format(FONT_SIZE_TEMPLATE, value);
info.value = value;
info.func = FCF_SetChatWindowFontSize;
local fontFile, fontHeight, fontFlags = FCF_GetCurrentChatFrame():GetFont();
if ( value == floor(fontHeight+0.5) ) then
info.checked = 1;
end
UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
end
return;
end
return;
end
-- Window options
info = UIDropDownMenu_CreateInfo();
if ( FCF_GetCurrentChatFrame(dropDown) and FCF_GetCurrentChatFrame(dropDown).isLocked ) then
info.text = UNLOCK_WINDOW;
else
info.text = LOCK_WINDOW;
end
info.func = FCF_ToggleLock;
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
--Add Uninteractable button
info = UIDropDownMenu_CreateInfo();
if ( FCF_GetCurrentChatFrame(dropDown) and FCF_GetCurrentChatFrame(dropDown).isUninteractable) then
info.text = MAKE_INTERACTABLE;
else
info.text = MAKE_UNINTERACTABLE;
end
info.func = FCF_ToggleUninteractable;
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
if ( not isTemporary ) then
-- Add name button
info = UIDropDownMenu_CreateInfo();
info.text = RENAME_CHAT_WINDOW;
info.func = FCF_RenameChatWindow_Popup;
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
end
if ( chatFrame == DEFAULT_CHAT_FRAME ) then
-- Create new chat window
info = UIDropDownMenu_CreateInfo();
info.text = NEW_CHAT_WINDOW;
info.func = FCF_NewChatWindow;
info.notCheckable = 1;
if (FCF_GetNumActiveChatFrames() == NUM_CHAT_WINDOWS ) then
info.disabled = 1;
end
UIDropDownMenu_AddButton(info);
-- Reset Chat windows to default
info = UIDropDownMenu_CreateInfo();
info.text = RESET_ALL_WINDOWS;
info.func = FCF_ResetAllWindows;
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
end
-- Close current chat window
if ( chatFrame and shown and (chatFrame ~= DEFAULT_CHAT_FRAME and not IsCombatLog(chatFrame)) ) then
if ( not chatFrame.isTemporary ) then
info = UIDropDownMenu_CreateInfo();
info.text = CLOSE_CHAT_WINDOW;
info.func = FCF_PopInWindow;
info.arg1 = FCF_GetCurrentChatFrame(dropDown);
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
elseif ( chatFrame.isTemporary and (chatFrame.chatType == "WHISPER" or chatFrame.chatType == "BN_WHISPER") ) then
info = UIDropDownMenu_CreateInfo();
info.text = CLOSE_CHAT_WHISPER_WINDOW;
info.func = FCF_PopInWindow;
info.arg1 = FCF_GetCurrentChatFrame(dropDown);
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
elseif ( chatFrame.isTemporary and (chatFrame.chatType == "BN_CONVERSATION" ) ) then
if ( GetCVar("conversationMode") == "popout" ) then
info = UIDropDownMenu_CreateInfo();
info.text = CLOSE_AND_LEAVE_CHAT_CONVERSATION_WINDOW;
info.func = FCF_LeaveConversation;
info.arg1 = FCF_GetCurrentChatFrame(dropDown);
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
else
info = UIDropDownMenu_CreateInfo();
info.text = CLOSE_CHAT_CONVERSATION_WINDOW;
info.func = FCF_PopInWindow;
info.arg1 = FCF_GetCurrentChatFrame(dropDown);
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
end
else
error(format("Unhandled temporary window type. chatType: %s, chatTarget %s", tostring(chatFrame.chatType), tostring(chatFrame.chatTarget)));
end
end
-- Display header
info = UIDropDownMenu_CreateInfo();
info.text = DISPLAY;
info.notClickable = 1;
info.isTitle = 1;
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
-- Font size
info = UIDropDownMenu_CreateInfo();
info.text = FONT_SIZE;
--info.notClickable = 1;
info.hasArrow = 1;
info.func = nil;
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
-- Set Background color
info = UIDropDownMenu_CreateInfo();
info.text = BACKGROUND;
info.hasColorSwatch = 1;
info.r = r;
info.g = g;
info.b = b;
-- Done because the slider is reversed
if ( a ) then
a = 1- a;
end
info.opacity = a;
info.swatchFunc = FCF_SetChatWindowBackGroundColor;
info.func = UIDropDownMenuButton_OpenColorPicker;
--info.notCheckable = 1;
info.hasOpacity = 1;
info.opacityFunc = FCF_SetChatWindowOpacity;
info.cancelFunc = FCF_CancelWindowColorSettings;
UIDropDownMenu_AddButton(info);
if ( not isTemporary ) then
-- Filter header
info = UIDropDownMenu_CreateInfo();
info.text = FILTERS;
--info.notClickable = 1;
info.isTitle = 1;
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
-- Configure settings
info = UIDropDownMenu_CreateInfo();
info.text = CHAT_CONFIGURATION;
info.func = function() ShowUIPanel(ChatConfigFrame); end;
info.notCheckable = 1;
UIDropDownMenu_AddButton(info);
end
end
--[[
function FCFDropDown_LoadServerChannels(...)
local checked;
local channelList = FCF_GetCurrentChatFrame().channelList;
local zoneChannelList = FCF_GetCurrentChatFrame().zoneChannelList;
local info, channel;
-- Server Channels header
info = UIDropDownMenu_CreateInfo();
info.text = SERVER_CHANNELS;
info.notClickable = 1;
info.isTitle = 1;
UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
info = UIDropDownMenu_CreateInfo();
for i=1, select("#", ...) do
checked = nil;
channel = select(i, ...);
if ( channelList ) then
for index, value in pairs(channelList) do
if ( value == channel ) then
checked = 1;
end
end
end
if ( zoneChannelList ) then
for index, value in pairs(zoneChannelList) do
if ( value == channel ) then
checked = 1;
end
end
end
info.text = channel;
info.value = channel;
info.func = FCFServerChannelsDropDown_OnClick;
info.checked = checked;
info.keepShownOnClick = 1;
UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
end
end
function FCFServerChannelsDropDown_OnClick()
if ( UIDropDownMenuButton_GetChecked() ) then
ChatFrame_RemoveChannel(FCF_GetCurrentChatFrame(), UIDropDownMenuButton_GetName());
else
JoinPermanentChannel(UIDropDownMenuButton_GetName(), nil, FCF_GetCurrentChatFrameID(), 1);
ChatFrame_AddChannel(FCF_GetCurrentChatFrame(), UIDropDownMenuButton_GetName());
end
end
]]
function FCFDropDown_LoadChannels(...)
local checked;
local channelList = FCF_GetCurrentChatFrame().channelList;
local zoneChannelList = FCF_GetCurrentChatFrame().zoneChannelList;
local info = UIDropDownMenu_CreateInfo();
local channel, tag;
for i=1, select("#", ...), 2 do
checked = nil;
tag = "CHANNEL"..select(i, ...);
channel = select(i+1, ...);
if ( channelList ) then
for index, value in pairs(channelList) do
if ( value == channel ) then
checked = 1;
end
end
end
if ( zoneChannelList ) then
for index, value in pairs(zoneChannelList) do
if ( value == channel ) then
checked = 1;
end
end
end
info.text = channel;
info.value = tag;
info.func = FCFChannelDropDown_OnClick;
info.checked = checked;
info.keepShownOnClick = 1;
-- Color the chat channel
local color = ChatTypeInfo[tag];
info.hasColorSwatch = 1;
info.r = color.r;
info.g = color.g;
info.b = color.b;
-- Set the function the color picker calls
info.swatchFunc = FCF_SetChatTypeColor;
info.cancelFunc = FCF_CancelFontColorSettings;
UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
end
end
function FCFChannelDropDown_OnClick()
if ( UIDropDownMenuButton_GetChecked() ) then
ChatFrame_RemoveChannel(FCF_GetCurrentChatFrame(), UIDropDownMenuButton_GetName());
else
ChatFrame_AddChannel(FCF_GetCurrentChatFrame(), UIDropDownMenuButton_GetName());
end
end
-- Used to display chattypegroups
function FCFDropDown_LoadChatTypes(menuChatTypeGroups)
local checked, chatTypeInfo;
local messageTypeList = FCF_GetCurrentChatFrame().messageTypeList;
local info, group;
for index, value in pairs(menuChatTypeGroups) do
checked = nil;
if ( messageTypeList ) then
for joinedIndex, joinedValue in pairs(messageTypeList) do
if ( value == joinedValue ) then
checked = 1;
end
end
end
info = UIDropDownMenu_CreateInfo();
info.value = value;
info.func = FCFMessageTypeDropDown_OnClick;
info.checked = checked;
-- Set to keep shown on button click
info.keepShownOnClick = 1;
-- If more than one message type in a Chat Type Group need to show an expand arrow
group = ChatTypeGroup[value];
if ( getn(group) > 1 ) then
info.text = _G[value];
info.hasArrow = 1;
UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
else
info.text = _G[group[1]];
chatTypeInfo = ChatTypeInfo[FCF_StripChatMsg(group[1])];
-- If no chatTypeInfo then don't display
if ( chatTypeInfo ) then
-- Set the function to be called when a color is set
info.swatchFunc = FCF_SetChatTypeColor;
-- Set the swatch color info
info.hasColorSwatch = 1;
info.r = chatTypeInfo.r;
info.g = chatTypeInfo.g;
info.b = chatTypeInfo.b;
info.cancelFunc = FCF_CancelFontColorSettings;
UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
end
end
end
end
-- Used to display chatsubtypes
function FCF_LoadChatSubTypes(chatGroup)
if ( chatGroup ) then
chatGroup = ChatTypeGroup[chatGroup];
else
chatGroup = ChatTypeGroup[UIDROPDOWNMENU_MENU_VALUE];
end
if ( chatGroup ) then
local info = UIDropDownMenu_CreateInfo();
local chatTypeInfo
for index, value in pairs(chatGroup) do
chatTypeInfo = ChatTypeInfo[FCF_StripChatMsg(value)];
if ( chatTypeInfo ) then
info.text = _G[value];
info.value = FCF_StripChatMsg(value);
-- Disable the button and color the text white
info.notClickable = 1;
-- Set to be notcheckable
info.notCheckable = 1;
-- Set the function to be called when a color is set
info.swatchFunc = FCF_SetChatTypeColor;
-- Set the swatch color info
info.hasColorSwatch = 1;
info.r = chatTypeInfo.r;
info.g = chatTypeInfo.g;
info.b = chatTypeInfo.b;
-- Set function called when cancel is clicked in the colorpicker
info.cancelFunc = FCF_CancelFontColorSettings;
UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
end
end
end
end
function FCFMessageTypeDropDown_OnClick(self)
if ( UIDropDownMenuButton_GetChecked() ) then
ChatFrame_RemoveMessageGroup(FCF_GetCurrentChatFrame(), self.value);
else
ChatFrame_AddMessageGroup(FCF_GetCurrentChatFrame(), self.value);
end
end
function FCF_OpenNewWindow(name)
local count = 1;
local chatFrame, chatTab;
for i=1, NUM_CHAT_WINDOWS do
local _, _, _, _, _, _, shown = FCF_GetChatWindowInfo(i);
chatFrame = _G["ChatFrame"..i];
chatTab = _G["ChatFrame"..i.."Tab"];
if ( (not shown and not chatFrame.isDocked) or (count == NUM_CHAT_WINDOWS) ) then
if ( not name or name == "" ) then
name = format(CHAT_NAME_TEMPLATE, i);
end
-- initialize the frame
FCF_SetWindowName(chatFrame, name);
FCF_SetWindowColor(chatFrame, DEFAULT_CHATFRAME_COLOR.r, DEFAULT_CHATFRAME_COLOR.g, DEFAULT_CHATFRAME_COLOR.b);
FCF_SetWindowAlpha(chatFrame, DEFAULT_CHATFRAME_ALPHA);
SetChatWindowLocked(i, nil);
-- clear stale messages
chatFrame:Clear();
-- Listen to the standard messages
ChatFrame_RemoveAllMessageGroups(chatFrame);
ChatFrame_RemoveAllChannels(chatFrame);
ChatFrame_ReceiveAllPrivateMessages(chatFrame);
ChatFrame_ReceiveAllBNConversations(chatFrame);
ChatFrame_AddMessageGroup(chatFrame, "SAY");
ChatFrame_AddMessageGroup(chatFrame, "YELL");
ChatFrame_AddMessageGroup(chatFrame, "GUILD");
ChatFrame_AddMessageGroup(chatFrame, "WHISPER");
ChatFrame_AddMessageGroup(chatFrame, "BN_WHISPER");
ChatFrame_AddMessageGroup(chatFrame, "PARTY");
ChatFrame_AddMessageGroup(chatFrame, "PARTY_LEADER");
ChatFrame_AddMessageGroup(chatFrame, "CHANNEL");
--Clear the edit box history.
chatFrame.editBox:ClearHistory();
-- Show the frame and tab
chatFrame:Show();
chatTab:Show();
SetChatWindowShown(i, 1);
-- Dock the frame by default
FCF_DockFrame(chatFrame, (#FCFDock_GetChatFrames(GENERAL_CHAT_DOCK)+1), true);
FCF_FadeInChatFrame(FCFDock_GetSelectedWindow(GENERAL_CHAT_DOCK));
return chatFrame;
end
count = count + 1;
end
end
function FCF_SetTemporaryWindowType(chatFrame, chatType, chatTarget)
local chatTab = _G[chatFrame:GetName().."Tab"];
--If the frame was already registered, unregister it.
if ( chatFrame.isRegistered ) then
FCFManager_UnregisterDedicatedFrame(chatFrame, chatFrame.chatType, chatFrame.chatTarget);
chatFrame.isRegistered = false;
end
--Set the title text
local name;
if ( chatType == "WHISPER" or chatType == "BN_WHISPER" ) then
name = chatTarget;
elseif ( chatType == "BN_CONVERSATION" ) then
name = format(CONVERSATION_NAME, tonumber(chatTarget) + MAX_WOW_CHAT_CHANNELS);
end
FCF_SetWindowName(chatFrame, name);
--Set up the window to receive the message types we want.
chatFrame.chatType = chatType;
chatFrame.chatTarget = chatTarget;
ChatFrame_RemoveAllMessageGroups(chatFrame);
ChatFrame_RemoveAllChannels(chatFrame);
ChatFrame_ReceiveAllPrivateMessages(chatFrame);
ChatFrame_ReceiveAllBNConversations(chatFrame);
ChatFrame_AddMessageGroup(chatFrame, chatType);
chatFrame.editBox:SetAttribute("chatType", chatType);
chatFrame.editBox:SetAttribute("stickyType", chatType);
if ( chatType == "WHISPER" or chatType == "BN_WHISPER" ) then
chatFrame.editBox:SetAttribute("tellTarget", chatTarget);
ChatFrame_AddPrivateMessageTarget(chatFrame, chatTarget);
elseif ( chatType == "BN_CONVERSATION" ) then
chatFrame.editBox:SetAttribute("channelTarget", chatTarget);
ChatFrame_AddBNConversationTarget(chatFrame, chatTarget);
end
-- Set up the colors
local info = ChatTypeInfo[chatType];
chatTab.selectedColorTable = { r = info.r, g = info.g, b = info.b };
FCFTab_UpdateColors(chatTab, not chatFrame.isDocked or chatFrame == FCFDock_GetSelectedWindow(GENERAL_CHAT_DOCK));
--If it's a conversation, create the conversation button
if ( chatType == "BN_CONVERSATION" or chatType == "BN_WHISPER" ) then
if ( chatFrame.conversationButton ) then
BNConversationButton_UpdateTarget(chatFrame.conversationButton);
chatFrame.conversationButton:Show();
else
CreateFrame("Button", chatFrame:GetName().."ConversationButton", chatFrame.buttonFrame, "BNConversationRosterButtonTemplate", chatFrame:GetID());
end
if ( chatFrame:GetHeight() < CHAT_FRAME_BIGGER_MIN_HEIGHT ) then
chatFrame:SetHeight(CHAT_FRAME_BIGGER_MIN_HEIGHT);
end
chatFrame:SetMinResize(CHAT_FRAME_MIN_WIDTH, CHAT_FRAME_BIGGER_MIN_HEIGHT);
else
if ( chatFrame.conversationButton ) then
chatFrame.conversationButton:Hide();
end
chatFrame:SetMinResize(CHAT_FRAME_MIN_WIDTH, CHAT_FRAME_NORMAL_MIN_HEIGHT);
end
--If it's a conversation, get it ready to convert to a whisper if needed.
if ( chatType == "BN_CONVERSATION" ) then
chatFrame:RegisterEvent("BN_CHAT_CHANNEL_CLOSED");
else
chatFrame:UnregisterEvent("BN_CHAT_CHANNEL_CLOSED");
end
--Set the icon
local conversationIcon;
if ( chatType == "WHISPER" or chatType == "BN_WHISPER" ) then
conversationIcon = "Interface\\ChatFrame\\UI-ChatWhisperIcon";
else
conversationIcon = "Interface\\ChatFrame\\UI-ChatConversationIcon";
end
chatTab.conversationIcon:SetTexture(conversationIcon);
if ( chatFrame.minFrame ) then
chatFrame.minFrame.conversationIcon:SetTexture(conversationIcon);
end
--Register this frame
FCFManager_RegisterDedicatedFrame(chatFrame, chatType, chatTarget);
chatFrame.isRegistered = true;
--The window name may have been updated, so update the dock and tabs.
FCF_DockUpdate();
end
local maxTempIndex = NUM_CHAT_WINDOWS + 1;
function FCF_OpenTemporaryWindow(chatType, chatTarget, sourceChatFrame, selectWindow)
local chatFrame, chatTab, conversationIcon;
for _, chatFrameName in pairs(CHAT_FRAMES) do
local frame = _G[chatFrameName];
if ( frame.isTemporary ) then
if ( not frame.inUse and not frame.isDocked ) then
chatFrame = frame;
chatTab = _G[chatFrame:GetName().."Tab"];
break;
end
end
end
if ( not chatFrame ) then
chatTab = CreateFrame("Button", "ChatFrame"..maxTempIndex.."Tab", UIParent, "ChatTabTemplate", maxTempIndex);
conversationIcon = chatTab:CreateTexture(chatTab:GetName().."ConversationIcon", "ARTWORK", "ChatTabConversationIconTemplate");
conversationIcon:ClearAllPoints();
conversationIcon:SetPoint("RIGHT", chatTab:GetFontString(), "LEFT", 0, -2);
chatTab.conversationIcon = conversationIcon;
local tabText = _G[chatTab:GetName().."Text"];
tabText:SetPoint("LEFT", chatTab.leftTexture, "RIGHT", 10, -6);
tabText:SetJustifyH("LEFT");
chatTab.sizePadding = 10;
chatFrame = CreateFrame("ScrollingMessageFrame", "ChatFrame"..maxTempIndex, UIParent, "FloatingChatFrameTemplate", maxTempIndex);
if ( GetCVarBool("chatMouseScroll") ) then
chatFrame:SetScript("OnMouseWheel", FloatingChatFrame_OnMouseScroll);
chatFrame:EnableMouseWheel(true);
end
maxTempIndex = maxTempIndex + 1;
end
--Copy chat settings from the source frame.
FCF_CopyChatSettings(chatFrame, sourceChatFrame or DEFAULT_CHAT_FRAME);
-- clear stale messages
chatFrame:Clear();
chatFrame.inUse = true;
chatFrame.isTemporary = true;
FCF_SetTemporaryWindowType(chatFrame, chatType, chatTarget);
--Clear the edit box history.
chatFrame.editBox:ClearHistory();
if ( sourceChatFrame ) then
--Stop displaying this type of chat in the old chat frame.
if ( chatType == "WHISPER" or chatType == "BN_WHISPER" ) then
ChatFrame_ExcludePrivateMessageTarget(sourceChatFrame, chatTarget);
elseif ( chatType == "BN_CONVERSATION" ) then
ChatFrame_ExcludeBNConversationTarget(sourceChatFrame, chatTarget);
end
--Copy over messages
local accessID = ChatHistory_GetAccessID(chatType, chatTarget);
for i = 1, sourceChatFrame:GetNumMessages(accessID) do
local text, accessID, lineID, extraData = sourceChatFrame:GetMessageInfo(i, accessID);
local cType, cTarget = ChatHistory_GetChatType(extraData);
local info = ChatTypeInfo[cType];
chatFrame:AddMessage(text, info.r, info.g, info.b, lineID, false, accessID, extraData);
end
--Remove the messages from the old frame.
sourceChatFrame:RemoveMessagesByAccessID(accessID);
end
--Close the Editbox
ChatEdit_DeactivateChat(chatFrame.editBox);
-- Show the frame and tab
chatFrame:Show();
chatTab:Show();
-- Dock the frame by default
FCF_DockFrame(chatFrame, (#FCFDock_GetChatFrames(GENERAL_CHAT_DOCK)+1), selectWindow);
return chatFrame;
end
function FCF_GetNumActiveChatFrames()
local count = 0;
local chatFrame;
for i=1, NUM_CHAT_WINDOWS do
local _, _, _, _, _, _, shown = FCF_GetChatWindowInfo(i);
chatFrame = _G["ChatFrame"..i];
if ( chatFrame ) then
if ( shown or chatFrame.isDocked ) then
count = count + 1;
end
end
end
return count;
end
function FCF_RenameChatWindow_Popup()
local dialog = StaticPopup_Show("NAME_CHAT");
dialog.data = FCF_GetCurrentChatFrameID();
end
function FCF_NewChatWindow()
StaticPopup_Show("NAME_CHAT");
end
function FCF_ResetAllWindows()
StaticPopup_Show("RESET_CHAT");
end
--[[function FCF_ChatChannels()
ToggleFriendsFrame(4);
end]]--
function FCF_SetWindowName(frame, name, doNotSave)
if ( not name or name == "") then
-- Hack to initialize the chat window names, since globalstrings are not available on init
if ( frame:GetID() == 1 ) then
name = GENERAL;
doNotSave = nil;
elseif ( frame:GetID() == 2 ) then
name = COMBAT_LOG;
doNotSave = nil;
else
name = format(CHAT_NAME_TEMPLATE, frame:GetID());
end
else
FCFDock_SetDirty(GENERAL_CHAT_DOCK);
end
frame.name = name;
local tab = _G[frame:GetName().."Tab"];
tab:SetText(name);
PanelTemplates_TabResize(tab, tab.sizePadding or 0);
-- Save this off so we know how big the tab should always be, even if it gets shrunken on the dock.
tab.textWidth = _G[tab:GetName().."Text"]:GetWidth();
if ( not doNotSave ) then
SetChatWindowName(frame:GetID(), name);
end
if ( frame.minFrame ) then
frame.minFrame:SetText(name);
end
end
function FCF_SetWindowColor(frame, r, g, b, doNotSave)
local name = frame:GetName();
for index, value in pairs(CHAT_FRAME_TEXTURES) do
--NOTE - If this is changed, please change the equivalent code in GMChatFrame_OnLoad.
local object = _G[name..value];
local objectType = object:GetObjectType();
if ( objectType == "Button" ) then
object:GetNormalTexture():SetVertexColor(r, g, b);
object:GetHighlightTexture():SetVertexColor(r, g, b);
object:GetPushedTexture():SetVertexColor(r, g, b);
elseif ( objectType == "Texture" ) then
_G[name..value]:SetVertexColor(r,g,b);
else
--error("Unhandled frame type...");
end
end
if ( not doNotSave ) then
SetChatWindowColor(frame:GetID(), r, g, b);
end
end
function FCF_SetWindowAlpha(frame, alpha, doNotSave)
local name = frame:GetName();
for index, value in pairs(CHAT_FRAME_TEXTURES) do
_G[name..value]:SetAlpha(alpha);
end
if ( not doNotSave ) then
SetChatWindowAlpha(frame:GetID(), alpha);
end
-- Remember the alpha
frame.oldAlpha = alpha;
end
function FCF_GetCurrentChatFrameID()
return CURRENT_CHAT_FRAME_ID;
end
function FCF_GetCurrentChatFrame(child)
local currentChatFrame = nil;
if ( CURRENT_CHAT_FRAME_ID ) then
currentChatFrame = _G["ChatFrame"..CURRENT_CHAT_FRAME_ID];
end
if ( not currentChatFrame and child ) then
currentChatFrame = _G["ChatFrame"..child:GetParent():GetID()];
end
return currentChatFrame;
end
function FCF_SetChatTypeColor()
local r,g,b = ColorPickerFrame:GetColorRGB();
ChangeChatColor(UIDROPDOWNMENU_MENU_VALUE, r, g, b);
end
function FCF_SetChatWindowBackGroundColor()
local r,g,b = ColorPickerFrame:GetColorRGB();
FCF_SetWindowColor(FCF_GetCurrentChatFrame(), r, g, b)
SetChatWindowColor(FCF_GetCurrentChatFrameID(), r, g, b);
end
function FCF_SetChatWindowOpacity()
local alpha = 1.0 - OpacitySliderFrame:GetValue();
FCF_SetWindowAlpha(FCF_GetCurrentChatFrame(), alpha);
end
function FCF_SetChatWindowFontSize(self, chatFrame, fontSize)
if ( not chatFrame ) then
chatFrame = FCF_GetCurrentChatFrame();
end
if ( not fontSize ) then
fontSize = self.value;
end
local fontFile, unused, fontFlags = chatFrame:GetFont();
chatFrame:SetFont(fontFile, fontSize, fontFlags);
if ( GMChatFrame and chatFrame == DEFAULT_CHAT_FRAME ) then
GMChatFrame:SetFont(fontFile, fontSize, fontFlags);
end
SetChatWindowSize(chatFrame:GetID(), fontSize);
end
function FCF_CancelFontColorSettings(previousValues)
if ( previousValues.r ) then
ChangeChatColor(UIDROPDOWNMENU_MENU_VALUE, previousValues.r, previousValues.g, previousValues.b);
end
end
function FCF_CancelWindowColorSettings(previousValues)
if ( previousValues.r ) then
FCF_SetWindowColor(FCF_GetCurrentChatFrame(), previousValues.r, previousValues.g, previousValues.b)
SetChatWindowColor(FCF_GetCurrentChatFrameID(), previousValues.r, previousValues.g, previousValues.b);
end
if ( previousValues.opacity ) then
FCF_SetWindowAlpha(FCF_GetCurrentChatFrame(), 1 - previousValues.opacity);
end
end
function FCF_StripChatMsg(string)
if ( strsub(string,1,8) == "CHAT_MSG" ) then
return strsub(string,10);
else
return string;
end
end
function FCF_ToggleLock()
local chatFrame = FCF_GetCurrentChatFrame();
if ( chatFrame.isLocked ) then
-- If unlocking a docked frame then undock it and center it on the screen
if ( chatFrame.isDocked and chatFrame ~= DEFAULT_CHAT_FRAME ) then
FCF_UnDockFrame(chatFrame);
chatFrame:ClearAllPoints();
chatFrame:SetPoint("CENTER", "UIParent", "CENTER", 0, 0);
FCF_SetTabPosition(chatFrame, 0);
chatFrame:Show();
end
FCF_SetLocked(chatFrame, nil);
else
FCF_SetLocked(chatFrame, 1);
end
end
function FCF_SetLocked(chatFrame, isLocked)
chatFrame.isLocked = isLocked;
if ( chatFrame.isUninteractable or isLocked ) then
chatFrame.resizeButton:Hide();
else
chatFrame.resizeButton:Show();
--chatFrame.resizeButton:SetAlpha(_G[chatFrame:GetName().."Background"]:GetAlpha());
end
SetChatWindowLocked(chatFrame:GetID(), isLocked);
end
function FCF_ToggleUninteractable()
local chatFrame = FCF_GetCurrentChatFrame();
if ( chatFrame.isUninteractable ) then
FCF_SetExpandedUninteractable(chatFrame, false)
else
FCF_SetExpandedUninteractable(chatFrame, true)
end
end
function FCF_SetExpandedUninteractable(chatFrame, isUninteractable)
if ( chatFrame.isDocked ) then
for _, frame in pairs(GENERAL_CHAT_DOCK.DOCKED_CHAT_FRAMES) do
FCF_SetUninteractable(frame, isUninteractable);
end
else
FCF_SetUninteractable(chatFrame, isUninteractable);
end
end
function FCF_SetUninteractable(chatFrame, isUninteractable) --No, uninteractable is not really a word.
chatFrame.isUninteractable = isUninteractable;
SetChatWindowUninteractable(chatFrame:GetID(), isUninteractable);
if ( not chatFrame.overrideHyperlinksEnabled ) then
chatFrame:SetHyperlinksEnabled(not isUninteractable);
end
local chatFrameName = chatFrame:GetName();
if ( isUninteractable or chatFrame.isLocked ) then
_G[chatFrameName.."ResizeButton"]:Hide();
else
_G[chatFrameName.."ResizeButton"]:Show();
end
end
function FCF_FadeInChatFrame(chatFrame)
local frameName = chatFrame:GetName();
chatFrame.hasBeenFaded = true;
for index, value in pairs(CHAT_FRAME_TEXTURES) do
local object = _G[frameName..value];
if ( object:IsShown() ) then
UIFrameFadeIn(object, CHAT_FRAME_FADE_TIME, object:GetAlpha(), max(chatFrame.oldAlpha, DEFAULT_CHATFRAME_ALPHA));