godot-resources-as-sheets-p.../addons/resources_speadsheet_view/settings_grid.gd

30 lines
835 B
GDScript3
Raw Normal View History

2022-09-24 17:36:54 +02:00
tool
class_name SettingsGrid
extends GridContainer
const SETTING_PREFIX = "addons/resources_spreadsheet_view/"
func _ready():
for x in get_children():
2022-09-30 19:56:25 +02:00
var setting = SETTING_PREFIX + TextEditingUtils.pascal_case_to_snake_case(x.name)
2022-09-24 17:36:54 +02:00
if x is BaseButton:
x.connect("toggled", self, "_set_setting", [setting])
if !ProjectSettings.has_setting(setting):
call("_set_setting", x.pressed, setting)
else:
x.pressed = ProjectSettings.get_setting(setting)
elif x is Range:
x.connect("value_changed", self, "_set_setting", [setting])
if !ProjectSettings.has_setting(setting):
call("_set_setting", x.value, setting)
else:
x.value = ProjectSettings.get_setting(setting)
func _set_setting(new_value, setting):
ProjectSettings.set_setting(setting, new_value)