97 lines
2.5 KiB
GDScript
97 lines
2.5 KiB
GDScript
extends Control
|
|
|
|
var credits_text = """
|
|
CONGRATULATIONS
|
|
THIS SECTOR IS NOW INFECTED
|
|
YOU NOW HAVE ACCESS TO THE NEXT SECTION
|
|
|
|
"""
|
|
|
|
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 button
|
|
|
|
func _ready():
|
|
_initialize_menu()
|
|
_start_typing()
|
|
|
|
func _initialize_menu():
|
|
button = $VBoxContainer/BackToMenu
|
|
_update_button_visibility()
|
|
_blink_current_button()
|
|
|
|
func _update_button_visibility():
|
|
var hbox_container = button
|
|
var label_node = hbox_container.get_child(0)
|
|
if label_node != null:
|
|
label_node.visible
|
|
|
|
func _process(_delta: float) -> void:
|
|
if not is_typing:
|
|
if Input.is_action_pressed("ui_accept"):
|
|
typing_speed = fast_typing_speed
|
|
|
|
func _blink_current_button() -> void:
|
|
while true:
|
|
var hbox_container = button
|
|
var label_node = hbox_container.get_child(0)
|
|
if label_node != null:
|
|
label_node.visible = true
|
|
await get_tree().create_timer(0.5).timeout
|
|
if label_node != null:
|
|
label_node.visible = false
|
|
await get_tree().create_timer(0.5).timeout
|
|
|
|
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("ui_accept"):
|
|
button.get_child(1).emit_signal("pressed")
|
|
|
|
func _start_typing() -> void:
|
|
current_text = ""
|
|
char_index = 0
|
|
is_typing = true
|
|
_update_text()
|
|
|
|
func _update_text() -> void:
|
|
if char_index < credits_text.length():
|
|
current_text += credits_text[char_index]
|
|
$VBoxContainer/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:
|
|
$VBoxContainer/BackToMenu.visible = true
|
|
|
|
func _return_to_main_menu() -> void:
|
|
get_tree().change_scene_to_file("res://menu/level_menu/level_select.tscn")
|
|
|
|
func _show_full_text() -> void:
|
|
current_text = credits_text
|
|
$VBoxContainer/Label.text = current_text
|
|
char_index = credits_text.length()
|
|
_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
|