diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-01 15:46:13 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-01 15:46:13 +0200 |
commit | 69cce2c92e067595d862c479104df6e966a1e8ee (patch) | |
tree | 33c5f8ca6993f4d8fdc38516ca7684406eb66e1d /client | |
parent | 1e28d68b1fc17a95b0dda305633be2016b692836 (diff) | |
download | hurrycurry-69cce2c92e067595d862c479104df6e966a1e8ee.tar hurrycurry-69cce2c92e067595d862c479104df6e966a1e8ee.tar.bz2 hurrycurry-69cce2c92e067595d862c479104df6e966a1e8ee.tar.zst |
refactor menu system yet again
Diffstat (limited to 'client')
-rw-r--r-- | client/audio/sound.gd | 3 | ||||
-rw-r--r-- | client/game.gd | 9 | ||||
-rw-r--r-- | client/game.tscn | 7 | ||||
-rw-r--r-- | client/global.gd | 27 | ||||
-rw-r--r-- | client/menu/character.gd (renamed from client/menu/character_menu.gd) | 7 | ||||
-rw-r--r-- | client/menu/character.tscn (renamed from client/menu/character_menu.tscn) | 2 | ||||
-rw-r--r-- | client/menu/credits.gd (renamed from client/menu/credits_menu.gd) | 8 | ||||
-rw-r--r-- | client/menu/credits.tscn (renamed from client/menu/credits_menu.tscn) | 12 | ||||
-rw-r--r-- | client/menu/entry.gd | 29 | ||||
-rw-r--r-- | client/menu/entry.tscn | 12 | ||||
-rw-r--r-- | client/menu/error.gd | 8 | ||||
-rw-r--r-- | client/menu/error.tscn (renamed from client/menu/error_menu.tscn) | 2 | ||||
-rw-r--r-- | client/menu/error_menu.gd | 8 | ||||
-rw-r--r-- | client/menu/game.gd | 8 | ||||
-rw-r--r-- | client/menu/game.tscn | 16 | ||||
-rw-r--r-- | client/menu/ingame.gd | 35 | ||||
-rw-r--r-- | client/menu/ingame.tscn (renamed from client/menu/ingame_menu.tscn) | 29 | ||||
-rw-r--r-- | client/menu/ingame_menu.gd | 27 | ||||
-rw-r--r-- | client/menu/main.gd (renamed from client/menu/main_menu.gd) | 24 | ||||
-rw-r--r-- | client/menu/main.tscn (renamed from client/menu/main_menu.tscn) | 21 | ||||
-rw-r--r-- | client/menu/menu.gd | 89 | ||||
-rw-r--r-- | client/menu/menu.tscn | 8 | ||||
-rw-r--r-- | client/menu/menu_manager.gd | 68 | ||||
-rw-r--r-- | client/menu/menu_manager.tscn | 34 | ||||
-rw-r--r-- | client/menu/scene_transition.gd | 58 | ||||
-rw-r--r-- | client/menu/scene_transition.tscn | 59 | ||||
-rw-r--r-- | client/menu/settings.gd (renamed from client/menu/settings_menu.gd) | 9 | ||||
-rw-r--r-- | client/menu/settings.tscn (renamed from client/menu/settings_menu.tscn) | 2 | ||||
-rw-r--r-- | client/menu/setup.gd (renamed from client/menu/setup_menu.gd) | 0 | ||||
-rw-r--r-- | client/menu/setup.tscn (renamed from client/menu/setup_menu.tscn) | 2 | ||||
-rw-r--r-- | client/player/player.gd | 1 | ||||
-rw-r--r-- | client/project.godot | 2 |
32 files changed, 313 insertions, 313 deletions
diff --git a/client/audio/sound.gd b/client/audio/sound.gd index ddb610c5..6a562d75 100644 --- a/client/audio/sound.gd +++ b/client/audio/sound.gd @@ -10,9 +10,6 @@ func play_hover(): hover_sound.play() func play_hover_maybe(element): - if Global.focus_auto_changed: - Global.focus_auto_changed = false - return if element is Button: if element.is_hovered(): return diff --git a/client/game.gd b/client/game.gd index 79db16ea..fcab85dd 100644 --- a/client/game.gd +++ b/client/game.gd @@ -22,7 +22,6 @@ extends Node3D @onready var map: Map = $Map @onready var marker: Marker = $Marker @onready var environment = $WorldEnvironment -@onready var transition: SceneTransition = $SceneTransition var player_id: int = -1 var item_names: Array = [] @@ -43,7 +42,7 @@ func _ready(): mp.connection_closed.connect(func(reason: String): Global.error_message = reason; - $SceneTransition.instant_to("res://menu/error_menu.tscn") + get_parent().replace_menu("res://menu/error_menu.tscn") ) mp.init.connect(func(player_id_: int): player_id = player_id_) @@ -175,13 +174,12 @@ func _ready(): mp.set_ingame.connect(func (state): if state: - await transition.fade_out() map.gi_bake() - await transition.fade_in() + await get_parent().menu_anim_open() map.autobake = true else: map.autobake = false - await transition.fade_out() + await get_parent().menu_anim_exit() ) mp.score.connect($Overlay.update) @@ -202,4 +200,3 @@ func get_tile_interactive(pos: Vector2i) -> bool: func set_tile(tile: Vector2i, kind = null, neighbors = null): if neighbors != null: neighbors = neighbors.map(func (x): return tile_names[x] if x != null else null) map.set_tile(tile, tile_names[kind], neighbors) - diff --git a/client/game.tscn b/client/game.tscn index 492176fc..b44974b2 100644 --- a/client/game.tscn +++ b/client/game.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=11 format=3 uid="uid://c6krh36hoqfg8"] +[gd_scene load_steps=10 format=3 uid="uid://c6krh36hoqfg8"] [ext_resource type="Script" path="res://game.gd" id="1_sftfn"] [ext_resource type="PackedScene" uid="uid://b31mlnao6ybt8" path="res://player/follow_camera.tscn" id="2_s8y6o"] [ext_resource type="PackedScene" uid="uid://c0euiv7duqfp4" path="res://player/marker.tscn" id="4_igl0o"] -[ext_resource type="PackedScene" uid="uid://bg2d78ycorcqk" path="res://menu/scene_transition.tscn" id="5_yg6cl"] [ext_resource type="Script" path="res://multiplayer.gd" id="6_fbxu8"] [ext_resource type="PackedScene" uid="uid://b4gone8fu53r7" path="res://map/map.tscn" id="6_prg6t"] [ext_resource type="PackedScene" uid="uid://bpikve6wlsjfl" path="res://menu/overlay.tscn" id="7_7xrr6"] @@ -48,7 +47,3 @@ visible = false [node name="Overlay" parent="." instance=ExtResource("7_7xrr6")] offset_left = -280.0 offset_bottom = 102.0 - -[node name="SceneTransition" parent="." instance=ExtResource("5_yg6cl")] -ingame = true -auto_fade_in = false diff --git a/client/global.gd b/client/global.gd index e756fcfe..ca0a9603 100644 --- a/client/global.gd +++ b/client/global.gd @@ -129,16 +129,15 @@ var settings: Dictionary var server_url = "" var error_message = "" -var focus_auto_changed := false - -var fade_next := false # Set true when transitioning from another scene (fade in requried) - func _init(): profile = load_dict("user://profile", default_profile) settings = load_dict("user://settings", default_settings) update_fullscreen() update_language() +func _ready(): + get_viewport().gui_focus_changed.connect(Sound.play_hover_maybe) + func _input(event): if Input.is_action_just_pressed("fullscreen"): Global.set_setting("fullscreen", not Global.get_setting("fullscreen")) @@ -187,26 +186,6 @@ func load_dict(path: String, default: Dictionary) -> Dictionary: func on_vulkan() -> bool: return ProjectSettings.get_setting("rendering/rendering_device/driver") == "vulkan" -func focus_first_button(node: Node) -> bool: - focus_auto_changed = true - - if node is Button: - node.grab_focus() - print("Node %s (%s) was selected for focus" % [node.name, node]) - return true - for c in node.get_children(): - if focus_first_button(c): - return true - return false - -func connect_button_sounds(node: Node): - if node is Button: - node.pressed.connect(Sound.play_click) - if node is Button or node is LineEdit or node is Slider: - node.mouse_entered.connect(Sound.play_hover) - for c in node.get_children(): - connect_button_sounds(c) - func add_missing_keys(dict: Dictionary, reference: Dictionary): for k in reference.keys(): if !dict.has(k): diff --git a/client/menu/character_menu.gd b/client/menu/character.gd index 8c42a404..b6999acd 100644 --- a/client/menu/character_menu.gd +++ b/client/menu/character.gd @@ -13,7 +13,7 @@ # 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 Control +extends Menu @onready var character: Character = $Node3D/Character @onready var num_hairstyles := character.hairstyles.keys().size() @@ -22,9 +22,9 @@ extends Control @onready var username_edit = $VBoxContainer/top_panel/a/username func _ready(): + super() $VBoxContainer/top_panel/a/username.text = Global.profile["username"] character.select_hairstyle(Global.profile["character"]) - Global.focus_first_button(self) init_map() func init_map(): @@ -63,8 +63,7 @@ func _on_back_pressed(): Global.profile["username"] = username_edit.text Global.save_profile() - Global.fade_next = true - $SceneTransition.transition_to("res://menu/menu_manager.tscn") + replace_menu("res://menu/main.tscn") func _on_character_back_pressed(): Global.profile["character"] = (Global.profile["character"] - 1) % num_hairstyles diff --git a/client/menu/character_menu.tscn b/client/menu/character.tscn index 4c38ffaf..891b5842 100644 --- a/client/menu/character_menu.tscn +++ b/client/menu/character.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=11 format=3 uid="uid://1f7xpirm5d28"] [ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_ak2pw"] -[ext_resource type="Script" path="res://menu/character_menu.gd" id="1_brhd1"] +[ext_resource type="Script" path="res://menu/character.gd" id="1_brhd1"] [ext_resource type="PackedScene" uid="uid://b4gone8fu53r7" path="res://map/map.tscn" id="3_6mc88"] [ext_resource type="PackedScene" uid="uid://b3hhir2fvnunu" path="res://player/character/character.tscn" id="3_odq7n"] [ext_resource type="PackedScene" uid="uid://bg2d78ycorcqk" path="res://menu/scene_transition.tscn" id="4_c0ocf"] diff --git a/client/menu/credits_menu.gd b/client/menu/credits.gd index 59e7bab9..0ab94fd5 100644 --- a/client/menu/credits_menu.gd +++ b/client/menu/credits.gd @@ -13,7 +13,7 @@ # 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 Control +extends Menu var contributors := ["sofviic", "metamuffin", "nokoe", "tpart"] var cc_0 := ["kenney.nl", "Kay Lousberg"] @@ -26,10 +26,10 @@ var cc_by_4 := { "Page_Turn_24.wav": "Koops" } -@onready var menu_manager: MenuManager = get_parent() @onready var label = $MarginContainer/Panel/MarginContainer/VBoxContainer/RichTextLabel -func prepare(): +func _ready(): + super() contributors.shuffle() label.text = "[center][b]" label.text += tr("undercooked - a game about cooking") @@ -57,4 +57,4 @@ func prepare(): label.text += "\n".join(cc_0) func _on_back_pressed(): - menu_manager.go_back() + exit() diff --git a/client/menu/credits_menu.tscn b/client/menu/credits.tscn index 04797e0d..ff44627a 100644 --- a/client/menu/credits_menu.tscn +++ b/client/menu/credits.tscn @@ -1,8 +1,8 @@ [gd_scene load_steps=4 format=3 uid="uid://7mqbxa054bjv"] -[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_emk5o"] -[ext_resource type="Script" path="res://menu/credits_menu.gd" id="1_igs63"] -[ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="3_d30oq"] +[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_16kk6"] +[ext_resource type="Script" path="res://menu/credits.gd" id="2_alvab"] +[ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="3_nwoiv"] [node name="CreditsMenu" type="Control"] layout_mode = 3 @@ -11,8 +11,8 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -theme = ExtResource("1_emk5o") -script = ExtResource("1_igs63") +theme = ExtResource("1_16kk6") +script = ExtResource("2_alvab") [node name="MarginContainer" type="MarginContainer" parent="."] layout_mode = 1 @@ -23,7 +23,7 @@ grow_horizontal = 2 grow_vertical = 2 [node name="Panel" type="Panel" parent="MarginContainer"] -material = ExtResource("3_d30oq") +material = ExtResource("3_nwoiv") layout_mode = 2 [node name="MarginContainer" type="MarginContainer" parent="MarginContainer/Panel"] diff --git a/client/menu/entry.gd b/client/menu/entry.gd new file mode 100644 index 00000000..b1620df9 --- /dev/null +++ b/client/menu/entry.gd @@ -0,0 +1,29 @@ +# Undercooked - a game about cooking +# Copyright 2024 metamuffin +# Copyright 2024 tpart +# +# 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 +class_name MenuManager + +func _ready(): + super() + if not Global.get_setting("setup_complete"): + await submenu("res://menu/setup.tscn") + else: + await submenu("res://menu/main.tscn") + get_tree().quit() + +func quit(): + pass diff --git a/client/menu/entry.tscn b/client/menu/entry.tscn new file mode 100644 index 00000000..85b16fbf --- /dev/null +++ b/client/menu/entry.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=2 format=3 uid="uid://cd52sr1cmo8oj"] + +[ext_resource type="Script" path="res://menu/entry.gd" id="1_kibw2"] + +[node name="MenuManager" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_kibw2") diff --git a/client/menu/error.gd b/client/menu/error.gd new file mode 100644 index 00000000..84b2e56e --- /dev/null +++ b/client/menu/error.gd @@ -0,0 +1,8 @@ +extends Menu + +func _ready(): + super() + $Panel/contents/mesage.text = Global.error_message + +func _on_return_pressed(): + replace_menu("res://menu/main.tscn") diff --git a/client/menu/error_menu.tscn b/client/menu/error.tscn index ea01ddc3..d1bf034d 100644 --- a/client/menu/error_menu.tscn +++ b/client/menu/error.tscn @@ -2,7 +2,7 @@ [ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_cabdu"] [ext_resource type="PackedScene" uid="uid://l4vm07dtda4j" path="res://menu/menu_background.tscn" id="2_5fxol"] -[ext_resource type="Script" path="res://menu/error_menu.gd" id="2_dbe41"] +[ext_resource type="Script" path="res://menu/error.gd" id="2_dbe41"] [ext_resource type="PackedScene" uid="uid://bg2d78ycorcqk" path="res://menu/scene_transition.tscn" id="4_1nbt3"] [node name="ErrorMenu" type="Control"] diff --git a/client/menu/error_menu.gd b/client/menu/error_menu.gd deleted file mode 100644 index 087261e5..00000000 --- a/client/menu/error_menu.gd +++ /dev/null @@ -1,8 +0,0 @@ -extends Control - -func _ready(): - Global.focus_first_button(self) - $Panel/contents/mesage.text = Global.error_message - -func _on_return_pressed(): - $SceneTransition.transition_to("res://menu/menu_manager.tscn") diff --git a/client/menu/game.gd b/client/menu/game.gd new file mode 100644 index 00000000..ae44957a --- /dev/null +++ b/client/menu/game.gd @@ -0,0 +1,8 @@ +extends Menu + +func _ready(): + super() + +func _input(_event): + if Input.is_action_just_pressed("pause"): + submenu("res://menu/ingame.tscn") diff --git a/client/menu/game.tscn b/client/menu/game.tscn new file mode 100644 index 00000000..708adf74 --- /dev/null +++ b/client/menu/game.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=3 format=3 uid="uid://bbjwoxs71fnsk"] + +[ext_resource type="Script" path="res://menu/game.gd" id="1_cdpsh"] +[ext_resource type="PackedScene" uid="uid://c6krh36hoqfg8" path="res://game.tscn" id="2_uojcy"] + +[node name="GameMenu" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_cdpsh") +auto_anim = false + +[node name="Game" parent="." instance=ExtResource("2_uojcy")] diff --git a/client/menu/ingame.gd b/client/menu/ingame.gd new file mode 100644 index 00000000..306b15b2 --- /dev/null +++ b/client/menu/ingame.gd @@ -0,0 +1,35 @@ +extends Menu + +@onready var anim = $AnimationPlayer +@onready var options = $Side/Margin/Options + +func _ready(): + super() + +func anim_setup(): pass +func menu_anim_open(): + print("ingame open") + anim.play("activate") + await anim.animation_finished +func menu_anim_exit(): + print("ingame exit") + anim.play_backwards("activate") + await anim.animation_finished + +func _on_resume_pressed(): + exit() + +func _on_main_menu_pressed(): + parent_menu.replace_menu("res://menu/main.tscn") + +func _on_settings_pressed(): + submenu("res://menu/settings.tscn") + +func _on_reconnect_pressed(): + parent_menu.replace_menu("res://menu/game.tscn") + +func _on_quit_pressed(): + quit() + +func _input(event): + if Input.is_action_just_pressed("pause"): exit() diff --git a/client/menu/ingame_menu.tscn b/client/menu/ingame.tscn index 1e9a2f46..f704f348 100644 --- a/client/menu/ingame_menu.tscn +++ b/client/menu/ingame.tscn @@ -1,9 +1,9 @@ [gd_scene load_steps=10 format=3 uid="uid://lxlgtjm8hw7v"] -[ext_resource type="Script" path="res://menu/ingame_menu.gd" id="1_gd1i3"] -[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_lb056"] -[ext_resource type="Shader" path="res://menu/blur_mix.gdshader" id="1_o42mc"] -[ext_resource type="FontFile" uid="uid://bo4vh5xkpvrh1" path="res://menu/theme/font-sansita-swashed.woff2" id="4_27kbu"] +[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_2vmyh"] +[ext_resource type="Script" path="res://menu/ingame.gd" id="2_0h3no"] +[ext_resource type="Shader" path="res://menu/blur_mix.gdshader" id="3_f6s5h"] +[ext_resource type="FontFile" uid="uid://bo4vh5xkpvrh1" path="res://menu/theme/font-sansita-swashed.woff2" id="4_scupw"] [sub_resource type="Animation" id="Animation_8sedy"] length = 0.001 @@ -40,13 +40,13 @@ _data = { } [sub_resource type="ShaderMaterial" id="ShaderMaterial_o2vtr"] -shader = ExtResource("1_o42mc") +shader = ExtResource("3_f6s5h") shader_parameter/blur_amount = 3.5 shader_parameter/mix_amount = 0.3 shader_parameter/color_over = null [sub_resource type="FontVariation" id="FontVariation_ud3l8"] -base_font = ExtResource("4_27kbu") +base_font = ExtResource("4_scupw") variation_embolden = 0.5 [node name="IngameMenu" type="Control"] @@ -56,8 +56,8 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -theme = ExtResource("1_lb056") -script = ExtResource("1_gd1i3") +theme = ExtResource("1_2vmyh") +script = ExtResource("2_0h3no") [node name="AnimationPlayer" type="AnimationPlayer" parent="."] libraries = { @@ -72,7 +72,6 @@ anchors_preset = 9 anchor_bottom = 1.0 offset_left = -400.0 offset_right = -90.0 -offset_bottom = 648.0 grow_vertical = 2 [node name="Margin" type="MarginContainer" parent="Side"] @@ -98,11 +97,21 @@ text = "Undercooked" custom_minimum_size = Vector2(0, 10) layout_mode = 2 +[node name="Resume" type="Button" parent="Side/Margin/Options"] +layout_mode = 2 +text = "Resume" +alignment = 0 + [node name="Reconnect" type="Button" parent="Side/Margin/Options"] layout_mode = 2 text = "Reconnect" alignment = 0 +[node name="Settings" type="Button" parent="Side/Margin/Options"] +layout_mode = 2 +text = "Settings" +alignment = 0 + [node name="MainMenu" type="Button" parent="Side/Margin/Options"] layout_mode = 2 text = "Main menu" @@ -113,6 +122,8 @@ layout_mode = 2 text = "Quit game" alignment = 0 +[connection signal="pressed" from="Side/Margin/Options/Resume" to="." method="_on_resume_pressed"] [connection signal="pressed" from="Side/Margin/Options/Reconnect" to="." method="_on_reconnect_pressed"] +[connection signal="pressed" from="Side/Margin/Options/Settings" to="." method="_on_settings_pressed"] [connection signal="pressed" from="Side/Margin/Options/MainMenu" to="." method="_on_main_menu_pressed"] [connection signal="pressed" from="Side/Margin/Options/Quit" to="." method="_on_quit_pressed"] diff --git a/client/menu/ingame_menu.gd b/client/menu/ingame_menu.gd deleted file mode 100644 index 6fa83a55..00000000 --- a/client/menu/ingame_menu.gd +++ /dev/null @@ -1,27 +0,0 @@ -extends Control - -@onready var anim = $AnimationPlayer -@onready var options = $Side/Margin/Options - -func _ready(): - Global.connect_button_sounds(self) - -func act(): - show() - anim.play("activate") - Global.focus_first_button(options) - -func deact(): - anim.play_backwards("activate") - await anim.animation_finished - hide() - -func _on_main_menu_pressed(): - Global.fade_next = true - get_parent().transition_to("res://menu/menu_manager.tscn") - -func _on_quit_pressed(): - get_parent().quit() - -func _on_reconnect_pressed(): - get_parent().transition_to("res://game.tscn") diff --git a/client/menu/main_menu.gd b/client/menu/main.gd index c96d6c13..d3f0f773 100644 --- a/client/menu/main_menu.gd +++ b/client/menu/main.gd @@ -14,9 +14,7 @@ # 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 Control - -@onready var menu_manager: MenuManager = get_parent() +extends Menu @onready var quit_button = $side/margin/options/quit @onready var connect_uri = $side/margin/options/connect/uri @@ -25,16 +23,20 @@ extends Control @onready var server_connect = $side/margin/options/server/connect func _ready(): + super() if OS.has_feature("web"): quit_button.hide() server.hide() connect_uri.text = Global.profile["last_server_url"] +func menu_anim_cover(covered): + $side.visible = not covered + func _on_quit_pressed(): - menu_manager.transition.quit() + quit() func _on_credits_pressed(): - menu_manager.goto("credits") + submenu("res://menu/credits.tscn", true) func _on_connect_pressed(): var url = connect_uri.text @@ -55,13 +57,13 @@ func _on_quick_connect_pressed(): func connect_to(url): print("Connecting to %s" % url) Global.server_url = url - menu_manager.transition.transition_to("res://game.tscn") + replace_menu("res://menu/game.tscn") func _on_change_character_pressed(): - menu_manager.transition.transition_to("res://menu/character_menu.tscn") + replace_menu("res://menu/character.tscn") func _on_settings_pressed(): - menu_manager.goto("settings") + submenu("res://menu/settings.tscn", true) func _on_server_pressed(): match Server.state: @@ -69,6 +71,9 @@ func _on_server_pressed(): 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 @@ -93,6 +98,3 @@ func _process(_delta): server_control.text = tr("Server (Unavailable)") server_control.disabled = true server_control.tooltip_text = tr("Server binary was not found. Please install the server seperately.") - -func _on_server_connect_pressed(): - connect_to("ws://127.0.0.1:27032/") diff --git a/client/menu/main_menu.tscn b/client/menu/main.tscn index 36f417f4..b36e1ddb 100644 --- a/client/menu/main_menu.tscn +++ b/client/menu/main.tscn @@ -1,14 +1,15 @@ -[gd_scene load_steps=7 format=3 uid="uid://dbj8508whxgwv"] +[gd_scene load_steps=8 format=3 uid="uid://dbj8508whxgwv"] -[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_nlcpo"] -[ext_resource type="Script" path="res://menu/main_menu.gd" id="2_qot2j"] -[ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="3_k58q5"] -[ext_resource type="FontFile" uid="uid://bo4vh5xkpvrh1" path="res://menu/theme/font-sansita-swashed.woff2" id="4_mfs30"] +[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_3qfu3"] +[ext_resource type="Script" path="res://menu/main.gd" id="2_xjnc3"] +[ext_resource type="PackedScene" uid="uid://l4vm07dtda4j" path="res://menu/menu_background.tscn" id="3_4evao"] +[ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="4_wf51p"] +[ext_resource type="FontFile" uid="uid://bo4vh5xkpvrh1" path="res://menu/theme/font-sansita-swashed.woff2" id="5_k7bqq"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ukani"] [sub_resource type="FontVariation" id="FontVariation_htgmg"] -base_font = ExtResource("4_mfs30") +base_font = ExtResource("5_k7bqq") variation_embolden = 0.5 [node name="MainMenu" type="Control"] @@ -18,11 +19,13 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -theme = ExtResource("1_nlcpo") -script = ExtResource("2_qot2j") +theme = ExtResource("1_3qfu3") +script = ExtResource("2_xjnc3") + +[node name="MenuBackground" parent="." instance=ExtResource("3_4evao")] [node name="side" type="PanelContainer" parent="."] -material = ExtResource("3_k58q5") +material = ExtResource("4_wf51p") layout_mode = 1 anchors_preset = 9 anchor_bottom = 1.0 diff --git a/client/menu/menu.gd b/client/menu/menu.gd new file mode 100644 index 00000000..a911ca83 --- /dev/null +++ b/client/menu/menu.gd @@ -0,0 +1,89 @@ +class_name Menu +extends Control + + +#enum Anim { NONE, FADE } +#@export var animation: Anim = Anim.NONE +@export var support_anim := true +@export var auto_anim := true + +signal submenu_close() + +const transition_scene = preload("res://menu/scene_transition.tscn") +var transition: SceneTransition +var parent_menu: Menu = null + +func _ready(): + focus_first_button(self) + connect_button_sounds(self) + update_parent_menu(self.get_parent()) + if support_anim: anim_setup() + if auto_anim: menu_anim_open() + +func anim_setup(): + transition = transition_scene.instantiate() + add_child(transition) +func menu_anim_open(): + print("open ", transition) + if transition != null: await transition.fade_in() +func menu_anim_exit(): + print("exit ", transition) + if transition != null: await transition.fade_out() +func menu_anim_cover(state: bool): + pass + +var popup: Menu = null +func submenu(path: String, instant: bool = false): + if popup != null: return + await menu_anim_cover(true) + popup = load(path).instantiate() + if instant: popup.support_anim = false + add_child(popup) + print("Submenu opened ", path) + await submenu_close + print("Submenu closed ", path) + await menu_anim_cover(false) + +func exit(): + await self.menu_anim_exit() + get_parent().submenu_close.emit() + queue_free() + +func quit(): + await exit() + get_parent().quit() + +func replace_menu(path: String): + if popup != null: await popup.exit() + await menu_anim_exit() + get_parent().add_child(load(path).instantiate()) + queue_free() + +var focus_auto_changed := false +func focus_first_button(node: Node) -> bool: + focus_auto_changed = true + if node is Button: + node.grab_focus() + print("Node %s (%s) was selected for focus" % [node.name, node]) + return true + for c in node.get_children(): + if focus_first_button(c): + return true + return false + +func connect_button_sounds(node: Node): + if node is Button: + node.pressed.connect(Sound.play_click) + if node is Button or node is LineEdit or node is Slider: + node.mouse_entered.connect(Sound.play_hover) + for c in node.get_children(): + connect_button_sounds(c) + +func update_parent_menu(node: Node): + if node is Menu: parent_menu = node + elif node.get_parent() != null: update_parent_menu(node.get_parent()) + +#func _input(_event): + #if Input.is_action_just_pressed("ui_cancel"): + #Sound.play_click() + #exit() diff --git a/client/menu/menu.tscn b/client/menu/menu.tscn new file mode 100644 index 00000000..641e5c3a --- /dev/null +++ b/client/menu/menu.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=3 uid="uid://bgo1j6isr7fdy"] + +[ext_resource type="Script" path="res://menu/menu.gd" id="1_le42d"] + +[node name="Menu" type="Control"] +layout_mode = 3 +anchors_preset = 0 +script = ExtResource("1_le42d") diff --git a/client/menu/menu_manager.gd b/client/menu/menu_manager.gd deleted file mode 100644 index bba074f6..00000000 --- a/client/menu/menu_manager.gd +++ /dev/null @@ -1,68 +0,0 @@ -# Undercooked - a game about cooking -# Copyright 2024 metamuffin -# Copyright 2024 tpart -# -# 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 Control -class_name MenuManager - -@onready var menus = { - "main": $MainMenu, - "credits": $CreditsMenu, - "settings": $SettingsMenu -} -@onready var transition: SceneTransition = $SceneTransition - -var menu_stack = ["main"] - -func _ready(): - if not Global.settings["setup_complete"]["value"]: return transition.instant_to("res://menu/setup_menu.tscn") - get_viewport().gui_focus_changed.connect(Sound.play_hover_maybe) - Global.focus_first_button(menus[menu_stack.back()]) - - for m in menus.values(): - Global.connect_button_sounds(m) - - if Global.fade_next: - Global.fade_next = false - transition.fade_in() - -func _input(_event): - if Input.is_action_just_pressed("ui_cancel") && menu_stack.size() > 1: - Sound.play_click() - go_back() - -func goto(menu_name: String): - show_menu(menu_name) - menu_stack.push_back(menu_name) - print("Go to called. Stack: " + str(menu_stack)) - -func go_back(): - menu_stack.pop_back() - if menu_stack.is_empty(): - Global.showError("Menu stack empty") - show_menu(menu_stack.back()) - print("Go back called. Stack: " + str(menu_stack)) - -func show_menu(menu_name: String): - await transition.fade_out() - for k in menus.keys(): - if k == menu_name: - menus[k].show() - if menus[k].has_method("prepare"): - menus[k].prepare() # Optionally run some code - Global.focus_first_button(menus[k]) - else: - menus[k].hide() - await transition.fade_in() diff --git a/client/menu/menu_manager.tscn b/client/menu/menu_manager.tscn deleted file mode 100644 index 56cc6442..00000000 --- a/client/menu/menu_manager.tscn +++ /dev/null @@ -1,34 +0,0 @@ -[gd_scene load_steps=7 format=3 uid="uid://cd52sr1cmo8oj"] - -[ext_resource type="Script" path="res://menu/menu_manager.gd" id="1_c0rjm"] -[ext_resource type="PackedScene" uid="uid://l4vm07dtda4j" path="res://menu/menu_background.tscn" id="2_nf7b6"] -[ext_resource type="PackedScene" uid="uid://dbj8508whxgwv" path="res://menu/main_menu.tscn" id="3_ccpur"] -[ext_resource type="PackedScene" uid="uid://7mqbxa054bjv" path="res://menu/credits_menu.tscn" id="4_xhcd8"] -[ext_resource type="PackedScene" uid="uid://8ic77jmadadj" path="res://menu/settings_menu.tscn" id="5_lifj8"] -[ext_resource type="PackedScene" uid="uid://bg2d78ycorcqk" path="res://menu/scene_transition.tscn" id="6_p4u45"] - -[node name="MenuManager" type="Control"] -layout_mode = 3 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -script = ExtResource("1_c0rjm") - -[node name="MenuBackground" parent="." instance=ExtResource("2_nf7b6")] - -[node name="MainMenu" parent="." instance=ExtResource("3_ccpur")] -layout_mode = 1 - -[node name="CreditsMenu" parent="." instance=ExtResource("4_xhcd8")] -visible = false -layout_mode = 1 - -[node name="SettingsMenu" parent="." instance=ExtResource("5_lifj8")] -visible = false -layout_mode = 1 - -[node name="SceneTransition" parent="." instance=ExtResource("6_p4u45")] -visible = false -layout_mode = 1 diff --git a/client/menu/scene_transition.gd b/client/menu/scene_transition.gd index f68f6aa7..8fe078e6 100644 --- a/client/menu/scene_transition.gd +++ b/client/menu/scene_transition.gd @@ -14,57 +14,35 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. # class_name SceneTransition -extends ColorRect +extends Control -@onready var anim: AnimationPlayer = $animation -@export var ingame = false - -@export var auto_fade_in := true +@onready var anim: AnimationPlayer = $AnimationPlayer var black = true var fading = false +signal close() + func _ready(): - visible = true - if auto_fade_in: fade_in() + $ColorRect.visible = true func fade_in(): - if black: anim.play("fade_in"); fading = true - black = false - if fading: await anim.animation_finished - fading = false + if fading: push_error("transition busy (in)"); return + if not black: push_error("already faded in"); return + fading = true + anim.play_backwards("fade") + await anim.animation_finished self.mouse_filter = Control.MOUSE_FILTER_IGNORE + fading = false; black = false func fade_out(): + if fading: push_error("transition busy (out)"); return + if black: push_error("already faded out"); return + fading = true self.mouse_filter = Control.MOUSE_FILTER_STOP - if not black: anim.play("fade_out"); fading = true - black = true - if fading: await anim.animation_finished - fading = false - -func transition_to(path: String): - await out() - get_tree().change_scene_to_file(path) - -func instant_to(path: String): - get_tree().change_scene_to_file(path) - -func quit(): - await out() - get_tree().quit() - -func out(): - visible = true - if menu.visible: - menu.anim.play_backwards("activate") - await menu.anim.animation_finished - anim.play("fade_out") + anim.play("fade") await anim.animation_finished + fading = false; black = true -@onready var menu = $IngameMenu -func _process(_delta): - if ingame: - if not menu.visible and Input.is_action_just_pressed("pause"): - menu.act() - elif menu.visible and Input.is_action_just_pressed("pause"): - menu.deact() +func _exit_tree(): + if fading: push_error("SceneTransition destroyed while fading") diff --git a/client/menu/scene_transition.tscn b/client/menu/scene_transition.tscn index ddfd6238..4ebf809e 100644 --- a/client/menu/scene_transition.tscn +++ b/client/menu/scene_transition.tscn @@ -1,48 +1,20 @@ -[gd_scene load_steps=7 format=3 uid="uid://bg2d78ycorcqk"] +[gd_scene load_steps=5 format=3 uid="uid://bg2d78ycorcqk"] [ext_resource type="Script" path="res://menu/scene_transition.gd" id="1_fpbwj"] -[ext_resource type="PackedScene" uid="uid://lxlgtjm8hw7v" path="res://menu/ingame_menu.tscn" id="2_aqaj2"] [sub_resource type="Animation" id="Animation_xgn2a"] length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:color") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Color(0, 0, 0, 1)] -} -[sub_resource type="Animation" id="Animation_tglmc"] -resource_name = "fade_in" +[sub_resource type="Animation" id="Animation_cq5i2"] +resource_name = "fade" tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true -tracks/0/path = NodePath(".:color") +tracks/0/path = NodePath("ColorRect:color") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/keys = { -"times": PackedFloat32Array(0, 0.9), -"transitions": PackedFloat32Array(1, 1), -"update": 0, -"values": [Color(0, 0, 0, 1), Color(0, 0, 0, 0)] -} - -[sub_resource type="Animation" id="Animation_egop8"] -resource_name = "fade_out" -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:color") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0, 0.9), +"times": PackedFloat32Array(0, 1), "transitions": PackedFloat32Array(1, 1), "update": 0, "values": [Color(0, 0, 0, 0), Color(0, 0, 0, 1)] @@ -51,28 +23,31 @@ tracks/0/keys = { [sub_resource type="AnimationLibrary" id="AnimationLibrary_pea72"] _data = { "RESET": SubResource("Animation_xgn2a"), -"fade_in": SubResource("Animation_tglmc"), -"fade_out": SubResource("Animation_egop8") +"fade": SubResource("Animation_cq5i2") } -[node name="SceneTransition" type="ColorRect"] +[node name="SceneTransition" type="Control"] +layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -mouse_filter = 2 -color = Color(0, 0, 0, 1) script = ExtResource("1_fpbwj") -[node name="animation" type="AnimationPlayer" parent="."] +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] libraries = { "": SubResource("AnimationLibrary_pea72") } speed_scale = 4.0 -[node name="IngameMenu" parent="." instance=ExtResource("2_aqaj2")] +[node name="ColorRect" type="ColorRect" parent="."] visible = false layout_mode = 1 -offset_right = 2304.0 -offset_bottom = 1296.0 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +color = Color(0, 0, 0, 1) diff --git a/client/menu/settings_menu.gd b/client/menu/settings.gd index 9f033d40..66b53f64 100644 --- a/client/menu/settings_menu.gd +++ b/client/menu/settings.gd @@ -13,10 +13,9 @@ # 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 Control +extends Menu @onready var options: VBoxContainer = $OuterGap/Panel/InnerGap/VBoxContainer/ScrollContainer/Options -@onready var menu_manager: MenuManager = get_parent() var settings: Dictionary @@ -26,14 +25,12 @@ func _on_back_pressed(): Global.save_settings() Global.update_language() Global.update_fullscreen() - menu_manager.go_back() + exit() func _ready(): + super() update_rows() -func show_graphis(): - menu_manager.goto("settings_graphics") - func update_rows(fix_focus = false): for c in options.get_children(): c.queue_free() diff --git a/client/menu/settings_menu.tscn b/client/menu/settings.tscn index ecaea17c..2b83b3f1 100644 --- a/client/menu/settings_menu.tscn +++ b/client/menu/settings.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=3 uid="uid://8ic77jmadadj"] [ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_foq3a"] -[ext_resource type="Script" path="res://menu/settings_menu.gd" id="2_3hgm8"] +[ext_resource type="Script" path="res://menu/settings.gd" id="2_3hgm8"] [ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="3_8nykw"] [node name="SettingsMenu" type="Control"] diff --git a/client/menu/setup_menu.gd b/client/menu/setup.gd index 565753d8..565753d8 100644 --- a/client/menu/setup_menu.gd +++ b/client/menu/setup.gd diff --git a/client/menu/setup_menu.tscn b/client/menu/setup.tscn index 5f856c28..7b38b2a1 100644 --- a/client/menu/setup_menu.tscn +++ b/client/menu/setup.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=16 format=3 uid="uid://ddl3efikvqp66"] -[ext_resource type="Script" path="res://menu/setup_menu.gd" id="1_mo46n"] +[ext_resource type="Script" path="res://menu/setup.gd" id="1_mo46n"] [ext_resource type="Theme" uid="uid://ci2qajdoa1an1" path="res://menu/theme/paper.tres" id="1_yq0aa"] [ext_resource type="FontFile" uid="uid://bo4vh5xkpvrh1" path="res://menu/theme/font-sansita-swashed.woff2" id="3_2vg4d"] [ext_resource type="PackedScene" uid="uid://bg2d78ycorcqk" path="res://menu/scene_transition.tscn" id="4_u444t"] diff --git a/client/player/player.gd b/client/player/player.gd index b47216d6..33606bc4 100644 --- a/client/player/player.gd +++ b/client/player/player.gd @@ -62,7 +62,6 @@ func _init(_id: int, new_name: String, pos: Vector2, new_character_idx: int, new character_idx = new_character_idx - func _ready(): character.select_hairstyle(character_idx) clear_timer.timeout.connect(clear_message) diff --git a/client/project.godot b/client/project.godot index c2204768..32f0e7eb 100644 --- a/client/project.godot +++ b/client/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="undercooked" -run/main_scene="res://menu/menu_manager.tscn" +run/main_scene="res://menu/entry.tscn" config/features=PackedStringArray("4.2", "Forward Plus") boot_splash/bg_color=Color(0.282353, 0.141176, 0.141176, 1) boot_splash/image="res://icon.png" |