From 2397ef872d8c7bfedcb68afdfce596ff91ab4d70 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Tue, 9 Jul 2024 23:51:19 -0400 Subject: [PATCH] GH-488 Update InspectorDock when ProjectSettings change --- src/script/nodes/input/input_action.cpp | 30 +++++++++++++++++++++++++ src/script/nodes/input/input_action.h | 5 +++++ 2 files changed, 35 insertions(+) diff --git a/src/script/nodes/input/input_action.cpp b/src/script/nodes/input/input_action.cpp index a0880835..3e0cf4af 100644 --- a/src/script/nodes/input/input_action.cpp +++ b/src/script/nodes/input/input_action.cpp @@ -64,6 +64,14 @@ class OScriptNodeInputActionInstance : public OScriptNodeInstance //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void OScriptNodeInputAction::_settings_changed() +{ + // If the node is selected and the user modifies the project settings, this makes sure that the action + // list will be regenerated in the InspectorDock to reflect the changes potentially to any new InputMap + // actions that were defined. + notify_property_list_changed(); +} + PackedStringArray OScriptNodeInputAction::_get_action_names() const { PackedStringArray action_names; @@ -144,6 +152,28 @@ void OScriptNodeInputAction::_bind_methods() BIND_ENUM_CONSTANT(AM_JUST_RELEASED) } +void OScriptNodeInputAction::post_initialize() +{ + if (_is_in_editor()) + { + ProjectSettings* settings = ProjectSettings::get_singleton(); + settings->connect("settings_changed", callable_mp(this, &OScriptNodeInputAction::_settings_changed)); + } + + super::post_initialize(); +} + +void OScriptNodeInputAction::post_placed_new_node() +{ + if (_is_in_editor()) + { + ProjectSettings* settings = ProjectSettings::get_singleton(); + settings->connect("settings_changed", callable_mp(this, &OScriptNodeInputAction::_settings_changed)); + } + + super::post_placed_new_node(); +} + void OScriptNodeInputAction::allocate_default_pins() { create_pin(PD_Output, PT_Data, PropertyUtils::make_typed("state", Variant::BOOL))->set_label(_get_mode()); diff --git a/src/script/nodes/input/input_action.h b/src/script/nodes/input/input_action.h index c6c577a9..0b845cfc 100644 --- a/src/script/nodes/input/input_action.h +++ b/src/script/nodes/input/input_action.h @@ -44,12 +44,17 @@ class OScriptNodeInputAction : public OScriptNode bool _set(const StringName &p_name, const Variant &p_value); //~ End Wrapped Interface + /// Called when the project settings are modified. + void _settings_changed(); + PackedStringArray _get_action_names() const; String _get_mode() const; public: //~ Begin OScriptNode Interface + void post_initialize() override; + void post_placed_new_node() override; void allocate_default_pins() override; String get_tooltip_text() const override; String get_node_title() const override;