| -rw-r--r-- | Chat.gd | 38 | ||||
| -rw-r--r-- | WS.gd | 16 | ||||
| -rw-r--r-- | WS.tscn | 1 | ||||
| -rw-r--r-- | matrix.gd | 29 | ||||
| -rw-r--r-- | project.godot | 5 | ||||
| -rw-r--r-- | theme.tres | 19 |
6 files changed, 86 insertions, 22 deletions
@@ -7,12 +7,25 @@ onready var scroller = find_node("scroller") onready var tween = find_node("Tween") onready var scrollbar = scroller.get_v_scrollbar() +const server_says = "[b]server[color=#f0e67e]:[/color][/b] " + func _ready(): add_label( - "[b]server[color=#f0e67e]:[/color] [matrix]welcome to[/matrix] [rainbow freq=.3 sat=.7][shake rate=20 level=25]room 2!", + ( + "%s[b][matrix]welcome to [/matrix][rainbow freq=.3 sat=.7][shake rate=20 level=25]room 2!" + % server_says + ), "server" ) + add_label( + ( + "%s[b][tornado freq=5 radius=10] you can use [/tornado][wave amp=20 freq=20][url=https://en.wikipedia.org/wiki/BBCode]bbcode" + % server_says + ), + "howto", + Vector2(1000, 80) + ) func _on_Main_recieved(data): @@ -20,18 +33,30 @@ func _on_Main_recieved(data): add_label(string) -func add_label(bbcode: String, name = "richtextlabel"): +func add_label(bbcode: String, name = "richtextlabel", size = Vector2(1000, 40)) -> RichTextLabel: var l = RichTextLabel.new() l.name = name - l.rect_min_size = Vector2(1000, 40) + l.rect_min_size = size l.install_effect(RichTextMatrix.new()) l.bbcode_enabled = true + l.scroll_active = false labels.add_child(l) - l.append_bbcode(bbcode) + l.connect("meta_clicked", self, "open_url") + l.bbcode_text = bbcode + l.fit_content_height = true tween.interpolate_property( scrollbar, "value", scrollbar.value, scrollbar.max_value, .5, Tween.TRANS_BOUNCE ) tween.start() + return l + + +func open_url(meta): + var err = OS.shell_open(meta) + if err == OK: + print("Opened link '%s' successfully!" % meta) + else: + printerr("Failed opening the link '%s'!" % meta) func _on_text_entered(t): @@ -51,3 +76,8 @@ func _on_whoami_text_entered(t): whoami.text = "Anonymous" t = t.strip_edges() whoami.text = t + + +func _on_Main_err(err: String): + add_label("[b][color=#ff6347]error:[i] %s" % err) + text.editable = false @@ -5,6 +5,9 @@ var ws = WebSocketClient.new() var timer = Timer.new() signal recieved(data) +signal err(err) + +const HEADERS = {"chat": "C", "ping": "P"} func _ready(): @@ -15,7 +18,11 @@ func _ready(): ws.connect("connection_closed", self, "_connection_closed") ws.connect("connection_error", self, "_connection_error") ws.connect("data_received", self, "_data_recieved") + ws.connect("connection_failed", self, "connectwebsocket") + connectwebsocket() + +func connectwebsocket(): var url = "https://chat-server-gd.herokuapp.com/" print("Connecting to " + url) ws.connect_to_url(url) @@ -30,17 +37,18 @@ func _connection_established(protocol): func _connection_closed(_err): - print("Connection closed") + emit_signal("err", "Connection closed") func _connection_error(): - print("Connection error") + emit_signal("err", "Connection error") func _data_recieved(): var text = ws.get_peer(1).get_var() - emit_signal("recieved", text) - print("recieved %s" % text.text) + if text.header == HEADERS.chat: + emit_signal("recieved", text) + print("recieved %s" % text.text) func _process(_delta): @@ -101,6 +101,7 @@ text = "send" [node name="Tween" type="Tween" parent="Chat"] +[connection signal="err" from="." to="Chat" method="_on_Main_err"] [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"] @@ -1,28 +1,31 @@ -tool extends RichTextEffect +tool +extends RichTextEffect class_name RichTextMatrix var bbcode = "matrix" + func _init(): resource_name = "RichTextMatrix" -func _process_custom_fx(char_fx : CharFXTransform) -> bool: + +func _process_custom_fx(char_fx: CharFXTransform) -> bool: var clear_time = char_fx.env.get("clean", 2.0) var dirty_time = char_fx.env.get("dirty", 1.0) var text_span = char_fx.env.get("span", 50) - + var value = char_fx.character - - var matrix_time = fmod(char_fx.elapsed_time + (char_fx.absolute_index / float(text_span)), \ - clear_time + dirty_time) - - matrix_time = 0.0 if matrix_time < clear_time else \ - (matrix_time - clear_time)/dirty_time - - if( value >= 65 && value < 126 && matrix_time > 0.0 ): + + var matrix_time = fmod( + char_fx.elapsed_time + (char_fx.absolute_index / float(text_span)), clear_time + dirty_time + ) + + matrix_time = 0.0 if matrix_time < clear_time else (matrix_time - clear_time) / dirty_time + + if value >= 65 && value < 126 && matrix_time > 0.0: value -= 65 - value = value + int((1 * matrix_time * (126-65))) + value = value + int(1 * matrix_time * (126 - 65)) value %= (126 - 65) value += 65 char_fx.character = value - return true
\ No newline at end of file + return true diff --git a/project.godot b/project.godot index 77f90ef..ed52250 100644 --- a/project.godot +++ b/project.godot @@ -30,6 +30,10 @@ config/name="room2" run/main_scene="res://WS.tscn" config/icon="res://icon.png" +[debug] + +gdscript/warnings/return_value_discarded=false + [display] window/stretch/mode="2d" @@ -37,4 +41,5 @@ window/stretch/aspect="expand" [rendering] +quality/driver/driver_name="GLES2" environment/default_environment="res://default_env.tres" @@ -1,4 +1,4 @@ -[gd_resource type="Theme" load_steps=9 format=2] +[gd_resource type="Theme" load_steps=13 format=2] [ext_resource path="res://bg.tres" type="StyleBox" id=1] [ext_resource path="res://verdana-bold.tres" type="DynamicFont" id=2] @@ -8,6 +8,18 @@ [sub_resource type="StyleBoxFlat" id=4] bg_color = Color( 0.196078, 0.309804, 0.396078, 1 ) +[sub_resource type="StyleBoxFlat" id=6] +bg_color = Color( 0.827451, 0.419608, 0.419608, 1 ) + +[sub_resource type="StyleBoxFlat" id=7] +bg_color = Color( 0.847059, 0.368627, 0.368627, 1 ) + +[sub_resource type="StyleBoxFlat" id=5] +content_margin_top = 10.0 + +[sub_resource type="StyleBoxFlat" id=8] +bg_color = Color( 0.521569, 0.521569, 0.521569, 1 ) + [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.145098, 0.117647, 0.117647, 1 ) @@ -22,6 +34,11 @@ Button/styles/focus = SubResource( 4 ) Button/styles/hover = SubResource( 4 ) Button/styles/normal = ExtResource( 1 ) Button/styles/pressed = SubResource( 4 ) +HScrollBar/styles/grabber = SubResource( 6 ) +HScrollBar/styles/grabber_highlight = SubResource( 7 ) +HScrollBar/styles/grabber_pressed = SubResource( 7 ) +HScrollBar/styles/scroll = SubResource( 5 ) +HScrollBar/styles/scroll_focus = SubResource( 8 ) LineEdit/colors/font_color = Color( 1, 1, 1, 1 ) LineEdit/styles/focus = SubResource( 1 ) LineEdit/styles/normal = SubResource( 2 ) |