Chat UI tweaks
parent
1bd5547df8
commit
b1e2eec834
|
@ -2,21 +2,26 @@ extends Control
|
||||||
|
|
||||||
@onready var main = get_tree().get_root().get_node("Main")
|
@onready var main = get_tree().get_root().get_node("Main")
|
||||||
@onready var player = main.player
|
@onready var player = main.player
|
||||||
|
@onready var chat_history = $VBoxContainer/ChatHistory
|
||||||
|
@onready var chat_typing = $VBoxContainer/Typing
|
||||||
|
@onready var chat_editor = $VBoxContainer/Typing/Editor
|
||||||
|
@onready var chat_label = $VBoxContainer/Typing/Label
|
||||||
|
|
||||||
class chat_message:
|
|
||||||
var sender_id := 0
|
|
||||||
var team := 0
|
|
||||||
var message := ''
|
|
||||||
|
|
||||||
func _init(sender_id, team, message):
|
|
||||||
self.sender_id = sender_id
|
|
||||||
self.team = team
|
|
||||||
self.message = message
|
|
||||||
|
|
||||||
@remotesync var message: chat_message:
|
#class chat_message:
|
||||||
set(new_message):
|
# var sender_id := 0
|
||||||
print("message changed")
|
# var team := 0
|
||||||
$VBoxContainer/ChatHistory.text += "\n" + str(new_message.sender_id) + ' : ' + new_message.message
|
# var message := ''
|
||||||
|
#
|
||||||
|
# func _init(sender_id, team, message):
|
||||||
|
# self.sender_id = sender_id
|
||||||
|
# self.team = team
|
||||||
|
# self.message = message
|
||||||
|
|
||||||
|
#@remotesync var message: chat_message:
|
||||||
|
# set(new_message):
|
||||||
|
# print("message changed : ", new_message)
|
||||||
|
# $VBoxContainer/ChatHistory.text += "\n" + str(new_message[0]) + ' : ' + new_message[2]
|
||||||
|
|
||||||
enum ChatState {INACTIVE, TYPING_ALL, TYPING_TEAM}
|
enum ChatState {INACTIVE, TYPING_ALL, TYPING_TEAM}
|
||||||
|
|
||||||
|
@ -27,52 +32,53 @@ var state = ChatState.INACTIVE :
|
||||||
state = new_state
|
state = new_state
|
||||||
match new_state:
|
match new_state:
|
||||||
0: #ChatState.INACTIVE:
|
0: #ChatState.INACTIVE:
|
||||||
$VBoxContainer/Typing.hide()
|
chat_typing.hide()
|
||||||
$VBoxContainer/Typing/LineEdit.release_focus()
|
chat_editor.release_focus()
|
||||||
1: #ChatState.TYPING_ALL:
|
1: #ChatState.TYPING_ALL:
|
||||||
$VBoxContainer/Typing/Label.text = "all: "
|
chat_label.text = "all: "
|
||||||
$VBoxContainer/Typing.show()
|
chat_typing.show()
|
||||||
$VBoxContainer/Typing/LineEdit.grab_focus()
|
chat_editor.grab_focus()
|
||||||
$VBoxContainer/Typing/LineEdit.text = ''
|
chat_editor.text = ''
|
||||||
2: #ChatState.TYPING_TEAM:
|
2: #ChatState.TYPING_TEAM:
|
||||||
$VBoxContainer/Typing/Label.text = "team: "
|
chat_label.text = "team: "
|
||||||
$VBoxContainer/Typing.show()
|
chat_typing.show()
|
||||||
$VBoxContainer/Typing/LineEdit.grab_focus()
|
chat_editor.grab_focus()
|
||||||
$VBoxContainer/Typing/LineEdit.text = ''
|
chat_editor.text = ''
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _input(event) -> void:
|
func _input(_event) -> void:
|
||||||
if state == ChatState.INACTIVE:
|
if state == ChatState.INACTIVE:
|
||||||
if Input.is_action_just_pressed("say_all"):
|
if Input.is_action_just_pressed("say_all"):
|
||||||
main.focus = 2 #main.GameFocus.CHAT
|
main.focus = 2 #main.GameFocus.CHAT
|
||||||
state = 1 #ChatState.TYPING_ALL
|
state = 1 #ChatState.TYPING_ALL
|
||||||
get_tree().get_root().set_input_as_handled()
|
get_tree().get_root().set_input_as_handled()
|
||||||
|
|
||||||
if Input.is_action_just_pressed("say_team"):
|
if Input.is_action_just_pressed("say_team"):
|
||||||
main.focus = 2 #main.GameFocus.CHAT
|
main.focus = 2 #main.GameFocus.CHAT
|
||||||
state = 2 #ChatState.TYPING_TEAM
|
state = 2 #ChatState.TYPING_TEAM
|
||||||
get_tree().get_root().set_input_as_handled()
|
get_tree().get_root().set_input_as_handled()
|
||||||
|
|
||||||
elif Input.is_action_just_pressed("say_cancel"):
|
elif Input.is_action_just_pressed("say_cancel"):
|
||||||
main.focus = 1 #main.GameFocus.GAME
|
main.focus = 1 #main.GameFocus.GAME
|
||||||
state = 0 #ChatState.INACTIVE
|
state = 0 #ChatState.INACTIVE
|
||||||
|
|
||||||
func _unhandled_input(event) -> void:
|
func _unhandled_input(_event) -> void:
|
||||||
if state != 0: #ChatState.INACTIVE:
|
if state != 0: #ChatState.INACTIVE:
|
||||||
get_tree().get_root().set_input_as_handled()
|
get_tree().get_root().set_input_as_handled()
|
||||||
|
|
||||||
# doesn't work due to missing RPC implementation in Godot 4
|
# doesn't work over network due to missing RPC implementation in Godot 4
|
||||||
#@remotesync func chat_message(peer_id: int, message: String) -> void:
|
@remotesync func chat_message(sender_id: int, recipient_team, message: String) -> void:
|
||||||
# var player = str(peer_id)
|
chat_history.text += '\n' + str(sender_id) + " | " + message
|
||||||
# $VBoxContainer/ChatHistory.text += '\n' + player + " | " + message
|
|
||||||
|
|
||||||
func _on_LineEdit_text_entered(new_text):
|
func _on_LineEdit_text_entered(new_text):
|
||||||
# RPC is currently not implemented in the engine
|
# RPC is currently not implemented in the engine
|
||||||
var sender_id = get_tree().get_network_unique_id()
|
var sender_id = get_tree().get_network_unique_id()
|
||||||
var new_message = chat_message.new(sender_id, 0, new_text)
|
var new_message = [sender_id, 0, new_text]
|
||||||
rset("message", new_message)
|
chat_message(sender_id, 0, new_text)
|
||||||
#chat_message.rpc(get_tree().get_network_unique_id(), $VBoxContainer/Typing/LineEdit.text)
|
#chat_message.rpc(get_tree().get_network_unique_id(), $VBoxContainer/Typing/LineEdit.text)
|
||||||
$VBoxContainer/Typing/LineEdit.text = ''
|
chat_editor.text = ''
|
||||||
state = 0 #ChatState.INACTIVE
|
state = 0 #ChatState.INACTIVE
|
||||||
main.focus = 0 #main.GameFocus.GAME
|
main.focus = 0 #main.GameFocus.GAME
|
||||||
|
|
|
@ -153,11 +153,8 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="Chat"]
|
[node name="VBoxContainer" type="VBoxContainer" parent="Chat"]
|
||||||
anchor_top = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
offset_top = -500.0
|
|
||||||
offset_right = 300.0
|
offset_right = 300.0
|
||||||
offset_bottom = 37.0
|
offset_bottom = 507.0
|
||||||
alignment = 2
|
alignment = 2
|
||||||
script = null
|
script = null
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
@ -165,15 +162,10 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="ChatHistory" type="RichTextLabel" parent="Chat/VBoxContainer"]
|
[node name="ChatHistory" type="RichTextLabel" parent="Chat/VBoxContainer"]
|
||||||
offset_top = 422.0
|
offset_top = 37.0
|
||||||
offset_right = 300.0
|
offset_right = 300.0
|
||||||
offset_bottom = 537.0
|
offset_bottom = 507.0
|
||||||
text = "text
|
rect_min_size = Vector2( 0, 470 )
|
||||||
text
|
|
||||||
text
|
|
||||||
text
|
|
||||||
text"
|
|
||||||
fit_content_height = true
|
|
||||||
scroll_active = false
|
scroll_active = false
|
||||||
scroll_following = true
|
scroll_following = true
|
||||||
custom_effects = [ ]
|
custom_effects = [ ]
|
||||||
|
@ -185,9 +177,9 @@ __meta__ = {
|
||||||
|
|
||||||
[node name="Typing" type="HBoxContainer" parent="Chat/VBoxContainer"]
|
[node name="Typing" type="HBoxContainer" parent="Chat/VBoxContainer"]
|
||||||
visible = false
|
visible = false
|
||||||
offset_top = 504.0
|
offset_top = 474.0
|
||||||
offset_right = 300.0
|
offset_right = 339.0
|
||||||
offset_bottom = 537.0
|
offset_bottom = 507.0
|
||||||
script = null
|
script = null
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
|
@ -195,8 +187,9 @@ __meta__ = {
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="Chat/VBoxContainer/Typing"]
|
[node name="Label" type="Label" parent="Chat/VBoxContainer/Typing"]
|
||||||
offset_top = 3.0
|
offset_top = 3.0
|
||||||
offset_right = 34.0
|
offset_right = 55.0
|
||||||
offset_bottom = 29.0
|
offset_bottom = 29.0
|
||||||
|
rect_min_size = Vector2( 55, 0 )
|
||||||
text = "say: "
|
text = "say: "
|
||||||
structured_text_bidi_override_options = [ ]
|
structured_text_bidi_override_options = [ ]
|
||||||
script = null
|
script = null
|
||||||
|
@ -204,20 +197,24 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="LineEdit" type="LineEdit" parent="Chat/VBoxContainer/Typing"]
|
[node name="Editor" type="LineEdit" parent="Chat/VBoxContainer/Typing"]
|
||||||
offset_left = 38.0
|
offset_left = 59.0
|
||||||
offset_right = 238.0
|
offset_right = 339.0
|
||||||
offset_bottom = 33.0
|
offset_bottom = 33.0
|
||||||
rect_min_size = Vector2( 200, 0 )
|
rect_min_size = Vector2( 250, 0 )
|
||||||
|
max_length = 80
|
||||||
|
expand_to_text_length = true
|
||||||
context_menu_enabled = false
|
context_menu_enabled = false
|
||||||
virtual_keyboard_enabled = false
|
virtual_keyboard_enabled = false
|
||||||
shortcut_keys_enabled = false
|
shortcut_keys_enabled = false
|
||||||
selecting_enabled = false
|
selecting_enabled = false
|
||||||
structured_text_bidi_override_options = [ ]
|
structured_text_bidi_override_options = [ ]
|
||||||
|
placeholder_text = "ENTER to send, ESC to cancel"
|
||||||
|
placeholder_alpha = 0.5
|
||||||
caret_blink = true
|
caret_blink = true
|
||||||
script = null
|
script = null
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[connection signal="text_entered" from="Chat/VBoxContainer/Typing/LineEdit" to="Chat" method="_on_LineEdit_text_entered"]
|
[connection signal="text_entered" from="Chat/VBoxContainer/Typing/Editor" to="Chat" method="_on_LineEdit_text_entered"]
|
||||||
|
|
Reference in New Issue