aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortpart <tpart120@proton.me>2024-07-25 19:34:55 +0200
committertpart <tpart120@proton.me>2024-07-25 19:34:55 +0200
commit5edf5a9aaed90fbf5b80cb14c4a61b9b5a6ccec8 (patch)
tree105423468e3af55a69a952483089671eff2c3c83
parent2191602fb7a78f952e6523f4a74910d6199f1db6 (diff)
downloadhurrycurry-5edf5a9aaed90fbf5b80cb14c4a61b9b5a6ccec8.tar
hurrycurry-5edf5a9aaed90fbf5b80cb14c4a61b9b5a6ccec8.tar.bz2
hurrycurry-5edf5a9aaed90fbf5b80cb14c4a61b9b5a6ccec8.tar.zst
Refactor main menu scene to fix focus issues
-rw-r--r--client/menu/main.gd85
-rw-r--r--client/menu/main.tscn50
-rw-r--r--client/menu/play.gd105
-rw-r--r--client/menu/play.tscn105
4 files changed, 211 insertions, 134 deletions
diff --git a/client/menu/main.gd b/client/menu/main.gd
index dbb096f1..9b809776 100644
--- a/client/menu/main.gd
+++ b/client/menu/main.gd
@@ -17,24 +17,12 @@
#
extends Menu
-var url_regex: RegEx = RegEx.new()
-
@onready var quit_button = $side/margin/options/first/quit
-@onready var connect_uri = $side/margin/options/second/connect/uri
-@onready var server = $side/margin/options/second/server
-@onready var server_control = $side/margin/options/second/server/control
-@onready var server_connect = $side/margin/options/second/server/connect
-
-@onready var first_menu = $side/margin/options/first
-@onready var second_menu = $side/margin/options/second
func _ready():
super()
- url_regex.compile("^(?:(ws|wss)://)?([^:]+)(?::([0-9]+))?$")
if OS.has_feature("web"):
quit_button.hide()
- server.hide()
- connect_uri.text = Global.get_profile("last_server_url")
Sound.play_music("MainMenu")
func _menu_cover(state):
@@ -46,82 +34,11 @@ func _on_quit_pressed():
func _on_credits_pressed():
submenu("res://menu/credits.tscn")
-func _on_connect_pressed():
- var url = connect_uri.text
- var result := url_regex.search(url)
- if result != null:
- if result.get_string(1) == "":
- url = "ws://" + url
- # only set default port for non-tls websocket connections
- if result.get_string(3) == "" and result.get_string(1) != "wss":
- url = url + ":27032"
- connect_uri.text = url
- Global.set_profile("last_server_url", url)
- connect_to(url)
-
-
-func _on_quick_connect_pressed():
- if OS.has_feature("JavaScript"):
- connect_to(JavaScriptBridge.eval("""
- window.location.protocol.endsWith("s:")
- ? `wss://${window.location.host}/`
- : `ws://${window.location.hostname}:27032/`
- """))
- else:
- connect_to("wss://hurrycurry.metamuffin.org/")
-
-func connect_to(url: String):
- print("Connecting to %s" % url)
- Global.server_url = url
- replace_menu("res://menu/game.tscn")
-
func _on_change_character_pressed():
replace_menu("res://menu/character.tscn")
func _on_settings_pressed():
submenu("res://menu/settings.tscn")
-func _on_server_pressed():
- match Server.state:
- Server.State.RUNNING: Server.stop()
- Server.State.STOPPED: Server.start()
- Server.State.FAILED: Server.start()
-
-func _on_server_connect_pressed():
- connect_to("ws://127.0.0.1:27032/")
-
-func _process(_delta):
- server_control.disabled = false
- server_connect.visible = Server.state == Server.State.RUNNING
- server_control.modulate = Color.WHITE
- match Server.state:
- Server.State.RUNNING:
- server_control.text = tr("Stop Server")
- server_control.modulate = Color.AQUAMARINE
- Server.State.TESTING:
- server_control.text = tr("Server (Testing)")
- server_control.disabled = true
- Server.State.STARTING:
- server_control.text = tr("Server is starting...")
- server_control.disabled = true
- Server.State.STOPPED:
- server_control.text = tr("Start Server")
- Server.State.FAILED:
- server_control.text = tr("Server (Failed)")
- server_control.modulate = Color(1,0.4,0.5)
- server_control.tooltip_text = tr("The server crashed or exited in some way or another.\nGodot's APIs are so bad however, that we really can't know why that happend.\nYou should try starting the server from the command-line.")
- Server.State.UNAVAILABLE:
- server_control.text = tr("Server (Unavailable)")
- server_control.disabled = true
- server_control.tooltip_text = tr("Server binary was not found. Please install the server separately.")
-
-func _on_uri_text_changed(new_text):
- connect_uri.modulate = Color.WHITE if url_regex.search(new_text) else Color.RED
-
func _on_play_pressed():
- first_menu.hide()
- second_menu.show()
-
-func _on_back_pressed():
- first_menu.show()
- second_menu.hide()
+ submenu("res://menu/play.tscn")
diff --git a/client/menu/main.tscn b/client/menu/main.tscn
index 592ad1a9..c903bba5 100644
--- a/client/menu/main.tscn
+++ b/client/menu/main.tscn
@@ -84,58 +84,8 @@ layout_mode = 2
text = "Quit"
alignment = 0
-[node name="second" type="VBoxContainer" parent="side/margin/options"]
-visible = false
-layout_mode = 2
-
-[node name="quick_connect" type="Button" parent="side/margin/options/second"]
-layout_mode = 2
-text = "Quick Connect"
-alignment = 0
-
-[node name="connect" type="HBoxContainer" parent="side/margin/options/second"]
-layout_mode = 2
-
-[node name="uri" type="LineEdit" parent="side/margin/options/second/connect"]
-layout_mode = 2
-size_flags_horizontal = 3
-auto_translate = false
-placeholder_text = "wss://example.org"
-
-[node name="connect" type="Button" parent="side/margin/options/second/connect"]
-layout_mode = 2
-text = "Connect"
-
-[node name="server" type="HBoxContainer" parent="side/margin/options/second"]
-layout_mode = 2
-
-[node name="control" type="Button" parent="side/margin/options/second/server"]
-layout_mode = 2
-size_flags_horizontal = 3
-text = "Server"
-alignment = 0
-
-[node name="connect" type="Button" parent="side/margin/options/second/server"]
-layout_mode = 2
-text = "Connect"
-
-[node name="spacer2" type="Control" parent="side/margin/options/second"]
-custom_minimum_size = Vector2(0, 10)
-layout_mode = 2
-
-[node name="back" type="Button" parent="side/margin/options/second"]
-layout_mode = 2
-text = "Back"
-alignment = 0
-
[connection signal="pressed" from="side/margin/options/first/play" to="." method="_on_play_pressed"]
[connection signal="pressed" from="side/margin/options/first/change_character" to="." method="_on_change_character_pressed"]
[connection signal="pressed" from="side/margin/options/first/settings" to="." method="_on_settings_pressed"]
[connection signal="pressed" from="side/margin/options/first/credits" to="." method="_on_credits_pressed"]
[connection signal="pressed" from="side/margin/options/first/quit" to="." method="_on_quit_pressed"]
-[connection signal="pressed" from="side/margin/options/second/quick_connect" to="." method="_on_quick_connect_pressed"]
-[connection signal="text_changed" from="side/margin/options/second/connect/uri" to="." method="_on_uri_text_changed"]
-[connection signal="pressed" from="side/margin/options/second/connect/connect" to="." method="_on_connect_pressed"]
-[connection signal="pressed" from="side/margin/options/second/server/control" to="." method="_on_server_pressed"]
-[connection signal="pressed" from="side/margin/options/second/server/connect" to="." method="_on_server_connect_pressed"]
-[connection signal="pressed" from="side/margin/options/second/back" to="." method="_on_back_pressed"]
diff --git a/client/menu/play.gd b/client/menu/play.gd
new file mode 100644
index 00000000..61b777d1
--- /dev/null
+++ b/client/menu/play.gd
@@ -0,0 +1,105 @@
+# Hurry Curry! - a game about cooking
+# Copyright 2024 metamuffin
+# Copyright 2024 nokoe
+# Copyright 2024 BigBrotherNii
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, version 3 of the License only.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+extends Menu
+
+var url_regex: RegEx = RegEx.new()
+
+@onready var connect_uri = $side/margin/options/second/connect/uri
+@onready var server = $side/margin/options/second/server
+@onready var server_control = $side/margin/options/second/server/control
+@onready var server_connect = $side/margin/options/second/server/connect
+
+func _ready():
+ super()
+ url_regex.compile("^(?:(ws|wss)://)?([^:]+)(?::([0-9]+))?$")
+ if OS.has_feature("web"):
+ server.hide()
+ connect_uri.text = Global.get_profile("last_server_url")
+ Sound.play_music("MainMenu")
+
+func _menu_cover(state):
+ $side.visible = not state
+
+func _on_connect_pressed():
+ var url = connect_uri.text
+ var result := url_regex.search(url)
+ if result != null:
+ if result.get_string(1) == "":
+ url = "ws://" + url
+ # only set default port for non-tls websocket connections
+ if result.get_string(3) == "" and result.get_string(1) != "wss":
+ url = url + ":27032"
+ connect_uri.text = url
+ Global.set_profile("last_server_url", url)
+ connect_to(url)
+
+
+func _on_quick_connect_pressed():
+ if OS.has_feature("JavaScript"):
+ connect_to(JavaScriptBridge.eval("""
+ window.location.protocol.endsWith("s:")
+ ? `wss://${window.location.host}/`
+ : `ws://${window.location.hostname}:27032/`
+ """))
+ else:
+ connect_to("wss://hurrycurry.metamuffin.org/")
+
+func connect_to(url: String):
+ print("Connecting to %s" % url)
+ Global.server_url = url
+ get_parent().replace_menu("res://menu/game.tscn")
+
+func _on_server_pressed():
+ match Server.state:
+ Server.State.RUNNING: Server.stop()
+ Server.State.STOPPED: Server.start()
+ Server.State.FAILED: Server.start()
+
+func _on_server_connect_pressed():
+ connect_to("ws://127.0.0.1:27032/")
+
+func _process(_delta):
+ server_control.disabled = false
+ server_connect.visible = Server.state == Server.State.RUNNING
+ server_control.modulate = Color.WHITE
+ match Server.state:
+ Server.State.RUNNING:
+ server_control.text = tr("Stop Server")
+ server_control.modulate = Color.AQUAMARINE
+ Server.State.TESTING:
+ server_control.text = tr("Server (Testing)")
+ server_control.disabled = true
+ Server.State.STARTING:
+ server_control.text = tr("Server is starting...")
+ server_control.disabled = true
+ Server.State.STOPPED:
+ server_control.text = tr("Start Server")
+ Server.State.FAILED:
+ server_control.text = tr("Server (Failed)")
+ server_control.modulate = Color(1,0.4,0.5)
+ server_control.tooltip_text = tr("The server crashed or exited in some way or another.\nGodot's APIs are so bad however, that we really can't know why that happend.\nYou should try starting the server from the command-line.")
+ Server.State.UNAVAILABLE:
+ server_control.text = tr("Server (Unavailable)")
+ server_control.disabled = true
+ server_control.tooltip_text = tr("Server binary was not found. Please install the server separately.")
+
+func _on_uri_text_changed(new_text):
+ connect_uri.modulate = Color.WHITE if url_regex.search(new_text) else Color.RED
+
+func _on_back_pressed():
+ exit()
diff --git a/client/menu/play.tscn b/client/menu/play.tscn
new file mode 100644
index 00000000..cc98ae2a
--- /dev/null
+++ b/client/menu/play.tscn
@@ -0,0 +1,105 @@
+[gd_scene load_steps=7 format=3 uid="uid://c8url5fpttbem"]
+
+[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_cckds"]
+[ext_resource type="Script" path="res://menu/play.gd" id="2_phxx0"]
+[ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="4_iobxo"]
+[ext_resource type="FontFile" uid="uid://bo4vh5xkpvrh1" path="res://menu/theme/font-sansita-swashed.woff2" id="5_ojpbf"]
+
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ukani"]
+
+[sub_resource type="FontVariation" id="FontVariation_htgmg"]
+base_font = ExtResource("5_ojpbf")
+variation_embolden = 0.5
+
+[node name="PlayMenu" type="Control"]
+layout_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+theme = ExtResource("1_cckds")
+script = ExtResource("2_phxx0")
+support_anim = false
+
+[node name="side" type="PanelContainer" parent="."]
+material = ExtResource("4_iobxo")
+layout_mode = 1
+anchors_preset = 9
+anchor_bottom = 1.0
+offset_right = 294.0
+grow_vertical = 2
+theme_override_styles/panel = SubResource("StyleBoxFlat_ukani")
+
+[node name="margin" type="MarginContainer" parent="side"]
+layout_mode = 2
+theme_override_constants/margin_left = 20
+theme_override_constants/margin_top = 20
+theme_override_constants/margin_right = 20
+theme_override_constants/margin_bottom = 20
+
+[node name="options" type="VBoxContainer" parent="side/margin"]
+layout_mode = 2
+
+[node name="title" type="Label" parent="side/margin/options"]
+layout_mode = 2
+auto_translate = false
+theme_override_colors/font_outline_color = Color(0.566408, 0.208917, 0.266045, 1)
+theme_override_constants/outline_size = 10
+theme_override_fonts/font = SubResource("FontVariation_htgmg")
+theme_override_font_sizes/font_size = 48
+text = "Hurry Curry!"
+
+[node name="spacer" type="Control" parent="side/margin/options"]
+custom_minimum_size = Vector2(0, 10)
+layout_mode = 2
+
+[node name="second" type="VBoxContainer" parent="side/margin/options"]
+layout_mode = 2
+
+[node name="quick_connect" type="Button" parent="side/margin/options/second"]
+layout_mode = 2
+text = "Quick Connect"
+alignment = 0
+
+[node name="connect" type="HBoxContainer" parent="side/margin/options/second"]
+layout_mode = 2
+
+[node name="uri" type="LineEdit" parent="side/margin/options/second/connect"]
+layout_mode = 2
+size_flags_horizontal = 3
+auto_translate = false
+placeholder_text = "wss://example.org"
+
+[node name="connect" type="Button" parent="side/margin/options/second/connect"]
+layout_mode = 2
+text = "Connect"
+
+[node name="server" type="HBoxContainer" parent="side/margin/options/second"]
+layout_mode = 2
+
+[node name="control" type="Button" parent="side/margin/options/second/server"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "Server"
+alignment = 0
+
+[node name="connect" type="Button" parent="side/margin/options/second/server"]
+layout_mode = 2
+text = "Connect"
+
+[node name="spacer2" type="Control" parent="side/margin/options/second"]
+custom_minimum_size = Vector2(0, 10)
+layout_mode = 2
+
+[node name="back" type="Button" parent="side/margin/options/second"]
+layout_mode = 2
+text = "Back"
+alignment = 0
+
+[connection signal="pressed" from="side/margin/options/second/quick_connect" to="." method="_on_quick_connect_pressed"]
+[connection signal="text_changed" from="side/margin/options/second/connect/uri" to="." method="_on_uri_text_changed"]
+[connection signal="pressed" from="side/margin/options/second/connect/connect" to="." method="_on_connect_pressed"]
+[connection signal="pressed" from="side/margin/options/second/server/control" to="." method="_on_server_pressed"]
+[connection signal="pressed" from="side/margin/options/second/server/connect" to="." method="_on_server_connect_pressed"]
+[connection signal="pressed" from="side/margin/options/second/back" to="." method="_on_back_pressed"]