pause menu WIP
This commit is contained in:
parent
033718351e
commit
9d43b070af
7 changed files with 258 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
|||
[gd_scene load_steps=13 format=4 uid="uid://ba6afuig8bqrg"]
|
||||
[gd_scene load_steps=14 format=4 uid="uid://ba6afuig8bqrg"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://s683ua4q2ewm" path="res://menu/PauseMenu.tscn" id="1_dtdta"]
|
||||
[ext_resource type="PackedScene" uid="uid://snxpqx0ony7s" path="res://objects/Player.tscn" id="1_prjlb"]
|
||||
[ext_resource type="PackedScene" uid="uid://dii1q3f5dj72y" path="res://objects/CRT.tscn" id="2_mxtem"]
|
||||
[ext_resource type="Shader" path="res://shaders/scrolling.gdshader" id="3_lcf1n"]
|
||||
|
@ -138,6 +139,7 @@ size = Vector2(1289, 70.5)
|
|||
[node name="Player" parent="." instance=ExtResource("1_prjlb")]
|
||||
|
||||
[node name="CanvasLayer" parent="." instance=ExtResource("2_mxtem")]
|
||||
visible = false
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
|
||||
|
@ -183,3 +185,10 @@ collision_mask = 4
|
|||
[node name="Ground" type="CollisionShape2D" parent="Ground"]
|
||||
position = Vector2(10, 375)
|
||||
shape = SubResource("RectangleShape2D_1vofj")
|
||||
|
||||
[node name="PauseMenu" parent="." instance=ExtResource("1_dtdta")]
|
||||
visible = false
|
||||
offset_left = -320.0
|
||||
offset_top = -160.0
|
||||
offset_right = -320.0
|
||||
offset_bottom = -160.0
|
||||
|
|
87
gmtk_2024/menu/PauseMenu.tscn
Normal file
87
gmtk_2024/menu/PauseMenu.tscn
Normal file
|
@ -0,0 +1,87 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://s683ua4q2ewm"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://cohbys634cf18" path="res://menu/main_menu/MainMenuTheme.tres" id="1_fna2g"]
|
||||
[ext_resource type="PackedScene" uid="uid://dii1q3f5dj72y" path="res://objects/CRT.tscn" id="2_vaod1"]
|
||||
[ext_resource type="Script" path="res://scripts/pause_menu_control.gd" id="3_tyr11"]
|
||||
[ext_resource type="FontFile" uid="uid://d3pbvdemdbxes" path="res://CommodoreSixtyFour.ttf" id="4_u4plf"]
|
||||
|
||||
[node name="PauseMenu" type="MarginContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme = ExtResource("1_fna2g")
|
||||
|
||||
[node name="CanvasLayer" parent="." instance=ExtResource("2_vaod1")]
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
layout_mode = 2
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="Control" type="Control" parent="."]
|
||||
layout_mode = 2
|
||||
script = ExtResource("3_tyr11")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Control"]
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="VBoxContainer2" type="VBoxContainer" parent="Control/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Control/VBoxContainer/VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Buttons" type="VBoxContainer" parent="Control/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Control/VBoxContainer/Buttons"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Control/VBoxContainer/Buttons/HBoxContainer"]
|
||||
custom_minimum_size = Vector2(8, 0)
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("4_u4plf")
|
||||
text = ">"
|
||||
|
||||
[node name="continue" type="Button" parent="Control/VBoxContainer/Buttons/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "continue"
|
||||
flat = true
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="Control/VBoxContainer/Buttons"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Control/VBoxContainer/Buttons/HBoxContainer2"]
|
||||
custom_minimum_size = Vector2(8, 0)
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("4_u4plf")
|
||||
text = ">"
|
||||
|
||||
[node name="restart" type="Button" parent="Control/VBoxContainer/Buttons/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = "restart"
|
||||
flat = true
|
||||
|
||||
[node name="HBoxContainer3" type="HBoxContainer" parent="Control/VBoxContainer/Buttons"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Control/VBoxContainer/Buttons/HBoxContainer3"]
|
||||
custom_minimum_size = Vector2(8, 0)
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("4_u4plf")
|
||||
text = ">"
|
||||
|
||||
[node name="main menu" type="Button" parent="Control/VBoxContainer/Buttons/HBoxContainer3"]
|
||||
layout_mode = 2
|
||||
text = "main menu"
|
||||
flat = true
|
||||
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Buttons/HBoxContainer/continue" to="Control" method="_on_continue_button_pressed"]
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Buttons/HBoxContainer2/restart" to="Control" method="_on_restart_button_pressed"]
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Buttons/HBoxContainer3/main menu" to="Control" method="_on_back_to_main_menu_button_pressed"]
|
|
@ -62,9 +62,9 @@ layout_mode = 2
|
|||
theme_override_fonts/font = ExtResource("1_1tx2i")
|
||||
text = ">"
|
||||
|
||||
[node name="credits" type="Button" parent="Control/VBoxContainer/Buttons/HBoxContainer2"]
|
||||
[node name="level_select" type="Button" parent="Control/VBoxContainer/Buttons/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = "credits"
|
||||
text = "level selection"
|
||||
flat = true
|
||||
|
||||
[node name="HBoxContainer3" type="HBoxContainer" parent="Control/VBoxContainer/Buttons"]
|
||||
|
@ -77,11 +77,27 @@ layout_mode = 2
|
|||
theme_override_fonts/font = ExtResource("1_1tx2i")
|
||||
text = ">"
|
||||
|
||||
[node name="quit" type="Button" parent="Control/VBoxContainer/Buttons/HBoxContainer3"]
|
||||
[node name="credits" type="Button" parent="Control/VBoxContainer/Buttons/HBoxContainer3"]
|
||||
layout_mode = 2
|
||||
text = "credits"
|
||||
flat = true
|
||||
|
||||
[node name="HBoxContainer4" type="HBoxContainer" parent="Control/VBoxContainer/Buttons"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Control/VBoxContainer/Buttons/HBoxContainer4"]
|
||||
custom_minimum_size = Vector2(8, 0)
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("1_1tx2i")
|
||||
text = ">"
|
||||
|
||||
[node name="quit" type="Button" parent="Control/VBoxContainer/Buttons/HBoxContainer4"]
|
||||
layout_mode = 2
|
||||
text = "quit"
|
||||
flat = true
|
||||
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Buttons/HBoxContainer/start" to="Control" method="_on_start_button_pressed"]
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Buttons/HBoxContainer2/credits" to="Control" method="_on_credits_button_pressed"]
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Buttons/HBoxContainer3/quit" to="Control" method="_on_quit_button_pressed"]
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Buttons/HBoxContainer2/level_select" to="Control" method="_on_level_select_pressed"]
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Buttons/HBoxContainer3/credits" to="Control" method="_on_credits_button_pressed"]
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Buttons/HBoxContainer4/quit" to="Control" method="_on_quit_button_pressed"]
|
||||
|
|
|
@ -71,6 +71,11 @@ accept={
|
|||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
pause={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ extends Control
|
|||
|
||||
var display_text = """
|
||||
STARTING Infiltrate.exe ...
|
||||
---------------------------------------
|
||||
MADE FOR GMTK GAME JAM 2024
|
||||
---------------------------------------
|
||||
|
||||
>> SECURITY PROTOCOLS: ACTIVE
|
||||
>> SCANNING FOR THREATS...
|
||||
|
@ -119,6 +119,9 @@ func get_time_since_last_click() -> float:
|
|||
func _on_start_button_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://menu/level_menu/level_select.tscn")
|
||||
|
||||
func _on_level_select_pressed():
|
||||
get_tree().change_scene_to_file("res://menu/level_menu/level_select.tscn")
|
||||
|
||||
func _on_credits_button_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://menu/main_menu/CreditsScene.tscn")
|
||||
|
||||
|
|
130
gmtk_2024/scripts/pause_menu_control.gd
Normal file
130
gmtk_2024/scripts/pause_menu_control.gd
Normal file
|
@ -0,0 +1,130 @@
|
|||
extends Control
|
||||
|
||||
var display_text = """
|
||||
PAUSING OPERATION ...
|
||||
---------------------------------------
|
||||
"""
|
||||
|
||||
signal continue_game
|
||||
signal restart_game
|
||||
signal back_to_main_menu
|
||||
|
||||
var current_text = ""
|
||||
var char_index = 0
|
||||
var typing_speed = 0.05
|
||||
var fast_typing_speed = 0.0001
|
||||
var last_click_time = 0.0
|
||||
var double_click_time = 0.3
|
||||
var is_typing = true
|
||||
var current_button_index = 0
|
||||
var buttons = []
|
||||
var current_scene = null
|
||||
var pause_menu_node = null
|
||||
|
||||
func _ready():
|
||||
current_scene = get_tree().current_scene
|
||||
|
||||
# Referenz auf das übergeordnete Pausenmenü
|
||||
pause_menu_node = get_parent()
|
||||
|
||||
for hbox in $VBoxContainer/Buttons.get_children():
|
||||
hbox.visible = false
|
||||
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
|
||||
_initialize_menu()
|
||||
_start_typing()
|
||||
|
||||
func _initialize_menu():
|
||||
buttons = $VBoxContainer/Buttons.get_children()
|
||||
_update_button_visibility()
|
||||
|
||||
func _update_button_visibility():
|
||||
for i in range(len(buttons)):
|
||||
var hbox_container = buttons[i]
|
||||
var label_node = hbox_container.get_child(0)
|
||||
if label_node != null:
|
||||
label_node.visible = (i == current_button_index)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if is_typing:
|
||||
if event is InputEventKey and event.is_pressed():
|
||||
if get_time_since_last_click() <= double_click_time:
|
||||
_show_full_text()
|
||||
else:
|
||||
typing_speed = fast_typing_speed
|
||||
elif event is InputEventKey and not event.is_pressed():
|
||||
typing_speed = 0.05
|
||||
else:
|
||||
if event.is_action_pressed("pause"):
|
||||
toggle_pause_menu()
|
||||
|
||||
# Navigation mit den Pfeiltasten
|
||||
if event.is_action_pressed("ui_down"):
|
||||
navigate_menu(1)
|
||||
elif event.is_action_pressed("ui_up"):
|
||||
navigate_menu(-1)
|
||||
|
||||
# Bestätigen mit der Leertaste oder Enter
|
||||
if event.is_action_pressed("ui_accept"):
|
||||
buttons[current_button_index].get_child(1).emit_signal("pressed")
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not is_typing and Input.is_action_pressed("ui_accept"):
|
||||
typing_speed = fast_typing_speed
|
||||
|
||||
func _start_typing() -> void:
|
||||
current_text = ""
|
||||
char_index = 0
|
||||
is_typing = true
|
||||
_update_text()
|
||||
|
||||
func _update_text() -> void:
|
||||
if char_index < display_text.length():
|
||||
current_text += display_text[char_index]
|
||||
$VBoxContainer/VBoxContainer2/Label.text = current_text
|
||||
char_index += 1
|
||||
await get_tree().create_timer(typing_speed).timeout
|
||||
_update_text()
|
||||
else:
|
||||
is_typing = false
|
||||
_show_menu_options()
|
||||
|
||||
func _show_menu_options() -> void:
|
||||
for hbox in $VBoxContainer/Buttons.get_children():
|
||||
hbox.visible = true
|
||||
grab_focus() # Menü erhält den Fokus, um Eingaben zu empfangen
|
||||
|
||||
func _show_full_text() -> void:
|
||||
current_text = display_text
|
||||
$VBoxContainer/VBoxContainer2/Label.text = current_text
|
||||
char_index = display_text.length()
|
||||
is_typing = false
|
||||
_show_menu_options()
|
||||
|
||||
func get_time_since_last_click() -> float:
|
||||
var current_time = Time.get_ticks_msec() / 1000.0 # Zeit in Sekunden
|
||||
var time_since_last_click = current_time - last_click_time
|
||||
last_click_time = current_time
|
||||
return time_since_last_click
|
||||
|
||||
func toggle_pause_menu():
|
||||
if pause_menu_node.visible:
|
||||
_on_continue_button_pressed()
|
||||
else:
|
||||
pause_menu_node.visible = true
|
||||
get_tree().paused = true
|
||||
grab_focus() # Menü erhält den Fokus, um Eingaben zu empfangen
|
||||
|
||||
func _on_continue_button_pressed():
|
||||
pause_menu_node.visible = false
|
||||
get_tree().paused = false
|
||||
|
||||
func _on_restart_button_pressed():
|
||||
emit_signal("restart_game")
|
||||
|
||||
func _on_back_to_main_menu_button_pressed():
|
||||
emit_signal("back_to_main_menu")
|
||||
|
||||
func navigate_menu(direction: int) -> void:
|
||||
current_button_index = (current_button_index + direction + buttons.size()) % buttons.size()
|
||||
_update_button_visibility()
|
|
@ -27,7 +27,7 @@ var cursor_scale_down = preload("res://textures/cursor_scale_down.png")
|
|||
func _ready():
|
||||
data_link = $data_link
|
||||
|
||||
func _unhandled_input(event):
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("click"):
|
||||
var nearest_block = find_nearest_block()
|
||||
if nearest_block:
|
||||
|
|
Loading…
Add table
Reference in a new issue