-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatBox.gd
More file actions
56 lines (48 loc) · 1.63 KB
/
Copy pathChatBox.gd
File metadata and controls
56 lines (48 loc) · 1.63 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
extends Control
onready var chatLog = get_node("VBoxContainer/RichTextLabel")
onready var inputLabel = get_node("VBoxContainer/HBoxContainer/Label")
onready var inputField = get_node("VBoxContainer/HBoxContainer/LineEdit")
var groups = [
{'name': 'Team', 'color': '#00abc7'},
{'name': 'Match', 'color': '#ffdd8b'},
{'name': 'Global', 'color': '#ffffff'}
]
var group_index = 0
var user_name = 'Player'
func _ready():
inputField.connect("text_entered", self,'text_entered')
change_group(0)
func _input(event):
if event is InputEventKey:
if event.pressed and event.scancode == KEY_ENTER:
inputField.grab_focus()
if event.pressed and event.scancode == KEY_ESCAPE:
inputField.release_focus()
if event.pressed and event.scancode == KEY_TAB:
change_group(1)
func change_group(value):
group_index += value
if group_index > (groups.size() - 1):
group_index = 0
inputLabel.text = '[' + groups[group_index]['name'] + ']'
inputLabel.set("custom_colors/font_color", Color(groups[group_index]['color']))
func add_message(username, text, group = 0, color = ''):
chatLog.bbcode_text += '\n'
if color == '':
chatLog.bbcode_text += '[color=' + groups[group]['color'] + ']'
else:
chatLog.bbcode_text += '[color=' + color + ']'
if username != '':
chatLog.bbcode_text += '[' + username + ']: '
chatLog.bbcode_text += text
chatLog.bbcode_text += '[/color]'
func text_entered(text):
if text =='/h':
add_message('', 'There is no help message yet!', 0, '#ff5757')
inputField.text = ''
return
if text != '':
add_message(user_name, text, group_index)
# Here you have to send the message to the server
print(text)
inputField.text = ''