Files
DungeonCrawlerWorld/scripts/presentation/menu/main_menu.gd
T

82 lines
2.9 KiB
GDScript

class_name MainMenu
extends Control
signal game_started(settings: RunSettings, run_state: RunState)
const GameScene = preload("res://scenes/Game.tscn")
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
@onready var menu: Control = $Menu
@onready var character_creation: CharacterCreation = $CharacterCreation
@onready var catalog_browser: CatalogBrowser = $CatalogBrowser
@onready var status_label: Label = $Menu/Layout/StatusLabel
var _catalog: ContentCatalog
func _ready() -> void:
$Menu/Layout/NewRunButton.pressed.connect(_show_character_creation)
$Menu/Layout/ContinueButton.pressed.connect(_show_unavailable.bind("Continue"))
$Menu/Layout/LoadSlotButton.pressed.connect(_show_unavailable.bind("Load Slot"))
$Menu/Layout/OptionsButton.pressed.connect(_show_unavailable.bind("Options"))
$Menu/Layout/CatalogButton.pressed.connect(_show_catalog)
$Menu/Layout/QuitButton.pressed.connect(func() -> void: get_tree().quit())
character_creation.run_requested.connect(_start_new_run)
character_creation.cancelled.connect(_show_main_menu)
_show_main_menu()
if _get_capture_mode():
_start_new_run(RunSettings.new("visual-check", &"crawler", false, false), "Visual Check", &"vanguard")
func _get_capture_mode() -> bool:
var arguments := OS.get_cmdline_user_args()
return "--capture" in arguments or "--capture-exit" in arguments
func _show_character_creation() -> void:
menu.visible = false
character_creation.visible = true
func _show_main_menu() -> void:
menu.visible = true
character_creation.visible = false
catalog_browser.dismiss()
status_label.text = ""
func _show_catalog() -> void:
if _catalog == null:
_catalog = ContentCatalogType.load_from_directory("res://data/ascii")
menu.visible = false
character_creation.visible = false
catalog_browser.present(_catalog)
func _unhandled_input(event: InputEvent) -> void:
if not event is InputEventKey or not event.is_pressed():
return
if catalog_browser.visible:
if event.keycode == KEY_TAB:
catalog_browser.next_kind()
elif event.keycode == KEY_PAGEUP:
catalog_browser.previous_page()
elif event.keycode == KEY_PAGEDOWN:
catalog_browser.next_page()
elif event.keycode == KEY_ESCAPE:
_show_main_menu()
else:
return
get_viewport().set_input_as_handled()
return
if event.keycode == KEY_C:
_show_catalog()
get_viewport().set_input_as_handled()
func _show_unavailable(action_name: String) -> void:
status_label.text = "%s will be available when save slots arrive." % action_name
func _start_new_run(settings: RunSettings, player_name: String, base_archetype: StringName) -> void:
var game := GameScene.instantiate() as Game
game.name = "Game"
game.configure_new_run(settings, player_name, base_archetype)
add_child(game)
menu.visible = false
character_creation.visible = false
game.game_started.connect(func(started_settings: RunSettings, run_state: RunState) -> void:
game_started.emit(started_settings, run_state)
)