void EntityModel::set(Lumix::Entity entity, uint32_t component_type, int index, Lumix::IPropertyDescriptor* desc, QVariant value) { m_is_setting = true; Lumix::ComponentUID cmp = m_editor.getComponent(entity, component_type); ASSERT(cmp.isValid()); switch (desc->getType()) { case Lumix::IPropertyDescriptor::BOOL: { bool b = value.toBool(); m_editor.setProperty(cmp.type, index, *desc, &b, sizeof(b)); break; } case Lumix::IPropertyDescriptor::COLOR: { QColor color = value.value<QColor>(); Lumix::Vec3 v; v.x = color.redF(); v.y = color.greenF(); v.z = color.blueF(); m_editor.setProperty(cmp.type, index, *desc, &v, sizeof(v)); break; } case Lumix::IPropertyDescriptor::DECIMAL: { float f = value.toFloat(); m_editor.setProperty(cmp.type, index, *desc, &f, sizeof(f)); break; } case Lumix::IPropertyDescriptor::INTEGER: { int i = value.toInt(); m_editor.setProperty(cmp.type, index, *desc, &i, sizeof(i)); break; } case Lumix::IPropertyDescriptor::RESOURCE: case Lumix::IPropertyDescriptor::FILE: case Lumix::IPropertyDescriptor::STRING: { auto tmp = value.toString().toLatin1(); m_editor.setProperty( cmp.type, index, *desc, tmp.data(), tmp.length()); } break; default: Q_ASSERT(false); break; } m_is_setting = false; }
void getEntityListDisplayName(Lumix::WorldEditor& editor, char* buf, int max_size, Lumix::Entity entity) { const char* name = editor.getUniverse()->getEntityName(entity); static const Lumix::uint32 RENDERABLE_HASH = Lumix::crc32("renderable"); Lumix::ComponentUID renderable = editor.getComponent(entity, RENDERABLE_HASH); if (renderable.isValid()) { auto* scene = static_cast<Lumix::RenderScene*>(renderable.scene); const char* path = scene->getRenderablePath(renderable.index); if (path && path[0] != 0) { char basename[Lumix::MAX_PATH_LENGTH]; Lumix::copyString(buf, max_size, path); Lumix::PathUtils::getBasename(basename, Lumix::MAX_PATH_LENGTH, path); if (name && name[0] != '\0') Lumix::copyString(buf, max_size, name); else Lumix::toCString(entity, buf, max_size); Lumix::catString(buf, max_size, " - "); Lumix::catString(buf, max_size, basename); return; } } if (name && name[0] != '\0') { Lumix::copyString(buf, max_size, name); } else { Lumix::toCString(entity, buf, max_size); } }
QVariant EntityModel::get(Lumix::Entity entity, uint32_t component_type, int index, Lumix::IPropertyDescriptor* desc) { Lumix::ComponentUID cmp = m_editor.getComponent(entity, component_type); ASSERT(cmp.isValid()); Lumix::StackAllocator<256> allocator; Lumix::OutputBlob stream(allocator); if (index == -1) { desc->get(cmp, stream); } else { desc->get(cmp, index, stream); } Lumix::InputBlob input(stream); switch (desc->getType()) { case Lumix::IPropertyDescriptor::BOOL: { bool b; input.read(b); return b; } case Lumix::IPropertyDescriptor::DECIMAL: { float f; input.read(f); return f; } case Lumix::IPropertyDescriptor::INTEGER: { int i; input.read(i); return i; } case Lumix::IPropertyDescriptor::COLOR: { Lumix::Vec3 c; input.read(c); QColor color((int)(c.x * 255), (int)(c.y * 255), (int)(c.z * 255)); return color; } case Lumix::IPropertyDescriptor::VEC3: { Lumix::Vec3 v; input.read(v); return QString("%1; %2; %3").arg(v.x).arg(v.y).arg(v.z); } case Lumix::IPropertyDescriptor::STRING: case Lumix::IPropertyDescriptor::RESOURCE: case Lumix::IPropertyDescriptor::FILE: { return (const char*)stream.getData(); } case Lumix::IPropertyDescriptor::ARRAY: return QString("%1 members") .arg( static_cast<Lumix::IArrayDescriptor*>(desc)->getCount(cmp)); default: Q_ASSERT(false); break; } return QVariant(); }