| 52 | } |
| 53 | |
| 54 | void EntityEditor::update_editors() { |
| 55 | const Color section_color = get_theme_color(SNAME("prop_subsection"), SNAME("Editor")); |
| 56 | |
| 57 | if (add_component_menu) { |
| 58 | // Remove all old components. |
| 59 | add_component_menu->get_popup()->clear(); |
| 60 | |
| 61 | const LocalVector<StringName> &components = ECS::get_registered_components(); |
| 62 | for (uint32_t i = 0; i < components.size(); i += 1) { |
| 63 | add_component_menu->get_popup()->add_item(components[i]); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (components_section) { |
| 68 | // Remove old childs. |
| 69 | for (int i = components_section->get_vbox()->get_child_count() - 1; i >= 0; i -= 1) { |
| 70 | components_section->get_vbox()->get_child(i)->queue_delete(); // TODO is this enough to also destroy the internally created things? |
| 71 | } |
| 72 | components_properties.clear(); |
| 73 | |
| 74 | const OAHashMap<StringName, Ref<ComponentDepot>> &components = entity_get_components_data(); |
| 75 | for (OAHashMap<StringName, Ref<ComponentDepot>>::Iterator it = components.iter(); it.valid; it = components.next_iter(it)) { |
| 76 | // Add the components of this Entity |
| 77 | EditorInspectorSection *component_section = memnew(EditorInspectorSection); |
| 78 | component_section->setup("component_" + String(*it.key), String(*it.key), entity, section_color, true); |
| 79 | component_section->unfold(); |
| 80 | |
| 81 | Button *del_btn = memnew(Button); |
| 82 | del_btn->set_text("Drop"); |
| 83 | del_btn->set_icon(editor->get_theme_base()->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); |
| 84 | del_btn->set_flat(false); |
| 85 | del_btn->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT); |
| 86 | del_btn->connect(SNAME("pressed"), callable_mp(this, &EntityEditor::_remove_component_pressed).bind(*it.key)); |
| 87 | component_section->get_vbox()->add_child(del_btn); |
| 88 | |
| 89 | create_component_inspector(*it.key, *it.value, component_section->get_vbox()); |
| 90 | |
| 91 | components_section->get_vbox()->add_child(component_section); |
| 92 | update_component_inspector(*it.key); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void EntityEditor::create_component_inspector(StringName p_component_name, const Ref<ComponentDepot> &p_depot, VBoxContainer *p_container) { |
| 98 | ERR_FAIL_COND(!p_depot.is_valid()); |