You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-10 13:00:37 +00:00
Merge pull request #96611 from Dynamic-Pistol/master
Add `PROPERTY_HINT_INPUT_NAME` for use with `@export_custom` to allow using input actions
This commit is contained in:
@@ -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"
|
||||
@@ -3638,6 +3639,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");
|
||||
|
||||
@@ -3751,6 +3784,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;
|
||||
@@ -3903,6 +3938,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) {
|
||||
|
||||
Reference in New Issue
Block a user