feat: singleplayer level selector
This commit is contained in:
+113
-15
@@ -1,6 +1,11 @@
|
||||
extends Control
|
||||
|
||||
var _ui_vbox: VBoxContainer
|
||||
var _level_selector_panel: VBoxContainer
|
||||
|
||||
func _ready() -> void:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
|
||||
# ==========================================
|
||||
# BACKGROUND: 3D DIORAMA (Sliding Player)
|
||||
# ==========================================
|
||||
@@ -19,13 +24,13 @@ func _ready() -> void:
|
||||
# ==========================================
|
||||
# FOREGROUND: UI (Title and Buttons)
|
||||
# ==========================================
|
||||
var ui_vbox = VBoxContainer.new()
|
||||
ui_vbox.add_theme_constant_override("separation", 30)
|
||||
ui_vbox.set_anchor_and_offset(SIDE_LEFT, 0.0, 50)
|
||||
ui_vbox.set_anchor_and_offset(SIDE_TOP, 0.0, 50)
|
||||
ui_vbox.set_anchor_and_offset(SIDE_RIGHT, 0.0, 600)
|
||||
ui_vbox.set_anchor_and_offset(SIDE_BOTTOM, 1.0, -50)
|
||||
add_child(ui_vbox)
|
||||
_ui_vbox = VBoxContainer.new()
|
||||
_ui_vbox.add_theme_constant_override("separation", 30)
|
||||
_ui_vbox.set_anchor_and_offset(SIDE_LEFT, 0.0, 50)
|
||||
_ui_vbox.set_anchor_and_offset(SIDE_TOP, 0.0, 50)
|
||||
_ui_vbox.set_anchor_and_offset(SIDE_RIGHT, 0.0, 600)
|
||||
_ui_vbox.set_anchor_and_offset(SIDE_BOTTOM, 1.0, -50)
|
||||
add_child(_ui_vbox)
|
||||
|
||||
# Title
|
||||
var title = Label.new()
|
||||
@@ -34,20 +39,108 @@ func _ready() -> void:
|
||||
title.add_theme_color_override("font_color", Color(1, 0.6, 0.2)) # Papaya orange
|
||||
title.add_theme_color_override("font_outline_color", Color(0, 0, 0))
|
||||
title.add_theme_constant_override("outline_size", 12)
|
||||
ui_vbox.add_child(title)
|
||||
_ui_vbox.add_child(title)
|
||||
|
||||
# Spacer
|
||||
var spacer = Control.new()
|
||||
spacer.custom_minimum_size = Vector2(0, 40)
|
||||
ui_vbox.add_child(spacer)
|
||||
_ui_vbox.add_child(spacer)
|
||||
|
||||
# Buttons
|
||||
_add_button(ui_vbox, "Singleplayer", _on_singleplayer_pressed)
|
||||
_add_button(ui_vbox, "Multiplayer", _on_multiplayer_pressed)
|
||||
_add_button(ui_vbox, "Settings", _on_settings_pressed)
|
||||
_add_button(ui_vbox, "Exit Game", _on_exit_pressed)
|
||||
_add_button(_ui_vbox, "Singleplayer", _on_singleplayer_pressed)
|
||||
_add_button(_ui_vbox, "Multiplayer", _on_multiplayer_pressed)
|
||||
_add_button(_ui_vbox, "Settings", _on_settings_pressed)
|
||||
_add_button(_ui_vbox, "Exit Game", _on_exit_pressed)
|
||||
|
||||
func _add_button(parent: VBoxContainer, text: String, callback: Callable) -> void:
|
||||
# ==========================================
|
||||
# LEVEL SELECTOR PANEL
|
||||
# ==========================================
|
||||
_level_selector_panel = VBoxContainer.new()
|
||||
_level_selector_panel.add_theme_constant_override("separation", 20)
|
||||
_level_selector_panel.set_anchor_and_offset(SIDE_LEFT, 0.0, 50)
|
||||
_level_selector_panel.set_anchor_and_offset(SIDE_TOP, 0.0, 50)
|
||||
_level_selector_panel.set_anchor_and_offset(SIDE_RIGHT, 0.0, 800)
|
||||
_level_selector_panel.set_anchor_and_offset(SIDE_BOTTOM, 1.0, -50)
|
||||
_level_selector_panel.hide()
|
||||
add_child(_level_selector_panel)
|
||||
|
||||
var ls_title = Label.new()
|
||||
ls_title.text = "Select Level"
|
||||
ls_title.add_theme_font_size_override("font_size", 64)
|
||||
ls_title.add_theme_color_override("font_color", Color(1, 1, 1))
|
||||
ls_title.add_theme_color_override("font_outline_color", Color(0, 0, 0))
|
||||
ls_title.add_theme_constant_override("outline_size", 8)
|
||||
_level_selector_panel.add_child(ls_title)
|
||||
|
||||
# Cards Container
|
||||
var cards_hbox = HBoxContainer.new()
|
||||
cards_hbox.add_theme_constant_override("separation", 30)
|
||||
cards_hbox.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
_level_selector_panel.add_child(cards_hbox)
|
||||
|
||||
# Level 1: Dust 2
|
||||
var d2_gradient = Gradient.new()
|
||||
d2_gradient.add_point(0.0, Color(0.9, 0.8, 0.6)) # Sand
|
||||
d2_gradient.add_point(1.0, Color(0.6, 0.5, 0.3)) # Dark sand
|
||||
_build_level_card(cards_hbox, "Dust 2", "res://scenes/dust2_level/dust2_level.tscn", d2_gradient)
|
||||
|
||||
# Level 2: Test Level
|
||||
var tl_gradient = Gradient.new()
|
||||
tl_gradient.add_point(0.0, Color(0.2, 0.2, 0.25)) # Dark grey
|
||||
tl_gradient.add_point(1.0, Color(0.3, 0.5, 0.6)) # Steel blue
|
||||
_build_level_card(cards_hbox, "Test Level", "res://scenes/test_level/test_level.tscn", tl_gradient)
|
||||
|
||||
var ls_spacer = Control.new()
|
||||
ls_spacer.custom_minimum_size = Vector2(0, 20)
|
||||
_level_selector_panel.add_child(ls_spacer)
|
||||
|
||||
_add_button(_level_selector_panel, "Back", _on_back_pressed)
|
||||
|
||||
func _build_level_card(parent: Container, title: String, scene_path: String, gradient: Gradient) -> void:
|
||||
var btn = TextureButton.new()
|
||||
btn.custom_minimum_size = Vector2(300, 400)
|
||||
|
||||
var tex = GradientTexture2D.new()
|
||||
tex.gradient = gradient
|
||||
tex.width = 300
|
||||
tex.height = 400
|
||||
tex.fill_to = Vector2(1, 1)
|
||||
btn.texture_normal = tex
|
||||
|
||||
var tex_hover = GradientTexture2D.new()
|
||||
tex_hover.gradient = gradient
|
||||
tex_hover.width = 300
|
||||
tex_hover.height = 400
|
||||
tex_hover.fill_to = Vector2(1, 1)
|
||||
tex_hover.use_hdr = true # Slight bright effect on hover
|
||||
btn.texture_hover = tex_hover
|
||||
btn.modulate = Color(1, 1, 1)
|
||||
|
||||
# VBox to hold the label
|
||||
var vbox = VBoxContainer.new()
|
||||
vbox.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
vbox.alignment = BoxContainer.ALIGNMENT_END
|
||||
btn.add_child(vbox)
|
||||
|
||||
# Dimming overlay at the bottom for text readability
|
||||
var overlay = ColorRect.new()
|
||||
overlay.color = Color(0, 0, 0, 0.6)
|
||||
overlay.custom_minimum_size = Vector2(0, 60)
|
||||
vbox.add_child(overlay)
|
||||
|
||||
var lbl = Label.new()
|
||||
lbl.text = title
|
||||
lbl.add_theme_font_size_override("font_size", 32)
|
||||
lbl.add_theme_color_override("font_color", Color.WHITE)
|
||||
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
lbl.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
overlay.add_child(lbl)
|
||||
|
||||
btn.pressed.connect(func(): get_tree().change_scene_to_file(scene_path))
|
||||
|
||||
parent.add_child(btn)
|
||||
|
||||
func _add_button(parent: Container, text: String, callback: Callable) -> void:
|
||||
var btn = Button.new()
|
||||
btn.text = text
|
||||
btn.add_theme_font_size_override("font_size", 32)
|
||||
@@ -56,8 +149,13 @@ func _add_button(parent: VBoxContainer, text: String, callback: Callable) -> voi
|
||||
btn.pressed.connect(callback)
|
||||
parent.add_child(btn)
|
||||
|
||||
func _on_back_pressed() -> void:
|
||||
_level_selector_panel.hide()
|
||||
_ui_vbox.show()
|
||||
|
||||
func _on_singleplayer_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://scenes/dust2_level/dust2_level.tscn")
|
||||
_ui_vbox.hide()
|
||||
_level_selector_panel.show()
|
||||
|
||||
func _on_multiplayer_pressed() -> void:
|
||||
print("Multiplayer not implemented yet.")
|
||||
|
||||
Reference in New Issue
Block a user