Menus organized in dirs
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
extends Control
|
||||
|
||||
|
||||
signal continue_game
|
||||
signal new_game
|
||||
signal quit_game
|
||||
signal show_options
|
||||
|
||||
|
||||
@onready var continue_button := $%ContinueButton
|
||||
@onready var start_button := $%StartButton
|
||||
@onready var quit_button := $%QuitButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
_update_continue_button()
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_node_ready(): return
|
||||
if not visible: return
|
||||
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
_update_continue_button()
|
||||
|
||||
|
||||
func _update_continue_button() -> void:
|
||||
continue_button.disabled = SaveManager.game_data.game_seed.is_empty()
|
||||
|
||||
|
||||
func _init_focus() -> void:
|
||||
if continue_button.disabled:
|
||||
start_button.grab_focus()
|
||||
else:
|
||||
continue_button.grab_focus()
|
||||
|
||||
|
||||
func _setup_neighbors() -> void:
|
||||
if continue_button.disabled:
|
||||
continue_button.focus_neighbor_top = ""
|
||||
start_button.focus_neighbor_top = quit_button.get_path()
|
||||
quit_button.focus_neighbor_bottom = start_button.get_path()
|
||||
else:
|
||||
continue_button.focus_neighbor_top = quit_button.get_path()
|
||||
start_button.focus_neighbor_top = ""
|
||||
quit_button.focus_neighbor_bottom = continue_button.get_path()
|
||||
|
||||
|
||||
func _on_continue_button_pressed() -> void:
|
||||
continue_game.emit()
|
||||
|
||||
|
||||
func _on_start_button_pressed() -> void:
|
||||
new_game.emit()
|
||||
|
||||
|
||||
func _on_options_button_pressed() -> void:
|
||||
show_options.emit()
|
||||
|
||||
|
||||
func _on_quit_button_pressed() -> void:
|
||||
quit_game.emit()
|
||||
@@ -0,0 +1 @@
|
||||
uid://dixdfabe2vfsj
|
||||
@@ -0,0 +1,54 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://bxlccevt52y70"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dixdfabe2vfsj" path="res://menu/main/main_menu.gd" id="1_chmv6"]
|
||||
[ext_resource type="Theme" uid="uid://dtnd3tqllufey" path="res://images/menu_button.tres" id="2_f5okj"]
|
||||
|
||||
[node name="MainMenu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
script = ExtResource("1_chmv6")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
top_level = true
|
||||
layout_mode = 0
|
||||
offset_left = 100.0
|
||||
offset_top = 100.0
|
||||
offset_right = 179.0
|
||||
offset_bottom = 236.0
|
||||
|
||||
[node name="ContinueButton" type="Button" parent="VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_f5okj")
|
||||
disabled = true
|
||||
button_mask = 0
|
||||
text = "CONTINUE"
|
||||
|
||||
[node name="StartButton" type="Button" parent="VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_f5okj")
|
||||
button_mask = 0
|
||||
text = "START"
|
||||
|
||||
[node name="OptionsButton" type="Button" parent="VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_f5okj")
|
||||
text = "OPTIONS"
|
||||
|
||||
[node name="QuitButton" type="Button" parent="VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_f5okj")
|
||||
text = "QUIT"
|
||||
|
||||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||
[connection signal="pressed" from="VBoxContainer/ContinueButton" to="." method="_on_continue_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/StartButton" to="." method="_on_start_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/QuitButton" to="." method="_on_quit_button_pressed"]
|
||||
@@ -0,0 +1,96 @@
|
||||
class_name SeedSelectionMenu
|
||||
extends Control
|
||||
|
||||
|
||||
signal back
|
||||
|
||||
|
||||
const SEED_CHARS := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
const DEFAULT_SEED_LENGTH := 16
|
||||
|
||||
|
||||
var _seed_regex := RegEx.new()
|
||||
var _random_seed := ""
|
||||
|
||||
|
||||
@onready var seed_label : Label = $%SeedLabel
|
||||
@onready var seed_edit : LineEdit = $%SeedEdit
|
||||
|
||||
@onready var use_random_button : Button = $%UseRandomButton
|
||||
@onready var use_custom_button : Button = $%UseCustomButton
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
var regex_pattern := "[%s]+" % SEED_CHARS
|
||||
_seed_regex.compile(regex_pattern)
|
||||
|
||||
|
||||
func _update_use_custom_button() -> void:
|
||||
var disabled := seed_edit.text.is_empty()
|
||||
use_custom_button.disabled = disabled
|
||||
use_custom_button.focus_mode = FOCUS_NONE if disabled else FOCUS_ALL
|
||||
|
||||
|
||||
func _init_focus() -> void:
|
||||
_update_use_custom_button()
|
||||
use_random_button.grab_focus()
|
||||
|
||||
|
||||
func _get_random_seed() -> String:
|
||||
var seed_chars_length := SEED_CHARS.length()
|
||||
|
||||
var random_seed := ""
|
||||
for i in range(DEFAULT_SEED_LENGTH):
|
||||
var index := randi_range(1, seed_chars_length) - 1
|
||||
random_seed += SEED_CHARS[index]
|
||||
|
||||
return random_seed
|
||||
|
||||
|
||||
func _start_game(game_seed: String) -> void:
|
||||
SaveManager.new_game(game_seed)
|
||||
get_tree().change_scene_to_file("res://game/game.tscn")
|
||||
|
||||
|
||||
func _on_seed_edit_text_changed(new_text: String) -> void:
|
||||
var result := _seed_regex.search_all(new_text)
|
||||
|
||||
var filtered_text := ""
|
||||
for text in result:
|
||||
filtered_text += text.get_string()
|
||||
|
||||
if seed_edit.text != filtered_text:
|
||||
var caret_position := seed_edit.caret_column
|
||||
seed_edit.text = filtered_text
|
||||
seed_edit.caret_column = min(caret_position, filtered_text.length())
|
||||
|
||||
_update_use_custom_button()
|
||||
|
||||
|
||||
func _on_seed_edit_text_submitted(new_text: String) -> void:
|
||||
if not new_text.is_empty():
|
||||
use_custom_button.grab_focus()
|
||||
|
||||
|
||||
func _on_back_button_pressed() -> void:
|
||||
back.emit()
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_node_ready(): return
|
||||
if not visible: return
|
||||
|
||||
_random_seed = _get_random_seed()
|
||||
|
||||
seed_edit.text = ""
|
||||
seed_label.text = _random_seed
|
||||
|
||||
_init_focus()
|
||||
|
||||
|
||||
func _on_use_random_button_pressed() -> void:
|
||||
_start_game(_random_seed)
|
||||
|
||||
|
||||
func _on_use_custom_button_pressed() -> void:
|
||||
_start_game(seed_edit.text)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dyynshvsgnepp
|
||||
@@ -0,0 +1,80 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://c36n317rhv8k7"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dyynshvsgnepp" path="res://menu/main/seed_selection_menu.gd" id="1_g2smo"]
|
||||
[ext_resource type="Theme" uid="uid://dtnd3tqllufey" path="res://images/menu_button.tres" id="2_s4s14"]
|
||||
|
||||
[sub_resource type="InputEventAction" id="InputEventAction_g2smo"]
|
||||
action = &"ui_cancel"
|
||||
|
||||
[sub_resource type="Shortcut" id="Shortcut_s4s14"]
|
||||
events = [SubResource("InputEventAction_g2smo")]
|
||||
|
||||
[node name="SeedSelectionMenu" 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_g2smo")
|
||||
|
||||
[node name="GridContainer" type="GridContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -107.5
|
||||
offset_top = -33.0
|
||||
offset_right = 107.5
|
||||
offset_bottom = 33.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
columns = 2
|
||||
|
||||
[node name="SeedLabel" type="Label" parent="GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="UseRandomButton" type="Button" parent="GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_s4s14")
|
||||
text = "Use random seed"
|
||||
|
||||
[node name="SeedEdit" type="LineEdit" parent="GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
placeholder_text = "Enter seed"
|
||||
alignment = 1
|
||||
max_length = 16
|
||||
|
||||
[node name="UseCustomButton" type="Button" parent="GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_s4s14")
|
||||
text = "Use custom seed"
|
||||
|
||||
[node name="Label" type="Label" parent="GridContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="BackButton" type="Button" parent="GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme = ExtResource("2_s4s14")
|
||||
shortcut = SubResource("Shortcut_s4s14")
|
||||
text = "Main menu"
|
||||
|
||||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||
[connection signal="pressed" from="GridContainer/UseRandomButton" to="." method="_on_use_random_button_pressed"]
|
||||
[connection signal="text_changed" from="GridContainer/SeedEdit" to="." method="_on_seed_edit_text_changed"]
|
||||
[connection signal="text_submitted" from="GridContainer/SeedEdit" to="." method="_on_seed_edit_text_submitted"]
|
||||
[connection signal="pressed" from="GridContainer/UseCustomButton" to="." method="_on_use_custom_button_pressed"]
|
||||
[connection signal="pressed" from="GridContainer/BackButton" to="." method="_on_back_button_pressed"]
|
||||
@@ -0,0 +1,53 @@
|
||||
extends Control
|
||||
|
||||
|
||||
@onready var main_menu : Control = $MainMenu
|
||||
@onready var options : Control = $Options
|
||||
@onready var credits : Control = $Credits
|
||||
@onready var seed_selection : Control = $SeedSelection
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
|
||||
_show_menu(main_menu)
|
||||
|
||||
|
||||
func _show_menu(menu: Control) -> void:
|
||||
var menus : Array[Control] = [ main_menu, options, credits, seed_selection ]
|
||||
|
||||
for m in menus:
|
||||
m.hide()
|
||||
|
||||
menu.show()
|
||||
|
||||
|
||||
func _on_main_menu_continue_game() -> void:
|
||||
get_tree().change_scene_to_file("res://game/game.tscn")
|
||||
|
||||
|
||||
func _on_main_menu_new_game() -> void:
|
||||
_show_menu(seed_selection)
|
||||
|
||||
|
||||
func _get_random_weapon_id() -> String:
|
||||
return AbstractShip.WEAPON_SCENES.keys().pick_random()
|
||||
|
||||
|
||||
func _on_main_menu_quit_game() -> void:
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func _on_main_menu_show_options() -> void:
|
||||
_show_menu(options)
|
||||
|
||||
|
||||
func _on_options_show_credits() -> void:
|
||||
_show_menu(credits)
|
||||
|
||||
|
||||
func _on_credits_back() -> void:
|
||||
_show_menu(options)
|
||||
|
||||
|
||||
func _show_main_menu() -> void:
|
||||
_show_menu(main_menu)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bqnepsuk13qo8
|
||||
@@ -0,0 +1,46 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://2oavbr7oaihg"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bqnepsuk13qo8" path="res://menu/main/title_screen.gd" id="1_lxdol"]
|
||||
[ext_resource type="PackedScene" uid="uid://bxlccevt52y70" path="res://menu/main/main_menu.tscn" id="2_o0rbc"]
|
||||
[ext_resource type="PackedScene" uid="uid://btr60idiit4y7" path="res://menu/common/options.tscn" id="3_88gnj"]
|
||||
[ext_resource type="PackedScene" uid="uid://c3q3g2647qc27" path="res://menu/common/credits.tscn" id="4_w1y3c"]
|
||||
[ext_resource type="PackedScene" uid="uid://chdrjc7c6bdpb" path="res://game/background.tscn" id="5_88gnj"]
|
||||
[ext_resource type="PackedScene" uid="uid://c36n317rhv8k7" path="res://menu/main/seed_selection_menu.tscn" id="5_w1y3c"]
|
||||
|
||||
[node name="TitleScreen" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
script = ExtResource("1_lxdol")
|
||||
|
||||
[node name="MainMenu" parent="." instance=ExtResource("2_o0rbc")]
|
||||
layout_mode = 0
|
||||
|
||||
[node name="Options" parent="." instance=ExtResource("3_88gnj")]
|
||||
layout_mode = 0
|
||||
|
||||
[node name="Credits" parent="." instance=ExtResource("4_w1y3c")]
|
||||
layout_mode = 0
|
||||
|
||||
[node name="SeedSelection" parent="." instance=ExtResource("5_w1y3c")]
|
||||
layout_mode = 0
|
||||
anchors_preset = 0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
offset_left = 320.0
|
||||
offset_top = 190.0
|
||||
offset_right = 320.0
|
||||
offset_bottom = 190.0
|
||||
grow_horizontal = 1
|
||||
grow_vertical = 1
|
||||
size_flags_horizontal = 4
|
||||
|
||||
[node name="Background" parent="." instance=ExtResource("5_88gnj")]
|
||||
|
||||
[connection signal="continue_game" from="MainMenu" to="." method="_on_main_menu_continue_game"]
|
||||
[connection signal="new_game" from="MainMenu" to="." method="_on_main_menu_new_game"]
|
||||
[connection signal="quit_game" from="MainMenu" to="." method="_on_main_menu_quit_game"]
|
||||
[connection signal="show_options" from="MainMenu" to="." method="_on_main_menu_show_options"]
|
||||
[connection signal="back" from="Options" to="." method="_show_main_menu"]
|
||||
[connection signal="show_credits" from="Options" to="." method="_on_options_show_credits"]
|
||||
[connection signal="back" from="Credits" to="." method="_on_credits_back"]
|
||||
[connection signal="back" from="SeedSelection" to="." method="_show_main_menu"]
|
||||
Reference in New Issue
Block a user