shoutbox with new users and message display
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
extends Control
|
||||
|
||||
# Lemonland Shoutbox UI
|
||||
|
||||
onready var chat_display = $VBox/ChatDisplay
|
||||
onready var chat_input = $VBox/ChatInput
|
||||
onready var leave_button = $VBox/VBox/HBox/LeaveButton
|
||||
onready var join_button = $VBox/VBox/HBox/JoinButton
|
||||
onready var username = $VBox/VBox/HBox/Name
|
||||
|
||||
func display_message(packet): # shout, alert, server_message, user_joined, user_left
|
||||
if packet['type'] == "shout":
|
||||
chat_display.text += packet['name'] + ": " + packet['message'] + "\n"
|
||||
else:
|
||||
chat_display.text += packet['message'] + "\n"
|
||||
|
||||
func join_chat():
|
||||
if !username.text:
|
||||
display_message({'type': "alert", "message": "!!! Enter your username before joining chat."})
|
||||
else:
|
||||
get_parent().join_chat(username.text)
|
||||
chat_input.show()
|
||||
join_button.hide()
|
||||
username.hide()
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventKey and get_parent().chat_name:
|
||||
if event.pressed and event.scancode == KEY_ENTER:
|
||||
get_parent().send_message(chat_input.text)
|
||||
chat_input.text = ""
|
||||
|
||||
func _ready():
|
||||
join_button.connect("button_up", self, "join_chat")
|
||||
@@ -0,0 +1,87 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://UI/Shoutbox/Shoutbox.gd" type="Script" id=1]
|
||||
[ext_resource path="res://UI/Label.gd" type="Script" id=2]
|
||||
[ext_resource path="res://UI/Button.gd" type="Script" id=3]
|
||||
[ext_resource path="res://UI/LineEdit.gd" type="Script" id=4]
|
||||
|
||||
[node name="Shoutbox" type="PanelContainer"]
|
||||
margin_left = 502.0
|
||||
margin_right = 786.0
|
||||
margin_bottom = 586.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="."]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 277.0
|
||||
margin_bottom = 579.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Label" type="Label" parent="VBox"]
|
||||
margin_right = 270.0
|
||||
margin_bottom = 14.0
|
||||
size_flags_horizontal = 3
|
||||
align = 1
|
||||
script = ExtResource( 2 )
|
||||
tl = "sbshou"
|
||||
|
||||
[node name="ChatDisplay" type="TextEdit" parent="VBox"]
|
||||
margin_top = 18.0
|
||||
margin_right = 270.0
|
||||
margin_bottom = 568.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
readonly = true
|
||||
show_line_numbers = true
|
||||
wrap_enabled = true
|
||||
|
||||
[node name="ChatInput" type="LineEdit" parent="VBox"]
|
||||
visible = false
|
||||
margin_top = 520.0
|
||||
margin_right = 270.0
|
||||
margin_bottom = 544.0
|
||||
size_flags_horizontal = 3
|
||||
script = ExtResource( 4 )
|
||||
tl = "sbchin"
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="VBox"]
|
||||
margin_top = 572.0
|
||||
margin_right = 270.0
|
||||
margin_bottom = 572.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="HBox" type="HBoxContainer" parent="VBox/VBox"]
|
||||
margin_right = 270.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Name" type="LineEdit" parent="VBox/VBox/HBox"]
|
||||
visible = false
|
||||
margin_right = 270.0
|
||||
margin_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
expand_to_text_length = true
|
||||
placeholder_text = "Username"
|
||||
|
||||
[node name="JoinButton" type="Button" parent="VBox/VBox/HBox"]
|
||||
visible = false
|
||||
margin_left = 137.0
|
||||
margin_right = 270.0
|
||||
margin_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
text = "join"
|
||||
script = ExtResource( 3 )
|
||||
tl = "sbjoin"
|
||||
|
||||
[node name="LeaveButton" type="Button" parent="VBox/VBox/HBox"]
|
||||
visible = false
|
||||
margin_left = 118.0
|
||||
margin_right = 645.0
|
||||
margin_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Leave"
|
||||
script = ExtResource( 3 )
|
||||
tl = "sbleav"
|
||||
Reference in New Issue
Block a user