Skip to content

Commit

Permalink
Merge pull request #62038 from KoBeWi/ChangedSettings
Browse files Browse the repository at this point in the history
Add `settings_changed` signal to ProjectSettings
  • Loading branch information
akien-mga committed Aug 10, 2023
2 parents 013e8e3 + c5ec847 commit 11cfb23
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
for (int i = 0; i < custom_feature_array.size(); i++) {
custom_features.insert(custom_feature_array[i]);
}
_queue_changed();
return true;
}

Expand Down Expand Up @@ -324,6 +325,7 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
}
}

_queue_changed();
return true;
}

Expand Down Expand Up @@ -424,6 +426,22 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
}
}

void ProjectSettings::_queue_changed() {
if (is_changed || !MessageQueue::get_singleton() || MessageQueue::get_singleton()->get_max_buffer_usage() == 0) {
return;
}
is_changed = true;
callable_mp(this, &ProjectSettings::_emit_changed).call_deferred();
}

void ProjectSettings::_emit_changed() {
if (!is_changed) {
return;
}
is_changed = false;
emit_signal("settings_changed");
}

bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) {
if (PackedData::get_singleton()->is_disabled()) {
return false;
Expand Down Expand Up @@ -1225,6 +1243,8 @@ void ProjectSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0));

ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);

ADD_SIGNAL(MethodInfo("settings_changed"));
}

void ProjectSettings::_add_builtin_input_map() {
Expand Down
5 changes: 5 additions & 0 deletions core/config/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class ProjectSettings : public Object {
_THREAD_SAFE_CLASS_
friend class TestProjectSettingsInternalsAccessor;

bool is_changed = false;

public:
typedef HashMap<String, Variant> CustomMap;
static const String PROJECT_DATA_DIR_NAME_SUFFIX;
Expand Down Expand Up @@ -115,6 +117,9 @@ class ProjectSettings : public Object {
bool _property_can_revert(const StringName &p_name) const;
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;

void _queue_changed();
void _emit_changed();

static ProjectSettings *singleton;

Error _load_settings_text(const String &p_path);
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2710,4 +2710,11 @@
If [code]true[/code], Godot will compile shaders required for XR.
</member>
</members>
<signals>
<signal name="settings_changed">
<description>
Emitted when any setting is changed, up to once per process frame.
</description>
</signal>
</signals>
</class>

0 comments on commit 11cfb23

Please sign in to comment.