Chat UI tweaks

pull/50/head
unfa 2021-06-07 11:56:16 +02:00
parent 1bd5547df8
commit b1e2eec834
2 changed files with 56 additions and 53 deletions

View File

@ -2,21 +2,26 @@ extends Control
@onready var main = get_tree().get_root().get_node("Main")
@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:
set(new_message):
print("message changed")
$VBoxContainer/ChatHistory.text += "\n" + str(new_message.sender_id) + ' : ' + new_message.message
#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:
# 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}
@ -27,52 +32,53 @@ var state = ChatState.INACTIVE :
state = new_state
match new_state:
0: #ChatState.INACTIVE:
$VBoxContainer/Typing.hide()
$VBoxContainer/Typing/LineEdit.release_focus()
chat_typing.hide()
chat_editor.release_focus()
1: #ChatState.TYPING_ALL:
$VBoxContainer/Typing/Label.text = "all: "
$VBoxContainer/Typing.show()
$VBoxContainer/Typing/LineEdit.grab_focus()
$VBoxContainer/Typing/LineEdit.text = ''
chat_label.text = "all: "
chat_typing.show()
chat_editor.grab_focus()
chat_editor.text = ''
2: #ChatState.TYPING_TEAM:
$VBoxContainer/Typing/Label.text = "team: "
$VBoxContainer/Typing.show()
$VBoxContainer/Typing/LineEdit.grab_focus()
$VBoxContainer/Typing/LineEdit.text = ''
chat_label.text = "team: "
chat_typing.show()
chat_editor.grab_focus()
chat_editor.text = ''
# Called when the node enters the scene tree for the first time.
func _ready():
pass
func _input(event) -> void:
func _input(_event) -> void:
if state == ChatState.INACTIVE:
if Input.is_action_just_pressed("say_all"):
main.focus = 2 #main.GameFocus.CHAT
state = 1 #ChatState.TYPING_ALL
get_tree().get_root().set_input_as_handled()
if Input.is_action_just_pressed("say_team"):
main.focus = 2 #main.GameFocus.CHAT
state = 2 #ChatState.TYPING_TEAM
get_tree().get_root().set_input_as_handled()
elif Input.is_action_just_pressed("say_cancel"):
main.focus = 1 #main.GameFocus.GAME
state = 0 #ChatState.INACTIVE
func _unhandled_input(event) -> void:
func _unhandled_input(_event) -> void:
if state != 0: #ChatState.INACTIVE:
get_tree().get_root().set_input_as_handled()
# doesn't work due to missing RPC implementation in Godot 4
#@remotesync func chat_message(peer_id: int, message: String) -> void:
# var player = str(peer_id)
# $VBoxContainer/ChatHistory.text += '\n' + player + " | " + message
# doesn't work over network due to missing RPC implementation in Godot 4
@remotesync func chat_message(sender_id: int, recipient_team, message: String) -> void:
chat_history.text += '\n' + str(sender_id) + " | " + message
func _on_LineEdit_text_entered(new_text):
# RPC is currently not implemented in the engine
var sender_id = get_tree().get_network_unique_id()
var new_message = chat_message.new(sender_id, 0, new_text)
rset("message", new_message)
var new_message = [sender_id, 0, new_text]
chat_message(sender_id, 0, new_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
main.focus = 0 #main.GameFocus.GAME

View File

@ -153,11 +153,8 @@ __meta__ = {
}
[node name="VBoxContainer" type="VBoxContainer" parent="Chat"]
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -500.0
offset_right = 300.0
offset_bottom = 37.0
offset_bottom = 507.0
alignment = 2
script = null
__meta__ = {
@ -165,15 +162,10 @@ __meta__ = {
}
[node name="ChatHistory" type="RichTextLabel" parent="Chat/VBoxContainer"]
offset_top = 422.0
offset_top = 37.0
offset_right = 300.0
offset_bottom = 537.0
text = "text
text
text
text
text"
fit_content_height = true
offset_bottom = 507.0
rect_min_size = Vector2( 0, 470 )
scroll_active = false
scroll_following = true
custom_effects = [ ]
@ -185,9 +177,9 @@ __meta__ = {
[node name="Typing" type="HBoxContainer" parent="Chat/VBoxContainer"]
visible = false
offset_top = 504.0
offset_right = 300.0
offset_bottom = 537.0
offset_top = 474.0
offset_right = 339.0
offset_bottom = 507.0
script = null
__meta__ = {
"_edit_use_anchors_": false
@ -195,8 +187,9 @@ __meta__ = {
[node name="Label" type="Label" parent="Chat/VBoxContainer/Typing"]
offset_top = 3.0
offset_right = 34.0
offset_right = 55.0
offset_bottom = 29.0
rect_min_size = Vector2( 55, 0 )
text = "say: "
structured_text_bidi_override_options = [ ]
script = null
@ -204,20 +197,24 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="LineEdit" type="LineEdit" parent="Chat/VBoxContainer/Typing"]
offset_left = 38.0
offset_right = 238.0
[node name="Editor" type="LineEdit" parent="Chat/VBoxContainer/Typing"]
offset_left = 59.0
offset_right = 339.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
virtual_keyboard_enabled = false
shortcut_keys_enabled = false
selecting_enabled = false
structured_text_bidi_override_options = [ ]
placeholder_text = "ENTER to send, ESC to cancel"
placeholder_alpha = 0.5
caret_blink = true
script = null
__meta__ = {
"_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"]