Skip to content

Commit c8fed1e

Browse files
Add PROPERTY_HINT_INPUT_NAME
Added PROPERTY_HINT_INPUT_NAME for StringName based off godotengine/godot-proposals#7559
1 parent 931820d commit c8fed1e

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
@@ -1668,7 +1668,7 @@ void InputEventAction::_bind_methods() {
16681668
ClassDB::bind_method(D_METHOD("set_event_index", "index"), &InputEventAction::set_event_index);
16691669
ClassDB::bind_method(D_METHOD("get_event_index"), &InputEventAction::get_event_index);
16701670

1671-
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action"), "set_action", "get_action");
1671+
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action", PROPERTY_HINT_INPUT_NAME, "show_builtin,loose_mode"), "set_action", "get_action");
16721672
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
16731673
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
16741674
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
@@ -2957,7 +2957,12 @@
29572957
<constant name="PROPERTY_HINT_GROUP_ENABLE" value="42" enum="PropertyHint">
29582958
Hints that a boolean property will enable the feature associated with the group that it occurs in. Only works within a group or subgroup.
29592959
</constant>
2960-
<constant name="PROPERTY_HINT_MAX" value="43" enum="PropertyHint">
2960+
<constant name="PROPERTY_HINT_INPUT_NAME" value="43" enum="PropertyHint">
2961+
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:
2962+
- If it contains [code]"show_builtin"[/code], built-in input actions are included in the selection.
2963+
- 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.
2964+
</constant>
2965+
<constant name="PROPERTY_HINT_MAX" value="44" enum="PropertyHint">
29612966
Represents the size of the [enum PropertyHint] enum.
29622967
</constant>
29632968
<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"
@@ -3570,6 +3571,38 @@ static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const Stri
35703571
return hint;
35713572
}
35723573

3574+
static EditorProperty *get_input_action_editor(const String &p_hint_text, bool is_string_name) {
3575+
// TODO: Should probably use a better editor GUI with a search bar.
3576+
// Said GUI could also handle showing builtin options, requiring 1 less hint.
3577+
EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
3578+
Vector<String> options;
3579+
Vector<String> builtin_options;
3580+
List<PropertyInfo> pinfo;
3581+
ProjectSettings::get_singleton()->get_property_list(&pinfo);
3582+
Vector<String> hints = p_hint_text.remove_char(' ').split(",", false);
3583+
3584+
HashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
3585+
bool show_builtin = hints.has("show_builtin");
3586+
3587+
for (const PropertyInfo &pi : pinfo) {
3588+
if (!pi.name.begins_with("input/")) {
3589+
continue;
3590+
}
3591+
3592+
const String action_name = pi.name.get_slicec('/', 1);
3593+
if (builtins.has(action_name)) {
3594+
if (show_builtin) {
3595+
builtin_options.append(action_name);
3596+
}
3597+
} else {
3598+
options.append(action_name);
3599+
}
3600+
}
3601+
options.append_array(builtin_options);
3602+
editor->setup(options, is_string_name, hints.has("loose_mode"));
3603+
return editor;
3604+
}
3605+
35733606
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) {
35743607
double default_float_step = EDITOR_GET("interface/inspector/default_float_step");
35753608

@@ -3680,6 +3713,8 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
36803713
Vector<String> options = p_hint_text.split(",", false);
36813714
editor->setup(options, false, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
36823715
return editor;
3716+
} else if (p_hint == PROPERTY_HINT_INPUT_NAME) {
3717+
return get_input_action_editor(p_hint_text, false);
36833718
} else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) {
36843719
EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText);
36853720
return editor;
@@ -3832,6 +3867,8 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
38323867
Vector<String> options = p_hint_text.split(",", false);
38333868
editor->setup(options, true, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
38343869
return editor;
3870+
} else if (p_hint == PROPERTY_HINT_INPUT_NAME) {
3871+
return get_input_action_editor(p_hint_text, true);
38353872
} else {
38363873
EditorPropertyText *editor = memnew(EditorPropertyText);
38373874
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)