part 1 - connection

master
chimchooree 2 years ago
commit a70269e9bc

@ -0,0 +1,3 @@
source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
dest_md5="26ea799ea0a3da9e753b3ebe822e0570"

@ -0,0 +1,41 @@
extends Node
export var websocket_url = "ws://127.0.0.1:8080"
var _client = WebSocketClient.new()
onready var UI = $UI
var chat_name
func join_chat(username):
pass
func send_message(message):
pass
sync func receive_message(packet):
pass
func _ready():
_client.connect("connection_closed", self, "_closed")
_client.connect("connection_error", self, "_error")
_client.connect("connection_established", self, "_connected")
_client.connect("data_received", self, "_on_data_received")
var err = _client.connect_to_url(websocket_url)
if err != OK:
print_debug("Unable to connect")
set_process(false)
func _error(was_clean = false):
print_debug("Error. Clean break? ", was_clean)
func _closed(was_clean = false):
print_debug("Closed. Clean break? ", was_clean)
func _connected(protocol = ""):
print_debug("Connected with protocol ", protocol)
func _on_data_received():
pass
func _process(_delta):
_client.poll()

@ -0,0 +1,61 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Client.gd" type="Script" id=1]
[ext_resource path="res://UI.gd" type="Script" id=2]
[node name="Client" type="Node"]
script = ExtResource( 1 )
[node name="UI" type="PanelContainer" parent="."]
margin_right = 250.0
margin_bottom = 600.0
script = ExtResource( 2 )
[node name="VBox" type="VBoxContainer" parent="UI"]
margin_left = 7.0
margin_top = 7.0
margin_right = 243.0
margin_bottom = 593.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="Title" type="Label" parent="UI/VBox"]
margin_right = 236.0
margin_bottom = 14.0
size_flags_horizontal = 3
size_flags_vertical = 0
text = "Chatbox"
align = 1
[node name="ChatLog" type="TextEdit" parent="UI/VBox"]
margin_top = 18.0
margin_right = 236.0
margin_bottom = 530.0
size_flags_horizontal = 3
size_flags_vertical = 3
show_line_numbers = true
[node name="ChatInput" type="LineEdit" parent="UI/VBox"]
margin_top = 534.0
margin_right = 236.0
margin_bottom = 558.0
size_flags_horizontal = 3
placeholder_text = "Enter your message..."
[node name="HBox" type="HBoxContainer" parent="UI/VBox"]
margin_top = 562.0
margin_right = 236.0
margin_bottom = 586.0
[node name="Name" type="LineEdit" parent="UI/VBox/HBox"]
margin_right = 116.0
margin_bottom = 24.0
size_flags_horizontal = 3
placeholder_text = "Username"
[node name="JoinButton" type="Button" parent="UI/VBox/HBox"]
margin_left = 120.0
margin_right = 236.0
margin_bottom = 24.0
size_flags_horizontal = 3
text = "Join"

21
UI.gd

@ -0,0 +1,21 @@
extends PanelContainer
onready var chat_log = $VBox/ChatLog
onready var chat_input = $VBox/ChatInput
onready var join_button = $VBox/HBox/JoinButton
onready var username = $VBox/HBox/Name
func display_message(packet): # shout, alert, server_message, user_joined, user_left
pass
func join_chat():
pass
func _input(event):
if event is InputEventKey:
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,7 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

@ -0,0 +1,31 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
[application]
config/name="Chat Client"
run/main_scene="res://Client.tscn"
config/icon="res://icon.png"
[display]
window/size/width=250
[gui]
common/drop_mouse_on_gui_input_disabled=true
[physics]
common/enable_pause_aware_picking=true
[rendering]
environment/default_environment="res://default_env.tres"
Loading…
Cancel
Save