-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_messages_ui.go
More file actions
104 lines (94 loc) · 2.46 KB
/
Copy pathchat_messages_ui.go
File metadata and controls
104 lines (94 loc) · 2.46 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
//go:build !test
package main
import (
"gothoom/eui"
"time"
clipboard "golang.design/x/clipboard"
)
var chatWin *eui.WindowData
var chatList *eui.ItemData
var chatHighlighted *eui.ItemData
func updateChatWindow() {
if chatWin == nil || !chatWin.IsOpen() {
return
}
scrollit := chatList.ScrollAtBottom()
msgs := getChatMessages()
updateTextWindow(chatWin, chatList, nil, msgs, gs.ChatFontSize, "", nil)
searchTextWindow(chatWin, chatList, chatWin.SearchText)
if chatList != nil {
for i, msg := range msgs {
if chatHasPlayerTag(msg) {
chatList.Contents[i].TextColor = eui.AccentColor()
chatList.Contents[i].ForceTextColor = true
} else {
chatList.Contents[i].ForceTextColor = false
}
}
// Auto-scroll list to bottom on new messages
if scrollit {
chatList.Scroll.Y = 1e9
}
chatWin.Refresh()
}
}
func makeChatWindow() error {
if gs.MessagesToConsole {
return nil
}
if chatWin != nil {
return nil
}
chatWin, chatList, _ = newTextWindow("Chat", eui.HZoneRight, eui.VZoneBottom, false, updateChatWindow)
chatWin.Searchable = true
chatWin.OnSearch = func(s string) { searchTextWindow(chatWin, chatList, s) }
updateChatWindow()
chatWin.Refresh()
return nil
}
// handleChatCopyRightClick copies the clicked chat line to the clipboard,
// highlights it, and optionally shows a notification. Returns true if a line
// was found under the cursor.
func handleChatCopyRightClick(mx, my int) bool {
if chatWin == nil || chatList == nil || !chatWin.IsOpen() {
return false
}
pos := eui.Point{X: float32(mx), Y: float32(my)}
for _, row := range chatList.Contents {
r := row.DrawRect
if pos.X >= r.X0 && pos.X <= r.X1 && pos.Y >= r.Y0 && pos.Y <= r.Y1 {
// Clear previous highlights in chat list.
for _, it := range chatList.Contents {
it.Filled = false
it.Focused = false
}
// Highlight selected line briefly and copy the text.
row.Filled = true
row.Focused = true
chatHighlighted = row
chatWin.Refresh()
scheduleChatUnhighlight(row)
if row.Text != "" {
clipboard.Write(clipboard.FmtText, []byte(row.Text))
if gs.NotifyCopyText {
showNotification("text copied")
}
}
return true
}
}
return false
}
func scheduleChatUnhighlight(row *eui.ItemData) {
go func(target *eui.ItemData) {
time.Sleep(1200 * time.Millisecond)
if chatHighlighted == target {
target.Filled = false
target.Focused = false
if chatWin != nil {
chatWin.Refresh()
}
chatHighlighted = nil
}
}(row)
}