1 /** 2 Object that holds the project-independent editor settings. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.editorsettings; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.resource; 24 /** 25 Object that holds the project-independent editor settings. 26 27 These settings are generally visible in the $(B Editor > Editor Settings) menu. 28 Property names use slash delimiters to distinguish sections. Setting values can be of any $(D Variant) type. It's recommended to use `snake_case` for editor settings to be consistent with the Godot editor itself. 29 Accessing the settings can be done using the following methods, such as: 30 31 32 # `settings.set("some/property", value)` also works as this class overrides `_set()` internally. 33 settings.set_setting("some/property",value) 34 35 # `settings.get("some/property", value)` also works as this class overrides `_get()` internally. 36 settings.get_setting("some/property") 37 38 var list_of_settings = settings.get_property_list() 39 40 41 $(B Note:) This class shouldn't be instantiated directly. Instead, access the singleton using $(D EditorInterface.getEditorSettings). 42 */ 43 @GodotBaseClass struct EditorSettings 44 { 45 package(godot) enum string _GODOT_internal_name = "EditorSettings"; 46 public: 47 @nogc nothrow: 48 union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; } 49 alias _GODOT_base this; 50 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 51 package(godot) __gshared bool _classBindingInitialized = false; 52 package(godot) static struct GDNativeClassBinding 53 { 54 __gshared: 55 @GodotName("add_property_info") GodotMethod!(void, Dictionary) addPropertyInfo; 56 @GodotName("erase") GodotMethod!(void, String) erase; 57 @GodotName("get_favorites") GodotMethod!(PoolStringArray) getFavorites; 58 @GodotName("get_project_metadata") GodotMethod!(Variant, String, String, Variant) getProjectMetadata; 59 @GodotName("get_project_settings_dir") GodotMethod!(String) getProjectSettingsDir; 60 @GodotName("get_recent_dirs") GodotMethod!(PoolStringArray) getRecentDirs; 61 @GodotName("get_setting") GodotMethod!(Variant, String) getSetting; 62 @GodotName("get_settings_dir") GodotMethod!(String) getSettingsDir; 63 @GodotName("has_setting") GodotMethod!(bool, String) hasSetting; 64 @GodotName("property_can_revert") GodotMethod!(bool, String) propertyCanRevert; 65 @GodotName("property_get_revert") GodotMethod!(Variant, String) propertyGetRevert; 66 @GodotName("set_favorites") GodotMethod!(void, PoolStringArray) setFavorites; 67 @GodotName("set_initial_value") GodotMethod!(void, String, Variant, bool) setInitialValue; 68 @GodotName("set_project_metadata") GodotMethod!(void, String, String, Variant) setProjectMetadata; 69 @GodotName("set_recent_dirs") GodotMethod!(void, PoolStringArray) setRecentDirs; 70 @GodotName("set_setting") GodotMethod!(void, String, Variant) setSetting; 71 } 72 /// 73 pragma(inline, true) bool opEquals(in EditorSettings other) const 74 { return _godot_object.ptr is other._godot_object.ptr; } 75 /// 76 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 77 { _godot_object.ptr = n; return null; } 78 /// 79 pragma(inline, true) bool opEquals(typeof(null) n) const 80 { return _godot_object.ptr is n; } 81 /// 82 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 83 mixin baseCasts; 84 /// Construct a new instance of EditorSettings. 85 /// Note: use `memnew!EditorSettings` instead. 86 static EditorSettings _new() 87 { 88 static godot_class_constructor constructor; 89 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorSettings"); 90 if(constructor is null) return typeof(this).init; 91 return cast(EditorSettings)(constructor()); 92 } 93 @disable new(size_t s); 94 /// 95 enum Constants : int 96 { 97 /** 98 Emitted after any editor setting has changed. It's used by various editor plugins to update their visuals on theme changes or logic on configuration changes. 99 */ 100 notificationEditorSettingsChanged = 10000, 101 } 102 /** 103 Adds a custom property info to a property. The dictionary must contain: 104 - `name`: $(D String) (the name of the property) 105 - `type`: $(D long) (see $(D Variant.type)) 106 - optionally `hint`: $(D long) (see $(D propertyhint)) and `hint_string`: $(D String) 107 $(B Example:) 108 109 110 editor_settings.set("category/property_name", 0) 111 112 var property_info = { 113 "name": "category/property_name", 114 "type": TYPE_INT, 115 "hint": PROPERTY_HINT_ENUM, 116 "hint_string": "one,two,three" 117 } 118 119 editor_settings.add_property_info(property_info) 120 121 122 */ 123 void addPropertyInfo(in Dictionary info) 124 { 125 checkClassBinding!(typeof(this))(); 126 ptrcall!(void)(GDNativeClassBinding.addPropertyInfo, _godot_object, info); 127 } 128 /** 129 Erases the setting whose name is specified by `property`. 130 */ 131 void erase(in String property) 132 { 133 checkClassBinding!(typeof(this))(); 134 ptrcall!(void)(GDNativeClassBinding.erase, _godot_object, property); 135 } 136 /** 137 Returns the list of favorite files and directories for this project. 138 */ 139 PoolStringArray getFavorites() const 140 { 141 checkClassBinding!(typeof(this))(); 142 return ptrcall!(PoolStringArray)(GDNativeClassBinding.getFavorites, _godot_object); 143 } 144 /** 145 Returns project-specific metadata for the `section` and `key` specified. If the metadata doesn't exist, `default` will be returned instead. See also $(D setProjectMetadata). 146 */ 147 Variant getProjectMetadata(VariantArg2)(in String section, in String key, in VariantArg2 _default = Variant.nil) const 148 { 149 checkClassBinding!(typeof(this))(); 150 return ptrcall!(Variant)(GDNativeClassBinding.getProjectMetadata, _godot_object, section, key, _default); 151 } 152 /** 153 Returns the project-specific settings path. Projects all have a unique subdirectory inside the settings path where project-specific settings are saved. 154 */ 155 String getProjectSettingsDir() const 156 { 157 checkClassBinding!(typeof(this))(); 158 return ptrcall!(String)(GDNativeClassBinding.getProjectSettingsDir, _godot_object); 159 } 160 /** 161 Returns the list of recently visited folders in the file dialog for this project. 162 */ 163 PoolStringArray getRecentDirs() const 164 { 165 checkClassBinding!(typeof(this))(); 166 return ptrcall!(PoolStringArray)(GDNativeClassBinding.getRecentDirs, _godot_object); 167 } 168 /** 169 Returns the value of the setting specified by `name`. This is equivalent to using $(D GodotObject.get) on the EditorSettings instance. 170 */ 171 Variant getSetting(in String name) const 172 { 173 checkClassBinding!(typeof(this))(); 174 return ptrcall!(Variant)(GDNativeClassBinding.getSetting, _godot_object, name); 175 } 176 /** 177 Gets the global settings path for the engine. Inside this path, you can find some standard paths such as: 178 `settings/tmp` - Used for temporary storage of files 179 `settings/templates` - Where export templates are located 180 */ 181 String getSettingsDir() const 182 { 183 checkClassBinding!(typeof(this))(); 184 return ptrcall!(String)(GDNativeClassBinding.getSettingsDir, _godot_object); 185 } 186 /** 187 Returns `true` if the setting specified by `name` exists, `false` otherwise. 188 */ 189 bool hasSetting(in String name) const 190 { 191 checkClassBinding!(typeof(this))(); 192 return ptrcall!(bool)(GDNativeClassBinding.hasSetting, _godot_object, name); 193 } 194 /** 195 Returns `true` if the setting specified by `name` can have its value reverted to the default value, `false` otherwise. When this method returns `true`, a Revert button will display next to the setting in the Editor Settings. 196 */ 197 bool propertyCanRevert(in String name) 198 { 199 checkClassBinding!(typeof(this))(); 200 return ptrcall!(bool)(GDNativeClassBinding.propertyCanRevert, _godot_object, name); 201 } 202 /** 203 Returns the default value of the setting specified by `name`. This is the value that would be applied when clicking the Revert button in the Editor Settings. 204 */ 205 Variant propertyGetRevert(in String name) 206 { 207 checkClassBinding!(typeof(this))(); 208 return ptrcall!(Variant)(GDNativeClassBinding.propertyGetRevert, _godot_object, name); 209 } 210 /** 211 Sets the list of favorite files and directories for this project. 212 */ 213 void setFavorites(in PoolStringArray dirs) 214 { 215 checkClassBinding!(typeof(this))(); 216 ptrcall!(void)(GDNativeClassBinding.setFavorites, _godot_object, dirs); 217 } 218 /** 219 Sets the initial value of the setting specified by `name` to `value`. This is used to provide a value for the Revert button in the Editor Settings. If `update_current` is true, the current value of the setting will be set to `value` as well. 220 */ 221 void setInitialValue(VariantArg1)(in String name, in VariantArg1 value, in bool update_current) 222 { 223 checkClassBinding!(typeof(this))(); 224 ptrcall!(void)(GDNativeClassBinding.setInitialValue, _godot_object, name, value, update_current); 225 } 226 /** 227 Sets project-specific metadata with the `section`, `key` and `data` specified. This metadata is stored outside the project folder and therefore won't be checked into version control. See also $(D getProjectMetadata). 228 */ 229 void setProjectMetadata(VariantArg2)(in String section, in String key, in VariantArg2 data) 230 { 231 checkClassBinding!(typeof(this))(); 232 ptrcall!(void)(GDNativeClassBinding.setProjectMetadata, _godot_object, section, key, data); 233 } 234 /** 235 Sets the list of recently visited folders in the file dialog for this project. 236 */ 237 void setRecentDirs(in PoolStringArray dirs) 238 { 239 checkClassBinding!(typeof(this))(); 240 ptrcall!(void)(GDNativeClassBinding.setRecentDirs, _godot_object, dirs); 241 } 242 /** 243 Sets the `value` of the setting specified by `name`. This is equivalent to using $(D GodotObject.set) on the EditorSettings instance. 244 */ 245 void setSetting(VariantArg1)(in String name, in VariantArg1 value) 246 { 247 checkClassBinding!(typeof(this))(); 248 ptrcall!(void)(GDNativeClassBinding.setSetting, _godot_object, name, value); 249 } 250 }