diff options
| -rw-r--r-- | client/global.gd | 69 | ||||
| -rw-r--r-- | client/menu/credits_menu.gd | 2 | ||||
| -rw-r--r-- | client/menu/settings_menu.gd | 24 | ||||
| -rw-r--r-- | client/menu/settings_menu.tscn | 23 | ||||
| -rw-r--r-- | client/menu/settings_row.gd | 42 | ||||
| -rw-r--r-- | client/menu/theme/theme.tres | 20 | 
6 files changed, 140 insertions, 40 deletions
| diff --git a/client/global.gd b/client/global.gd index f25845a6..35244fa7 100644 --- a/client/global.gd +++ b/client/global.gd @@ -17,6 +17,15 @@  #  extends Node +# Each setting contains a dictionary with the following keys: +# "type": The type of the setting. Can be "toggle", "line", "dropdown", or "dropdown_preset" +# "value": The value of the setting. When using "dropdown", this contains an int +#	as the index for the respecitve element in the "options" array. +# "apply": Only for type "dropdown_preset": A dictionary to override all other settings. +# "description": The setting name displayed in the settings menu. +# (Optional: Only when type = "dropdown") "options": An array which contains all +# 	possible values. +  const DEFAULT_PROFILE := {  	"username": "Giovanni",  	"character": 0, @@ -25,27 +34,62 @@ const DEFAULT_PROFILE := {  var default_settings := {  	"interpolate_camera_rotation": { +		"type": "toggle",  		"value": true,  		"description": tr("Interpolate the camera rotation")  	},  	"server_binary": { +		"type": "line",  		"value": "",  		"description": tr("Server binary (leave empty to search PATH)")  	},  	"server_data": { +		"type": "line",  		"value": "",  		"description": tr("Server data directory (leave empty to auto-detect)")  	}, +	"graphics_preset": { +		"type": "dropdown_preset", +		"options": [tr("Low"), tr("Medium"), tr("High"), tr("Ultra")], +		"value":1, +		"description": tr("Graphics preset"), +		"apply": GRAPHICS_PRESETS +	},  	"voxel_gi": { +		"type": "toggle",  		"value": false,  		"description": tr("Use VoxelGI (Blocks the game on map update)")  	},  	"sdfgi": { +		"type": "toggle",  		"value": false,  		"description": tr("Use SDFGI (Doesn't block the game but is more resource-hungry)") -	}, +	}  } +const GRAPHICS_PRESETS = [ +	# Low: +	{ +		"voxel_gi": false, +		"sdfgi": false +	}, +	# Medium: +	{ +		"voxel_gi": false, +		"sdfgi": false +	}, +	# High: +	{ +		"voxel_gi": false, +		"sdfgi": true +	}, +	# Ultra: +	{ +		"voxel_gi": true, +		"sdfgi": false +	} +] +  var profile: Dictionary  var settings: Dictionary @@ -54,9 +98,10 @@ var error_message = ""  var fade_next := false # Set true when transitioning from another scene (fade in requried) -func _ready(): +func _init():  	profile = load_dict("user://profile", DEFAULT_PROFILE)  	settings = load_dict("user://settings", default_settings) +	print("DONE LOADING")  func save_profile():  	save_dict("user://profile", profile) @@ -75,16 +120,12 @@ func load_dict(path: String, default: Dictionary) -> Dictionary:  		return default  	var f = FileAccess.open(path, FileAccess.READ)  	var saved_dict = f.get_var() -	var res: Dictionary = {} +	  	if saved_dict != null and saved_dict is Dictionary: -		for i in default.keys(): -			if saved_dict.has(i): -				res[i] = saved_dict[i] -			else: -				res[i] = default[i] +		add_missing_keys(saved_dict, default) -	print("Loaded dict: ", res) -	return res +	print("Loaded dict: ", saved_dict) +	return saved_dict  func on_vulkan() -> bool:  	return ProjectSettings.get_setting("rendering/rendering_device/driver") == "vulkan" @@ -98,3 +139,11 @@ func focus_first_button(node: Node) -> bool:  		if focus_first_button(c):  			return true  	return false + +func add_missing_keys(dict: Dictionary, reference: Dictionary): +	for k in reference.keys(): +		if !dict.has(k): +			dict[k] = reference +		else: +			if dict[k] is Dictionary: +				add_missing_keys(dict[k], reference[k]) diff --git a/client/menu/credits_menu.gd b/client/menu/credits_menu.gd index c7afe95a..ece061ec 100644 --- a/client/menu/credits_menu.gd +++ b/client/menu/credits_menu.gd @@ -27,7 +27,7 @@ var cc_by_3 := {  func prepare():  	contributors.shuffle()  	label.text = "[center][b]" -	label.text += tr("undercookUSed - a game about cooking") +	label.text += tr("undercooked - a game about cooking")  	label.text += "[/b]\n\n"  	label.text += tr("developed by")  	label.text += "\n\n[b]" diff --git a/client/menu/settings_menu.gd b/client/menu/settings_menu.gd index 6b2a7f60..4c14a459 100644 --- a/client/menu/settings_menu.gd +++ b/client/menu/settings_menu.gd @@ -15,7 +15,7 @@  #  extends Control -@onready var options: VBoxContainer = $outer_gap/panel/inner_gap/options +@onready var options: VBoxContainer = $OuterGap/Panel/InnerGap/VBoxContainer/ScrollContainer/Options  @onready var menu_manager: MenuManager = get_parent()  var settings: Dictionary @@ -26,11 +26,29 @@ func _on_back_pressed():  	Global.save_settings()  	menu_manager.go_back() -  func _ready(): +	update_rows() + +func show_graphis(): +	menu_manager.goto("settings_graphics") + +func update_rows(): +	for c in options.get_children(): +		c.queue_free() +	  	for k in Global.settings.keys():  		var v = Global.settings[k]  		var row: SettingsRow = preload("res://menu/settings_row.tscn").instantiate() -		row.setup(v["description"], v["value"]) +		row.setup(k, Global.settings, Global.default_settings) +		row.connect("apply_preset", apply_preset)  		options.add_child(row)  		settings[k] = row + +func apply_preset(preset: Dictionary): +	for k in settings.keys(): +		Global.settings[k]["value"] = settings[k].get_value() +	 +	for k in preset.keys(): +		Global.settings[k]["value"] = preset[k] +	 +	update_rows() diff --git a/client/menu/settings_menu.tscn b/client/menu/settings_menu.tscn index 84da46f3..9be24d86 100644 --- a/client/menu/settings_menu.tscn +++ b/client/menu/settings_menu.tscn @@ -14,7 +14,7 @@ grow_vertical = 2  theme = ExtResource("1_foq3a")  script = ExtResource("2_3hgm8") -[node name="outer_gap" type="MarginContainer" parent="."] +[node name="OuterGap" type="MarginContainer" parent="."]  layout_mode = 1  anchors_preset = 15  anchor_right = 1.0 @@ -22,11 +22,11 @@ anchor_bottom = 1.0  grow_horizontal = 2  grow_vertical = 2 -[node name="panel" type="Panel" parent="outer_gap"] +[node name="Panel" type="Panel" parent="OuterGap"]  material = ExtResource("3_8nykw")  layout_mode = 2 -[node name="inner_gap" type="MarginContainer" parent="outer_gap/panel"] +[node name="InnerGap" type="MarginContainer" parent="OuterGap/Panel"]  layout_mode = 1  anchors_preset = 15  anchor_right = 1.0 @@ -38,18 +38,27 @@ theme_override_constants/margin_top = 40  theme_override_constants/margin_right = 40  theme_override_constants/margin_bottom = 40 -[node name="options" type="VBoxContainer" parent="outer_gap/panel/inner_gap"] +[node name="VBoxContainer" type="VBoxContainer" parent="OuterGap/Panel/InnerGap"]  layout_mode = 2 -[node name="title" type="Label" parent="outer_gap/panel/inner_gap/options"] +[node name="Title" type="Label" parent="OuterGap/Panel/InnerGap/VBoxContainer"]  layout_mode = 2  size_flags_horizontal = 0  theme_override_font_sizes/font_size = 36  text = "Settings" -[node name="back" type="Button" parent="outer_gap/panel/inner_gap"] +[node name="ScrollContainer" type="ScrollContainer" parent="OuterGap/Panel/InnerGap/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="Options" type="VBoxContainer" parent="OuterGap/Panel/InnerGap/VBoxContainer/ScrollContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="Back" type="Button" parent="OuterGap/Panel/InnerGap/VBoxContainer"]  layout_mode = 2  size_flags_vertical = 8  text = "Back to Main Menu" -[connection signal="pressed" from="outer_gap/panel/inner_gap/back" to="." method="_on_back_pressed"] +[connection signal="pressed" from="OuterGap/Panel/InnerGap/VBoxContainer/Back" to="." method="_on_back_pressed"] diff --git a/client/menu/settings_row.gd b/client/menu/settings_row.gd index ee4b8cb9..4f1d326f 100644 --- a/client/menu/settings_row.gd +++ b/client/menu/settings_row.gd @@ -1,20 +1,40 @@  class_name SettingsRow  extends PanelContainer +signal apply_preset +  @onready var value_parent = $HBoxContainer/BoxContainer  @onready var label = $HBoxContainer/Label  var value_node  var description = tr("no value was given to the row") -func setup(description_: String, value): -	description = description_ -	if value is bool: -		value_node = CheckButton.new() -		value_node.button_pressed = value -	elif value is String: -		value_node = LineEdit.new() -		value_node.text = value +func setup(key: String, dict: Dictionary, defaults: Dictionary): +	var setting = dict[key] +	description = setting["description"] +	var value = setting["value"] +	var default = defaults[key]["value"] +	match setting["type"]: +		"toggle": +			value_node = CheckButton.new() +			value_node.button_pressed = value +		"line": +			value_node = LineEdit.new() +			value_node.text = value +			value_node.placeholder_text = default +		"dropdown": +			value_node = OptionButton.new() +			for i in setting["options"]: +				value_node.add_item(i) +			value_node.select(value) +		"dropdown_preset": +			value_node = OptionButton.new() +			for i in setting["options"]: +				value_node.add_item(i) +			value_node.select(value) +			value_node.connect("item_selected", apply.bind(setting["apply"])) +		_: +			push_error("Could not set up SettingsRow: Unknown setting type \"%s\"" % setting["type"])  func _ready():  	if value_node != null: @@ -24,13 +44,19 @@ func _ready():  		label.text = description  		value_parent.add_child(c) +func apply(idx: int, apply: Array): +	emit_signal("apply_preset", apply[idx]) +  func get_value():  	if value_node != null:  		if value_node is CheckButton:  			return value_node.button_pressed  		elif value_node is LineEdit:  			return value_node.text +		elif value_node is OptionButton: +			return value_node.selected  		else: +			push_error("get_value() failed for unknown node type: %s" % value_node)  			return null  	else:  		return null diff --git a/client/menu/theme/theme.tres b/client/menu/theme/theme.tres index 467aa6d9..b30cd30a 100644 --- a/client/menu/theme/theme.tres +++ b/client/menu/theme/theme.tres @@ -4,11 +4,6 @@  [ext_resource type="StyleBox" uid="uid://b86kbd3pfkd5w" path="res://menu/theme/focus_style.tres" id="2_brg2c"]  [ext_resource type="FontFile" uid="uid://bo4vh5xkpvrh1" path="res://menu/theme/font-sansita-swashed.woff2" id="3_8u6ww"] -[sub_resource type="FontVariation" id="FontVariation_lyo8w"] -base_font = ExtResource("1_f8qb0") -variation_embolden = 1.25 -spacing_top = 5 -  [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_25x32"]  content_margin_left = 10.0  content_margin_top = 10.0 @@ -50,9 +45,14 @@ corner_radius_bottom_left = 8  base_font = ExtResource("3_8u6ww")  variation_embolden = 0.7 +[sub_resource type="FontVariation" id="FontVariation_lyo8w"] +base_font = ExtResource("1_f8qb0") +variation_embolden = 1.25 +spacing_top = 5 +  [resource] +default_font = SubResource("FontVariation_lyo8w")  Button/font_sizes/font_size = 18 -Button/fonts/font = SubResource("FontVariation_lyo8w")  Button/styles/disabled = SubResource("StyleBoxFlat_25x32")  Button/styles/focus = ExtResource("2_brg2c")  Button/styles/hover = SubResource("StyleBoxFlat_2fl8q") @@ -60,7 +60,6 @@ Button/styles/normal = SubResource("StyleBoxFlat_25x32")  Button/styles/pressed = SubResource("StyleBoxFlat_25x32")  HSeparator/styles/separator = SubResource("StyleBoxLine_emtvk")  Label/font_sizes/font_size = 16 -Label/fonts/font = ExtResource("3_8u6ww")  LineEdit/styles/focus = ExtResource("2_brg2c")  LineEdit/styles/normal = SubResource("StyleBoxFlat_25x32")  LineEdit/styles/read_only = SubResource("StyleBoxFlat_25x32") @@ -70,7 +69,6 @@ MarginContainer/constants/margin_right = 32  MarginContainer/constants/margin_top = 32  Panel/styles/panel = SubResource("StyleBoxFlat_sjrhv")  RichTextLabel/fonts/bold_font = SubResource("FontVariation_ff4nr") -RichTextLabel/fonts/bold_italics_font = null -RichTextLabel/fonts/italics_font = null -RichTextLabel/fonts/mono_font = null -RichTextLabel/fonts/normal_font = ExtResource("3_8u6ww") +RichTextLabel/fonts/bold_italics_font = SubResource("FontVariation_lyo8w") +RichTextLabel/fonts/italics_font = SubResource("FontVariation_lyo8w") +RichTextLabel/fonts/mono_font = SubResource("FontVariation_lyo8w") | 
