62 lines
2.2 KiB
GDScript
62 lines
2.2 KiB
GDScript
extends Control
|
|
|
|
@onready var game_scene = load("res://Scene/Game.tscn").instantiate()
|
|
var config = ConfigFile.new()
|
|
|
|
func _ready():
|
|
# Set Default Focus
|
|
$"MarginContainer/VBoxContainer/Tab Group/Menu Butons/Start Button".grab_focus()
|
|
|
|
#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():
|
|
$"AudioStreamPlayer Start".play()
|
|
await $"AudioStreamPlayer Start".finished
|
|
get_tree().change_scene_to_file("res://Scene/Game.tscn")
|
|
|
|
func _on_quit_button_pressed():
|
|
#config.clear()
|
|
#config.save("user://config.cfg")
|
|
get_tree().quit()
|
|
|
|
|
|
func _on_about_button_pressed():
|
|
OS.shell_open("https://git.euph.dev/snoweuph/Snake")
|
|
|
|
|
|
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()
|
|
|
|
func _on_grid_size_slider_value_changed(value):
|
|
$"AudioStreamPlayer Change Value".play()
|
|
$"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):
|
|
$"AudioStreamPlayer Change Value".play()
|
|
$"MarginContainer/VBoxContainer/Tab Group/Settings/Speed/Value".text = "%10.2f" % value
|
|
config.set_value("Game Play", "speed", value)
|
|
config.save("user://config.cfg")
|
|
|
|
func _on_focus_entered():
|
|
$"AudioStreamPlayer Change UI".play()
|