bold text and rainbow stuffs
bendn 2022-05-06
parent 315c1ef · commit 6cfaa60
-rw-r--r--Chat.gd28
-rw-r--r--WS.gd30
-rw-r--r--WS.tscn72
-rw-r--r--project.godot15
-rw-r--r--theme.tres11
-rw-r--r--verdana-bold-italic.ttfbin0 -> 226848 bytes
-rw-r--r--verdana-bold.tres (renamed from verdana.tres)0
-rw-r--r--verdana-italicbold.tres7
-rw-r--r--verdana-normal.tres7
-rw-r--r--verdana.ttfbin0 -> 149752 bytes
10 files changed, 125 insertions, 45 deletions
diff --git a/Chat.gd b/Chat.gd
index 57a6080..9caf8ad 100644
--- a/Chat.gd
+++ b/Chat.gd
@@ -9,13 +9,24 @@ onready var scrollbar = scroller.get_v_scrollbar()
func _ready():
- text.context_menu_enabled = false
+ add_label(
+ "[b]server[color=#f0e67e]:[/color][/b] [b] welcome to [rainbow freq=.3 sat=.7][shake rate=20 level=25]room 2![/shake][/rainbow]",
+ "server"
+ )
func _on_Main_recieved(data):
- var l = Label.new()
- l.text = data
+ var string = "[b]%s[color=#f0e67e]:[/color][/b] %s" % [data.who, data.text]
+ add_label(string)
+
+
+func add_label(bbcode: String, name = "richtextlabel"):
+ var l = RichTextLabel.new()
+ l.name = name
labels.add_child(l)
+ l.rect_min_size = Vector2(1000, 40)
+ l.bbcode_enabled = true
+ l.append_bbcode(bbcode)
tween.interpolate_property(
scrollbar, "value", scrollbar.value, scrollbar.max_value, .5, Tween.TRANS_BOUNCE
)
@@ -23,12 +34,19 @@ func _on_Main_recieved(data):
func _on_text_entered(t):
- t = t.strip_edges()
if !t:
return
+ t = t.strip_edges()
text.text = ""
- get_parent().send_packet(whoami.text + ": " + t)
+ get_parent().send_packet({"who": whoami.text, "text": t, "header": "C"})
func _on_send_pressed():
_on_text_entered(text.text)
+
+
+func _on_whoami_text_entered(t):
+ if !t:
+ whoami.text = "Anonymous"
+ t = t.strip_edges()
+ whoami.text = t
diff --git a/WS.gd b/WS.gd
index 5559493..e04bf78 100644
--- a/WS.gd
+++ b/WS.gd
@@ -1,23 +1,32 @@
extends Node
+class_name Network
-var ws = null
+var ws = WebSocketClient.new()
+var timer = Timer.new()
signal recieved(data)
func _ready():
- ws = WebSocketClient.new()
+ add_child(timer)
+ timer.start(5)
+ timer.connect("timeout", self, "ping")
ws.connect("connection_established", self, "_connection_established")
ws.connect("connection_closed", self, "_connection_closed")
ws.connect("connection_error", self, "_connection_error")
+ ws.connect("data_received", self, "_data_recieved")
var url = "https://chat-server-gd.herokuapp.com/"
print("Connecting to " + url)
ws.connect_to_url(url)
+func ping():
+ send_packet({"header": "P"})
+
+
func _connection_established(protocol):
- print("Connection established with protocol: ", protocol)
+ print("Connection established ", protocol)
func _connection_closed(_err):
@@ -28,19 +37,20 @@ func _connection_error():
print("Connection error")
+func _data_recieved():
+ var text = ws.get_peer(1).get_var()
+ emit_signal("recieved", text)
+ print("recieved %s" % text.text)
+
+
func _process(_delta):
if (
ws.get_connection_status() == ws.CONNECTION_CONNECTING
|| ws.get_connection_status() == ws.CONNECTION_CONNECTED
):
ws.poll()
- if ws.get_peer(1).is_connected_to_host():
- if ws.get_peer(1).get_available_packet_count() > 0:
- var text = ws.get_peer(1).get_var()
- emit_signal("recieved", text.value)
- print("recieved %s" % text.value)
-func send_packet(variant: String):
- if ws.get_peer(1).is_connected_to_host():
+func send_packet(variant):
+ if ws.get_peer(1).is_connected_to_host() and variant.header:
ws.get_peer(1).put_var(variant)
diff --git a/WS.tscn b/WS.tscn
index dbc11e5..5450672 100644
--- a/WS.tscn
+++ b/WS.tscn
@@ -16,64 +16,83 @@ script = ExtResource( 2 )
[node name="v" type="VBoxContainer" parent="Chat"]
anchor_right = 1.0
anchor_bottom = 1.0
-margin_left = 32.0
-margin_top = 64.0
-margin_right = -32.0
-margin_bottom = -60.0
custom_constants/separation = 0
[node name="h" type="HBoxContainer" parent="Chat/v"]
-margin_right = 960.0
+margin_right = 1024.0
margin_bottom = 38.0
+custom_constants/separation = 0
+
+[node name="Panel" type="Panel" parent="Chat/v/h"]
+margin_right = 10.0
+margin_bottom = 38.0
+rect_min_size = Vector2( 10, 0 )
[node name="whoami" type="LineEdit" parent="Chat/v/h"]
-margin_right = 200.0
+margin_left = 10.0
+margin_right = 230.0
margin_bottom = 38.0
-rect_min_size = Vector2( 200, 0 )
-text = "whoami"
+rect_min_size = Vector2( 220, 0 )
+text = "Anonymous"
max_length = 30
expand_to_text_length = true
-placeholder_text = "whoami"
+placeholder_text = "Anonymous"
caret_blink = true
caret_blink_speed = 0.5
-[node name="Label" type="Label" parent="Chat/v/h"]
-margin_left = 204.0
-margin_right = 324.0
+[node name="Panel2" type="Panel" parent="Chat/v/h"]
+margin_left = 230.0
+margin_right = 370.0
margin_bottom = 38.0
+rect_min_size = Vector2( 140, 0 )
+
+[node name="Label" type="Label" parent="Chat/v/h/Panel2"]
+anchor_right = 1.0
+anchor_bottom = 1.0
text = "room 2"
+align = 1
+valign = 1
[node name="p" type="Panel" parent="Chat/v"]
margin_top = 38.0
-margin_right = 960.0
-margin_bottom = 438.0
+margin_right = 1024.0
+margin_bottom = 562.0
rect_min_size = Vector2( 896, 400 )
+size_flags_vertical = 3
[node name="scroller" type="ScrollContainer" parent="Chat/v/p"]
-margin_right = 896.0
-margin_bottom = 400.0
-rect_min_size = Vector2( 0, 400 )
+anchor_right = 1.0
+anchor_bottom = 1.0
+margin_left = 10.0
+rect_min_size = Vector2( 1000, 400 )
[node name="labels" type="VBoxContainer" parent="Chat/v/p/scroller"]
[node name="h2" type="HBoxContainer" parent="Chat/v"]
-margin_top = 438.0
-margin_right = 960.0
-margin_bottom = 476.0
+margin_top = 562.0
+margin_right = 1024.0
+margin_bottom = 600.0
custom_constants/separation = 0
+[node name="Panel" type="Panel" parent="Chat/v/h2"]
+margin_right = 10.0
+margin_bottom = 38.0
+rect_min_size = Vector2( 10, 0 )
+
[node name="text" type="LineEdit" parent="Chat/v/h2"]
-margin_right = 800.0
+margin_left = 10.0
+margin_right = 900.0
margin_bottom = 38.0
-rect_min_size = Vector2( 800, 0 )
-max_length = 27
-placeholder_text = "send message"
+rect_min_size = Vector2( 890, 0 )
+max_length = 400
+context_menu_enabled = false
+placeholder_text = "message body goes here"
caret_blink = true
caret_blink_speed = 0.5
[node name="send" type="Button" parent="Chat/v/h2"]
-margin_left = 800.0
-margin_right = 960.0
+margin_left = 900.0
+margin_right = 1024.0
margin_bottom = 38.0
focus_mode = 0
size_flags_horizontal = 3
@@ -83,5 +102,6 @@ text = "send"
[node name="Tween" type="Tween" parent="Chat"]
[connection signal="recieved" from="." to="Chat" method="_on_Main_recieved"]
+[connection signal="text_entered" from="Chat/v/h/whoami" to="Chat" method="_on_whoami_text_entered"]
[connection signal="text_entered" from="Chat/v/h2/text" to="Chat" method="_on_text_entered"]
[connection signal="pressed" from="Chat/v/h2/send" to="Chat" method="_on_send_pressed"]
diff --git a/project.godot b/project.godot
index 70ae54f..b9a6c69 100644
--- a/project.godot
+++ b/project.godot
@@ -8,16 +8,27 @@
config_version=4
-_global_script_classes=[ ]
+_global_script_classes=[ {
+"base": "Node",
+"class": "Network",
+"language": "GDScript",
+"path": "res://WS.gd"
+} ]
_global_script_class_icons={
+"Network": ""
}
[application]
-config/name="gd-com-websocket-basic"
+config/name="chat app"
run/main_scene="res://WS.tscn"
config/icon="res://icon.png"
+[display]
+
+window/stretch/mode="2d"
+window/stretch/aspect="expand"
+
[rendering]
environment/default_environment="res://default_env.tres"
diff --git a/theme.tres b/theme.tres
index 48e0503..694285f 100644
--- a/theme.tres
+++ b/theme.tres
@@ -1,7 +1,9 @@
-[gd_resource type="Theme" load_steps=7 format=2]
+[gd_resource type="Theme" load_steps=9 format=2]
[ext_resource path="res://bg.tres" type="StyleBox" id=1]
-[ext_resource path="res://verdana.tres" type="DynamicFont" id=2]
+[ext_resource path="res://verdana-bold.tres" type="DynamicFont" id=2]
+[ext_resource path="res://verdana-normal.tres" type="DynamicFont" id=3]
+[ext_resource path="res://verdana-italicbold.tres" type="DynamicFont" id=4]
[sub_resource type="StyleBoxFlat" id=4]
bg_color = Color( 0.196078, 0.309804, 0.396078, 1 )
@@ -24,4 +26,9 @@ LineEdit/colors/font_color = Color( 1, 1, 1, 1 )
LineEdit/styles/focus = SubResource( 1 )
LineEdit/styles/normal = SubResource( 2 )
Panel/styles/panel = ExtResource( 1 )
+RichTextLabel/fonts/bold_font = ExtResource( 2 )
+RichTextLabel/fonts/bold_italics_font = ExtResource( 4 )
+RichTextLabel/fonts/italics_font = ExtResource( 4 )
+RichTextLabel/fonts/mono_font = ExtResource( 3 )
+RichTextLabel/fonts/normal_font = ExtResource( 3 )
VScrollBar/styles/scroll = SubResource( 3 )
diff --git a/verdana-bold-italic.ttf b/verdana-bold-italic.ttf
new file mode 100644
index 0000000..0a84b68
--- /dev/null
+++ b/verdana-bold-italic.ttf
Binary files differ
diff --git a/verdana.tres b/verdana-bold.tres
index d8abd0f..d8abd0f 100644
--- a/verdana.tres
+++ b/verdana-bold.tres
diff --git a/verdana-italicbold.tres b/verdana-italicbold.tres
new file mode 100644
index 0000000..abae217
--- /dev/null
+++ b/verdana-italicbold.tres
@@ -0,0 +1,7 @@
+[gd_resource type="DynamicFont" load_steps=2 format=2]
+
+[ext_resource path="res://verdana-bold-italic.ttf" type="DynamicFontData" id=1]
+
+[resource]
+size = 30
+font_data = ExtResource( 1 )
diff --git a/verdana-normal.tres b/verdana-normal.tres
new file mode 100644
index 0000000..29414be
--- /dev/null
+++ b/verdana-normal.tres
@@ -0,0 +1,7 @@
+[gd_resource type="DynamicFont" load_steps=2 format=2]
+
+[ext_resource path="res://verdana.ttf" type="DynamicFontData" id=1]
+
+[resource]
+size = 30
+font_data = ExtResource( 1 )
diff --git a/verdana.ttf b/verdana.ttf
new file mode 100644
index 0000000..aa4422f
--- /dev/null
+++ b/verdana.ttf
Binary files differ