implemented level select, options menu, different audio buses & sliders

This commit is contained in:
KingGurke 2023-10-02 11:43:44 +02:00
parent 17085c5148
commit f51914161e
14 changed files with 485 additions and 46 deletions

48
src/gui/hud/hud.tscn Normal file
View file

@ -0,0 +1,48 @@
[gd_scene load_steps=4 format=3 uid="uid://cdlbh3smpgg42"]
[ext_resource type="Script" path="res://src/gui/hud/hud_controller.gd" id="1_3pkgo"]
[sub_resource type="LabelSettings" id="LabelSettings_pv71o"]
font_size = 40
[sub_resource type="LabelSettings" id="LabelSettings_cu1nb"]
font_size = 34
[node name="hud" type="Control" node_paths=PackedStringArray("speed", "distance")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_3pkgo")
speed = NodePath("Speedometer")
distance = NodePath("Distancemeter")
[node name="Speedometer" type="Label" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -220.0
offset_top = -103.0
grow_horizontal = 0
grow_vertical = 0
text = "speed"
label_settings = SubResource("LabelSettings_pv71o")
horizontal_alignment = 2
vertical_alignment = 2
[node name="Distancemeter" type="Label" parent="."]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -20.0
offset_right = 20.0
offset_bottom = 23.0
grow_horizontal = 2
text = "distance"
label_settings = SubResource("LabelSettings_cu1nb")

View file

@ -0,0 +1,15 @@
extends Control
#references
## reference to the speedometer label
@export var speed: Label
## reference to the distance meter label
@export var distance: Label
func _on_player_speed_changed(speed_float:float):
var speed_string = "%.f" % speed_float
# print_debug("changing speed display to ", speed_string)
speed.set_text(speed_string)
func _on_level_distance_changed(distance_float):
var distance_string ="%.f" % distance_float
distance.set_text(distance_string)

12
src/gui/menu/level.tscn Normal file
View file

@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://dyo5dblkfivwn"]
[ext_resource type="Theme" uid="uid://dpktnl3r5wul1" path="res://src/gui/menu_theme.tres" id="1_62uke"]
[node name="level" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_62uke")

View file

@ -1,5 +1,8 @@
extends Control
@export var main_menu: Control
@export var level_select: Control
# Called when the node enters the scene tree for the first time.
func _ready():
@ -12,12 +15,24 @@ func _process(delta):
func _on_start_button_pressed():
get_tree().change_scene("res://game/main.tscn")
# get_tree().change_scene("res://game/main.tscn")
main_menu.hide()
level_select.show()
func _on_options_button_pressed():
var options = load("res://menu/options.tscn").instance()
var options = load("res://src/gui/menu/options.tscn").instantiate()
get_tree().current_scene.add_child((options))
func _on_quit_button_pressed():
get_tree().quit()
func _on_back_button_pressed():
level_select.hide()
main_menu.show()
func _on_level_button_pressed(level:int):
load_level("res://src/game/levels/level_%s.tscn" % level)
func load_level(path: String):
get_tree().change_scene_to_file(path)

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://bgtkxeh3lciik"]
[gd_scene load_steps=8 format=3 uid="uid://bgtkxeh3lciik"]
[ext_resource type="Script" path="res://src/gui/menu/main.gd" id="1_p5r7q"]
[ext_resource type="AudioStream" uid="uid://dh5jxxwim7ra8" path="res://assets/sounds/music/death_by_waveshaper.wav" id="2_yc480"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2u7je"]
bg_color = Color(1, 1, 1, 1)
@ -35,25 +36,37 @@ corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_5it3g"]
bg_color = Color(0, 0, 0, 1)
corner_radius_top_left = 10
corner_radius_top_right = 10
corner_radius_bottom_right = 10
corner_radius_bottom_left = 10
[sub_resource type="Theme" id="Theme_67fiq"]
Button/colors/font_color = Color(0, 0, 0, 1)
Button/colors/font_focus_color = Color(0, 0, 0, 1)
Button/colors/font_hover_color = Color(0, 0, 0, 1)
Button/colors/font_hover_pressed_color = Color(0, 0, 0, 1)
Button/colors/font_hover_pressed_color = Color(1, 1, 1, 1)
Button/colors/font_pressed_color = Color(1, 1, 1, 1)
Button/styles/hover = SubResource("StyleBoxFlat_2u7je")
Button/styles/normal = SubResource("StyleBoxFlat_uo2yv")
Button/styles/pressed = SubResource("StyleBoxFlat_sjhib")
Panel/styles/panel = SubResource("StyleBoxFlat_5it3g")
[node name="Menu" type="Control"]
[node name="Menu" type="Control" node_paths=PackedStringArray("main_menu", "level_select")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = 1.0
offset_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = SubResource("Theme_67fiq")
script = ExtResource("1_p5r7q")
main_menu = NodePath("VBoxContainer")
level_select = NodePath("LevelSelect")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
@ -86,6 +99,163 @@ layout_mode = 2
focus_neighbor_bottom = NodePath("../StartButton")
text = "Quit"
[node name="LevelSelect" type="Panel" parent="."]
visible = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -131.0
offset_top = -231.0
offset_right = 132.0
offset_bottom = 169.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="LevelSelect"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -86.5
offset_top = -65.0
offset_right = 85.5
offset_bottom = 127.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer2" type="VBoxContainer" parent="LevelSelect/VBoxContainer"]
layout_mode = 2
[node name="Row1" type="BoxContainer" parent="LevelSelect/VBoxContainer/VBoxContainer2"]
layout_mode = 2
[node name="1" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row1"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "1"
[node name="2" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row1"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "2"
[node name="3" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row1"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "3"
[node name="4" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row1"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "4"
[node name="Row2" type="BoxContainer" parent="LevelSelect/VBoxContainer/VBoxContainer2"]
layout_mode = 2
[node name="5" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row2"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "5"
[node name="6" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row2"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "6"
[node name="7" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row2"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "7"
[node name="8" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row2"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "8"
[node name="Row3" type="BoxContainer" parent="LevelSelect/VBoxContainer/VBoxContainer2"]
layout_mode = 2
[node name="9" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row3"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "9"
[node name="10" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row3"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "10"
[node name="11" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row3"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "11"
[node name="12" type="Button" parent="LevelSelect/VBoxContainer/VBoxContainer2/Row3"]
custom_minimum_size = Vector2(40, 40)
layout_mode = 2
size_flags_horizontal = 4
text = "12"
[node name="MarginContainer" type="MarginContainer" parent="LevelSelect/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_top = 20
[node name="BackButton" type="Button" parent="LevelSelect/VBoxContainer/MarginContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "Back"
[node name="Label" type="Label" parent="LevelSelect"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -52.0
offset_top = 24.0
offset_right = 52.0
offset_bottom = 50.0
grow_horizontal = 2
text = "LEVEL SELECT"
horizontal_alignment = 1
[node name="MenuMusic" type="AudioStreamPlayer" parent="."]
stream = ExtResource("2_yc480")
volume_db = -29.953
autoplay = true
bus = &"Music"
[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"]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/1" to="." method="_on_level_button_pressed" binds= [1]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/2" to="." method="_on_level_button_pressed" binds= [2]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/3" to="." method="_on_level_button_pressed" binds= [3]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/4" to="." method="_on_level_button_pressed" binds= [4]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row2/5" to="." method="_on_level_button_pressed" binds= [5]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row2/6" to="." method="_on_level_button_pressed" binds= [6]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row2/7" to="." method="_on_level_button_pressed" binds= [7]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row2/8" to="." method="_on_level_button_pressed" binds= [8]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/9" to="." method="_on_level_button_pressed" binds= [9]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/10" to="." method="_on_level_button_pressed" binds= [10]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/11" to="." method="_on_level_button_pressed" binds= [11]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/12" to="." method="_on_level_button_pressed" binds= [12]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/MarginContainer/BackButton" to="." method="_on_back_button_pressed"]

View file

@ -1,11 +1,4 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_back_button_pressed():
queue_free()

View file

@ -1,6 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://fqg6y7xp34u0"]
[gd_scene load_steps=4 format=3 uid="uid://fqg6y7xp34u0"]
[ext_resource type="Script" path="res://src/gui/menu/options.gd" id="1_0813x"]
[ext_resource type="Theme" uid="uid://dpktnl3r5wul1" path="res://src/gui/menu_theme.tres" id="1_stpo1"]
[ext_resource type="Script" path="res://src/gui/menu/volume_slider.gd" id="3_2vqm2"]
[node name="options" type="Control"]
layout_mode = 3
@ -9,4 +11,132 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_stpo1")
script = ExtResource("1_0813x")
[node name="Background" type="Panel" 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 = -131.0
offset_top = -231.0
offset_right = 132.0
offset_bottom = 169.0
grow_horizontal = 2
grow_vertical = 2
[node name="Label" type="Label" parent="Background"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -52.0
offset_top = 24.0
offset_right = 52.0
offset_bottom = 50.0
grow_horizontal = 2
text = "OPTIONS"
horizontal_alignment = 1
[node name="VBoxContainer" type="VBoxContainer" parent="Background"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -102.0
offset_top = -84.0
offset_right = 102.0
offset_bottom = 120.0
grow_horizontal = 2
grow_vertical = 2
[node name="Label" type="Label" parent="Background/VBoxContainer"]
layout_mode = 2
text = "AUDIO"
horizontal_alignment = 1
[node name="HBoxContainer" type="HBoxContainer" parent="Background/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="Background/VBoxContainer/HBoxContainer"]
custom_minimum_size = Vector2(65, 0)
layout_mode = 2
text = "MASTER"
[node name="MarginContainer" type="MarginContainer" parent="Background/VBoxContainer/HBoxContainer"]
layout_mode = 2
theme_override_constants/margin_top = 3
[node name="HSlider" type="HSlider" parent="Background/VBoxContainer/HBoxContainer/MarginContainer"]
custom_minimum_size = Vector2(125, 0)
layout_mode = 2
max_value = 1.0
step = 0.001
script = ExtResource("3_2vqm2")
bus_name = "Master"
[node name="HBoxContainer2" type="HBoxContainer" parent="Background/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="Background/VBoxContainer/HBoxContainer2"]
custom_minimum_size = Vector2(65, 0)
layout_mode = 2
text = "MUSIC"
[node name="MarginContainer" type="MarginContainer" parent="Background/VBoxContainer/HBoxContainer2"]
layout_mode = 2
theme_override_constants/margin_top = 3
[node name="HSlider" type="HSlider" parent="Background/VBoxContainer/HBoxContainer2/MarginContainer"]
custom_minimum_size = Vector2(125, 0)
layout_mode = 2
max_value = 1.0
step = 0.001
script = ExtResource("3_2vqm2")
bus_name = "Music"
[node name="HBoxContainer3" type="HBoxContainer" parent="Background/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="Background/VBoxContainer/HBoxContainer3"]
custom_minimum_size = Vector2(65, 0)
layout_mode = 2
text = "SFX"
[node name="MarginContainer" type="MarginContainer" parent="Background/VBoxContainer/HBoxContainer3"]
layout_mode = 2
theme_override_constants/margin_top = 3
[node name="HSlider" type="HSlider" parent="Background/VBoxContainer/HBoxContainer3/MarginContainer"]
custom_minimum_size = Vector2(125, 0)
layout_mode = 2
max_value = 1.0
step = 0.001
script = ExtResource("3_2vqm2")
bus_name = "Sfx"
[node name="BackButton" type="Button" parent="Background"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -60.0
offset_top = -64.0
offset_right = 60.0
offset_bottom = -24.0
grow_horizontal = 2
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "Back"
[connection signal="pressed" from="Background/BackButton" to="." method="_on_back_button_pressed"]

View file

@ -0,0 +1,14 @@
extends HSlider
@export
var bus_name: String
var bus_index: int
func _ready() -> void:
bus_index = AudioServer.get_bus_index(bus_name)
value_changed.connect(_on_value_changed)
value = db_to_linear(AudioServer.get_bus_volume_db(bus_index))
func _on_value_changed(value: float) -> void:
AudioServer.set_bus_volume_db(bus_index, linear_to_db(value))

52
src/gui/menu_theme.tres Normal file
View file

@ -0,0 +1,52 @@
[gd_resource type="Theme" load_steps=5 format=3 uid="uid://dpktnl3r5wul1"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2u7je"]
bg_color = Color(1, 1, 1, 1)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(0, 0, 0, 1)
border_blend = true
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_uo2yv"]
bg_color = Color(1, 1, 1, 1)
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_sjhib"]
bg_color = Color(0, 0, 0, 1)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(1, 1, 1, 1)
border_blend = true
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_5it3g"]
bg_color = Color(0, 0, 0, 1)
corner_radius_top_left = 10
corner_radius_top_right = 10
corner_radius_bottom_right = 10
corner_radius_bottom_left = 10
[resource]
Button/colors/font_color = Color(0, 0, 0, 1)
Button/colors/font_focus_color = Color(0, 0, 0, 1)
Button/colors/font_hover_color = Color(0, 0, 0, 1)
Button/colors/font_hover_pressed_color = Color(1, 1, 1, 1)
Button/colors/font_pressed_color = Color(1, 1, 1, 1)
Button/styles/hover = SubResource("StyleBoxFlat_2u7je")
Button/styles/normal = SubResource("StyleBoxFlat_uo2yv")
Button/styles/pressed = SubResource("StyleBoxFlat_sjhib")
Panel/styles/panel = SubResource("StyleBoxFlat_5it3g")