102 lines
2.9 KiB
GDScript
102 lines
2.9 KiB
GDScript
extends Control
|
|
## MainMenu - VR-fähiges Hauptmenü
|
|
## Wird in einem Viewport2Din3D angezeigt und ist über XR Pointer bedienbar
|
|
## WICHTIG: Diese Szene muss als 2D-Szene erstellt werden und dann
|
|
## in einem Viewport2Din3D eingebunden werden
|
|
|
|
# === NODE REFERENCES ===
|
|
@onready var start_button: Button = $MarginContainer/VBoxContainer/StartButton
|
|
@onready var continue_button: Button = $MarginContainer/VBoxContainer/ContinueButton
|
|
@onready var high_score_label: Label = $MarginContainer/VBoxContainer/HighScoreLabel
|
|
@onready var title_label: Label = $MarginContainer/VBoxContainer/TitleLabel
|
|
|
|
# === READY ===
|
|
func _ready() -> void:
|
|
print("[MainMenu] Initialisierung gestartet")
|
|
|
|
# Button-Signale verbinden
|
|
if start_button:
|
|
start_button.pressed.connect(_on_start_pressed)
|
|
|
|
if continue_button:
|
|
continue_button.pressed.connect(_on_continue_pressed)
|
|
|
|
# GameManager-Signale verbinden
|
|
if GameManager:
|
|
GameManager.high_score_updated.connect(_on_high_score_updated)
|
|
GameManager.game_state_changed.connect(_on_game_state_changed)
|
|
|
|
# Initial Update
|
|
_update_ui()
|
|
|
|
# Sichtbarkeit initialisieren
|
|
show()
|
|
print("[MainMenu] Bereit")
|
|
|
|
# === UI UPDATES ===
|
|
func _update_ui() -> void:
|
|
"""Aktualisiert die UI-Elemente basierend auf GameManager Status"""
|
|
if not GameManager:
|
|
return
|
|
|
|
# High Score anzeigen
|
|
if high_score_label:
|
|
high_score_label.text = "High Score: %d" % GameManager.high_score
|
|
|
|
# Continue Button nur aktivieren, wenn es einen Spielstand gibt
|
|
if continue_button:
|
|
var has_progress = GameManager.completed_levels.size() > 0 or GameManager.current_level_index > 0
|
|
continue_button.disabled = not has_progress
|
|
continue_button.visible = has_progress
|
|
|
|
func _on_high_score_updated(new_high_score: int) -> void:
|
|
"""Callback wenn sich der High Score ändert"""
|
|
if high_score_label:
|
|
high_score_label.text = "High Score: %d" % new_high_score
|
|
|
|
func _on_game_state_changed(new_state: GameManager.GameState) -> void:
|
|
"""Callback wenn sich der Spielzustand ändert"""
|
|
match new_state:
|
|
GameManager.GameState.MENU:
|
|
show()
|
|
_update_ui()
|
|
GameManager.GameState.LOADING, GameManager.GameState.PLAYING:
|
|
hide()
|
|
|
|
# === BUTTON CALLBACKS ===
|
|
func _on_start_pressed() -> void:
|
|
"""Start Button wurde gedrückt - Neues Spiel beginnen"""
|
|
print("[MainMenu] Start Button gedrückt")
|
|
|
|
if GameManager:
|
|
# Score zurücksetzen für neues Spiel
|
|
GameManager.reset_score()
|
|
GameManager.current_level_index = 0
|
|
|
|
# Erstes Level starten
|
|
GameManager.start_level()
|
|
|
|
# Menü ausblenden
|
|
hide()
|
|
|
|
func _on_continue_pressed() -> void:
|
|
"""Continue Button wurde gedrückt - Gespeichertes Spiel fortsetzen"""
|
|
print("[MainMenu] Continue Button gedrückt")
|
|
|
|
if GameManager:
|
|
# Aktuelles Level fortsetzen
|
|
GameManager.start_level()
|
|
|
|
# Menü ausblenden
|
|
hide()
|
|
|
|
# === PUBLIC METHODS ===
|
|
func show_menu() -> void:
|
|
"""Zeigt das Menü an"""
|
|
show()
|
|
_update_ui()
|
|
|
|
func hide_menu() -> void:
|
|
"""Versteckt das Menü"""
|
|
hide()
|