-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.lua
More file actions
executable file
·1610 lines (1418 loc) · 58.4 KB
/
ui.lua
File metadata and controls
executable file
·1610 lines (1418 loc) · 58.4 KB
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
local _, ns = ...
---------------------------------------------------------------------------
-- UIFrameFade compat — Blizzard removed these in recent Retail builds.
-- Provide lightweight polyfills so fade code works on all clients.
---------------------------------------------------------------------------
if not UIFrameFadeIn then
function UIFrameFadeIn(frame, timeToFade, startAlpha, endAlpha)
frame:SetAlpha(endAlpha or 1.0)
end
end
if not UIFrameFadeOut then
function UIFrameFadeOut(frame, timeToFade, startAlpha, endAlpha)
frame:SetAlpha(endAlpha or 0)
end
end
if not UIFrameFadeRemoveFrame then
function UIFrameFadeRemoveFrame(frame) end
end
---------------------------------------------------------------------------
-- UI — Main window, panels, conversation list, compose, context menus,
-- keyboard shortcuts, auto-fade, and copy/note editor popups
--
-- Builds the entire iChat interface:
-- - Title bar with compose, settings, minimize, close buttons
-- - Left panel: searchable, scrollable conversation list with badges
-- - Right panel: chat area (bubbles rendered by bubbles.lua), input bar,
-- emoji button, send button, quick reply bar
-- - Auto-fade system: window fades to 25% opacity when idle
-- - Context menus: pin, mute, note, copy, delete (Retail MenuUtil or
-- Classic EasyMenu depending on client version)
---------------------------------------------------------------------------
-- Color palette
local C = {
BLUE = { 0.00, 0.48, 1.00, 1.0 },
BNET_BLUE = { 0.00, 0.72, 1.00, 1.0 }, -- Blizzard's BNet cyan-blue (matches friends list)
GREEN = { 0.20, 0.78, 0.35, 1.0 },
BG_DARK = { 0.05, 0.05, 0.05, 0.95 },
BG_PANEL = { 0.06, 0.06, 0.06, 1.0 },
BG_INPUT = { 0.12, 0.12, 0.12, 1.0 },
TEXT_WHITE = { 1.0, 1.0, 1.0, 1.0 },
TEXT_GRAY = { 0.5, 0.5, 0.5, 1.0 },
TEXT_TIME = { 0.4, 0.4, 0.4, 1.0 },
DIVIDER = { 0.15, 0.15, 0.15, 1.0 },
HOVER = { 0.14, 0.14, 0.14, 1.0 },
ACTIVE = { 0.00, 0.48, 1.00, 0.15 },
BADGE = { 1.0, 0.22, 0.17, 1.0 },
}
ns.C = C
local LEFT_WIDTH = 140
local ENTRY_HEIGHT = 52
local PILL_TEXTURE = "Interface\\AddOns\\iChat\\media\\textures\\pill"
-- Portrait logic lives in portraits.lua (ns.CreatePortraitFrame / ns.UpdatePortrait)
---------------------------------------------------------------------------
-- Main Window
---------------------------------------------------------------------------
function ns.CreateMainWindow()
local win = CreateFrame("Frame", "iChatMainWindow", UIParent, "BackdropTemplate")
win:SetSize(450, 550)
win:SetPoint("CENTER")
win:SetFrameStrata("DIALOG")
win:SetMovable(true)
win:SetResizable(true)
if win.SetResizeBounds then
win:SetResizeBounds(350, 400, 700, 800)
else
win:SetMinResize(350, 400)
win:SetMaxResize(700, 800)
end
win:SetClampedToScreen(true)
win:EnableMouse(true)
win:Hide()
win:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
win:SetBackdropColor(0.05, 0.05, 0.05, 0.95)
win:SetBackdropBorderColor(0.2, 0.2, 0.2, 1)
win:SetScale(ns.db.settings.scale)
-- Drag to move (combat guard)
win:RegisterForDrag("LeftButton")
win:SetScript("OnDragStart", function(self)
if not InCombatLockdown() then self:StartMoving() end
end)
win:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
end)
-- Resize handle
local resizer = CreateFrame("Button", nil, win)
resizer:SetSize(16, 16)
resizer:SetPoint("BOTTOMRIGHT")
resizer:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
resizer:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
resizer:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
resizer:SetScript("OnMouseDown", function()
if not InCombatLockdown() and win:IsResizable() then win:StartSizing("BOTTOMRIGHT") end
end)
resizer:SetScript("OnMouseUp", function()
win:StopMovingOrSizing()
end)
-- ESC to close
tinsert(UISpecialFrames, "iChatMainWindow")
ns.mainWindow = win
ns.CreateTitleBar(win)
ns.CreateLeftPanel(win)
ns.CreateDivider(win)
ns.CreateRightPanel(win)
-- Apply saved transparency
ns.ApplyTransparency()
-- Set up always-on fade behavior
ns.SetupFadeHooks()
-- Set up keyboard shortcuts
ns.SetupKeyboardShortcuts()
end
---------------------------------------------------------------------------
-- Title Bar
---------------------------------------------------------------------------
function ns.CreateTitleBar(parent)
local bar = CreateFrame("Frame", nil, parent)
bar:SetHeight(30)
bar:SetPoint("TOPLEFT")
bar:SetPoint("TOPRIGHT")
-- Bottom border
local border = bar:CreateTexture(nil, "OVERLAY")
border:SetHeight(1)
border:SetPoint("BOTTOMLEFT")
border:SetPoint("BOTTOMRIGHT")
border:SetColorTexture(unpack(C.DIVIDER))
-- Title text
local title = bar:CreateFontString(nil, "OVERLAY")
title:SetFont("Fonts\\FRIZQT__.TTF", 13, "")
title:SetTextColor(unpack(C.BLUE))
title:SetPoint("CENTER")
title:SetText("iChat v" .. (ns.version or "?"))
-- Close button
local closeBtn = CreateFrame("Button", nil, bar)
closeBtn:SetSize(20, 20)
closeBtn:SetPoint("RIGHT", -6, 0)
local closeTex = closeBtn:CreateFontString(nil, "OVERLAY")
closeTex:SetFont("Fonts\\FRIZQT__.TTF", 16, "")
closeTex:SetPoint("CENTER")
closeTex:SetText("x")
closeTex:SetTextColor(0.6, 0.6, 0.6)
closeBtn:SetScript("OnClick", function() parent:Hide() end)
closeBtn:SetScript("OnEnter", function() closeTex:SetTextColor(1, 0.3, 0.3) end)
closeBtn:SetScript("OnLeave", function() closeTex:SetTextColor(0.6, 0.6, 0.6) end)
-- Minimize button
local minBtn = CreateFrame("Button", nil, bar)
minBtn:SetSize(20, 20)
minBtn:SetPoint("RIGHT", closeBtn, "LEFT", -4, 0)
local minTex = minBtn:CreateFontString(nil, "OVERLAY")
minTex:SetFont("Fonts\\FRIZQT__.TTF", 16, "")
minTex:SetPoint("CENTER", 0, -1)
minTex:SetText("-")
minTex:SetTextColor(0.6, 0.6, 0.6)
minBtn:SetScript("OnClick", function() ns.ToggleMinimize() end)
minBtn:SetScript("OnEnter", function() minTex:SetTextColor(1, 1, 1) end)
minBtn:SetScript("OnLeave", function() minTex:SetTextColor(0.6, 0.6, 0.6) end)
ns.minBtn = minBtn
ns.minTex = minTex
-- Settings (gear) button
local gearBtn = CreateFrame("Button", nil, bar)
gearBtn:SetSize(20, 20)
gearBtn:SetPoint("RIGHT", minBtn, "LEFT", -4, 0)
local gearIcon = gearBtn:CreateTexture(nil, "ARTWORK")
gearIcon:SetSize(16, 16)
gearIcon:SetPoint("CENTER")
gearIcon:SetTexture("Interface\\Buttons\\UI-OptionsButton")
gearIcon:SetVertexColor(0.6, 0.6, 0.6)
gearBtn:SetScript("OnClick", function() ns.ToggleSettings() end)
gearBtn:SetScript("OnEnter", function() gearIcon:SetVertexColor(1, 1, 1) end)
gearBtn:SetScript("OnLeave", function() gearIcon:SetVertexColor(0.6, 0.6, 0.6) end)
-- Compose (new chat) button — chat bubble icon
local composeBtn = CreateFrame("Button", nil, bar)
composeBtn:SetSize(40, 40)
composeBtn:SetPoint("LEFT", 4, 0)
local composeIcon = composeBtn:CreateTexture(nil, "ARTWORK")
composeIcon:SetSize(36, 36)
composeIcon:SetPoint("CENTER")
composeIcon:SetTexture("Interface\\CHATFRAME\\UI-ChatIcon-Chat-Up")
composeIcon:SetVertexColor(0.2, 0.8, 1.0) -- Bright cyan
composeBtn:SetScript("OnClick", function() ns.ToggleCompose() end)
composeBtn:SetScript("OnEnter", function() composeIcon:SetVertexColor(0.4, 0.9, 1.0) end)
composeBtn:SetScript("OnLeave", function() composeIcon:SetVertexColor(0.2, 0.8, 1.0) end)
ns.titleBar = bar
end
---------------------------------------------------------------------------
-- Left Panel (Conversation List)
---------------------------------------------------------------------------
function ns.CreateLeftPanel(parent)
local panel = CreateFrame("Frame", nil, parent)
panel:SetWidth(LEFT_WIDTH)
panel:SetPoint("TOPLEFT", ns.titleBar, "BOTTOMLEFT", 0, 0)
panel:SetPoint("BOTTOMLEFT", parent, "BOTTOMLEFT", 0, 0)
local bg = panel:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetColorTexture(unpack(C.BG_PANEL))
ns.leftPanelBg = bg
-- Search bar
local searchBar = CreateFrame("Frame", nil, panel)
searchBar:SetHeight(24)
searchBar:SetPoint("TOPLEFT", 4, -4)
searchBar:SetPoint("TOPRIGHT", -4, -4)
local searchBg = searchBar:CreateTexture(nil, "BACKGROUND")
searchBg:SetAllPoints()
searchBg:SetColorTexture(0.1, 0.1, 0.1, 1)
local searchBox = CreateFrame("EditBox", "iChatSearchBox", searchBar)
searchBox:SetPoint("LEFT", 6, 0)
searchBox:SetPoint("RIGHT", -20, 0)
searchBox:SetHeight(20)
searchBox:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
searchBox:SetTextColor(0.8, 0.8, 0.8)
searchBox:SetAutoFocus(false)
searchBox:SetMaxLetters(50)
-- Placeholder text
local placeholder = searchBox:CreateFontString(nil, "OVERLAY")
placeholder:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
placeholder:SetTextColor(0.35, 0.35, 0.35)
placeholder:SetPoint("LEFT", 0, 0)
placeholder:SetText("Search...")
searchBox:SetScript("OnTextChanged", function(self)
local text = self:GetText()
if text and text ~= "" then
placeholder:Hide()
else
placeholder:Show()
end
ns.searchFilter = (text and text ~= "") and text:lower() or nil
ns.RefreshConversationList()
end)
searchBox:SetScript("OnEscapePressed", function(self)
self:SetText("")
self:ClearFocus()
end)
-- Clear button
local clearBtn = CreateFrame("Button", nil, searchBar)
clearBtn:SetSize(16, 16)
clearBtn:SetPoint("RIGHT", -2, 0)
local clearText = clearBtn:CreateFontString(nil, "OVERLAY")
clearText:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
clearText:SetPoint("CENTER")
clearText:SetText("x")
clearText:SetTextColor(0.4, 0.4, 0.4)
clearBtn:SetScript("OnClick", function()
searchBox:SetText("")
searchBox:ClearFocus()
end)
ns.searchBox = searchBox
ns.searchFilter = nil
-- Scroll frame (below search bar)
local scroll = CreateFrame("ScrollFrame", "iChatConvoScroll", panel)
scroll:SetPoint("TOPLEFT", searchBar, "BOTTOMLEFT", -4, -2)
scroll:SetPoint("BOTTOMRIGHT")
scroll:EnableMouseWheel(true)
scroll:EnableMouse(true)
local child = CreateFrame("Frame", "iChatConvoScrollChild", scroll)
child:SetWidth(LEFT_WIDTH)
child:SetHeight(1)
scroll:SetScrollChild(child)
scroll:SetScript("OnMouseWheel", function(self, delta)
local current = self:GetVerticalScroll()
local maxScroll = math.max(0, child:GetHeight() - self:GetHeight())
local newVal = math.max(0, math.min(maxScroll, current - (delta * 30)))
self:SetVerticalScroll(newVal)
end)
-- Click on conversation list area clears input focus
scroll:SetScript("OnMouseDown", function(self, button)
if ns.inputBox then
ns.inputBox:ClearFocus()
end
end)
ns.leftPanel = panel
ns.convoScrollFrame = scroll
ns.convoScrollChild = child
ns.convoEntries = {}
end
---------------------------------------------------------------------------
-- Conversation Entry
---------------------------------------------------------------------------
function ns.CreateConvoEntry(index)
local entry = CreateFrame("Button", nil, ns.convoScrollChild)
entry:SetHeight(ENTRY_HEIGHT)
entry:SetPoint("TOPLEFT", ns.convoScrollChild, "TOPLEFT", 0, -(index - 1) * ENTRY_HEIGHT)
entry:SetPoint("RIGHT", ns.convoScrollChild, "RIGHT")
entry:RegisterForClicks("LeftButtonUp", "RightButtonUp")
local bg = entry:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetColorTexture(0, 0, 0, 0)
entry.bg = bg
-- Online status dot
local statusDot = entry:CreateTexture(nil, "OVERLAY")
statusDot:SetSize(8, 8)
statusDot:SetPoint("TOPLEFT", 4, -10)
statusDot:SetTexture(PILL_TEXTURE)
statusDot:SetVertexColor(0.4, 0.4, 0.4) -- default: gray/offline
statusDot:Hide()
entry.statusDot = statusDot
-- Player name (shifted right if status dot is shown)
local name = entry:CreateFontString(nil, "OVERLAY")
name:SetFont("Fonts\\FRIZQT__.TTF", 11, "")
name:SetTextColor(unpack(C.TEXT_WHITE))
name:SetPoint("TOPLEFT", 14, -8)
name:SetPoint("RIGHT", -30, 0)
name:SetJustifyH("LEFT")
name:SetWordWrap(false)
entry.nameText = name
-- Pin icon (small text indicator)
local pinIcon = entry:CreateFontString(nil, "OVERLAY")
pinIcon:SetFont("Fonts\\FRIZQT__.TTF", 8, "")
pinIcon:SetTextColor(0.5, 0.5, 0.5)
pinIcon:SetPoint("LEFT", name, "RIGHT", 2, 0)
pinIcon:SetText("")
pinIcon:Hide()
entry.pinIcon = pinIcon
-- Muted icon
local mutedIcon = entry:CreateFontString(nil, "OVERLAY")
mutedIcon:SetFont("Fonts\\FRIZQT__.TTF", 8, "")
mutedIcon:SetTextColor(0.5, 0.5, 0.5)
mutedIcon:SetPoint("BOTTOMLEFT", 14, 10)
mutedIcon:SetText("")
mutedIcon:Hide()
entry.mutedIcon = mutedIcon
-- Preview
local preview = entry:CreateFontString(nil, "OVERLAY")
preview:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
preview:SetTextColor(unpack(C.TEXT_GRAY))
preview:SetPoint("TOPLEFT", name, "BOTTOMLEFT", 0, -2)
preview:SetPoint("RIGHT", -8, 0)
preview:SetJustifyH("LEFT")
preview:SetWordWrap(false)
preview:SetMaxLines(1)
entry.previewText = preview
-- Relative time
local timeText = entry:CreateFontString(nil, "OVERLAY")
timeText:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
timeText:SetTextColor(unpack(C.TEXT_TIME))
timeText:SetPoint("TOPRIGHT", -8, -8)
entry.timeText = timeText
-- Unread badge
local badge = CreateFrame("Frame", nil, entry)
badge:SetSize(18, 18)
badge:SetPoint("BOTTOMRIGHT", -8, 8)
local badgeBg = badge:CreateTexture(nil, "ARTWORK")
badgeBg:SetAllPoints()
badgeBg:SetColorTexture(unpack(C.BADGE))
local badgeCount = badge:CreateFontString(nil, "OVERLAY")
badgeCount:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
badgeCount:SetPoint("CENTER")
badgeCount:SetTextColor(1, 1, 1)
badge:Hide()
entry.unreadBadge = badge
entry.unreadCount = badgeCount
-- Bottom divider
local div = entry:CreateTexture(nil, "OVERLAY")
div:SetHeight(1)
div:SetPoint("BOTTOMLEFT", 8, 0)
div:SetPoint("BOTTOMRIGHT", -8, 0)
div:SetColorTexture(unpack(C.DIVIDER))
-- Click (left = select, right = context menu)
entry:SetScript("OnClick", function(self, button)
if button == "RightButton" then
ns.ShowContextMenu(self.playerName)
else
ns.SelectConversation(self.playerName)
end
end)
entry:SetScript("OnEnter", function(self)
if ns.activeConversation ~= self.playerName then
bg:SetColorTexture(unpack(C.HOVER))
end
end)
entry:SetScript("OnLeave", function(self)
if ns.activeConversation ~= self.playerName then
bg:SetColorTexture(0, 0, 0, 0)
end
end)
return entry
end
---------------------------------------------------------------------------
-- Divider
---------------------------------------------------------------------------
function ns.CreateDivider(parent)
local div = parent:CreateTexture(nil, "OVERLAY")
div:SetWidth(1)
div:SetPoint("TOPLEFT", ns.titleBar, "BOTTOMLEFT", LEFT_WIDTH, 0)
div:SetPoint("BOTTOMLEFT", parent, "BOTTOMLEFT", LEFT_WIDTH, 0)
div:SetColorTexture(unpack(C.DIVIDER))
end
---------------------------------------------------------------------------
-- Right Panel (Chat Area)
---------------------------------------------------------------------------
function ns.CreateRightPanel(parent)
local panel = CreateFrame("Frame", nil, parent)
panel:SetPoint("TOPLEFT", ns.titleBar, "BOTTOMLEFT", LEFT_WIDTH + 1, 0)
panel:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", 0, 0)
-- Header
local header = CreateFrame("Frame", nil, panel)
header:SetHeight(36)
header:SetPoint("TOPLEFT")
header:SetPoint("TOPRIGHT")
header:EnableMouse(true)
local headerBorder = header:CreateTexture(nil, "OVERLAY")
headerBorder:SetHeight(1)
headerBorder:SetPoint("BOTTOMLEFT")
headerBorder:SetPoint("BOTTOMRIGHT")
headerBorder:SetColorTexture(unpack(C.DIVIDER))
-- Click on header clears input focus
header:SetScript("OnMouseDown", function(self, button)
if ns.inputBox then
ns.inputBox:ClearFocus()
end
end)
local headerName = header:CreateFontString(nil, "OVERLAY")
headerName:SetFont("Fonts\\FRIZQT__.TTF", 12, "")
headerName:SetTextColor(unpack(C.TEXT_WHITE))
headerName:SetPoint("LEFT", 10, 2)
headerName:SetText("")
ns.headerName = headerName
-- Contact note (below name in header)
local headerNote = header:CreateFontString(nil, "OVERLAY")
headerNote:SetFont("Fonts\\FRIZQT__.TTF", 8, "")
headerNote:SetTextColor(0.45, 0.45, 0.45)
headerNote:SetPoint("TOPLEFT", headerName, "BOTTOMLEFT", 0, -1)
headerNote:SetPoint("RIGHT", -120, 0)
headerNote:SetJustifyH("LEFT")
headerNote:SetWordWrap(false)
headerNote:SetText("")
ns.headerNote = headerNote
-- Player portrait (3D model) — logic in portraits.lua
ns.CreatePortraitFrame(header)
-- Block button (rightmost)
local blockBtn = CreateFrame("Button", nil, header)
blockBtn:SetSize(48, 22)
blockBtn:SetPoint("RIGHT", -6, 0)
local blockText = blockBtn:CreateFontString(nil, "OVERLAY")
blockText:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
blockText:SetPoint("CENTER")
blockText:SetText("Block")
blockText:SetTextColor(0.8, 0.25, 0.2)
blockBtn:SetScript("OnEnter", function() blockText:SetTextColor(1, 0.4, 0.3) end)
blockBtn:SetScript("OnLeave", function()
if ns.activeConversation and ns.IsIgnored(ns.activeConversation) then
blockText:SetTextColor(0.5, 0.5, 0.5)
else
blockText:SetTextColor(0.8, 0.25, 0.2)
end
end)
blockBtn:SetScript("OnClick", function()
if not ns.activeConversation then return end
if ns.IsIgnored(ns.activeConversation) then
if C_FriendList and C_FriendList.DelIgnore then
C_FriendList.DelIgnore(ns.activeConversation)
elseif DelIgnore then
DelIgnore(ns.activeConversation)
end
else
if C_FriendList and C_FriendList.AddIgnore then
C_FriendList.AddIgnore(ns.activeConversation)
elseif AddIgnore then
AddIgnore(ns.activeConversation)
end
end
C_Timer.After(0.1, function() ns.UpdateHeaderButtons() end)
end)
blockBtn:Hide()
ns.blockBtn = blockBtn
ns.blockText = blockText
-- Invite button (left of Add Friend)
local inviteBtn = CreateFrame("Button", nil, header)
inviteBtn:SetSize(48, 22)
local inviteText = inviteBtn:CreateFontString(nil, "OVERLAY")
inviteText:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
inviteText:SetPoint("CENTER")
inviteText:SetText("Invite")
inviteText:SetTextColor(0.2, 0.78, 0.35)
inviteBtn:SetScript("OnEnter", function() inviteText:SetTextColor(0.5, 1, 0.6) end)
inviteBtn:SetScript("OnLeave", function() inviteText:SetTextColor(0.2, 0.78, 0.35) end)
inviteBtn:SetScript("OnClick", function()
if not ns.activeConversation then return end
InviteUnit(ns.activeConversation)
end)
inviteBtn:Hide()
ns.inviteBtn = inviteBtn
ns.inviteText = inviteText
-- Add Friend button (left of block)
local friendBtn = CreateFrame("Button", nil, header)
friendBtn:SetSize(64, 22)
friendBtn:SetPoint("RIGHT", blockBtn, "LEFT", -4, 0)
local friendText = friendBtn:CreateFontString(nil, "OVERLAY")
friendText:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
friendText:SetPoint("CENTER")
friendText:SetText("Add Friend")
friendText:SetTextColor(unpack(C.BLUE))
friendBtn:SetScript("OnEnter", function() friendText:SetTextColor(1, 1, 1) end)
friendBtn:SetScript("OnLeave", function() friendText:SetTextColor(unpack(C.BLUE)) end)
friendBtn:SetScript("OnClick", function()
if not ns.activeConversation then return end
if C_FriendList and C_FriendList.AddFriend then
C_FriendList.AddFriend(ns.activeConversation)
elseif AddFriend then
AddFriend(ns.activeConversation)
end
C_Timer.After(0.2, function()
ns:FRIENDLIST_UPDATE()
ns.UpdateHeaderButtons()
end)
end)
friendBtn:Hide()
ns.friendBtn = friendBtn
ns.friendText = friendText
-- Position inviteBtn now that friendBtn exists
inviteBtn:SetPoint("RIGHT", friendBtn, "LEFT", -4, 0)
-- Empty state text (shown when no conversation selected)
local emptyText = panel:CreateFontString(nil, "OVERLAY")
emptyText:SetFont("Fonts\\FRIZQT__.TTF", 11, "")
emptyText:SetTextColor(0.35, 0.35, 0.35)
emptyText:SetPoint("CENTER", panel, "CENTER", 0, 20)
emptyText:SetText("Select a conversation\nor /w someone to start")
ns.emptyText = emptyText
-- Quick reply bar (created in settings.lua, sits above input)
-- Reserve space: input=40, quickReply=26
ns.CreateQuickReplyBar(panel)
-- Chat scroll area
local qrOffset = (ns.quickReplyBar and ns.quickReplyBar:IsShown()) and 66 or 40
local chatScroll = CreateFrame("ScrollFrame", "iChatBubbleScroll", panel)
chatScroll:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 0, 0)
chatScroll:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", 0, qrOffset)
chatScroll:EnableMouseWheel(true)
chatScroll:EnableMouse(true)
local chatChild = CreateFrame("Frame", "iChatBubbleScrollChild", chatScroll)
chatChild:SetWidth(1) -- updated in OnSizeChanged
chatChild:SetHeight(1)
chatScroll:SetScrollChild(chatChild)
chatScroll:SetScript("OnMouseWheel", function(self, delta)
local current = self:GetVerticalScroll()
local maxScroll = math.max(0, chatChild:GetHeight() - self:GetHeight())
local newVal = math.max(0, math.min(maxScroll, current - (delta * 40)))
self:SetVerticalScroll(newVal)
end)
-- Click on chat area clears input focus
chatScroll:SetScript("OnMouseDown", function(self, button)
if ns.inputBox then
ns.inputBox:ClearFocus()
end
end)
chatScroll:SetScript("OnSizeChanged", function(self, w, h)
chatChild:SetWidth(w)
if ns.activeConversation then
ns.RebuildBubbles(ns.activeConversation)
end
end)
ns.chatScrollFrame = chatScroll
ns.chatScrollChild = chatChild
-- Input bar
local inputBar = CreateFrame("Frame", nil, panel)
inputBar:SetHeight(40)
inputBar:SetPoint("BOTTOMLEFT")
inputBar:SetPoint("BOTTOMRIGHT")
local inputBg = inputBar:CreateTexture(nil, "BACKGROUND")
inputBg:SetAllPoints()
inputBg:SetColorTexture(0.08, 0.08, 0.08, 1)
local inputTopBorder = inputBar:CreateTexture(nil, "OVERLAY")
inputTopBorder:SetHeight(1)
inputTopBorder:SetPoint("TOPLEFT")
inputTopBorder:SetPoint("TOPRIGHT")
inputTopBorder:SetColorTexture(unpack(C.DIVIDER))
-- Input EditBox
local inputBox = CreateFrame("EditBox", "iChatInputBox", inputBar)
inputBox:SetPoint("LEFT", 10, 0)
inputBox:SetPoint("RIGHT", -74, 0)
inputBox:SetHeight(24)
inputBox:SetFont("Fonts\\FRIZQT__.TTF", 11, "")
inputBox:SetTextColor(1, 1, 1)
inputBox:SetAutoFocus(false)
inputBox:SetMaxLetters(255)
local inputBoxBg = inputBox:CreateTexture(nil, "BACKGROUND")
inputBoxBg:SetPoint("TOPLEFT", inputBar, "TOPLEFT", 6, -6)
inputBoxBg:SetPoint("BOTTOMRIGHT", inputBar, "BOTTOMRIGHT", -70, 6)
inputBoxBg:SetTexture("Interface\\AddOns\\iChat\\media\\textures\\inputbox")
inputBoxBg:SetVertexColor(0.18, 0.18, 0.18, 1)
inputBox:SetScript("OnEnterPressed", function(self)
local text = self:GetText()
if text ~= "" and ns.activeConversation then
ns.SendWhisper(ns.activeConversation, text)
self:SetText("")
end
end)
inputBox:SetScript("OnEscapePressed", function(self)
self:ClearFocus()
end)
-- Send button
local sendBtn = CreateFrame("Button", nil, inputBar)
sendBtn:SetSize(28, 28)
sendBtn:SetPoint("RIGHT", -6, 0)
local sendTex = sendBtn:CreateFontString(nil, "OVERLAY")
sendTex:SetFont("Fonts\\FRIZQT__.TTF", 18, "")
sendTex:SetPoint("CENTER")
sendTex:SetText(">")
sendTex:SetTextColor(unpack(C.BLUE))
sendBtn:SetScript("OnClick", function()
local text = inputBox:GetText()
if text ~= "" and ns.activeConversation then
ns.SendWhisper(ns.activeConversation, text)
inputBox:SetText("")
end
end)
sendBtn:SetScript("OnEnter", function() sendTex:SetTextColor(1, 1, 1) end)
sendBtn:SetScript("OnLeave", function() sendTex:SetTextColor(unpack(C.BLUE)) end)
-- Emoji picker button (between input and send)
local emojiBtn = CreateFrame("Button", nil, inputBar)
emojiBtn:SetSize(32, 32)
emojiBtn:SetPoint("RIGHT", sendBtn, "LEFT", -2, 0)
local emojiIcon = emojiBtn:CreateTexture(nil, "ARTWORK")
emojiIcon:SetSize(28, 28)
emojiIcon:SetPoint("CENTER")
emojiIcon:SetTexture("Interface\\AddOns\\iChat\\media\\emoji\\smile.png")
emojiIcon:SetVertexColor(1.0, 1.0, 0.9) -- Bright default
emojiBtn:SetScript("OnClick", function() ns.ToggleEmojiPicker() end)
emojiBtn:SetScript("OnEnter", function()
emojiIcon:SetVertexColor(1.0, 1.0, 1.0) -- Pure white on hover
GameTooltip:SetOwner(emojiBtn, "ANCHOR_TOP")
GameTooltip:SetText("Emoji")
GameTooltip:Show()
end)
emojiBtn:SetScript("OnLeave", function()
emojiIcon:SetVertexColor(1.0, 1.0, 0.9) -- Back to bright default
GameTooltip:Hide()
end)
-- Create emoji picker panel
if ns.CreateEmojiPicker then
ns.CreateEmojiPicker(ns.mainWindow)
ns.emojiPicker:ClearAllPoints()
ns.emojiPicker:SetPoint("BOTTOMRIGHT", emojiBtn, "TOPRIGHT", 0, 4)
end
ns.inputBox = inputBox
ns.rightPanel = panel
-- Enable Emoji-Core autocomplete on input box if available
if Emojis and Emojis.EnableEmojiCompleterForEditBox then
Emojis.EnableEmojiCompleterForEditBox(inputBox)
end
end
---------------------------------------------------------------------------
-- Conversation List Management
---------------------------------------------------------------------------
function ns.RefreshConversationList()
-- Build list with search filter
local sorted = {}
local filter = ns.searchFilter
for name, convo in pairs(ns.db.conversations) do
local include = true
if filter then
-- Match name or message content
include = name:lower():find(filter, 1, true) ~= nil
if not include and convo.messages then
for _, msg in ipairs(convo.messages) do
if msg.text and msg.text:lower():find(filter, 1, true) then
include = true
break
end
end
end
end
if include then
table.insert(sorted, { name = name, convo = convo })
end
end
-- Sort: pinned first, then by lastActivity descending
local pinned = ns.db.pinnedConversations or {}
table.sort(sorted, function(a, b)
local aPinned = pinned[a.name] and true or false
local bPinned = pinned[b.name] and true or false
if aPinned ~= bPinned then return aPinned end
return (a.convo.lastActivity or 0) > (b.convo.lastActivity or 0)
end)
-- Ensure enough entry frames
while #ns.convoEntries < #sorted do
local entry = ns.CreateConvoEntry(#ns.convoEntries + 1)
table.insert(ns.convoEntries, entry)
end
-- Update each entry
for i, data in ipairs(sorted) do
local entry = ns.convoEntries[i]
entry.playerName = data.name
-- Display name with colors
local displayName = data.name
local useColoredText = false
-- BNet conversations: "BattleTag (CharName)" with BNet blue + class color
if ns.IsBNetConversation and ns.IsBNetConversation(data.name) then
local bnetIDAccount = ns.GetBNetIDFromName and ns.GetBNetIDFromName(data.name)
if bnetIDAccount then
local battleTag = ns.GetBNetBattleTag and ns.GetBNetBattleTag(bnetIDAccount) or "BNet Friend"
local charName = ns.GetBNetCharacterName and ns.GetBNetCharacterName(bnetIDAccount)
if charName then
-- Get class color for character name
local playerInfo = ns.GetPlayerInfo and ns.GetPlayerInfo(data.name)
local classColorHex = "ffffffff" -- white default
if playerInfo and playerInfo.classFile and RAID_CLASS_COLORS then
local cc = RAID_CLASS_COLORS[playerInfo.classFile]
if cc then
classColorHex = string.format("ff%02x%02x%02x", cc.r * 255, cc.g * 255, cc.b * 255)
end
end
-- Format: BattleTag (CharName) with BNet blue + class color
displayName = string.format("|cff00b8ff%s|r |c%s(%s)|r", battleTag, classColorHex, charName)
useColoredText = true
else
displayName = battleTag
end
end
end
entry.nameText:SetText(displayName)
-- Set text color (only for non-colored text since colored text has inline codes)
if useColoredText then
-- For colored text (BNet with inline codes), use white as base so codes work
entry.nameText:SetTextColor(1, 1, 1)
elseif ns.IsBNetConversation and ns.IsBNetConversation(data.name) then
entry.nameText:SetTextColor(unpack(C.BNET_BLUE))
elseif ns.db.settings.classColoredNames then
local playerInfo = ns.GetPlayerInfo and ns.GetPlayerInfo(data.name)
if playerInfo and playerInfo.classFile and RAID_CLASS_COLORS then
local cc = RAID_CLASS_COLORS[playerInfo.classFile]
if cc then
entry.nameText:SetTextColor(cc.r, cc.g, cc.b)
else
entry.nameText:SetTextColor(unpack(C.TEXT_WHITE))
end
else
entry.nameText:SetTextColor(unpack(C.TEXT_WHITE))
end
else
entry.nameText:SetTextColor(unpack(C.TEXT_WHITE))
end
-- Online status dot
if ns.db.settings.showOnlineStatus and entry.statusDot then
local online = ns.onlineCache and ns.onlineCache[data.name:lower()]
if ns.IsFriend(data.name) then
entry.statusDot:Show()
if online then
entry.statusDot:SetVertexColor(0.2, 0.8, 0.2) -- green
else
entry.statusDot:SetVertexColor(0.4, 0.4, 0.4) -- gray
end
else
entry.statusDot:Hide()
end
elseif entry.statusDot then
entry.statusDot:Hide()
end
-- Pin icon
if pinned[data.name] and entry.pinIcon then
entry.pinIcon:SetText("|TInterface\\AddOns\\iChat\\media\\textures\\pill:8|t")
entry.pinIcon:Show()
elseif entry.pinIcon then
entry.pinIcon:Hide()
end
-- Muted icon
if ns.db.mutedContacts and ns.db.mutedContacts[data.name] and entry.mutedIcon then
entry.mutedIcon:SetText("(muted)")
entry.mutedIcon:Show()
elseif entry.mutedIcon then
entry.mutedIcon:Hide()
end
-- Last message preview
local msgs = data.convo.messages
if msgs and #msgs > 0 then
local last = msgs[#msgs]
local prefix = last.sender == "me" and "You: " or ""
local preview = prefix .. last.text
if #preview > 22 then preview = preview:sub(1, 22) .. "..." end
if ns.ReplaceEmoji then
preview = ns.ReplaceEmoji(preview, 14)
end
if Emojis and Emojis.ReplaceEmojiToIcon then
preview = Emojis:ReplaceEmojiToIcon(preview, 14)
end
entry.previewText:SetText(preview)
entry.timeText:SetText(ns.FormatTimestamp(last.time))
else
entry.previewText:SetText("")
entry.timeText:SetText("")
end
-- Unread badge
if (data.convo.unread or 0) > 0 then
entry.unreadBadge:Show()
entry.unreadCount:SetText(tostring(data.convo.unread))
else
entry.unreadBadge:Hide()
end
-- Highlight active
if ns.activeConversation == data.name then
entry.bg:SetColorTexture(unpack(C.ACTIVE))
else
entry.bg:SetColorTexture(0, 0, 0, 0)
end
-- Reposition
entry:ClearAllPoints()
entry:SetPoint("TOPLEFT", ns.convoScrollChild, "TOPLEFT", 0, -(i - 1) * ENTRY_HEIGHT)
entry:SetPoint("RIGHT", ns.convoScrollChild, "RIGHT")
entry:Show()
end
-- Hide extra entries
for i = #sorted + 1, #ns.convoEntries do
ns.convoEntries[i]:Hide()
end
-- Update scroll child height
ns.convoScrollChild:SetHeight(math.max(#sorted * ENTRY_HEIGHT, 1))
-- Store sorted list for keyboard navigation
ns._sortedConvos = sorted
end
---------------------------------------------------------------------------
-- Update Header Buttons (friend / block state)
---------------------------------------------------------------------------
function ns.UpdateHeaderButtons()
local name = ns.activeConversation
if not name then
if ns.inviteBtn then ns.inviteBtn:Hide() end
if ns.friendBtn then ns.friendBtn:Hide() end
if ns.blockBtn then ns.blockBtn:Hide() end
return
end
-- Friend button: show "Add Friend" or "Friend" (muted, non-clickable)
if ns.IsFriend(name) then
ns.friendText:SetText("Friend")
ns.friendText:SetTextColor(0.4, 0.4, 0.4)
ns.friendBtn:SetScript("OnEnter", nil)
ns.friendBtn:SetScript("OnLeave", nil)
ns.friendBtn:SetScript("OnClick", nil)
else
ns.friendText:SetText("Add Friend")
ns.friendText:SetTextColor(unpack(C.BLUE))
ns.friendBtn:SetScript("OnEnter", function() ns.friendText:SetTextColor(1, 1, 1) end)
ns.friendBtn:SetScript("OnLeave", function() ns.friendText:SetTextColor(unpack(C.BLUE)) end)
ns.friendBtn:SetScript("OnClick", function()
if not ns.activeConversation then return end
if C_FriendList and C_FriendList.AddFriend then
C_FriendList.AddFriend(ns.activeConversation)
elseif AddFriend then
AddFriend(ns.activeConversation)
end
C_Timer.After(0.2, function()
ns:FRIENDLIST_UPDATE()
ns.UpdateHeaderButtons()
end)
end)
end
ns.friendBtn:Show()
-- Block button: toggle between Block / Unblock
if ns.IsIgnored(name) then
ns.blockText:SetText("Unblock")
ns.blockText:SetTextColor(0.5, 0.5, 0.5)
else
ns.blockText:SetText("Block")
ns.blockText:SetTextColor(0.8, 0.25, 0.2)
end
ns.blockBtn:Show()
-- Invite button: always show when a conversation is open
if ns.inviteBtn then ns.inviteBtn:Show() end
end
---------------------------------------------------------------------------
-- Select Conversation
---------------------------------------------------------------------------
function ns.SelectConversation(playerName)
ns.activeConversation = playerName
-- Display name for BNet: just the account name (e.g., "Jim Fano") in cyan-blue
local displayName = playerName
local gameInfo = ""
local useBNetColors = false
if ns.IsBNetConversation and ns.IsBNetConversation(playerName) then
local bnetIDAccount = ns.GetBNetIDFromName and ns.GetBNetIDFromName(playerName)
if bnetIDAccount then
gameInfo = ns.GetBNetGameInfo and ns.GetBNetGameInfo(bnetIDAccount) or ""
local battleTag = ns.GetBNetBattleTag and ns.GetBNetBattleTag(bnetIDAccount) or "BNet Friend"
-- Simple format: just the account name in BNet blue
displayName = string.format("|cff00b8ff%s|r", battleTag)
useBNetColors = true
end
end
ns.headerName:SetText(displayName)
-- Set white color for BNet (so inline codes work), UpdatePortrait will handle others
if useBNetColors then
ns.headerName:SetTextColor(1, 1, 1)
end
-- Show player info + contact note + relationship tags + game info in header
if ns.headerNote then
local note = ns.db.contactNotes and ns.db.contactNotes[playerName] or ""
local tags = ns.FormatRelationshipTags and ns.FormatRelationshipTags(playerName) or ""