Improved UI and Added Settings

This commit is contained in:
Snoweuph 2023-04-04 19:12:24 +02:00
parent 86131d8430
commit ed964981cc
6 changed files with 411 additions and 72 deletions

File diff suppressed because one or more lines are too long

BIN
Assets/tile_selected.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://nimd0066t7qm"
path="res://.godot/imported/tile_selected.png-b6ca25c977e696fcf5a4350cf08a3708.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Assets/tile_selected.png"
dest_files=["res://.godot/imported/tile_selected.png-b6ca25c977e696fcf5a4350cf08a3708.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

@ -85,10 +85,55 @@ text = "Quit"
[node name="Settings" type="VBoxContainer" parent="MarginContainer/VBoxContainer/Tab Group"]
layout_mode = 2
[node name="HSlider" type="HSlider" parent="MarginContainer/VBoxContainer/Tab Group/Settings"]
custom_minimum_size = Vector2(0, 32)
[node name="GridSize" type="HBoxContainer" parent="MarginContainer/VBoxContainer/Tab Group/Settings"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Tab Group/Settings/GridSize"]
layout_mode = 2
theme = ExtResource("1_b1d2h")
theme_override_font_sizes/font_size = 64
text = "Grid Size "
[node name="GridSize_Slider" type="HSlider" parent="MarginContainer/VBoxContainer/Tab Group/Settings/GridSize"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 4
theme = ExtResource("1_b1d2h")
min_value = 6.0
max_value = 32.0
value = 10.0
rounded = true
[node name="Value" type="Label" parent="MarginContainer/VBoxContainer/Tab Group/Settings/GridSize"]
layout_mode = 2
theme = ExtResource("1_b1d2h")
theme_override_font_sizes/font_size = 64
text = "00"
[node name="Speed" type="HBoxContainer" parent="MarginContainer/VBoxContainer/Tab Group/Settings"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Tab Group/Settings/Speed"]
layout_mode = 2
theme = ExtResource("1_b1d2h")
theme_override_font_sizes/font_size = 64
text = "Speed "
[node name="Speed_Slider" type="HSlider" parent="MarginContainer/VBoxContainer/Tab Group/Settings/Speed"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 4
theme = ExtResource("1_b1d2h")
min_value = 0.25
max_value = 5.0
step = 0.25
value = 1.0
[node name="Value" type="Label" parent="MarginContainer/VBoxContainer/Tab Group/Settings/Speed"]
layout_mode = 2
theme = ExtResource("1_b1d2h")
theme_override_font_sizes/font_size = 64
text = "00"
[node name="Back Button" type="Button" parent="MarginContainer/VBoxContainer/Tab Group/Settings"]
layout_mode = 2
@ -100,4 +145,6 @@ text = "Back"
[connection signal="pressed" from="MarginContainer/VBoxContainer/Tab Group/Menu Butons/Settings Button" to="." method="_on_settings_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/Tab Group/Menu Butons/About Button" to="." method="_on_about_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/Tab Group/Menu Butons/Quit Button" to="." method="_on_quit_button_pressed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer/Tab Group/Settings/GridSize/GridSize_Slider" to="." method="_on_grid_size_slider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer/Tab Group/Settings/Speed/Speed_Slider" to="." method="_on_speed_slider_value_changed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/Tab Group/Settings/Back Button" to="." method="_on_back_button_pressed"]

View file

@ -1,5 +1,7 @@
extends GridContainer
var config = ConfigFile.new()
@export var map_size := 15
@export var texture : Texture2D
@export var speed := 0.25
@ -94,6 +96,14 @@ func process_snake_rotation():
snake_move_vector = input.normalized()
func _ready():
#load Config
var err = config.load("user://config.cfg")
if err != OK:
return
map_size = config.get_value("Game Play", "grid_size", 10)
speed = float(config.get_value("Game Play", "speed", 1))
print(speed)
game_start()
pass
@ -116,7 +126,7 @@ func _process(delta):
if !game_is_running:
return
process_snake_rotation()
if(timer >= speed):
if(timer * speed >= 0.25):
timer = 0
process_tiles()
timer += delta

View file

@ -1,14 +1,32 @@
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():
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()
@ -24,3 +42,14 @@ func _on_settings_button_pressed():
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):
$"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):
$"MarginContainer/VBoxContainer/Tab Group/Settings/Speed/Value".text = "%10.2f" % value
config.set_value("Game Play", "speed", value)
config.save("user://config.cfg")