58 lines
2.2 KiB
GDScript
58 lines
2.2 KiB
GDScript
extends Control
|
|
|
|
const GAME_SCENE := "res://scenes/game/game.tscn"
|
|
const CATALOG := preload("res://scripts/game/ship_catalog.gd")
|
|
|
|
@onready var ship_grid: GridContainer = %ShipGrid
|
|
@onready var selected_label: Label = %SelectedLabel
|
|
@onready var continue_button: Button = %ContinueButton
|
|
|
|
var button_group := ButtonGroup.new()
|
|
|
|
func _ready() -> void:
|
|
button_group.allow_unpress = false
|
|
continue_button.pressed.connect(_start_game)
|
|
_load_ships()
|
|
|
|
func _load_ships() -> void:
|
|
var selected_ship := CATALOG.for_path(GameState.selected_ship_path)
|
|
for chassis in CATALOG.SHIPS:
|
|
var ship_path := CATALOG.texture_path(chassis)
|
|
var texture := load(ship_path) as Texture2D
|
|
if texture == null:
|
|
continue
|
|
var button := Button.new()
|
|
button.name = "Ship%d" % int(chassis["number"])
|
|
button.custom_minimum_size = Vector2(250, 260)
|
|
button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
button.toggle_mode = true
|
|
button.button_group = button_group
|
|
var preview := TextureRect.new()
|
|
preview.texture = texture
|
|
preview.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
preview.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
preview.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
button.add_child(preview)
|
|
preview.set_anchors_and_offsets_preset(Control.PRESET_CENTER_TOP)
|
|
preview.offset_left = -50.0
|
|
preview.offset_right = 50.0
|
|
preview.offset_top = 12.0
|
|
preview.offset_bottom = 102.0
|
|
button.text = "%s\n%s\n\n%s" % [chassis["name"], chassis["role"], CATALOG.stats_text(chassis)]
|
|
button.add_theme_font_size_override("font_size", 13)
|
|
button.tooltip_text = "%s — %s\nStatystyki bazowe przed bonusami modułów.\n%s" % [chassis["name"], chassis["role"], CATALOG.stats_text(chassis)]
|
|
button.pressed.connect(_select_ship.bind(chassis, button))
|
|
ship_grid.add_child(button)
|
|
if chassis["number"] == selected_ship["number"]:
|
|
_select_ship(chassis, button)
|
|
|
|
func _select_ship(chassis: Dictionary, button: Button) -> void:
|
|
GameState.selected_ship_path = CATALOG.texture_path(chassis)
|
|
button.button_pressed = true
|
|
selected_label.text = "Wybrano: %s · %s" % [chassis["name"], chassis["role"]]
|
|
continue_button.disabled = false
|
|
|
|
func _start_game() -> void:
|
|
GameState.start_new_run()
|
|
get_tree().change_scene_to_file(GAME_SCENE)
|