From 3f9e261a532f9a129e67f5d14b49ef339f1ddc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Thu, 14 Aug 2025 23:20:05 +0200 Subject: [PATCH] game: add menu --- game/Player.gd | 9 +++++++-- game/main_menu.gd | 13 +++++++++++++ game/main_menu.gd.uid | 1 + game/main_menu.tscn | 36 ++++++++++++++++++++++++++++++++++++ game/options_menu.gd | 12 ++++++++++++ game/options_menu.gd.uid | 1 + game/options_menu.tscn | 34 ++++++++++++++++++++++++++++++++++ game/overlay_fps.gd | 10 +++++++++- game/player.tscn | 4 +++- 9 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 game/main_menu.gd create mode 100644 game/main_menu.gd.uid create mode 100644 game/main_menu.tscn create mode 100644 game/options_menu.gd create mode 100644 game/options_menu.gd.uid create mode 100644 game/options_menu.tscn diff --git a/game/Player.gd b/game/Player.gd index 0862f8d..2b4b1af 100644 --- a/game/Player.gd +++ b/game/Player.gd @@ -12,7 +12,7 @@ var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") @onready var head = $Head @onready var camera = $Head/PlayerCamera @onready var player_debug = $Head/PlayerCamera/PlayerDebug -@onready var overylay_fps = $Head/PlayerCamera/OverlayFPS +@onready var overlay_fps = $Head/PlayerCamera/OverlayFPS @onready var player_stats = $PlayerStats @onready var anim_player = $AnimationPlayer @onready var muzzle_flash = $Head/PlayerCamera/pistol/MuzzleFlash @@ -41,7 +41,12 @@ func _unhandled_input(event: InputEvent) -> void: player_debug.visible = !player_debug.visible if Input.is_action_just_pressed("overlay_fps"): - overylay_fps.visible = true + if !overlay_fps.visible: + overlay_fps.visible = true + elif !overlay_fps.advanced_output: + overlay_fps.advanced_output = true + else: + overlay_fps.advanced_output = false func _physics_process(delta: float) -> void: if not is_on_floor(): diff --git a/game/main_menu.gd b/game/main_menu.gd new file mode 100644 index 0000000..c692cfc --- /dev/null +++ b/game/main_menu.gd @@ -0,0 +1,13 @@ +extends Control + + +func _on_play_pressed() -> void: + get_tree().change_scene_to_file("res://world.tscn") + + +func _on_options_pressed() -> void: + get_tree().change_scene_to_file("res://options_menu.tscn") + + +func _on_quit_pressed() -> void: + get_tree().quit(0) diff --git a/game/main_menu.gd.uid b/game/main_menu.gd.uid new file mode 100644 index 0000000..3db280d --- /dev/null +++ b/game/main_menu.gd.uid @@ -0,0 +1 @@ +uid://bsx7nporxaoa6 diff --git a/game/main_menu.tscn b/game/main_menu.tscn new file mode 100644 index 0000000..2875cac --- /dev/null +++ b/game/main_menu.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=2 format=3 uid="uid://3pysj67x88uw"] + +[ext_resource type="Script" uid="uid://bsx7nporxaoa6" path="res://main_menu.gd" id="1_06t4h"] + +[node name="MainMenu" 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_06t4h") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 + +[node name="Play" type="Button" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Play Game" + +[node name="Options" type="Button" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Options" + +[node name="Quit" type="Button" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Quit" + +[connection signal="pressed" from="MarginContainer/VBoxContainer/Play" to="." method="_on_play_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/Options" to="." method="_on_options_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/Quit" to="." method="_on_quit_pressed"] diff --git a/game/options_menu.gd b/game/options_menu.gd new file mode 100644 index 0000000..d015373 --- /dev/null +++ b/game/options_menu.gd @@ -0,0 +1,12 @@ +extends Control + + +func _on_back_pressed() -> void: + get_tree().change_scene_to_file("res://main_menu.tscn") + + +func _on_check_button_toggled(toggled_on: bool) -> void: + if toggled_on: + DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) + else: + DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) diff --git a/game/options_menu.gd.uid b/game/options_menu.gd.uid new file mode 100644 index 0000000..a69900b --- /dev/null +++ b/game/options_menu.gd.uid @@ -0,0 +1 @@ +uid://csr3f6vfeqim8 diff --git a/game/options_menu.tscn b/game/options_menu.tscn new file mode 100644 index 0000000..f53466e --- /dev/null +++ b/game/options_menu.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=2 format=3 uid="uid://gu2cm1ekgftu"] + +[ext_resource type="Script" uid="uid://csr3f6vfeqim8" path="res://options_menu.gd" id="1_lbr8e"] + +[node name="OptionsMenu" 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_lbr8e") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 + +[node name="Back" type="Button" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Back" + +[node name="CheckButton" type="CheckButton" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Fullscreen" + +[connection signal="pressed" from="MarginContainer/VBoxContainer/Back" to="." method="_on_back_pressed"] +[connection signal="toggled" from="MarginContainer/VBoxContainer/CheckButton" to="." method="_on_check_button_toggled"] diff --git a/game/overlay_fps.gd b/game/overlay_fps.gd index 9b7bc95..1a09464 100644 --- a/game/overlay_fps.gd +++ b/game/overlay_fps.gd @@ -3,12 +3,20 @@ extends CanvasLayer @onready var text = $RichTextLabel @onready var timer = $Timer +var advanced_output: bool = false + func _ready() -> void: visible = false func _on_timer_timeout() -> void: text.clear() - text.add_text("FPS: %s" % Engine.get_frames_per_second()) + text.add_text("FPS: %s\n" % Engine.get_frames_per_second()) + if advanced_output: + var res = DisplayServer.window_get_size() + text.add_text("res: %sx%s\n" % [res.x, res.y]) + var device = RenderingServer.get_rendering_device() + text.add_text("rendering_device: %s\n" % device.get_device_name()) + text.add_text("%s\n" % device.get_perf_report()) func _on_visibility_changed() -> void: if visible: diff --git a/game/player.tscn b/game/player.tscn index dead64f..2279825 100644 --- a/game/player.tscn +++ b/game/player.tscn @@ -219,12 +219,14 @@ script = ExtResource("5_2hs0m") anchors_preset = 1 anchor_left = 1.0 anchor_right = 1.0 -offset_left = -117.0 +offset_left = -1153.0 offset_bottom = 40.0 grow_horizontal = 0 size_flags_horizontal = 8 size_flags_vertical = 0 text = "FPS: 10.0" +fit_content = true +horizontal_alignment = 2 [node name="Timer" type="Timer" parent="Head/PlayerCamera/OverlayFPS"] wait_time = 0.5