diff options
author | Juan Linietsky <juan@godotengine.org> | 2020-02-20 18:58:05 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-02-21 14:25:29 +0100 |
commit | 3c0059650da3f1feb3c95364d571fe706826dec6 (patch) | |
tree | a36ba94f313e2dee88dc2eb253175849fb2d4138 /editor | |
parent | 7ac0973e9abb308b91597dd8881aeed62682733c (diff) |
Added StringName as a variant type.
Also changed all relevant properties defined manually to StringName.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/animation_track_editor.cpp | 8 | ||||
-rw-r--r-- | editor/connections_dialog.cpp | 2 | ||||
-rw-r--r-- | editor/doc/doc_dump.cpp | 3 | ||||
-rw-r--r-- | editor/editor_feature_profile.cpp | 10 | ||||
-rw-r--r-- | editor/editor_inspector.cpp | 10 | ||||
-rw-r--r-- | editor/editor_properties.cpp | 37 | ||||
-rw-r--r-- | editor/editor_properties.h | 5 | ||||
-rw-r--r-- | editor/editor_properties_array_dict.cpp | 6 |
8 files changed, 63 insertions, 18 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index b538161443..f5c7b91a99 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -593,7 +593,7 @@ public: } break; case Animation::TYPE_METHOD: { - p_list->push_back(PropertyInfo(Variant::STRING, "name")); + p_list->push_back(PropertyInfo(Variant::STRING_NAME, "name")); p_list->push_back(PropertyInfo(Variant::INT, "arg_count", PROPERTY_HINT_RANGE, "0,5,1")); Dictionary d = animation->track_get_key_value(track, key); @@ -654,7 +654,7 @@ public: } animations += "[stop]"; - p_list->push_back(PropertyInfo(Variant::STRING, "animation", PROPERTY_HINT_ENUM, animations)); + p_list->push_back(PropertyInfo(Variant::STRING_NAME, "animation", PROPERTY_HINT_ENUM, animations)); } break; } @@ -1293,7 +1293,7 @@ public: } break; case Animation::TYPE_METHOD: { - p_list->push_back(PropertyInfo(Variant::STRING, "name")); + p_list->push_back(PropertyInfo(Variant::STRING_NAME, "name")); p_list->push_back(PropertyInfo(Variant::INT, "arg_count", PROPERTY_HINT_RANGE, "0,5,1")); Dictionary d = animation->track_get_key_value(first_track, first_key); @@ -1354,7 +1354,7 @@ public: } animations += "[stop]"; - p_list->push_back(PropertyInfo(Variant::STRING, "animation", PROPERTY_HINT_ENUM, animations)); + p_list->push_back(PropertyInfo(Variant::STRING_NAME, "animation", PROPERTY_HINT_ENUM, animations)); } break; } } diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 69a19b3e83..b309a16858 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -168,6 +168,7 @@ void ConnectDialog::_add_bind() { case Variant::INT: value = 0; break; case Variant::REAL: value = 0.0; break; case Variant::STRING: value = ""; break; + case Variant::STRING_NAME: value = ""; break; case Variant::VECTOR2: value = Vector2(); break; case Variant::RECT2: value = Rect2(); break; case Variant::VECTOR3: value = Vector3(); break; @@ -415,6 +416,7 @@ ConnectDialog::ConnectDialog() { type_list->add_item("int", Variant::INT); type_list->add_item("real", Variant::REAL); type_list->add_item("String", Variant::STRING); + type_list->add_item("StringName", Variant::STRING_NAME); type_list->add_item("Vector2", Variant::VECTOR2); type_list->add_item("Rect2", Variant::RECT2); type_list->add_item("Vector3", Variant::VECTOR3); diff --git a/editor/doc/doc_dump.cpp b/editor/doc/doc_dump.cpp index 4763091b8e..4bcf0c5bf5 100644 --- a/editor/doc/doc_dump.cpp +++ b/editor/doc/doc_dump.cpp @@ -165,6 +165,9 @@ void DocDump::dump(const String &p_file) { //keep it break; case Variant::STRING: + case Variant::STRING_NAME: + default_arg_text = "@\"" + default_arg_text + "\""; + break; case Variant::NODE_PATH: default_arg_text = "\"" + default_arg_text + "\""; break; diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index 0d53cb5189..32fadfc60e 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -534,7 +534,7 @@ void EditorFeatureProfileManager::_class_list_item_selected() { } Variant md = item->get_metadata(0); - if (md.get_type() != Variant::STRING) { + if (md.get_type() != Variant::STRING && md.get_type() != Variant::STRING_NAME) { return; } @@ -598,7 +598,7 @@ void EditorFeatureProfileManager::_class_list_item_edited() { bool checked = item->is_checked(0); Variant md = item->get_metadata(0); - if (md.get_type() == Variant::STRING) { + if (md.get_type() == Variant::STRING || md.get_type() == Variant::STRING_NAME) { String class_selected = md; edited->set_disable_class(class_selected, !checked); _save_and_update(); @@ -620,7 +620,7 @@ void EditorFeatureProfileManager::_property_item_edited() { } Variant md = class_item->get_metadata(0); - if (md.get_type() != Variant::STRING) { + if (md.get_type() != Variant::STRING && md.get_type() != Variant::STRING_NAME) { return; } @@ -633,7 +633,7 @@ void EditorFeatureProfileManager::_property_item_edited() { bool checked = item->is_checked(0); md = item->get_metadata(0); - if (md.get_type() == Variant::STRING) { + if (md.get_type() == Variant::STRING || md.get_type() == Variant::STRING_NAME) { String property_selected = md; edited->set_disable_class_property(class_name, property_selected, !checked); _save_and_update(); @@ -657,7 +657,7 @@ void EditorFeatureProfileManager::_update_selected_profile() { if (class_list->get_selected()) { Variant md = class_list->get_selected()->get_metadata(0); - if (md.get_type() == Variant::STRING) { + if (md.get_type() == Variant::STRING || md.get_type() == Variant::STRING_NAME) { class_selected = md; } else if (md.get_type() == Variant::INT) { feature_selected = md; diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 2ed5686a21..c3daf39b48 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -828,13 +828,13 @@ void EditorProperty::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "checked"), "set_checked", "is_checked"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_red"), "set_draw_red", "is_draw_red"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keying"), "set_keying", "is_keying"); - ADD_SIGNAL(MethodInfo("property_changed", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); + ADD_SIGNAL(MethodInfo("property_changed", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); ADD_SIGNAL(MethodInfo("multiple_properties_changed", PropertyInfo(Variant::PACKED_STRING_ARRAY, "properties"), PropertyInfo(Variant::ARRAY, "value"))); - ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING, "property"))); - ADD_SIGNAL(MethodInfo("property_keyed_with_value", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); - ADD_SIGNAL(MethodInfo("property_checked", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::STRING, "bool"))); + ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING_NAME, "property"))); + ADD_SIGNAL(MethodInfo("property_keyed_with_value", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); + ADD_SIGNAL(MethodInfo("property_checked", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::STRING, "bool"))); ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); - ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::INT, "id"))); + ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "focusable_idx"))); MethodInfo vm; diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 7ac321019a..b18c6fc59f 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -64,7 +64,11 @@ void EditorPropertyText::_text_changed(const String &p_string) { if (updating) return; - emit_changed(get_edited_property(), p_string, "", true); + if (string_name) { + emit_changed(get_edited_property(), StringName(p_string), "", true); + } else { + emit_changed(get_edited_property(), p_string, "", true); + } } void EditorPropertyText::update_property() { @@ -75,6 +79,9 @@ void EditorPropertyText::update_property() { updating = false; } +void EditorPropertyText::set_string_name(bool p_enabled) { + string_name = p_enabled; +} void EditorPropertyText::set_placeholder(const String &p_string) { text->set_placeholder(p_string); } @@ -92,6 +99,7 @@ EditorPropertyText::EditorPropertyText() { text->connect_compat("text_changed", this, "_text_changed"); text->connect_compat("text_entered", this, "_text_entered"); + string_name = false; updating = false; } @@ -172,7 +180,12 @@ EditorPropertyMultilineText::EditorPropertyMultilineText() { void EditorPropertyTextEnum::_option_selected(int p_which) { - emit_changed(get_edited_property(), options->get_item_text(p_which)); + if (string_name) { + + emit_changed(get_edited_property(), StringName(options->get_item_text(p_which))); + } else { + emit_changed(get_edited_property(), options->get_item_text(p_which)); + } } void EditorPropertyTextEnum::update_property() { @@ -187,10 +200,11 @@ void EditorPropertyTextEnum::update_property() { } } -void EditorPropertyTextEnum::setup(const Vector<String> &p_options) { +void EditorPropertyTextEnum::setup(const Vector<String> &p_options, bool p_string_name) { for (int i = 0; i < p_options.size(); i++) { options->add_item(p_options[i], i); } + string_name = p_string_name; } void EditorPropertyTextEnum::_bind_methods() { @@ -202,6 +216,7 @@ EditorPropertyTextEnum::EditorPropertyTextEnum() { options = memnew(OptionButton); options->set_clip_text(true); options->set_flat(true); + string_name = false; add_child(options); add_focusable(options); @@ -3305,6 +3320,22 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ editor->setup(p_hint != PROPERTY_HINT_COLOR_NO_ALPHA); add_property_editor(p_path, editor); } break; + case Variant::STRING_NAME: { + + if (p_hint == PROPERTY_HINT_ENUM) { + EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); + Vector<String> options = p_hint_text.split(","); + editor->setup(options, true); + add_property_editor(p_path, editor); + } else { + EditorPropertyText *editor = memnew(EditorPropertyText); + if (p_hint == PROPERTY_HINT_PLACEHOLDER_TEXT) { + editor->set_placeholder(p_hint_text); + } + editor->set_string_name(true); + add_property_editor(p_path, editor); + } + } break; case Variant::NODE_PATH: { EditorPropertyNodePath *editor = memnew(EditorPropertyNodePath); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 7c343f1c67..c5fc8aaf77 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -53,6 +53,7 @@ class EditorPropertyText : public EditorProperty { LineEdit *text; bool updating; + bool string_name; void _text_changed(const String &p_string); void _text_entered(const String &p_string); @@ -60,6 +61,7 @@ protected: static void _bind_methods(); public: + void set_string_name(bool p_enabled); virtual void update_property(); void set_placeholder(const String &p_string); EditorPropertyText(); @@ -91,12 +93,13 @@ class EditorPropertyTextEnum : public EditorProperty { OptionButton *options; void _option_selected(int p_which); + bool string_name; protected: static void _bind_methods(); public: - void setup(const Vector<String> &p_options); + void setup(const Vector<String> &p_options, bool p_string_name = false); virtual void update_property(); EditorPropertyTextEnum(); }; diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index ba66586c81..53ee86c71e 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -804,6 +804,12 @@ void EditorPropertyDictionary::update_property() { prop = memnew(EditorPropertyColor); } break; + case Variant::STRING_NAME: { + EditorPropertyText *ept = memnew(EditorPropertyText); + ept->set_string_name(true); + prop = ept; + + } break; case Variant::NODE_PATH: { prop = memnew(EditorPropertyNodePath); |