feat: settings

This commit is contained in:
newt 2024-08-19 03:16:36 +01:00
parent dbcd06e1fe
commit 0c599830bb
16 changed files with 218 additions and 28 deletions

View file

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://cavipaqyic82h" uid="uid://cavipaqyic82h"
path="res://.godot/imported/bars.png-cf5fff97d300ec62385570bfe6d84fda.ctex" path="res://.godot/imported/artwork.png-ae994aa3741bd5935bb8df0387bf6245.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://assets/art/bars.png" source_file="res://assets/art/bars/artwork.png"
dest_files=["res://.godot/imported/bars.png-cf5fff97d300ec62385570bfe6d84fda.ctex"] dest_files=["res://.godot/imported/artwork.png-ae994aa3741bd5935bb8df0387bf6245.ctex"]
[params] [params]

BIN
assets/art/bars/crystal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ba4kmbeffsaxr"
path="res://.godot/imported/crystal.png-9a078245697205aa94366b700fd03b34.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/art/bars/crystal.png"
dest_files=["res://.godot/imported/crystal.png-9a078245697205aa94366b700fd03b34.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

BIN
assets/art/bars/stone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

View file

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

@ -1,15 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://clptnshbcs6cn"] [gd_scene load_steps=3 format=3 uid="uid://clptnshbcs6cn"]
[ext_resource type="Texture2D" uid="uid://cavipaqyic82h" path="res://assets/art/bars.png" id="1_xyrd0"] [ext_resource type="Script" path="res://components/bars.gd" id="1_5icge"]
[ext_resource type="Texture2D" uid="uid://cavipaqyic82h" path="res://assets/art/bars/artwork.png" id="1_xyrd0"]
[node name="Bars" type="Control"] [node name="Bars" type="TextureRect"]
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 0
offset_right = 40.0 offset_right = 40.0
offset_bottom = 40.0 offset_bottom = 40.0
texture = ExtResource("1_xyrd0") texture = ExtResource("1_xyrd0")
script = ExtResource("1_5icge")

16
components/bars.gd Normal file
View file

@ -0,0 +1,16 @@
extends TextureRect
var artwork = load("res://assets/art/bars/artwork.png")
var stone = load("res://assets/art/bars/stone.png")
var crystal = load("res://assets/art/bars/crystal.png")
func _ready() -> void:
var bar_index = ConfigManager.get_setting("bars")
match bar_index:
0:
set_texture(artwork)
1:
set_texture(stone)
2:
set_texture(crystal)

View file

@ -24,7 +24,8 @@ animation/layers/only_include_visible_layers_by_default=true
[autoload] [autoload]
GlobalKeybinds="*res://scripts/global.gd" Global="*res://scripts/global.gd"
ConfigManager="*res://scripts/config_manager.gd"
[display] [display]
@ -68,7 +69,7 @@ toggle_fullscreen={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194342,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194342,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
] ]
} }
quit={ back={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
] ]

36
scripts/config_manager.gd Normal file
View file

@ -0,0 +1,36 @@
extends Node
const CONFIG_PATH = "user://claustrophemia.cfg"
var settings = {
"bars": 0
}
func _ready() -> void:
load_settings()
func load_settings() -> void:
var config = ConfigFile.new()
if config.load(CONFIG_PATH) == OK:
for key in settings.keys():
if config.has_section_key("Settings", key):
settings[key] = config.get_value("Settings", key, settings[key])
func save_settings():
var config = ConfigFile.new()
for key in settings.keys():
config.set_value("Settings", key, settings[key])
config.save(CONFIG_PATH)
func set_setting(key: String, value) -> void:
if settings.has(key):
settings[key] = value
save_settings()
func get_setting(key: String):
if settings.has(key):
return settings[key]
return null

View file

@ -5,13 +5,20 @@ var previous_window_mode = -1
func _process(delta: float) -> void: func _process(delta: float) -> void:
# keybinds # keybinds
if Input.is_action_just_pressed("toggle_fullscreen"): if Input.is_action_just_pressed("toggle_fullscreen"):
if get_window().mode == Window.MODE_FULLSCREEN: var window = get_window()
if window.mode == Window.MODE_FULLSCREEN:
if previous_window_mode != -1: if previous_window_mode != -1:
get_window().mode = previous_window_mode window.mode = previous_window_mode
else: else:
get_window().mode = Window.MODE_MAXIMIZED window.mode = Window.MODE_MAXIMIZED
else: else:
previous_window_mode = get_window().mode previous_window_mode = window.mode
get_window().mode = Window.MODE_FULLSCREEN window.mode = Window.MODE_FULLSCREEN
elif Input.is_action_just_pressed("quit") and not OS.has_feature("web"): elif Input.is_action_just_pressed("back") and not OS.has_feature("web"):
get_tree().quit() var tree = get_tree()
print(tree.current_scene.name)
if tree.current_scene.name == "MainMenu":
tree.quit()
else:
tree.change_scene_to_file("res://ui/MainMenu.tscn")

View file

