|
1 | | -class_name InterfaceConfig |
| 1 | +# Copyright (c) 2025 Liam Sherwin. All rights reserved. |
| 2 | +# This file is part of the Spectrum Lighting Controller, licensed under the GPL v3.0 or later. |
| 3 | +# See the LICENSE file for details. |
| 4 | + |
| 5 | +class_name InterfaceConfig extends Object |
| 6 | +## Store interface configs |
| 7 | + |
2 | 8 |
|
3 | 9 | ## File location to store the UI Save |
4 | 10 | var ui_save_location: String = "user://" |
5 | 11 |
|
6 | 12 | ## File name to store the UI Save |
7 | 13 | var ui_save_file: String = "ui.json" |
8 | 14 |
|
| 15 | +## File location to store the UI Save |
| 16 | +var config_save_location: String = "user://" |
| 17 | + |
| 18 | +## File name to store the UI Save |
| 19 | +var config_save_file: String = "interface.conf" |
| 20 | + |
| 21 | +## Array of notice ID not to show again |
| 22 | +var notices_dont_show_again: Array[String] |
| 23 | + |
| 24 | +## True if the UI should be saved to disk before the program closes |
| 25 | +var save_ui_on_quit: bool = true |
| 26 | + |
| 27 | +## UI Scale factor |
| 28 | +var scale_factor: float = 1 |
| 29 | + |
| 30 | + |
9 | 31 | ## Default items in the UICommandPalette |
10 | 32 | var command_palette_default_items: Array[CommandPaletteEntry] = [ |
11 | 33 | CommandPaletteEntry.new( |
@@ -45,3 +67,78 @@ var object_picker_default_items: Dictionary[Script, ClassTreeConfig] = { |
45 | 67 | Callable() |
46 | 68 | ) |
47 | 69 | } |
| 70 | + |
| 71 | + |
| 72 | +## Built in start up notics |
| 73 | +var startup_notices: Array[StartUpNotice] = [ |
| 74 | + StartUpNotice.new() |
| 75 | + .set_title("Beta Software Notice!") |
| 76 | + .set_title_icon("res://assets/logos/spectrum/dark_scaled/spectrum_dark-64x64.png") |
| 77 | + .set_version(Details.version) |
| 78 | + .set_bbcode_body( |
| 79 | + """[ul] |
| 80 | + Spectrum is currently in [b]active development[/b] and is considered [b]beta software[/b]. |
| 81 | + Features may change, bugs may exist, and stability is [b]not yet guaranteed[/b]. |
| 82 | + It is [b]not recommended for mission-critical or production use[/b] at this stage. |
| 83 | + [/ul]""" |
| 84 | + .replace("\t", "")) |
| 85 | + .set_confirm_button_text("Acknowledge") |
| 86 | + .set_link_text("Github Issues") |
| 87 | + .set_link_url("https://github.com/SpectrumPro/Spectrum/issues") |
| 88 | + .set_notice_id("BETANOTICEV1.0.0-beta.3") |
| 89 | +] |
| 90 | + |
| 91 | +## ConfigFile to save and load user config |
| 92 | +var _config_access: ConfigFile |
| 93 | + |
| 94 | + |
| 95 | +## init |
| 96 | +func _init() -> void: |
| 97 | + DirAccess.make_dir_recursive_absolute(config_save_location) |
| 98 | + _config_access = ConfigFile.new() |
| 99 | + |
| 100 | + |
| 101 | +## Loads (or creates if not already) the user config override |
| 102 | +func load_user_config() -> Error: |
| 103 | + _config_access.load(get_user_config_path()) |
| 104 | + |
| 105 | + var block_list: Array[String] = [] |
| 106 | + block_list.assign(type_convert(_config_access.get_value("Interface", "notices_dont_show_again"), TYPE_ARRAY)) |
| 107 | + notices_dont_show_again = block_list |
| 108 | + |
| 109 | + scale_factor = type_convert(_config_access.get_value("Interface", "scale_factor", scale_factor), TYPE_FLOAT) |
| 110 | + save_ui_on_quit = type_convert(_config_access.get_value("Interface", "save_ui_on_quit", save_ui_on_quit), TYPE_BOOL) |
| 111 | + |
| 112 | + save_user_config() |
| 113 | + return OK |
| 114 | + |
| 115 | + |
| 116 | +## Saves the user config to a file |
| 117 | +func save_user_config() -> Error: |
| 118 | + _config_access.set_value("Interface", "notices_dont_show_again", notices_dont_show_again) |
| 119 | + |
| 120 | + _config_access.set_value("Interface", "scale_factor", scale_factor) |
| 121 | + _config_access.set_value("Interface", "save_ui_on_quit", save_ui_on_quit) |
| 122 | + |
| 123 | + return _config_access.save(get_user_config_path()) |
| 124 | + |
| 125 | + |
| 126 | +## Adds the given notice to the list of don't show again |
| 127 | +func notice_dont_show_again(p_id: String) -> void: |
| 128 | + if notices_dont_show_again.has(p_id): |
| 129 | + return |
| 130 | + |
| 131 | + notices_dont_show_again.append(p_id) |
| 132 | + |
| 133 | + |
| 134 | +## Checks if a notice can be shown |
| 135 | +func can_show_notice(p_id: String) -> bool: |
| 136 | + return notices_dont_show_again.has(p_id) |
| 137 | + |
| 138 | + |
| 139 | +## Returns the full filepath to the user config |
| 140 | +func get_user_config_path() -> String: |
| 141 | + if config_save_location.ends_with("/"): |
| 142 | + return config_save_location + config_save_file |
| 143 | + else: |
| 144 | + return config_save_location + "/" + config_save_file |
0 commit comments