Add settings feature
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Moe Poi ~ 2023-11-14 22:02:05 +07:00
parent 02a8c38300
commit 946f211330
23 changed files with 234 additions and 10 deletions

BIN
assets/icons/settings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cgaqy7lcu4x78"
path="res://.godot/imported/settings.png-9e60c86d9b162ed0f32eee17a57d027f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/icons/settings.png"
dest_files=["res://.godot/imported/settings.png-9e60c86d9b162ed0f32eee17a57d027f.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -20,6 +20,10 @@ boot_splash/fullsize=false
config/icon="res://assets/icons/logo.png"
boot_splash/minimum_display_time=3
[autoload]
Global="*res://scripts/global.gd"
[display]
window/stretch/mode="viewport"

View file

@ -600,7 +600,6 @@ one_shot = true
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("12_2v5rl")
volume_db = 1.0
autoplay = true
[connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Duration" to="." method="_on_duration_timeout"]

View file

@ -333,7 +333,6 @@ one_shot = true
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("12_uwk7b")
volume_db = 1.0
autoplay = true
[connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Path2D2/Timer" to="Path2D2" method="_on_timer_timeout"]

View file

@ -314,7 +314,6 @@ one_shot = true
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("12_1fpbf")
volume_db = 1.0
autoplay = true
[connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Duration" to="." method="_on_duration_timeout"]

View file

@ -330,7 +330,6 @@ one_shot = true
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("12_8sjqs")
volume_db = 1.0
autoplay = true
[connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Path2D2/Timer" to="Path2D2" method="_on_timer_timeout"]

View file

@ -328,7 +328,6 @@ one_shot = true
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("12_2xeuw")
volume_db = 1.0
autoplay = true
[connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Path2D2/Timer" to="Path2D2" method="_on_timer_timeout"]

View file

@ -730,7 +730,6 @@ one_shot = true
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("12_is64a")
volume_db = 1.0
autoplay = true
[connection signal="timeout" from="Path2D/Timer" to="Path2D" method="_on_timer_timeout"]
[connection signal="timeout" from="Path2D2/Timer" to="Path2D2" method="_on_timer_timeout"]

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=6 format=3 uid="uid://b8pdp1x331u5c"]
[gd_scene load_steps=7 format=3 uid="uid://b8pdp1x331u5c"]
[ext_resource type="Texture2D" uid="uid://c1qbpse383sys" path="res://assets/backgrounds/main-bg.png" id="1_28cjd"]
[ext_resource type="Script" path="res://scripts/ui/main_menu.gd" id="1_6741p"]
[ext_resource type="Texture2D" uid="uid://dm8ug0o5361wn" path="res://assets/icons/logo.png" id="2_l26fo"]
[ext_resource type="Theme" uid="uid://caw53lcko4jnt" path="res://themes/button.tres" id="4_4d3eq"]
[ext_resource type="Texture2D" uid="uid://cgaqy7lcu4x78" path="res://assets/icons/settings.png" id="5_kbtiw"]
[ext_resource type="AudioStream" uid="uid://dhydsnb0wpl7t" path="res://assets/audio/main.mp3" id="5_xkvpi"]
[node name="MainMenu" type="Control"]
@ -88,6 +89,15 @@ size_flags_horizontal = 10
theme = ExtResource("4_4d3eq")
text = "Exit"
[node name="Settings" type="TextureButton" parent="TextureRect/Panel"]
layout_mode = 0
offset_left = 52.0
offset_top = 51.0
offset_right = 572.0
offset_bottom = 571.0
scale = Vector2(0.1, 0.1)
texture_normal = ExtResource("5_kbtiw")
[node name="Timer" type="Timer" parent="."]
wait_time = 30.0
one_shot = true
@ -95,11 +105,13 @@ one_shot = true
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("5_xkvpi")
volume_db = 1.0
autoplay = true
[connection signal="pressed" from="TextureRect/Panel/MarginContainer/VBoxContainer/TextureButton" to="." method="_on_logo_pressed"]
[connection signal="pressed" from="TextureRect/Panel/MarginContainer/VBoxContainer/VBoxContainer/StartGame" to="." method="_on_start_game_pressed"]
[connection signal="pressed" from="TextureRect/Panel/MarginContainer/VBoxContainer/VBoxContainer/HowToPlay" to="." method="_on_how_to_play_pressed"]
[connection signal="pressed" from="TextureRect/Panel/MarginContainer/VBoxContainer/HBoxContainer/About" to="." method="_on_about_pressed"]
[connection signal="pressed" from="TextureRect/Panel/MarginContainer/VBoxContainer/HBoxContainer/Exit" to="." method="_on_exit_pressed"]
[connection signal="mouse_entered" from="TextureRect/Panel/Settings" to="." method="_on_settings_hold"]
[connection signal="mouse_exited" from="TextureRect/Panel/Settings" to="." method="_on_settings_release"]
[connection signal="pressed" from="TextureRect/Panel/Settings" to="." method="_on_settings_pressed"]
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

View file

@ -223,7 +223,6 @@ text = "6"
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("11_1rv5g")
volume_db = 1.0
autoplay = true
[connection signal="pressed" from="Panel/MarginContainer/VBoxContainer/HBoxContainer/Back" to="." method="_on_back_pressed"]
[connection signal="pressed" from="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Stage 1" to="." method="_on_stage_1_pressed"]

108
scenes/ui/settings.tscn Normal file
View file

@ -0,0 +1,108 @@
[gd_scene load_steps=6 format=3 uid="uid://ons67oqg25vu"]
[ext_resource type="Script" path="res://scripts/ui/settings.gd" id="1_kci63"]
[ext_resource type="Theme" uid="uid://bt3yyqwlp4f7j" path="res://themes/title_text.tres" id="2_2enke"]
[ext_resource type="Theme" uid="uid://caw53lcko4jnt" path="res://themes/button.tres" id="3_jiiby"]
[sub_resource type="Theme" id="Theme_ulpvq"]
Label/font_sizes/font_size = 30
[sub_resource type="Theme" id="Theme_23erg"]
[node name="Settings" 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_kci63")
[node name="Panel" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="HBoxContainer" type="HBoxContainer" parent="Panel"]
layout_mode = 2
offset_left = 20.0
offset_top = 20.0
offset_right = 1132.0
offset_bottom = 82.0
[node name="Label" type="Label" parent="Panel/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
theme = ExtResource("2_2enke")
text = "Settings"
[node name="Back" type="Button" parent="Panel/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 10
size_flags_vertical = 0
theme = ExtResource("3_jiiby")
text = "Back"
[node name="Volume" type="Label" parent="Panel"]
layout_mode = 0
offset_left = 23.0
offset_top = 173.0
offset_right = 233.0
offset_bottom = 218.0
theme = SubResource("Theme_ulpvq")
text = "Sound Volume"
[node name="VolumeSlider" type="HSlider" parent="Panel"]
layout_mode = 0
offset_left = 281.0
offset_top = 181.0
offset_right = 634.0
offset_bottom = 197.0
scale = Vector2(2, 2)
min_value = -40.0
max_value = 1.0
value = 1.0
[node name="BGM" type="Label" parent="Panel"]
layout_mode = 0
offset_left = 23.0
offset_top = 260.0
offset_right = 233.0
offset_bottom = 305.0
theme = SubResource("Theme_ulpvq")
text = "BGM"
[node name="BGMController" type="CheckButton" parent="Panel"]
layout_mode = 0
offset_left = 267.0
offset_top = 256.0
offset_right = 311.0
offset_bottom = 280.0
scale = Vector2(2, 2)
theme = SubResource("Theme_23erg")
[node name="SFX" type="Label" parent="Panel"]
layout_mode = 0
offset_left = 24.0
offset_top = 352.0
offset_right = 234.0
offset_bottom = 397.0
theme = SubResource("Theme_ulpvq")
text = "SFX"
[node name="SFXController" type="CheckButton" parent="Panel"]
layout_mode = 0
offset_left = 267.0
offset_top = 347.0
offset_right = 311.0
offset_bottom = 371.0
scale = Vector2(2, 2)
[connection signal="pressed" from="Panel/HBoxContainer/Back" to="." method="_on_back_pressed"]
[connection signal="value_changed" from="Panel/VolumeSlider" to="." method="_on_volume_slider_value_changed"]
[connection signal="toggled" from="Panel/BGMController" to="." method="_on_bgm_controller_toggled"]
[connection signal="toggled" from="Panel/SFXController" to="." method="_on_sfx_controller_toggled"]

6
scripts/global.gd Normal file
View file

@ -0,0 +1,6 @@
extends Node
var sound_volume = 1
var bgm_status = true
var sfx_status = true

View file

@ -23,6 +23,10 @@ func _ready():
# Init Engine time scale
Engine.time_scale = 1.0
# Check BGM Status
if Global.bgm_status:
$AudioStreamPlayer.play()
# Set Duration & Start Timer
duration.wait_time = config.game['duration']
duration.start()

View file

@ -22,6 +22,10 @@ func _ready():
# Init Engine time scale
Engine.time_scale = 1.0
# Check BGM Status
if Global.bgm_status:
$AudioStreamPlayer.play()
# Set Duration & Start Timer
duration.wait_time = config.game['duration']
duration.start()

View file

@ -22,6 +22,10 @@ func _ready():
# Init Engine time scale
Engine.time_scale = 1.0
# Check BGM Status
if Global.bgm_status:
$AudioStreamPlayer.play()
# Set Duration & Start Timer
duration.wait_time = config.game['duration']
duration.start()

View file

@ -22,6 +22,10 @@ func _ready():
# Init Engine time scale
Engine.time_scale = 1.0
# Check BGM Status
if Global.bgm_status:
$AudioStreamPlayer.play()
# Set Duration & Start Timer
duration.wait_time = config.game['duration']
duration.start()

View file

@ -22,6 +22,10 @@ func _ready():
# Init Engine time scale
Engine.time_scale = 1.0
# Check BGM Status
if Global.bgm_status:
$AudioStreamPlayer.play()
# Set Duration & Start Timer
duration.wait_time = config.game['duration']
duration.start()

View file

@ -22,6 +22,10 @@ func _ready():
# Init Engine time scale
Engine.time_scale = 1.0
# Check BGM Status
if Global.bgm_status:
$AudioStreamPlayer.play()
# Set Duration & Start Timer
duration.wait_time = config.game['duration']
duration.start()

View file

@ -59,7 +59,10 @@ func _physics_process(_delta):
func _shoot():
if bullet:
# Check SFX Status
if Global.sfx_status:
shoot.play()
var bullet_instance: Node2D = bullet.instantiate()
bullet_instance.dir = rotation
bullet_instance.rotation = rotation

View file

@ -21,6 +21,10 @@ func _ready():
if OS.get_name() == "Web":
$TextureRect/Panel/MarginContainer/VBoxContainer/HBoxContainer/Exit.hide()
# Check BGM Status
if Global.bgm_status:
$AudioStreamPlayer.play()
func _on_logo_pressed():
if timer.is_stopped():
timer.start()
@ -51,5 +55,14 @@ func _on_how_to_play_pressed():
func _on_about_pressed():
get_tree().change_scene_to_file("res://scenes/ui/about.tscn")
func _on_settings_pressed():
get_tree().change_scene_to_file("res://scenes/ui/settings.tscn")
func _on_settings_hold():
$TextureRect/Panel/Settings.modulate = Color(0.541176, 0.541176, 0.541176, 1)
func _on_settings_release():
$TextureRect/Panel/Settings.modulate = Color(1, 1, 1, 1)
func _on_exit_pressed():
get_tree().quit()

View file

@ -36,6 +36,10 @@ func _ready():
_:
pass
# Check BGM Status
if Global.bgm_status:
$AudioStreamPlayer.play()
func _on_back_pressed():
get_tree().change_scene_to_file("res://scenes/ui/main_menu.tscn")

23
scripts/ui/settings.gd Normal file
View file

@ -0,0 +1,23 @@
extends Control
var bus_master = AudioServer.get_bus_index("Master")
func _ready():
$Panel/VolumeSlider.value = Global.sound_volume
$Panel/BGMController.button_pressed = Global.bgm_status
$Panel/SFXController.button_pressed = Global.sfx_status
func _on_back_pressed():
get_tree().change_scene_to_file("res://scenes/ui/main_menu.tscn")
func _on_volume_slider_value_changed(value):
AudioServer.set_bus_volume_db(bus_master, value)
AudioServer.set_bus_mute(bus_master, value == $Panel/VolumeSlider.min_value)
Global.sound_volume = value
func _on_bgm_controller_toggled(button_pressed):
Global.bgm_status = button_pressed
func _on_sfx_controller_toggled(button_pressed):
Global.sfx_status = button_pressed