135 lines
5.2 KiB
GDScript
135 lines
5.2 KiB
GDScript
extends Control
|
|
|
|
const SHIP_SELECTION_SCENE := preload("res://scenes/ui/ship_selection.tscn")
|
|
const GAME_SCENE := "res://scenes/game/game.tscn"
|
|
|
|
@onready var start_button: Button = %StartButton
|
|
@onready var exit_button: Button = %ExitButton
|
|
var _ship_panel: Control
|
|
var _panel_open := false
|
|
var _launching := false
|
|
var _drawer_tween: Tween
|
|
var _guide: Control
|
|
var _instruction_button: Button
|
|
|
|
func _style_menu() -> void:
|
|
$Background.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
$Shade.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
var atmosphere := Control.new()
|
|
atmosphere.name = "MenuAtmosphere"
|
|
atmosphere.set_script(preload("res://scripts/ui/menu_atmosphere.gd"))
|
|
add_child(atmosphere)
|
|
move_child(atmosphere, $MenuLayout.get_index())
|
|
var layout := $MenuLayout as VBoxContainer
|
|
layout.add_theme_constant_override("separation", 10)
|
|
$MenuLayout/Spacer.hide()
|
|
var eyebrow := Label.new()
|
|
eyebrow.text = "DZIENNIK POKŁADOWY / NOWA WYPRAWA"
|
|
eyebrow.add_theme_font_override("font", ThemeDB.fallback_font)
|
|
eyebrow.add_theme_font_size_override("font_size", 11)
|
|
eyebrow.add_theme_color_override("font_color", Color("91dbea"))
|
|
layout.add_child(eyebrow)
|
|
layout.move_child(eyebrow, 0)
|
|
var title := $MenuLayout/Title as Label
|
|
title.add_theme_font_size_override("font_size", 46)
|
|
title.add_theme_color_override("font_color", Color("f4ead9"))
|
|
var subtitle := Label.new()
|
|
subtitle.text = "Nieznany kosmos. Niepowtarzalny łup."
|
|
subtitle.add_theme_font_override("font", ThemeDB.fallback_font)
|
|
subtitle.add_theme_font_size_override("font_size", 15)
|
|
subtitle.add_theme_color_override("font_color", Color("a9bcc8"))
|
|
layout.add_child(subtitle)
|
|
layout.move_child(subtitle, title.get_index() + 1)
|
|
var space := Control.new()
|
|
space.custom_minimum_size.y = 10
|
|
layout.add_child(space)
|
|
layout.move_child(space, subtitle.get_index() + 1)
|
|
_instruction_button = Button.new()
|
|
_instruction_button.name = "InstructionsButton"
|
|
layout.add_child(_instruction_button)
|
|
layout.move_child(_instruction_button, start_button.get_index() + 1)
|
|
var entries := [
|
|
[start_button, "NOWA WYPRAWA", "Wybierz statek i ruszaj w nieznane", "01", true],
|
|
[_instruction_button, "INSTRUKCJA", "Pierwszy lot? Zacznij tutaj", "02", false],
|
|
[$MenuLayout/SaveButton, "ZAPIS ROZGRYWKI", "Wgraj / zapisz — wkrótce", "03", false],
|
|
[$MenuLayout/OptionsButton, "OPCJE", "Ustawienia — wkrótce", "04", false],
|
|
[exit_button, "WYJŚCIE", "Zakończ grę", "05", false],
|
|
]
|
|
for entry in entries:
|
|
var button: Button = entry[0]
|
|
button.set_script(preload("res://scripts/ui/main_menu_button.gd"))
|
|
button.call("configure", entry[1], entry[2], entry[3], entry[4])
|
|
$MenuLayout/SaveButton.disabled = true
|
|
$MenuLayout/OptionsButton.disabled = true
|
|
_guide = Control.new()
|
|
_guide.set_script(preload("res://scripts/ui/player_guide.gd"))
|
|
add_child(_guide)
|
|
_instruction_button.pressed.connect(func() -> void: _guide.call("open"))
|
|
_guide.connect("closed", _instruction_button.grab_focus)
|
|
resized.connect(_layout_menu)
|
|
_layout_menu.call_deferred()
|
|
|
|
func _layout_menu() -> void:
|
|
var layout := $MenuLayout as VBoxContainer
|
|
layout.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
|
|
var factor := minf(1.0, minf((size.y - 120.0) / 520.0, (size.x - 64.0) / 420.0))
|
|
layout.scale = Vector2.ONE * factor
|
|
layout.size = Vector2(420, layout.get_combined_minimum_size().y)
|
|
layout.position = Vector2(maxf(32.0, size.x * 0.065), maxf(68.0, (size.y - layout.size.y * factor) * 0.5))
|
|
|
|
|
|
func _ready() -> void:
|
|
start_button.pressed.connect(_start_game)
|
|
exit_button.pressed.connect(_exit_game)
|
|
_ship_panel = SHIP_SELECTION_SCENE.instantiate() as Control
|
|
_ship_panel.name = "ShipSelectionPanel"
|
|
_ship_panel.hide()
|
|
add_child(_ship_panel)
|
|
_ship_panel.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
|
|
_ship_panel.connect("ship_selected", _launch_game)
|
|
_ship_panel.connect("close_requested", _close_ship_panel)
|
|
resized.connect(_layout_ship_panel)
|
|
_layout_ship_panel()
|
|
_style_menu()
|
|
|
|
func _start_game() -> void:
|
|
if _panel_open or _launching:
|
|
return
|
|
if _drawer_tween != null and _drawer_tween.is_running():
|
|
_drawer_tween.kill()
|
|
_panel_open = true
|
|
start_button.disabled = true
|
|
_ship_panel.position.x = size.x
|
|
_ship_panel.show()
|
|
_drawer_tween = create_tween()
|
|
_drawer_tween.tween_property(_ship_panel, "position:x", size.x - _ship_panel.size.x, 0.3).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
|
|
|
|
func _layout_ship_panel() -> void:
|
|
if _ship_panel == null:
|
|
return
|
|
if _drawer_tween != null and _drawer_tween.is_running():
|
|
_drawer_tween.kill()
|
|
_ship_panel.size = Vector2(minf(820.0, size.x), size.y)
|
|
_ship_panel.position = Vector2(size.x - _ship_panel.size.x if _panel_open else size.x, 0)
|
|
|
|
func _close_ship_panel() -> void:
|
|
if not _panel_open or _launching:
|
|
return
|
|
_panel_open = false
|
|
start_button.disabled = false
|
|
if _drawer_tween != null and _drawer_tween.is_running():
|
|
_drawer_tween.kill()
|
|
_drawer_tween = create_tween()
|
|
_drawer_tween.tween_property(_ship_panel, "position:x", size.x, 0.2).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_IN)
|
|
_drawer_tween.tween_callback(_ship_panel.hide)
|
|
|
|
func _launch_game() -> void:
|
|
if _launching:
|
|
return
|
|
_launching = true
|
|
GameState.start_new_run()
|
|
get_tree().change_scene_to_file(GAME_SCENE)
|
|
|
|
func _exit_game() -> void:
|
|
get_tree().quit()
|