Add PROPERTY_HINT_INPUT_NAME

Added PROPERTY_HINT_INPUT_NAME for StringName based off https://github.com/godotengine/godot-proposals/discussions/7559
This commit is contained in:
Dynamic-Pistol 2025-01-13 23:00:43 +02:00
parent 931820d33c
commit c8fed1e1d0
7 changed files with 49 additions and 3 deletions

View file

@ -31,6 +31,7 @@
#include "editor_properties.h"
#include "core/config/project_settings.h"
#include "core/input/input_map.h"
#include "editor/create_dialog.h"
#include "editor/editor_node.h"
#include "editor/editor_properties_array_dict.h"
@ -3570,6 +3571,38 @@ static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const Stri
return hint;
}
static EditorProperty *get_input_action_editor(const String &p_hint_text, bool is_string_name) {
// TODO: Should probably use a better editor GUI with a search bar.
// Said GUI could also handle showing builtin options, requiring 1 less hint.
EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum);
Vector<String> options;
Vector<String> builtin_options;
List<PropertyInfo> pinfo;
ProjectSettings::get_singleton()->get_property_list(&pinfo);
Vector<String> hints = p_hint_text.remove_char(' ').split(",", false);
HashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
bool show_builtin = hints.has("show_builtin");
for (const PropertyInfo &pi : pinfo) {
if (!pi.name.begins_with("input/")) {
continue;
}
const String action_name = pi.name.get_slicec('/', 1);
if (builtins.has(action_name)) {
if (show_builtin) {
builtin_options.append(action_name);
}
} else {
options.append(action_name);
}
}
options.append_array(builtin_options);
editor->setup(options, is_string_name, hints.has("loose_mode"));
return editor;
}
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) {
double default_float_step = EDITOR_GET("interface/inspector/default_float_step");
@ -3680,6 +3713,8 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
Vector<String> options = p_hint_text.split(",", false);
editor->setup(options, false, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
return editor;
} else if (p_hint == PROPERTY_HINT_INPUT_NAME) {
return get_input_action_editor(p_hint_text, false);
} else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) {
EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText);
return editor;
@ -3832,6 +3867,8 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
Vector<String> options = p_hint_text.split(",", false);
editor->setup(options, true, (p_hint == PROPERTY_HINT_ENUM_SUGGESTION));
return editor;
} else if (p_hint == PROPERTY_HINT_INPUT_NAME) {
return get_input_action_editor(p_hint_text, true);
} else {
EditorPropertyText *editor = memnew(EditorPropertyText);
if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) {