80 lines
2.8 KiB
GDScript
80 lines
2.8 KiB
GDScript
extends Control
|
|
|
|
const GAME_SCENE := "res://scenes/game/game.tscn"
|
|
const MENU_BACKGROUND := preload("res://assets/background/background_menu.jpg")
|
|
|
|
func _ready() -> void:
|
|
_build_menu()
|
|
|
|
func _build_menu() -> void:
|
|
var background := TextureRect.new()
|
|
background.name = "Background"
|
|
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
background.texture = MENU_BACKGROUND
|
|
background.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
background.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
|
|
add_child(background)
|
|
|
|
var shade := ColorRect.new()
|
|
shade.name = "Shade"
|
|
shade.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
shade.color = Color(0.015, 0.025, 0.06, 0.42)
|
|
add_child(shade)
|
|
|
|
var layout := VBoxContainer.new()
|
|
layout.name = "MenuLayout"
|
|
layout.set_anchors_preset(Control.PRESET_CENTER_LEFT)
|
|
layout.position = Vector2(90, -190)
|
|
layout.custom_minimum_size = Vector2(390, 380)
|
|
layout.add_theme_constant_override("separation", 18)
|
|
add_child(layout)
|
|
|
|
var title := Label.new()
|
|
title.text = "RANDOLOOT"
|
|
title.add_theme_font_size_override("font_size", 54)
|
|
title.add_theme_color_override("font_color", Color(0.92, 0.96, 1.0))
|
|
layout.add_child(title)
|
|
|
|
var subtitle := Label.new()
|
|
subtitle.text = "SPACE ROGUELITE"
|
|
subtitle.add_theme_font_size_override("font_size", 16)
|
|
subtitle.add_theme_color_override("font_color", Color(0.48, 0.78, 1.0))
|
|
layout.add_child(subtitle)
|
|
|
|
var spacer := Control.new()
|
|
spacer.custom_minimum_size.y = 12
|
|
layout.add_child(spacer)
|
|
|
|
_add_button(layout, "Start", _start_game, true)
|
|
_add_button(layout, "Wgraj / Zapisz", Callable(), false)
|
|
_add_button(layout, "Opcje", Callable(), false)
|
|
_add_button(layout, "Wyjście", _exit_game, false)
|
|
|
|
func _add_button(parent: VBoxContainer, label: String, action: Callable, primary: bool) -> void:
|
|
var button := Button.new()
|
|
button.text = label
|
|
button.custom_minimum_size = Vector2(300, 54)
|
|
button.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
|
|
button.add_theme_font_size_override("font_size", 20)
|
|
var normal := StyleBoxFlat.new()
|
|
normal.bg_color = Color(0.10, 0.33, 0.55, 0.92) if primary else Color(0.035, 0.075, 0.13, 0.88)
|
|
normal.border_color = Color(0.20, 0.68, 0.95, 0.9) if primary else Color(0.26, 0.43, 0.58, 0.75)
|
|
normal.set_border_width_all(1)
|
|
normal.set_corner_radius_all(5)
|
|
normal.content_margin_left = 22
|
|
button.add_theme_stylebox_override("normal", normal)
|
|
var hover := normal.duplicate() as StyleBoxFlat
|
|
hover.bg_color = Color(0.14, 0.44, 0.68, 0.98) if primary else Color(0.08, 0.17, 0.27, 0.98)
|
|
button.add_theme_stylebox_override("hover", hover)
|
|
button.add_theme_stylebox_override("pressed", hover)
|
|
if action.is_valid():
|
|
button.pressed.connect(action)
|
|
parent.add_child(button)
|
|
|
|
func _start_game() -> void:
|
|
get_tree().change_scene_to_file(GAME_SCENE)
|
|
|
|
func _exit_game() -> void:
|
|
get_tree().quit()
|
|
|