void PropertyGrid::showEntityProperty(Lumix::ComponentUID cmp, int index, Lumix::IPropertyDescriptor& desc) { Lumix::OutputBlob blob(m_editor.getAllocator()); desc.get(cmp, index, blob); int value = *(int*)blob.getData(); auto& universe = cmp.scene->getUniverse(); int count = universe.getEntityCount(); struct Data { Lumix::IPropertyDescriptor* descriptor; Lumix::IScene* scene; Lumix::WorldEditor* editor; }; auto getter = [](void* data, int index, const char** out) -> bool { auto* combo_data = static_cast<Data*>(data); static char buf[128]; Lumix::Entity entity = combo_data->scene->getUniverse().getEntityFromDenseIdx(index); getEntityListDisplayName(*combo_data->editor, buf, Lumix::lengthOf(buf), entity); *out = buf; return true; }; Data data; data.scene = cmp.scene; data.descriptor = &desc; data.editor = &m_editor; if(ImGui::Combo(desc.getName(), &value, getter, &data, count)) { m_editor.setProperty(cmp.type, index, desc, &value, sizeof(value)); } }
void HierarchyUI::showHierarchy(Lumix::Entity entity, bool has_parent) { auto* hierarchy = m_editor->getHierarchy(); char name[50]; getEntityListDisplayName(*m_editor, name, sizeof(name), entity); ImGui::BulletText(name); if (has_parent) { ImGui::SameLine(); if (ImGui::Button(StringBuilder<50>("Remove##r") << entity)) { auto* command = m_editor->getAllocator().newObject<SetParentEditorCommand>( *m_editor, *hierarchy, entity, -1); m_editor->executeCommand(command); } } auto* children = hierarchy->getChildren(entity); if (!children || children->empty()) return; ImGui::Indent(); for (auto c : *children) { showHierarchy(c.m_entity, true); } ImGui::Unindent(); }
static bool itemsGetter(void* data, int idx, const char** txt) { auto* d = static_cast<ListBoxData*>(data); auto entity = d->universe->getEntityFromDenseIdx(idx); getEntityListDisplayName(*d->m_editor, d->buffer, sizeof(d->buffer), entity); *txt = d->buffer; return true; }
bool PropertyGrid::entityInput(const char* label, const char* str_id, Lumix::Entity& entity) const { const auto& style = ImGui::GetStyle(); float item_w = ImGui::CalcItemWidth(); ImGui::PushItemWidth( item_w - ImGui::CalcTextSize("...").x - style.FramePadding.x * 2 - style.ItemSpacing.x); char buf[50]; getEntityListDisplayName(m_editor, buf, sizeof(buf), entity); ImGui::LabelText("", "%s", buf); ImGui::SameLine(); Lumix::StaticString<30> popup_name("pu", str_id); if (ImGui::Button(Lumix::StaticString<30>("...###br", str_id))) { ImGui::OpenPopup(popup_name); } ImGui::SameLine(); ImGui::Text("%s", label); ImGui::PopItemWidth(); if (ImGui::BeginPopup(popup_name)) { struct ListBoxData { Lumix::WorldEditor* m_editor; Lumix::Universe* universe; char buffer[1024]; static bool itemsGetter(void* data, int idx, const char** txt) { auto* d = static_cast<ListBoxData*>(data); auto entity = d->universe->getEntityFromDenseIdx(idx); getEntityListDisplayName(*d->m_editor, d->buffer, sizeof(d->buffer), entity); *txt = d->buffer; return true; } }; ListBoxData data; Lumix::Universe* universe = m_editor.getUniverse(); data.universe = universe; data.m_editor = &m_editor; static int current_item; if (ImGui::ListBox("Entities", ¤t_item, &ListBoxData::itemsGetter, &data, universe->getEntityCount(), 15)) { entity = universe->getEntityFromDenseIdx(current_item); ImGui::CloseCurrentPopup(); ImGui::EndPopup(); return true; }; ImGui::EndPopup(); } return false; }