Skip to content

Commit 1c4b660

Browse files
committed
Merge pull request #96611 from Dynamic-Pistol/master
Add `PROPERTY_HINT_INPUT_NAME` for use with `@export_custom` to allow using input actions
2 parents d9c8376 + c8fed1e commit 1c4b660

File tree

7 files changed

+49
-3
lines changed

7 files changed

+49
-3
lines changed

core/core_constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ void register_global_constants() {
679679
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_TOOL_BUTTON);
680680
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_ONESHOT);
681681
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_GROUP_ENABLE);
682+
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_INPUT_NAME);
682683
BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_MAX);
683684

684685
BIND_CORE_BITFIELD_FLAG(PROPERTY_USAGE_NONE);

core/input/input_event.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ void InputEventAction::_bind_methods() {
16651665
ClassDB::bind_method(D_METHOD("set_event_index", "index"), &InputEventAction::set_event_index);
16661666
ClassDB::bind_method(D_METHOD("get_event_index"), &InputEventAction::get_event_index);
16671667

1668-
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action"), "set_action", "get_action");
1668+
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action", PROPERTY_HINT_INPUT_NAME, "show_builtin,loose_mode"), "set_action", "get_action");
16691669
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
16701670
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
16711671
ADD_PROPERTY(PropertyInfo(Variant::INT, "event_index", PROPERTY_HINT_RANGE, "-1,31,1"), "set_event_index", "get_event_index"); // The max value equals to Input::MAX_EVENT - 1.

core/object/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ enum PropertyHint {
9494
PROPERTY_HINT_ONESHOT, ///< the property will be changed by self after setting, such as AudioStreamPlayer.playing, Particles.emitting.
9595
PROPERTY_HINT_NO_NODEPATH, /// < this property will not contain a NodePath, regardless of type (Array, Dictionary, List, etc.). Needed for SceneTreeDock.
9696
PROPERTY_HINT_GROUP_ENABLE, ///< used to make the property's group checkable. Only use for boolean types.
97+
PROPERTY_HINT_INPUT_NAME,
9798
PROPERTY_HINT_MAX,
9899
};
99100

doc/classes/@GlobalScope.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2960,7 +2960,12 @@
29602960
<constant name="PROPERTY_HINT_GROUP_ENABLE" value="42" enum="PropertyHint">
29612961
Hints that a boolean property will enable the feature associated with the group that it occurs in. Only works within a group or subgroup.
29622962
</constant>
2963-
<constant name="PROPERTY_HINT_MAX" value="43" enum="PropertyHint">
2963+
<constant name="PROPERTY_HINT_INPUT_NAME" value="43" enum="PropertyHint">
2964+
Hints that a [String] or [StringName] property is the name of an input action. This allows the selection of any action name from the Input Map in the Project Settings. The hint string may contain two options separated by commas:
2965+
- If it contains [code]"show_builtin"[/code], built-in input actions are included in the selection.
2966+
- If it contains [code]"loose_mode"[/code], loose mode is enabled. This allows inserting any action name even if it's not present in the input map.
2967+
</constant>
2968+
<constant name="PROPERTY_HINT_MAX" value="44" enum="PropertyHint">
29642969
Represents the size of the [enum PropertyHint] enum.
29652970
</constant>
29662971
<constant name="PROPERTY_USAGE_NONE" value="0" enum="PropertyUsageFlags" is_bitfield="true">

editor/editor_properties.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "editor_properties.h"
3232

3333
#include "core/config/project_settings.h"
34+
#include "core/input/input_map.h"
3435
#include "editor/create_dialog.h"
3536
#include "editor/editor_node.h"
3637
#include "editor/editor_properties_array_dict.h"
@@ -3638,6 +3639,38 @@ static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const Stri
36383639
return hint;
36393640
}
36403641

3642+
static EditorProperty *get_input_action_editor(const String &p_hint_text, bool is_string_name) {
3643+
// TODO: Should probably use a better editor GUI with a search bar.
3644+
// Said GUI could also handle showing builtin options, requiring 1 less hint.
3645+
EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
3646+
Vector<String> options;
3647+
Vector<String> builtin_options;
3648+
List<PropertyInfo> pinfo;
3649+
ProjectSettings::get_singleton()->get_property_list(&pinfo);
3650+
Vector<String> hints = p_hint_text.remove_char(' ').split(",", false);
3651+
3652+
HashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
3653+
bool show_builtin = hints.has("show_builtin");
3654+
3655+
for (const PropertyInfo &pi : pinfo) {
3656+
if (!pi.name.begins_with("input/")) {
3657+
continue;
3658+
}
3659+
3660+
const String action_name = pi.name.get_slicec('/', 1);
3661+
if (builtins.has(action_name)) {
3662+
if (show_builtin) {
3663+
builtin_options.append(action_name);
3664+
}
3665+
} else {
3666+
options.append(action_name);
3667+
}
3668+
}
3669+
options.append_array(builtin_options);
3670+
editor->setup(options, is_string_name, hints.has("loose_mode"));
3671+
return editor;
3672+
}
3673+
36413674
EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) {
36423675
double default_float_step = EDITOR_GET("interface/inspector/default_float_step");
36433676

@@ -3751,6 +3784,8 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
37513784
Vector<String> options = p_hint_text.split(",", false);
37523785
editor->setup(options, false, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
37533786
return editor;
3787+
} else if (p_hint == PROPERTY_HINT_INPUT_NAME) {
3788+
return get_input_action_editor(p_hint_text, false);
37543789
} else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) {
37553790
EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText);
37563791
return editor;
@@ -3903,6 +3938,8 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
39033938
Vector<String> options = p_hint_text.split(",", false);
39043939
editor->setup(options, true, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
39053940
return editor;
3941+
} else if (p_hint == PROPERTY_HINT_INPUT_NAME) {
3942+
return get_input_action_editor(p_hint_text, true);
39063943
} else {
39073944
EditorPropertyText *editor = memnew(EditorPropertyText);
39083945
if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) {

modules/gdscript/tests/scripts/utils.notest.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ static func get_property_hint_name(hint: PropertyHint) -> String:
206206
return "PROPERTY_HINT_PASSWORD"
207207
PROPERTY_HINT_TOOL_BUTTON:
208208
return "PROPERTY_HINT_TOOL_BUTTON"
209+
PROPERTY_HINT_INPUT_NAME:
210+
return "PROPERTY_HINT_INPUT_NAME"
209211

210212
printerr("Argument `hint` is invalid. Use `PROPERTY_HINT_*` constants.")
211213
return "<invalid hint>"

scene/2d/physics/touch_screen_button.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void TouchScreenButton::_bind_methods() {
438438
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shape_centered"), "set_shape_centered", "is_shape_centered");
439439
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shape_visible"), "set_shape_visible", "is_shape_visible");
440440
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "passby_press"), "set_passby_press", "is_passby_press_enabled");
441-
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action"), "set_action", "get_action");
441+
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action", PROPERTY_HINT_INPUT_NAME, "show_builtin,loose_mode"), "set_action", "get_action");
442442
ADD_PROPERTY(PropertyInfo(Variant::INT, "visibility_mode", PROPERTY_HINT_ENUM, "Always,TouchScreen Only"), "set_visibility_mode", "get_visibility_mode");
443443

444444
ADD_SIGNAL(MethodInfo("pressed"));

0 commit comments

Comments
 (0)