Files
Dawn-Godot/ui/mainmenu/MainMenu.gd
T
2026-06-14 10:19:31 -05:00

41 lines
1.2 KiB
GDScript

class_name MainMenu extends Control
@export var btnNewGame:Button
@export var btnSettings:Button
@export var btnQuit:Button
@export var settingsMenu:ClosableMenu
@export_file("*.tscn") var newGameScene:String
func _ready() -> void:
btnNewGame.pressed.connect(onNewGamePressed)
btnSettings.pressed.connect(onSettingsPressed)
btnQuit.pressed.connect(_onQuitPressed)
settingsMenu.closed.connect(_onSettingsClosed)
func _notification(what:int) -> void:
if what == NOTIFICATION_ENTER_TREE:
btnNewGame.call_deferred("grab_focus")
func _onSettingsClosed() -> void:
btnSettings.grab_focus()
func _unhandled_input(event:InputEvent) -> void:
if event.is_action_pressed("ui_cancel"):
if settingsMenu.isOpen:
settingsMenu.close()
get_viewport().set_input_as_handled()
func _onQuitPressed() -> void:
UI.QUIT_DIALOG.closed.connect(_onQuitDialogClosed, CONNECT_ONE_SHOT)
UI.QUIT_DIALOG.open()
func _onQuitDialogClosed() -> void:
btnQuit.grab_focus()
func onNewGamePressed() -> void:
SCENE.setScene(SceneSingleton.SceneType.OVERWORLD)
OVERWORLD.mapChange(newGameScene, "PlayerSpawnPoint")
func onSettingsPressed() -> void:
settingsMenu.open()