@ -12,6 +12,7 @@ offset_left = -2.0
offset_top = -2.0 offset_top = -2.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
theme = ExtResource("1_8e6h6")
color = Color(0.301961, 0, 0.00392157, 1) color = Color(0.301961, 0, 0.00392157, 1)
[node name="RichTextLabel" type="RichTextLabel" parent="."] [node name="RichTextLabel" type="RichTextLabel" parent="."]
@ -20,7 +21,6 @@ offset_left = 58.0
offset_top = 138.0 offset_top = 138.0
offset_right = 610.0 offset_right = 610.0
offset_bottom = 330.0 offset_bottom = 330.0
theme = ExtResource("1_8e6h6")
text = "Thank you for playing our GMTK Game Jam 2024 Game! We had to on-the-spot learn Godot to produce this, so I hope it is not too dreadful! text = "Thank you for playing our GMTK Game Jam 2024 Game! We had to on-the-spot learn Godot to produce this, so I hope it is not too dreadful!
Credits: Credits:

View file

@ -4,9 +4,11 @@
[ext_resource type="Texture2D" uid="uid://077ffi13hk2e" path="res://assets/art/export/claustrophemia-Layer 1.png" id="2_dgsrv"] [ext_resource type="Texture2D" uid="uid://077ffi13hk2e" path="res://assets/art/export/claustrophemia-Layer 1.png" id="2_dgsrv"]
[ext_resource type="Theme" uid="uid://r0t1dx6hpo2m" path="res://ui/menu.tres" id="3_5x31f"] [ext_resource type="Theme" uid="uid://r0t1dx6hpo2m" path="res://ui/menu.tres" id="3_5x31f"]
[node name="Main Menu" type="ColorRect"] [node name="MainMenu" type="ColorRect"]
offset_right = 640.0 offset_right = 640.0
offset_bottom = 360.0 offset_bottom = 363.0
scale = Vector2(1, 0.991561)
theme = ExtResource("3_5x31f")
color = Color(0.300955, 0, 0.00368265, 1) color = Color(0.300955, 0, 0.00368265, 1)
script = ExtResource("1_wuxjj") script = ExtResource("1_wuxjj")
@ -44,14 +46,20 @@ offset_left = 256.0
offset_top = 144.0 offset_top = 144.0
offset_right = 384.0 offset_right = 384.0
offset_bottom = 192.0 offset_bottom = 192.0
theme = ExtResource("3_5x31f")
text = "Start" text = "Start"
[node name="ExitButton" type="Button" parent="."] [node name="SettingsButton" type="Button" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 256.0 offset_left = 256.0
offset_top = 216.0 offset_top = 216.0
offset_right = 384.0 offset_right = 384.0
offset_bottom = 264.0 offset_bottom = 264.0
theme = ExtResource("3_5x31f") text = "Settings"
[node name="ExitButton" type="Button" parent="."]
layout_mode = 0
offset_left = 256.0
offset_top = 288.0
offset_right = 384.0
offset_bottom = 336.0
text = "Exit" text = "Exit"

44
ui/Settings.tscn Normal file
View file

@ -0,0 +1,44 @@
[gd_scene load_steps=3 format=3 uid="uid://ghsqwi0kr7vl"]
[ext_resource type="Script" path="res://ui/settings.gd" id="2_w2fss"]
[ext_resource type="Theme" uid="uid://r0t1dx6hpo2m" path="res://ui/menu.tres" id="3_mitji"]
[node name="Settings" type="ColorRect"]
offset_right = 640.0
offset_bottom = 360.0
theme = ExtResource("3_mitji")
color = Color(0.300955, 0, 0.00368265, 1)
script = ExtResource("2_w2fss")
[node name="Title" type="RichTextLabel" parent="."]
layout_mode = 0
offset_left = 176.0
offset_top = 24.0
offset_right = 448.0
offset_bottom = 104.0
theme_override_font_sizes/normal_font_size = 84
text = "Settings"
[node name="Bars" type="Control" parent="."]
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="Label" type="RichTextLabel" parent="Bars"]
offset_left = 204.0
offset_top = 133.0
offset_right = 252.0
offset_bottom = 157.0
text = "Bars"
[node name="Select" type="OptionButton" parent="Bars"]
offset_left = 272.0
offset_top = 128.0
offset_right = 375.0
offset_bottom = 159.0
item_count = 3
popup/item_0/text = "Artwork"
popup/item_1/text = "Stone"
popup/item_1/id = 1
popup/item_2/text = "Crystal"
popup/item_2/id = 2

View file

@ -1,10 +1,12 @@
extends Control extends Control
@onready var start_button = $StartButton @onready var start_button = $StartButton
@onready var settings_button = $SettingsButton
@onready var exit_button = $ExitButton @onready var exit_button = $ExitButton
func _ready() -> void: func _ready() -> void:
start_button.button_down.connect(start_game) start_button.button_down.connect(start_game)
settings_button.button_down.connect(open_settings)
if OS.has_feature("web"): if OS.has_feature("web"):
exit_button.queue_free() exit_button.queue_free()
@ -13,6 +15,9 @@ func _ready() -> void:
func start_game() -> void: func start_game() -> void:
get_tree().change_scene_to_file("res://levels/level1/stage1.tscn") get_tree().change_scene_to_file("res://levels/level1/stage1.tscn")
func open_settings() -> void:
get_tree().change_scene_to_file("res://ui/Settings.tscn")
func exit_game() -> void: func exit_game() -> void:
get_tree().quit() get_tree().quit()

10
ui/settings.gd Normal file
View file

@ -0,0 +1,10 @@
extends ColorRect
@onready var bar_option = $Bars/Select
func _ready() -> void:
bar_option.selected = ConfigManager.get_setting("bars")
bar_option.item_selected.connect(change_bar_selection)
func change_bar_selection(index: int) -> void:
ConfigManager.set_setting("bars", index)