Added main menu and settings
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
class_name MainMenu
|
||||
extends Control
|
||||
|
||||
|
||||
@onready var start_button : Button = $%StartButton
|
||||
@onready var options_button : Button = $%OptionsButton
|
||||
@onready var quit_button : Button = $%QuitButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
func _init_focus() -> void:
|
||||
start_button.grab_focus()
|
||||
|
||||
|
||||
func _setup_neighbors() -> void:
|
||||
start_button.focus_neighbor_top = quit_button.get_path()
|
||||
quit_button.focus_neighbor_bottom = start_button.get_path()
|
||||
|
||||
|
||||
func _on_start_button_pressed() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_options_button_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://game/menu/options_menu.tscn")
|
||||
|
||||
|
||||
func _on_quit_button_pressed() -> void:
|
||||
get_tree().quit()
|
||||
@@ -0,0 +1 @@
|
||||
uid://c3wyvemy5hxs2
|
||||
@@ -0,0 +1,65 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://c4iica45gnke0"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c3wyvemy5hxs2" path="res://game/menu/main_menu.gd" id="1_5d27k"]
|
||||
[ext_resource type="Theme" uid="uid://bh56my8b2htnr" path="res://themes/menu.tres" id="2_qnvmd"]
|
||||
[ext_resource type="Theme" uid="uid://lkf8obv8x5ve" path="res://themes/label.tres" id="3_i4f54"]
|
||||
|
||||
[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
|
||||
theme = ExtResource("2_qnvmd")
|
||||
script = ExtResource("1_5d27k")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="StartButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Start"
|
||||
|
||||
[node name="OptionsButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Options"
|
||||
|
||||
[node name="QuitButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Quit"
|
||||
|
||||
[node name="CopyrightLabel" type="Label" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 1
|
||||
theme = ExtResource("3_i4f54")
|
||||
text = "(c) Ruslan Ignatov 2026
|
||||
Powered by Godot Engine"
|
||||
horizontal_alignment = 2
|
||||
vertical_alignment = 2
|
||||
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/StartButton" to="." method="_on_start_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/QuitButton" to="." method="_on_quit_button_pressed"]
|
||||
@@ -0,0 +1,118 @@
|
||||
class_name OptionsMenu
|
||||
extends Control
|
||||
|
||||
|
||||
const WINDOW_FACTOR = "window_factor"
|
||||
|
||||
|
||||
signal back
|
||||
|
||||
|
||||
@onready var fullscreen_button : CheckButton = $%FullscreenCheckButton
|
||||
@onready var window_factor_buttons : HBoxContainer = $%WindowFactorContainer
|
||||
@onready var back_button : Button = $%BackButton
|
||||
@onready var master_slider : Slider = $%MasterSlider
|
||||
@onready var ui_slider : Slider = $%UISlider
|
||||
@onready var sfx_slider : Slider = $%SFXSlider
|
||||
@onready var music_slider : Slider = $%MusicSlider
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_connect_window_factor_buttons()
|
||||
_load_current_settings()
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
func _play_left_sound() -> bool:
|
||||
return _play_side_sound(1, 0)
|
||||
|
||||
|
||||
func _play_right_sound() -> bool:
|
||||
return _play_side_sound(0, 1)
|
||||
|
||||
|
||||
func _play_side_sound(offset_begin: int, offset_end: int) -> bool:
|
||||
for i in range(offset_begin, window_factor_buttons.get_child_count() - offset_end):
|
||||
var child := window_factor_buttons.get_child(i)
|
||||
if child is Button and child.has_focus():
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _connect_window_factor_buttons() -> void:
|
||||
for child in window_factor_buttons.get_children():
|
||||
if child is Button:
|
||||
var button : Button = child
|
||||
button.pressed.connect(_on_window_factor_button_pressed.bind(button))
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_node_ready(): return
|
||||
if not visible: return
|
||||
|
||||
_load_current_settings()
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
func _init_focus() -> void:
|
||||
fullscreen_button.grab_focus()
|
||||
|
||||
|
||||
func _setup_neighbors() -> void:
|
||||
music_slider.focus_neighbor_bottom = back_button.get_path()
|
||||
|
||||
|
||||
func _load_current_settings() -> void:
|
||||
fullscreen_button.button_pressed = SettingsManager.fullscreen
|
||||
for child in window_factor_buttons.get_children():
|
||||
if child is Button:
|
||||
var button : Button = child
|
||||
var window_factor : int = button.get_meta(WINDOW_FACTOR, 0)
|
||||
if window_factor == SettingsManager.window_factor:
|
||||
button.button_pressed = true
|
||||
_update_window_factor_disabled()
|
||||
|
||||
master_slider.value = SettingsManager.master_volume
|
||||
ui_slider.value = SettingsManager.ui_volume
|
||||
sfx_slider.value = SettingsManager.sfx_volume
|
||||
music_slider.value = SettingsManager.music_volume
|
||||
|
||||
|
||||
func _update_window_factor_disabled() -> void:
|
||||
for child in window_factor_buttons.get_children():
|
||||
if not child is Button: continue
|
||||
child.disabled = SettingsManager.fullscreen
|
||||
child.focus_mode = Control.FOCUS_NONE if SettingsManager.fullscreen else Control.FOCUS_ALL
|
||||
|
||||
|
||||
func _on_fullscreen_check_button_toggled(toggled: bool) -> void:
|
||||
SettingsManager.fullscreen = toggled
|
||||
_update_window_factor_disabled()
|
||||
|
||||
|
||||
func _on_back_button_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://game/menu/main_menu.tscn")
|
||||
|
||||
|
||||
func _on_window_factor_button_pressed(button: Button) -> void:
|
||||
var window_factor : int = button.get_meta(WINDOW_FACTOR, 0)
|
||||
if window_factor > 0:
|
||||
SettingsManager.window_factor = window_factor
|
||||
|
||||
|
||||
func _on_master_volume_changed(value: float) -> void:
|
||||
SettingsManager.master_volume = floor(value)
|
||||
|
||||
|
||||
func _on_ui_volume_changed(value: float) -> void:
|
||||
SettingsManager.ui_volume = floor(value)
|
||||
|
||||
|
||||
func _on_sfx_volume_changed(value: float) -> void:
|
||||
SettingsManager.sfx_volume = floor(value)
|
||||
|
||||
|
||||
func _on_music_volume_changed(value: float) -> void:
|
||||
SettingsManager.music_volume = floor(value)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cesv42oxhq2px
|
||||
@@ -0,0 +1,157 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b0uhlmrggp8xx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cesv42oxhq2px" path="res://game/menu/options_menu.gd" id="1_lq2ks"]
|
||||
[ext_resource type="Theme" uid="uid://bh56my8b2htnr" path="res://themes/menu.tres" id="2_e2bp2"]
|
||||
|
||||
[sub_resource type="InputEventAction" id="InputEventAction_e2bp2"]
|
||||
action = &"ui_cancel"
|
||||
|
||||
[sub_resource type="Shortcut" id="Shortcut_j72d6"]
|
||||
events = [SubResource("InputEventAction_e2bp2")]
|
||||
|
||||
[node name="OptionsMenu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme = ExtResource("2_e2bp2")
|
||||
script = ExtResource("1_lq2ks")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme = ExtResource("2_e2bp2")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="GridContainer" type="GridContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/h_separation = 12
|
||||
theme_override_constants/v_separation = 17
|
||||
columns = 2
|
||||
|
||||
[node name="FullscreenLabel" type="Label" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="FullscreenCheckButton" type="CheckButton" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Fullscreen"
|
||||
|
||||
[node name="WindowFactorLabel" type="Label" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "Window
|
||||
factor"
|
||||
|
||||
[node name="WindowFactorContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ButtonX1" type="Button" parent="MarginContainer/VBoxContainer/GridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
text = "*1"
|
||||
metadata/window_factor = 1
|
||||
|
||||
[node name="ButtonX2" type="Button" parent="MarginContainer/VBoxContainer/GridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
text = "*2"
|
||||
metadata/window_factor = 2
|
||||
|
||||
[node name="ButtonX3" type="Button" parent="MarginContainer/VBoxContainer/GridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
text = "*3"
|
||||
metadata/window_factor = 3
|
||||
|
||||
[node name="ButtonX4" type="Button" parent="MarginContainer/VBoxContainer/GridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
text = "*4"
|
||||
metadata/window_factor = 4
|
||||
|
||||
[node name="ButtonX5" type="Button" parent="MarginContainer/VBoxContainer/GridContainer/WindowFactorContainer"]
|
||||
layout_mode = 2
|
||||
text = "*5"
|
||||
metadata/window_factor = 5
|
||||
|
||||
[node name="MasterLabel" type="Label" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "Master"
|
||||
|
||||
[node name="MasterSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
step = 10.0
|
||||
value = 50.0
|
||||
tick_count = 11
|
||||
ticks_on_borders = true
|
||||
ticks_position = 3
|
||||
|
||||
[node name="UILabel" type="Label" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "UI"
|
||||
|
||||
[node name="UISlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
step = 10.0
|
||||
tick_count = 11
|
||||
ticks_on_borders = true
|
||||
ticks_position = 3
|
||||
|
||||
[node name="SFXLabel" type="Label" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "SFX"
|
||||
|
||||
[node name="SFXSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
step = 10.0
|
||||
tick_count = 11
|
||||
ticks_on_borders = true
|
||||
ticks_position = 3
|
||||
|
||||
[node name="MusicLabel" type="Label" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "Music"
|
||||
|
||||
[node name="MusicSlider" type="HSlider" parent="MarginContainer/VBoxContainer/GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
step = 10.0
|
||||
tick_count = 11
|
||||
ticks_on_borders = true
|
||||
ticks_position = 3
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="BackButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
shortcut = SubResource("Shortcut_j72d6")
|
||||
text = "Back"
|
||||
|
||||
[connection signal="toggled" from="MarginContainer/VBoxContainer/GridContainer/FullscreenCheckButton" to="." method="_on_fullscreen_check_button_toggled"]
|
||||
[connection signal="value_changed" from="MarginContainer/VBoxContainer/GridContainer/MasterSlider" to="." method="_on_master_volume_changed"]
|
||||
[connection signal="value_changed" from="MarginContainer/VBoxContainer/GridContainer/UISlider" to="." method="_on_ui_volume_changed"]
|
||||
[connection signal="value_changed" from="MarginContainer/VBoxContainer/GridContainer/SFXSlider" to="." method="_on_sfx_volume_changed"]
|
||||
[connection signal="value_changed" from="MarginContainer/VBoxContainer/GridContainer/MusicSlider" to="." method="_on_music_volume_changed"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer/BackButton" to="." method="_on_back_button_pressed"]
|
||||
Reference in New Issue
Block a user