Feat/9 adding main menu fundamentals #13
+14
-1
@@ -18,6 +18,12 @@ func _ready() -> void:
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _player_out_of_bounds:
|
||||
# If the player dies while out of bounds, stop the timer and remove the UI
|
||||
if "is_dead" in _player_out_of_bounds and _player_out_of_bounds.is_dead:
|
||||
_player_out_of_bounds = null
|
||||
_remove_ui()
|
||||
return
|
||||
|
||||
# Player is outside the combat area!
|
||||
time_left -= delta
|
||||
if time_left <= 0.0:
|
||||
@@ -39,6 +45,12 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _on_body_exited(body: Node3D) -> void:
|
||||
if body.name == "Player":
|
||||
# Don't trigger if the player is already dead or the scene is tearing down
|
||||
if "is_dead" in body and body.is_dead:
|
||||
return
|
||||
if body.is_queued_for_deletion() or not is_inside_tree():
|
||||
return
|
||||
|
||||
_player_out_of_bounds = body
|
||||
time_safe = 0.0 # Reset recovery timer
|
||||
_create_ui()
|
||||
@@ -74,7 +86,8 @@ func _create_ui() -> void:
|
||||
|
||||
_ui_layer.add_child(_ui_label)
|
||||
|
||||
get_tree().current_scene.add_child(_ui_layer)
|
||||
if get_tree().current_scene:
|
||||
get_tree().current_scene.call_deferred("add_child", _ui_layer)
|
||||
|
||||
func _remove_ui() -> void:
|
||||
if _ui_layer:
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ config_version=5
|
||||
[application]
|
||||
|
||||
config/name="Papaya-Shooter"
|
||||
run/main_scene="res://scenes/dust2_level/dust2_level.tscn"
|
||||
run/main_scene="res://ui/main_menu/main_menu.tscn"
|
||||
config/features=PackedStringArray("4.6", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
|
||||
@@ -0,0 +1,274 @@
|
||||
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)
|
||||
# ==========================================
|
||||
var right_panel = SubViewportContainer.new()
|
||||
right_panel.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
right_panel.stretch = true
|
||||
right_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(right_panel)
|
||||
|
||||
var viewport = SubViewport.new()
|
||||
viewport.own_world_3d = true
|
||||
right_panel.add_child(viewport)
|
||||
|
||||
_build_3d_diorama(viewport)
|
||||
|
||||
# ==========================================
|
||||
# FOREGROUND: UI (Title and Buttons)
|
||||
# ==========================================
|
||||
_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()
|
||||
title.text = "Papaya Shooter"
|
||||
title.add_theme_font_size_override("font_size", 72)
|
||||
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)
|
||||
|
||||
# Spacer
|
||||
var spacer = Control.new()
|
||||
spacer.custom_minimum_size = Vector2(0, 40)
|
||||
_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, "Loadouts", _on_loadouts_pressed)
|
||||
_add_button(_ui_vbox, "Settings", _on_settings_pressed)
|
||||
_add_button(_ui_vbox, "Exit Game", _on_exit_pressed)
|
||||
|
||||
# ==========================================
|
||||
# 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)
|
||||
btn.custom_minimum_size = Vector2(300, 60)
|
||||
btn.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
|
||||
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:
|
||||
_ui_vbox.hide()
|
||||
_level_selector_panel.show()
|
||||
|
||||
func _on_multiplayer_pressed() -> void:
|
||||
print("Multiplayer not implemented yet.")
|
||||
|
||||
func _on_loadouts_pressed() -> void:
|
||||
if has_node("/root/PauseMenu"):
|
||||
var pm = get_node("/root/PauseMenu")
|
||||
pm.visible = true
|
||||
pm._show_loadouts()
|
||||
|
||||
func _on_settings_pressed() -> void:
|
||||
if has_node("/root/PauseMenu"):
|
||||
var pm = get_node("/root/PauseMenu")
|
||||
pm.visible = true
|
||||
pm._show_settings()
|
||||
|
||||
func _on_exit_pressed() -> void:
|
||||
get_tree().quit()
|
||||
|
||||
# ==========================================
|
||||
# 3D DIORAMA BUILDER
|
||||
# ==========================================
|
||||
func _build_3d_diorama(viewport: SubViewport) -> void:
|
||||
var world = Node3D.new()
|
||||
viewport.add_child(world)
|
||||
|
||||
# Lighting and Env
|
||||
var env = WorldEnvironment.new()
|
||||
var environment = Environment.new()
|
||||
environment.background_mode = Environment.BG_COLOR
|
||||
environment.background_color = Color(0.1, 0.15, 0.2) # Dark stylish background
|
||||
environment.tonemap_mode = Environment.TONE_MAPPER_ACES
|
||||
env.environment = environment
|
||||
world.add_child(env)
|
||||
|
||||
var sun = DirectionalLight3D.new()
|
||||
sun.rotation_degrees = Vector3(-45, 45, 0)
|
||||
sun.light_color = Color(1.0, 0.9, 0.8)
|
||||
sun.light_energy = 1.5
|
||||
sun.shadow_enabled = true
|
||||
world.add_child(sun)
|
||||
|
||||
var fill = DirectionalLight3D.new()
|
||||
fill.rotation_degrees = Vector3(-30, -135, 0)
|
||||
fill.light_color = Color(0.5, 0.6, 1.0)
|
||||
fill.light_energy = 0.5
|
||||
world.add_child(fill)
|
||||
|
||||
# Floor
|
||||
var floor_mesh = MeshInstance3D.new()
|
||||
floor_mesh.mesh = PlaneMesh.new()
|
||||
floor_mesh.mesh.size = Vector2(20, 20)
|
||||
var floor_mat = StandardMaterial3D.new()
|
||||
floor_mat.albedo_color = Color(0.2, 0.2, 0.2)
|
||||
floor_mesh.mesh.surface_set_material(0, floor_mat)
|
||||
world.add_child(floor_mesh)
|
||||
|
||||
# Player Model (Sliding Pose)
|
||||
var player_model = Node3D.new()
|
||||
player_model.position = Vector3(0, 0.5, 0) # Lowered for slide
|
||||
world.add_child(player_model)
|
||||
|
||||
var body_mat = StandardMaterial3D.new()
|
||||
body_mat.albedo_color = Color(0.3, 0.6, 0.9)
|
||||
|
||||
# Torso (Capsule tilted back)
|
||||
var torso = MeshInstance3D.new()
|
||||
var t_mesh = CapsuleMesh.new()
|
||||
t_mesh.radius = 0.4
|
||||
t_mesh.height = 1.2
|
||||
t_mesh.material = body_mat
|
||||
torso.mesh = t_mesh
|
||||
torso.rotation_degrees.x = -60 # Tilted back
|
||||
torso.position = Vector3(0, 0.4, 0)
|
||||
player_model.add_child(torso)
|
||||
|
||||
# Legs (Sticking forward)
|
||||
var legs = MeshInstance3D.new()
|
||||
var l_mesh = BoxMesh.new()
|
||||
l_mesh.size = Vector3(0.6, 0.4, 1.2)
|
||||
l_mesh.material = body_mat
|
||||
legs.mesh = l_mesh
|
||||
legs.position = Vector3(0, -0.2, 0.6)
|
||||
player_model.add_child(legs)
|
||||
|
||||
# Arm holding shotgun
|
||||
var arm = Node3D.new()
|
||||
arm.position = Vector3(0.5, 0.6, 0.2)
|
||||
player_model.add_child(arm)
|
||||
|
||||
var arm_mesh = MeshInstance3D.new()
|
||||
var a_mesh = BoxMesh.new()
|
||||
a_mesh.size = Vector3(0.2, 0.2, 0.8)
|
||||
a_mesh.material = body_mat
|
||||
arm_mesh.mesh = a_mesh
|
||||
arm_mesh.position = Vector3(0, 0, 0.3)
|
||||
arm.add_child(arm_mesh)
|
||||
|
||||
# Shotgun
|
||||
var shotgun_script = load("res://weapons/double_barrel_shotgun.gd")
|
||||
if shotgun_script:
|
||||
var shotgun = shotgun_script.new()
|
||||
arm_mesh.add_child(shotgun)
|
||||
shotgun.position = Vector3(0, -0.1, 0.4)
|
||||
shotgun.rotation_degrees = Vector3(0, 0, 0)
|
||||
shotgun.set_process(false)
|
||||
shotgun.set_physics_process(false)
|
||||
if shotgun.has_method("set_process_input"):
|
||||
shotgun.set_process_input(false)
|
||||
|
||||
# Camera
|
||||
var camera = Camera3D.new()
|
||||
world.add_child(camera)
|
||||
camera.position = Vector3(3, 1.5, 4)
|
||||
camera.look_at(Vector3(0, 0.5, 0))
|
||||
@@ -0,0 +1 @@
|
||||
uid://dflvxkquwjl42
|
||||
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b0x123456789"]
|
||||
|
||||
[ext_resource type="Script" path="res://ui/main_menu/main_menu.gd" id="1_1a2b3"]
|
||||
|
||||
[node name="MainMenu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_1a2b3")
|
||||
@@ -6,6 +6,7 @@ var resume_btn: Button
|
||||
var respawn_btn: Button
|
||||
var loadouts_btn: Button
|
||||
var settings_btn: Button
|
||||
var return_btn: Button
|
||||
var exit_btn: Button
|
||||
|
||||
# Loadout UI
|
||||
@@ -48,6 +49,7 @@ var rebind_label: Label
|
||||
var waiting_for_input_action: String = ""
|
||||
|
||||
var quit_dialog: ConfirmationDialog
|
||||
var return_dialog: ConfirmationDialog
|
||||
|
||||
func _ready() -> void:
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
@@ -70,6 +72,10 @@ func _input(event: InputEvent) -> void:
|
||||
return
|
||||
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
# Don't open the pause menu if we are already in the main menu
|
||||
if get_tree().current_scene and get_tree().current_scene.name == "MainMenu":
|
||||
return
|
||||
|
||||
if visible:
|
||||
_resume()
|
||||
else:
|
||||
@@ -129,6 +135,11 @@ func _build_ui() -> void:
|
||||
settings_btn.custom_minimum_size = Vector2(200, 50)
|
||||
main_vbox.add_child(settings_btn)
|
||||
|
||||
return_btn = Button.new()
|
||||
return_btn.text = "Main Menu"
|
||||
return_btn.custom_minimum_size = Vector2(200, 50)
|
||||
main_vbox.add_child(return_btn)
|
||||
|
||||
exit_btn = Button.new()
|
||||
exit_btn.text = "Exit Game"
|
||||
exit_btn.custom_minimum_size = Vector2(200, 50)
|
||||
@@ -571,6 +582,12 @@ func _build_ui() -> void:
|
||||
quit_dialog.title = "Quit Game"
|
||||
quit_dialog.dialog_text = "Are you sure you want to close the game?"
|
||||
add_child(quit_dialog)
|
||||
|
||||
# ── Return Dialog ──
|
||||
return_dialog = ConfirmationDialog.new()
|
||||
return_dialog.title = "Main Menu"
|
||||
return_dialog.dialog_text = "Are you sure you want to return to the main menu?"
|
||||
add_child(return_dialog)
|
||||
|
||||
func _build_vol_control(parent: Node, label_name: String) -> Array:
|
||||
var hbox = HBoxContainer.new()
|
||||
@@ -619,13 +636,26 @@ func _connect_signals() -> void:
|
||||
respawn_btn.pressed.connect(_respawn)
|
||||
loadouts_btn.pressed.connect(_show_loadouts)
|
||||
settings_btn.pressed.connect(_show_settings)
|
||||
return_btn.pressed.connect(_show_return_dialog)
|
||||
exit_btn.pressed.connect(_show_exit_dialog)
|
||||
back_to_main_btn.pressed.connect(_show_main_menu)
|
||||
settings_back_btn.pressed.connect(_show_main_menu)
|
||||
save_loadout_btn.pressed.connect(_save_current_loadout)
|
||||
quit_dialog.confirmed.connect(_quit_game)
|
||||
return_dialog.confirmed.connect(_return_to_main_menu)
|
||||
|
||||
func _show_return_dialog() -> void:
|
||||
return_dialog.popup_centered()
|
||||
|
||||
func _return_to_main_menu() -> void:
|
||||
_resume() # Reset pause state and cursor mode
|
||||
get_tree().change_scene_to_file("res://ui/main_menu/main_menu.tscn")
|
||||
|
||||
func _show_main_menu() -> void:
|
||||
if get_tree().current_scene and get_tree().current_scene.name == "MainMenu":
|
||||
visible = false
|
||||
return
|
||||
|
||||
main_vbox.visible = true
|
||||
loadout_editor.visible = false
|
||||
settings_editor.visible = false
|
||||
|
||||
Reference in New Issue
Block a user