drag entity from entity list and drop it in property grid

This commit is contained in:
Mikulas Florek 2020-03-28 22:19:39 +01:00
parent 2a1b6fe536
commit f29e3d1391
3 changed files with 13 additions and 3 deletions

View file

@ -524,8 +524,7 @@ public:
if (!m_entity_to_prefab.empty()) serializer.write(m_entity_to_prefab.begin(), m_entity_to_prefab.byte_size());
serializer.write((u32)m_resources.size());
for (const PrefabVersion& prefab : m_resources)
{
for (const PrefabVersion& prefab : m_resources) {
serializer.writeString(prefab.resource->getPath().c_str());
serializer.write(prefab.content_hash);
}

View file

@ -262,6 +262,13 @@ struct GridUIVisitor final : Reflection::IPropertyVisitor
{
ImGui::OpenPopup(prop.name);
}
if (ImGui::BeginDragDropTarget()) {
if (auto* payload = ImGui::AcceptDragDropPayload("entity")) {
EntityRef dropped_entity = *(EntityRef*)payload->Data;
m_editor.setProperty(m_cmp_type, m_index, prop.name, m_entities, dropped_entity);
}
}
ImGui::EndGroup();
ImGui::SameLine();
ImGui::Text("%s", prop.name);

View file

@ -1652,7 +1652,6 @@ struct StudioAppImpl final : StudioApp
if (!has_child) flags = ImGuiTreeNodeFlags_Leaf;
if (selected) flags |= ImGuiTreeNodeFlags_Selected;
bool node_open = ImGui::TreeNodeEx(buffer, flags);
if (ImGui::IsItemClicked(0)) m_editor->selectEntities(&entity, 1, true);
if (ImGui::IsMouseReleased(1) && ImGui::IsItemHovered()) ImGui::OpenPopup("entity_context_menu");
if (ImGui::BeginPopup("entity_context_menu"))
{
@ -1674,6 +1673,11 @@ struct StudioAppImpl final : StudioApp
ImGui::SetDragDropPayload("entity", &entity, sizeof(entity));
ImGui::EndDragDropSource();
}
else {
if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
m_editor->selectEntities(&entity, 1, true);
}
}
if (ImGui::BeginDragDropTarget())
{
if (auto* payload = ImGui::AcceptDragDropPayload("entity"))