From 06baf4555dc1c7a64bed7d059fbe34c99e9638fb Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 6 Sep 2024 23:43:42 +0200 Subject: refactor settings again (part 1) --- client/map/auto_setup/environment_setup.gd | 17 +++++++++-------- client/map/auto_setup/light_setup.gd | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'client/map/auto_setup') diff --git a/client/map/auto_setup/environment_setup.gd b/client/map/auto_setup/environment_setup.gd index 3ce8add3..49f93ccb 100644 --- a/client/map/auto_setup/environment_setup.gd +++ b/client/map/auto_setup/environment_setup.gd @@ -22,12 +22,13 @@ func set_sky(sky_name: String): environment.sky.sky_material = load("res://map/environment/presets/%s_sky.tres" % sky_name) func _ready(): - apply_settings() - Global.settings_changed.connect(apply_settings) + pass + #Global.settings_changed.connect(apply_settings) -func apply_settings(): - environment.ssao_enabled = Global.get_setting("ssao") - environment.sdfgi_enabled = Global.get_setting("gi") == 1 and allow_sdfgi - environment.glow_enabled = Global.get_setting("glow") - if !Global.on_vulkan(): - environment.environment.tonemap_exposure = 0.5 +# TODO +#func apply_settings(): + #environment.ssao_enabled = Global.get_setting("graphics.ssao") + #environment.sdfgi_enabled = Global.get_setting("graphics.gi") == "sdfgi" and allow_sdfgi + #environment.glow_enabled = Global.get_setting("graphics.glow") + #if !Global.on_vulkan(): + #environment.environment.tonemap_exposure = 0.5 diff --git a/client/map/auto_setup/light_setup.gd b/client/map/auto_setup/light_setup.gd index 1e256dae..b42b3662 100644 --- a/client/map/auto_setup/light_setup.gd +++ b/client/map/auto_setup/light_setup.gd @@ -24,8 +24,8 @@ func _ready(): func apply_settings(): if completely_disable_light_if_shadows_disabled: - visible = Global.get_setting("shadows") - shadow_enabled = Global.get_setting("shadows") + visible = Global.get_setting("graphics.shadows") + shadow_enabled = Global.get_setting("graphics.shadows") func set_sky(sky_name: String): match sky_name: -- cgit v1.2.3-70-g09d2 From ad0630639977a7d14700cc2958b9aad52889a298 Mon Sep 17 00:00:00 2001 From: tpart Date: Sat, 7 Sep 2024 00:43:44 +0200 Subject: Fix settings application in light and environment --- client/map/auto_setup/environment_setup.gd | 16 ++++++---------- client/map/auto_setup/light_setup.gd | 9 ++++----- client/menu/setup.tscn | 2 +- client/settings.gd | 6 +++++- 4 files changed, 16 insertions(+), 17 deletions(-) (limited to 'client/map/auto_setup') diff --git a/client/map/auto_setup/environment_setup.gd b/client/map/auto_setup/environment_setup.gd index 49f93ccb..73c3ee32 100644 --- a/client/map/auto_setup/environment_setup.gd +++ b/client/map/auto_setup/environment_setup.gd @@ -22,13 +22,9 @@ func set_sky(sky_name: String): environment.sky.sky_material = load("res://map/environment/presets/%s_sky.tres" % sky_name) func _ready(): - pass - #Global.settings_changed.connect(apply_settings) - -# TODO -#func apply_settings(): - #environment.ssao_enabled = Global.get_setting("graphics.ssao") - #environment.sdfgi_enabled = Global.get_setting("graphics.gi") == "sdfgi" and allow_sdfgi - #environment.glow_enabled = Global.get_setting("graphics.glow") - #if !Global.on_vulkan(): - #environment.environment.tonemap_exposure = 0.5 + Settings.hook_changed_init("graphics.ssao", func (x): environment.ssao_enabled = x) + Settings.hook_changed_init("graphics.gi", func (x): environment.sdfgi_enabled = x == "sdfgi" and allow_sdfgi) + Settings.hook_changed_init("graphics.glow", func (x): environment.glow_enabled = x) + + if !Global.on_vulkan(): + environment.environment.tonemap_exposure = 0.5 diff --git a/client/map/auto_setup/light_setup.gd b/client/map/auto_setup/light_setup.gd index b42b3662..4da2886e 100644 --- a/client/map/auto_setup/light_setup.gd +++ b/client/map/auto_setup/light_setup.gd @@ -19,13 +19,12 @@ class_name LightSetup @export var completely_disable_light_if_shadows_disabled := false func _ready(): - apply_settings() - Global.settings_changed.connect(apply_settings) + Settings.hook_changed_init("graphics.shadows", apply_settings) -func apply_settings(): +func apply_settings(setting: bool): if completely_disable_light_if_shadows_disabled: - visible = Global.get_setting("graphics.shadows") - shadow_enabled = Global.get_setting("graphics.shadows") + visible = setting + shadow_enabled = setting func set_sky(sky_name: String): match sky_name: diff --git a/client/menu/setup.tscn b/client/menu/setup.tscn index 9d8e4975..53c4565e 100644 --- a/client/menu/setup.tscn +++ b/client/menu/setup.tscn @@ -209,8 +209,8 @@ layout_mode = 2 [node name="LineEdit" type="LineEdit" parent="ScrollContainer/Control/TextureRect/PaperMargin/Contents/PositionEntry"] custom_minimum_size = Vector2(300, 30) layout_mode = 2 -theme_override_colors/font_color = Color(0.458824, 0, 0, 1) theme_override_colors/font_uneditable_color = Color(0.458824, 0, 0, 1) +theme_override_colors/font_color = Color(0.458824, 0, 0, 1) editable = false [node name="LineEdit2" type="Label" parent="ScrollContainer/Control/TextureRect/PaperMargin/Contents/PositionEntry/LineEdit"] diff --git a/client/settings.gd b/client/settings.gd index 1c03ca5a..662fb280 100644 --- a/client/settings.gd +++ b/client/settings.gd @@ -93,9 +93,13 @@ static func get_root(): ]) ]) -static func hook_changed(key: String, callable): +static func hook_changed(key: String, callable: Callable): change_hooks[key] = callable +static func hook_changed_init(key: String, callable: Callable): + hook_changed(key, callable) + callable.call(Global.get_setting(key)) + static var change_hooks = { "graphics.aa": h_aa, "graphics.taa": h_taa, -- cgit v1.2.3-70-g09d2 From 923b4d1aa63b6226365a53a7fe227a734760ed1e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 7 Sep 2024 13:56:56 +0200 Subject: fix hooks overriding each other --- client/map/auto_setup/environment_setup.gd | 6 +++--- client/map/auto_setup/light_setup.gd | 2 +- client/map/map.gd | 2 +- client/menu/blur_setup.gd | 2 +- client/menu/settings/dropdown_setting.gd | 2 +- client/menu/settings/input/input_setting.gd | 2 +- client/menu/settings/range_setting.gd | 2 +- client/menu/settings/text_setting.gd | 2 +- client/menu/settings/toggle_setting.gd | 2 +- client/player/player.gd | 2 +- client/settings.gd | 9 +++++---- 11 files changed, 17 insertions(+), 16 deletions(-) (limited to 'client/map/auto_setup') diff --git a/client/map/auto_setup/environment_setup.gd b/client/map/auto_setup/environment_setup.gd index 73c3ee32..c484ca1d 100644 --- a/client/map/auto_setup/environment_setup.gd +++ b/client/map/auto_setup/environment_setup.gd @@ -22,9 +22,9 @@ func set_sky(sky_name: String): environment.sky.sky_material = load("res://map/environment/presets/%s_sky.tres" % sky_name) func _ready(): - Settings.hook_changed_init("graphics.ssao", func (x): environment.ssao_enabled = x) - Settings.hook_changed_init("graphics.gi", func (x): environment.sdfgi_enabled = x == "sdfgi" and allow_sdfgi) - Settings.hook_changed_init("graphics.glow", func (x): environment.glow_enabled = x) + Settings.hook_changed_init("graphics.ssao", false, func (x): environment.ssao_enabled = x) + Settings.hook_changed_init("graphics.gi", false, func (x): environment.sdfgi_enabled = x == "sdfgi" and allow_sdfgi) + Settings.hook_changed_init("graphics.glow", false, func (x): environment.glow_enabled = x) if !Global.on_vulkan(): environment.environment.tonemap_exposure = 0.5 diff --git a/client/map/auto_setup/light_setup.gd b/client/map/auto_setup/light_setup.gd index 4da2886e..7d1b0b7a 100644 --- a/client/map/auto_setup/light_setup.gd +++ b/client/map/auto_setup/light_setup.gd @@ -19,7 +19,7 @@ class_name LightSetup @export var completely_disable_light_if_shadows_disabled := false func _ready(): - Settings.hook_changed_init("graphics.shadows", apply_settings) + Settings.hook_changed_init("graphics.shadows", false, apply_settings) func apply_settings(setting: bool): if completely_disable_light_if_shadows_disabled: diff --git a/client/map/map.gd b/client/map/map.gd index f6258cc6..ce3c6dfa 100644 --- a/client/map/map.gd +++ b/client/map/map.gd @@ -52,7 +52,7 @@ func clear_tile(pos: Vector2i): func _ready(): voxelgi_timer.connect("timeout", gi_bake) - Settings.hook_changed("graphics.gi", apply_gi_setting) + Settings.hook_changed("graphics.gi", false, apply_gi_setting) func apply_gi_setting(state): if state == "voxelgi" and not currently_baked: diff --git a/client/menu/blur_setup.gd b/client/menu/blur_setup.gd index b5f80540..331d1f47 100644 --- a/client/menu/blur_setup.gd +++ b/client/menu/blur_setup.gd @@ -17,7 +17,7 @@ extends Control func _ready(): update(Global.get_setting("graphics.ui_blur")) - Settings.hook_changed("graphics.ui_blur", update) + Settings.hook_changed("graphics.ui_blur", false, update) func update(state): material.set_shader_parameter("enable_blur", state) diff --git a/client/menu/settings/dropdown_setting.gd b/client/menu/settings/dropdown_setting.gd index 4a3ce8c6..3d6b7c80 100644 --- a/client/menu/settings/dropdown_setting.gd +++ b/client/menu/settings/dropdown_setting.gd @@ -26,6 +26,6 @@ func create_row(): var row = super() row.value_node = OptionButton.new() for i in options: row.value_node.add_item(tr(nskey + "." + i)) - Settings.hook_changed_init(key, func (value): row.value_node.select(options.find(value))) + Settings.hook_changed_init(key, true, func (value): row.value_node.select(options.find(value))) row.value_node.item_selected.connect(func(item): Global.set_setting(key, options[item])) return row diff --git a/client/menu/settings/input/input_setting.gd b/client/menu/settings/input/input_setting.gd index 7a017ed2..7388af78 100644 --- a/client/menu/settings/input/input_setting.gd +++ b/client/menu/settings/input/input_setting.gd @@ -22,6 +22,6 @@ const INPUT_VALUE_NODE_SCENE = preload("res://menu/settings/input/input_value_no func create_row(): var row = super() row.value_node = INPUT_VALUE_NODE_SCENE.instantiate() - Settings.hook_changed_init(key, func(value): row.value_node.value = value) + Settings.hook_changed_init(key, true, func(value): row.value_node.value = value) row.value_node.changed.connect(func(): Global.set_setting(key, row.value_node.value)) return row diff --git a/client/menu/settings/range_setting.gd b/client/menu/settings/range_setting.gd index f1261b81..b119a205 100644 --- a/client/menu/settings/range_setting.gd +++ b/client/menu/settings/range_setting.gd @@ -36,6 +36,6 @@ func create_row(): row.value_node.max_value = max_value row.value_node.tick_count = abs(max_value - min_value) if tick_count == null else tick_count row.value_node.step = 0 if smooth else (1 if tick_count == null else abs(max_value - min_value) / (tick_count - 1)) - Settings.hook_changed_init(key, func(value): row.value_node.value = value) + Settings.hook_changed_init(key, true, func(value): row.value_node.value = value) row.value_node.value_changed.connect(func(value): Global.set_setting(key, value)) return row diff --git a/client/menu/settings/text_setting.gd b/client/menu/settings/text_setting.gd index 8bf2fa9f..dc9352ab 100644 --- a/client/menu/settings/text_setting.gd +++ b/client/menu/settings/text_setting.gd @@ -28,5 +28,5 @@ func create_row(): row.value_node = LineEdit.new() row.value_node.placeholder_text = placeholder row.value_node.text_changed.connect(func(text): Global.set_setting(key, text)) - Settings.hook_changed_init(key, func(text): row.value_node.text = text) + Settings.hook_changed_init(key, true, func(text): row.value_node.text = text) return row diff --git a/client/menu/settings/toggle_setting.gd b/client/menu/settings/toggle_setting.gd index c8c40469..8e0c030c 100644 --- a/client/menu/settings/toggle_setting.gd +++ b/client/menu/settings/toggle_setting.gd @@ -24,5 +24,5 @@ func create_row(): var row = super() row.value_node = CheckButton.new() row.value_node.pressed.connect(func(): Global.set_setting(key, row.value_node.button_pressed)) - Settings.hook_changed_init(key, func(value): row.value_node.button_pressed = value) + Settings.hook_changed_init(key, true, func(value): row.value_node.button_pressed = value) return row diff --git a/client/player/player.gd b/client/player/player.gd index f034f14d..f418337b 100644 --- a/client/player/player.gd +++ b/client/player/player.gd @@ -77,7 +77,7 @@ func _ready(): character.select_hairstyle(character_idx) clear_timer.timeout.connect(clear_message) - Settings.hook_changed_init("gameplay.usernames", update_username_tag) + Settings.hook_changed_init("gameplay.usernames", false, update_username_tag) func update_position(new_position: Vector2, new_rotation: float, new_boosting: bool): position_ = new_position diff --git a/client/settings.gd b/client/settings.gd index 828ecb62..5501f1ab 100644 --- a/client/settings.gd +++ b/client/settings.gd @@ -66,11 +66,12 @@ static func get_root(): ]) ]) -static func hook_changed(key: String, callable: Callable): - change_hooks_display[key] = callable +static func hook_changed(key: String, display: bool, callable: Callable): + if display: change_hooks_display[key] = callable + else: change_hooks_apply[key] = callable -static func hook_changed_init(key: String, callable: Callable): - hook_changed(key, callable) +static func hook_changed_init(key: String, display: bool, callable: Callable): + hook_changed(key, display, callable) callable.call(Global.get_setting(key)) static var change_hooks_display = {} -- cgit v1.2.3-70-g09d2