Snake/Scripts/Main Menu Buttons.gd

63 lines
2.2 KiB
GDScript3
Raw Normal View History

extends Control
@onready var game_scene = load("res://Scene/Game.tscn").instantiate()
2023-04-04 17:12:24 +00:00
var config = ConfigFile.new()
func _ready():
2023-04-04 17:12:24 +00:00
# Set Default Focus
2023-04-04 00:38:17 +00:00
$"MarginContainer/VBoxContainer/Tab Group/Menu Butons/Start Button".grab_focus()
2023-04-04 17:12:24 +00:00
#load Config
var err = config.load("user://config.cfg")
if err != OK:
return
# Read Config
$"MarginContainer/VBoxContainer/Tab Group/Settings/GridSize/GridSize_Slider".value = config.get_value("Game Play", "grid_size", 10)
$"MarginContainer/VBoxContainer/Tab Group/Settings/Speed/Speed_Slider".value = config.get_value("Game Play", "speed", 1)
# Apply Values to UI
$"MarginContainer/VBoxContainer/Tab Group/Settings/GridSize/Value".text = " " + str(int($"MarginContainer/VBoxContainer/Tab Group/Settings/GridSize/GridSize_Slider".value))
$"MarginContainer/VBoxContainer/Tab Group/Settings/Speed/Value".text = "%10.2f" % $"MarginContainer/VBoxContainer/Tab Group/Settings/Speed/Speed_Slider".value
func _on_start_button_pressed():
2023-04-04 17:50:55 +00:00
$"AudioStreamPlayer Start".play()
await $"AudioStreamPlayer Start".finished
get_tree().change_scene_to_file("res://Scene/Game.tscn")
func _on_quit_button_pressed():
2023-04-04 17:12:24 +00:00
#config.clear()
#config.save("user://config.cfg")
get_tree().quit()
func _on_about_button_pressed():
OS.shell_open("https://git.euph.dev/snoweuph/Snake")
2023-04-04 00:38:17 +00:00
func _on_settings_button_pressed():
$"MarginContainer/VBoxContainer/Tab Group".current_tab = 1
$"MarginContainer/VBoxContainer/Tab Group/Settings/Back Button".grab_focus()
func _on_back_button_pressed():
$"MarginContainer/VBoxContainer/Tab Group".current_tab = 0
$"MarginContainer/VBoxContainer/Tab Group/Menu Butons/Start Button".grab_focus()
2023-04-04 17:12:24 +00:00
func _on_grid_size_slider_value_changed(value):
2023-04-04 17:50:55 +00:00
$"AudioStreamPlayer Change Value".play()
2023-04-04 17:12:24 +00:00
$"MarginContainer/VBoxContainer/Tab Group/Settings/GridSize/Value".text = " " + str(int(value))
config.set_value("Game Play", "grid_size", int(value))
config.save("user://config.cfg")
func _on_speed_slider_value_changed(value):
2023-04-04 17:50:55 +00:00
$"AudioStreamPlayer Change Value".play()
2023-04-04 17:12:24 +00:00
$"MarginContainer/VBoxContainer/Tab Group/Settings/Speed/Value".text = "%10.2f" % value
config.set_value("Game Play", "speed", value)
config.save("user://config.cfg")
2023-04-04 17:50:55 +00:00
func _on_focus_entered():
$"AudioStreamPlayer Change UI".play()