mirror of https://github.com/godotengine/godot
Merge e1afbdc394 into 15ff450680
This commit is contained in:
commit
e172a0bb42
|
|
@ -558,6 +558,61 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
|
|||
} else {
|
||||
pi.hint_string = "Resource";
|
||||
}
|
||||
} else if (K.value.get_type() == Variant::ARRAY) {
|
||||
pi.hint = PROPERTY_HINT_TYPE_STRING;
|
||||
const int builtin = Array(K.value).get_typed_builtin();
|
||||
pi.hint_string = itos(builtin);
|
||||
if (builtin == Variant::OBJECT) {
|
||||
pi.hint_string += "/" + itos(PROPERTY_HINT_RESOURCE_TYPE) + ":";
|
||||
const Script *s = Object::cast_to<Script>(Array(K.value).get_typed_script());
|
||||
if (s) {
|
||||
if (s->get_global_name().is_empty()) {
|
||||
pi.hint_string += s->get_instance_base_type();
|
||||
} else {
|
||||
pi.hint_string += s->get_global_name();
|
||||
}
|
||||
} else {
|
||||
pi.hint_string += Array(K.value).get_typed_class_name();
|
||||
}
|
||||
} else {
|
||||
pi.hint_string += ":";
|
||||
}
|
||||
} else if (K.value.get_type() == Variant::DICTIONARY) {
|
||||
pi.hint = PROPERTY_HINT_TYPE_STRING;
|
||||
const int key_builtin = Dictionary(K.value).get_typed_key_builtin();
|
||||
pi.hint_string = itos(key_builtin);
|
||||
if (key_builtin == Variant::OBJECT) {
|
||||
pi.hint_string += "/" + itos(PROPERTY_HINT_RESOURCE_TYPE) + ":";
|
||||
const Script *s = Object::cast_to<Script>(Dictionary(K.value).get_typed_key_script());
|
||||
if (s) {
|
||||
if (s->get_global_name().is_empty()) {
|
||||
pi.hint_string += s->get_instance_base_type();
|
||||
} else {
|
||||
pi.hint_string += s->get_global_name();
|
||||
}
|
||||
} else {
|
||||
pi.hint_string += Dictionary(K.value).get_typed_key_class_name();
|
||||
}
|
||||
} else {
|
||||
pi.hint_string += ":";
|
||||
}
|
||||
const int value_builtin = Dictionary(K.value).get_typed_value_builtin();
|
||||
pi.hint_string += ";" + itos(value_builtin);
|
||||
if (value_builtin == Variant::OBJECT) {
|
||||
pi.hint_string += "/" + itos(PROPERTY_HINT_RESOURCE_TYPE) + ":";
|
||||
const Script *s = Object::cast_to<Script>(Dictionary(K.value).get_typed_value_script());
|
||||
if (s) {
|
||||
if (s->get_global_name().is_empty()) {
|
||||
pi.hint_string += s->get_instance_base_type();
|
||||
} else {
|
||||
pi.hint_string += s->get_global_name();
|
||||
}
|
||||
} else {
|
||||
pi.hint_string += Dictionary(K.value).get_typed_value_class_name();
|
||||
}
|
||||
} else {
|
||||
pi.hint_string += ":";
|
||||
}
|
||||
}
|
||||
p_list->push_back(pi);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,27 @@ AddMetadataDialog::AddMetadataDialog() {
|
|||
vbc->add_child(spacing);
|
||||
spacing->set_custom_minimum_size(Size2(0, 10 * EDSCALE));
|
||||
|
||||
HBoxContainer *typed_container = memnew(HBoxContainer);
|
||||
typed_container->hide();
|
||||
|
||||
Label *key_label = memnew(Label);
|
||||
typed_container->add_child(key_label);
|
||||
|
||||
add_meta_key_type = memnew(OptionButton);
|
||||
typed_container->add_child(add_meta_key_type);
|
||||
|
||||
Label *value_label = memnew(Label(TTR("Value:")));
|
||||
typed_container->add_child(value_label);
|
||||
|
||||
add_meta_value_type = memnew(OptionButton);
|
||||
typed_container->add_child(add_meta_value_type);
|
||||
|
||||
vbc->add_child(typed_container);
|
||||
|
||||
Control *spacing2 = memnew(Control);
|
||||
vbc->add_child(spacing2);
|
||||
spacing2->set_custom_minimum_size(Size2(0, 10 * EDSCALE));
|
||||
|
||||
set_ok_button_text(TTR("Add"));
|
||||
register_text_enter(add_meta_name);
|
||||
|
||||
|
|
@ -63,6 +84,7 @@ AddMetadataDialog::AddMetadataDialog() {
|
|||
validation_panel->set_accept_button(get_ok_button());
|
||||
|
||||
add_meta_name->connect(SceneStringName(text_changed), callable_mp(validation_panel, &EditorValidationPanel::update).unbind(1));
|
||||
add_meta_type->connect(SceneStringName(item_selected), callable_mp(this, &AddMetadataDialog::_update_controls).bind(typed_container, key_label, value_label).unbind(1));
|
||||
}
|
||||
|
||||
void AddMetadataDialog::_complete_init(const StringName &p_title) {
|
||||
|
|
@ -77,6 +99,10 @@ void AddMetadataDialog::_complete_init(const StringName &p_title) {
|
|||
}
|
||||
|
||||
// Theme icons can be retrieved only the Window has been initialized.
|
||||
// Need to be able to set untyped arrays and dictionaries.
|
||||
add_meta_key_type->add_icon_item(get_editor_theme_icon("Variant"), "Variant", 0);
|
||||
add_meta_value_type->add_icon_item(get_editor_theme_icon("Variant"), "Variant", 0);
|
||||
|
||||
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
|
||||
if (i == Variant::NIL || i == Variant::RID || i == Variant::CALLABLE || i == Variant::SIGNAL) {
|
||||
continue; //not editable by inspector.
|
||||
|
|
@ -84,6 +110,25 @@ void AddMetadataDialog::_complete_init(const StringName &p_title) {
|
|||
String type = i == Variant::OBJECT ? String("Resource") : Variant::get_type_name(Variant::Type(i));
|
||||
|
||||
add_meta_type->add_icon_item(get_editor_theme_icon(type), type, i);
|
||||
add_meta_key_type->add_icon_item(get_editor_theme_icon(type), type, i);
|
||||
add_meta_value_type->add_icon_item(get_editor_theme_icon(type), type, i);
|
||||
}
|
||||
}
|
||||
|
||||
// Parameters bound in init to prevent needing extra private variables just for this purpose.
|
||||
void AddMetadataDialog::_update_controls(HBoxContainer *p_typed_container, Label *p_key_label, Label *p_value_label) {
|
||||
if (add_meta_type->get_selected_id() == Variant::DICTIONARY) {
|
||||
p_value_label->show();
|
||||
add_meta_value_type->show();
|
||||
p_key_label->set_text(TTR("Key:"));
|
||||
p_typed_container->show();
|
||||
} else if (add_meta_type->get_selected_id() == Variant::ARRAY) {
|
||||
p_value_label->hide();
|
||||
add_meta_value_type->hide();
|
||||
p_key_label->set_text(TTR("Element:"));
|
||||
p_typed_container->show();
|
||||
} else {
|
||||
p_typed_container->hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,9 +144,31 @@ StringName AddMetadataDialog::get_meta_name() {
|
|||
}
|
||||
|
||||
Variant AddMetadataDialog::get_meta_defval() {
|
||||
const int type_id = add_meta_type->get_selected_id();
|
||||
|
||||
if (type_id == Variant::ARRAY) {
|
||||
const int elem_type_id = add_meta_key_type->get_selected_id();
|
||||
|
||||
Array defarray = Array();
|
||||
// Do not set Array[Variant] in metadata since untyped Array serves same purpose.
|
||||
if (elem_type_id != Variant::NIL) {
|
||||
defarray.set_typed(elem_type_id, elem_type_id == Variant::OBJECT ? "Resource" : "", Variant());
|
||||
}
|
||||
return defarray;
|
||||
} else if (type_id == Variant::DICTIONARY) {
|
||||
const int key_type_id = add_meta_key_type->get_selected_id();
|
||||
const int value_type_id = add_meta_value_type->get_selected_id();
|
||||
|
||||
Dictionary defdict = Dictionary();
|
||||
// Can set a Variant here if the other is typed.
|
||||
if (key_type_id != Variant::NIL || value_type_id != Variant::NIL) {
|
||||
defdict.set_typed(key_type_id, key_type_id == Variant::OBJECT ? "Resource" : "", Variant(), value_type_id, value_type_id == Variant::OBJECT ? "Resource" : "", Variant());
|
||||
}
|
||||
return defdict;
|
||||
}
|
||||
Variant defval;
|
||||
Callable::CallError ce;
|
||||
Variant::construct(Variant::Type(add_meta_type->get_selected_id()), defval, nullptr, 0, ce);
|
||||
Variant::construct(Variant::Type(type_id), defval, nullptr, 0, ce);
|
||||
return defval;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,10 +50,13 @@ private:
|
|||
List<StringName> _existing_metas;
|
||||
|
||||
void _check_meta_name();
|
||||
void _complete_init(const StringName &p_label);
|
||||
void _update_controls(HBoxContainer *p_typed_container, Label *p_key_label, Label *p_value_label);
|
||||
void _complete_init(const StringName &p_title);
|
||||
|
||||
LineEdit *add_meta_name = nullptr;
|
||||
OptionButton *add_meta_type = nullptr;
|
||||
OptionButton *add_meta_key_type = nullptr;
|
||||
OptionButton *add_meta_value_type = nullptr;
|
||||
EditorValidationPanel *validation_panel = nullptr;
|
||||
};
|
||||
#endif // ADD_METADATA_DIALOG_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue