diff options
Diffstat (limited to 'editor/connections_dialog.cpp')
-rw-r--r-- | editor/connections_dialog.cpp | 119 |
1 files changed, 38 insertions, 81 deletions
diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index c9d612d4dd..6fdd9563fb 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -180,59 +180,11 @@ void ConnectDialog::_unbind_count_changed(double p_count) { * Adds a new parameter bind to connection. */ void ConnectDialog::_add_bind() { - Variant::Type vt = (Variant::Type)type_list->get_item_id(type_list->get_selected()); + Variant::Type type = (Variant::Type)type_list->get_item_id(type_list->get_selected()); Variant value; - - switch (vt) { - case Variant::BOOL: - value = false; - break; - case Variant::INT: - value = 0; - break; - case Variant::FLOAT: - 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; - case Variant::PLANE: - value = Plane(); - break; - case Variant::QUATERNION: - value = Quaternion(); - break; - case Variant::AABB: - value = AABB(); - break; - case Variant::BASIS: - value = Basis(); - break; - case Variant::TRANSFORM3D: - value = Transform3D(); - break; - case Variant::COLOR: - value = Color(); - break; - default: { - ERR_FAIL(); - } break; - } - - ERR_FAIL_COND(value.get_type() == Variant::NIL); + Callable::CallError error; + Variant::construct(type, value, nullptr, 0, error); cdbinds->params.push_back(value); cdbinds->notify_changed(); @@ -277,6 +229,14 @@ void ConnectDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { bind_editor->edit(cdbinds); + + [[fallthrough]]; + } + case NOTIFICATION_THEME_CHANGED: { + for (int i = 0; i < type_list->get_item_count(); i++) { + String type_name = Variant::get_type_name((Variant::Type)type_list->get_item_id(i)); + type_list->set_item_icon(i, get_theme_icon(type_name, SNAME("EditorIcons"))); + } } break; } } @@ -469,21 +429,14 @@ ConnectDialog::ConnectDialog() { type_list = memnew(OptionButton); type_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); add_bind_hb->add_child(type_list); - type_list->add_item("bool", Variant::BOOL); - type_list->add_item("int", Variant::INT); - type_list->add_item("real", Variant::FLOAT); - 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); - type_list->add_item("Plane", Variant::PLANE); - type_list->add_item("Quaternion", Variant::QUATERNION); - type_list->add_item("AABB", Variant::AABB); - type_list->add_item("Basis", Variant::BASIS); - type_list->add_item("Transform3D", Variant::TRANSFORM3D); - type_list->add_item("Color", Variant::COLOR); - type_list->select(0); + for (int i = 0; i < Variant::VARIANT_MAX; i++) { + if (i == Variant::NIL || i == Variant::OBJECT || i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) { + // These types can't be constructed or serialized properly, so skip them. + continue; + } + + type_list->add_item(Variant::get_type_name(Variant::Type(i)), i); + } bind_controls.push_back(type_list); Button *add_bind = memnew(Button); @@ -541,8 +494,8 @@ ConnectDialog::ConnectDialog() { error = memnew(AcceptDialog); add_child(error); error->set_title(TTR("Cannot connect signal")); - error->get_ok_button()->set_text(TTR("Close")); - get_ok_button()->set_text(TTR("Connect")); + error->set_ok_button_text(TTR("Close")); + set_ok_button_text(TTR("Connect")); } ConnectDialog::~ConnectDialog() { @@ -674,7 +627,7 @@ void ConnectionsDock::_connect(ConnectDialog::ConnectionData p_cd) { Callable callable = p_cd.get_callable(); undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), String(p_cd.signal), String(p_cd.method))); - undo_redo->add_do_method(source, "connect", p_cd.signal, callable, varray(), p_cd.flags); + undo_redo->add_do_method(source, "connect", p_cd.signal, callable, p_cd.flags); undo_redo->add_undo_method(source, "disconnect", p_cd.signal, callable); undo_redo->add_do_method(this, "update_tree"); undo_redo->add_undo_method(this, "update_tree"); @@ -911,7 +864,11 @@ void ConnectionsDock::_handle_slot_menu_option(int p_option) { } } -void ConnectionsDock::_rmb_pressed(Vector2 p_position) { +void ConnectionsDock::_rmb_pressed(Vector2 p_position, MouseButton p_button) { + if (p_button != MouseButton::RIGHT) { + return; + } + TreeItem *item = tree->get_selected(); if (!item) { @@ -1076,27 +1033,27 @@ void ConnectionsDock::update_tree() { String descr; bool found = false; - Map<StringName, Map<StringName, String>>::Element *G = descr_cache.find(base); + HashMap<StringName, HashMap<StringName, String>>::Iterator G = descr_cache.find(base); if (G) { - Map<StringName, String>::Element *F = G->get().find(signal_name); + HashMap<StringName, String>::Iterator F = G->value.find(signal_name); if (F) { found = true; - descr = F->get(); + descr = F->value; } } if (!found) { DocTools *dd = EditorHelp::get_doc_data(); - Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(base); + HashMap<String, DocData::ClassDoc>::Iterator F = dd->class_list.find(base); while (F && descr.is_empty()) { - for (int i = 0; i < F->get().signals.size(); i++) { - if (F->get().signals[i].name == signal_name.operator String()) { - descr = DTR(F->get().signals[i].description); + for (int i = 0; i < F->value.signals.size(); i++) { + if (F->value.signals[i].name == signal_name.operator String()) { + descr = DTR(F->value.signals[i].description); break; } } - if (!F->get().inherits.is_empty()) { - F = dd->class_list.find(F->get().inherits); + if (!F->value.inherits.is_empty()) { + F = dd->class_list.find(F->value.inherits); } else { break; } @@ -1169,7 +1126,7 @@ ConnectionsDock::ConnectionsDock() { search_box = memnew(LineEdit); search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL); - search_box->set_placeholder(TTR("Filter signals")); + search_box->set_placeholder(TTR("Filter Signals")); search_box->set_clear_button_enabled(true); search_box->connect("text_changed", callable_mp(this, &ConnectionsDock::_filter_changed)); vbc->add_child(search_box); @@ -1213,7 +1170,7 @@ ConnectionsDock::ConnectionsDock() { connect_dialog->connect("connected", callable_mp(this, &ConnectionsDock::_make_or_edit_connection)); tree->connect("item_selected", callable_mp(this, &ConnectionsDock::_tree_item_selected)); tree->connect("item_activated", callable_mp(this, &ConnectionsDock::_tree_item_activated)); - tree->connect("item_rmb_selected", callable_mp(this, &ConnectionsDock::_rmb_pressed)); + tree->connect("item_mouse_selected", callable_mp(this, &ConnectionsDock::_rmb_pressed)); add_theme_constant_override("separation", 3 * EDSCALE); |