pause menu WIP
This commit is contained in:
parent
033718351e
commit
9d43b070af
7 changed files with 258 additions and 8 deletions
|
@ -2,8 +2,8 @@ extends Control
|
|||
|
||||
var display_text = """
|
||||
STARTING Infiltrate.exe ...
|
||||
---------------------------------------
|
||||
MADE FOR GMTK GAME JAM 2024
|
||||
---------------------------------------
|
||||
|
||||
>> SECURITY PROTOCOLS: ACTIVE
|
||||
>> SCANNING FOR THREATS...
|
||||
|
@ -118,6 +118,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
Add a link
Reference in a new issue