Skip to content

Commit

Permalink
fixed drag and drop of selected entities on entity folder; ux improve…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
nem0 committed Nov 20, 2024
1 parent 79ba915 commit 87f498f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 90 deletions.
8 changes: 3 additions & 5 deletions src/editor/property_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,22 +370,20 @@ struct GridUIVisitor final : reflection::IPropertyVisitor
}
ImGui::PopStyleVar();


World& world = *m_editor.getWorld();
if (ImGuiEx::BeginResizablePopup("popup", ImVec2(200, 300)))
{
if (ImGuiEx::BeginResizablePopup("popup", ImVec2(200, 300))) {
static TextFilter entity_filter;
entity_filter.gui("Filter", -1, ImGui::IsWindowAppearing());

if (ImGui::BeginChild("list", ImVec2(0, ImGui::GetContentRegionAvail().y))) {
for (EntityPtr i = world.getFirstEntity(); i.isValid(); i = world.getNextEntity((EntityRef)i))
{
for (EntityPtr i = world.getFirstEntity(); i.isValid(); i = world.getNextEntity(*i)) {
ImGui::PushID(i.index);
getEntityListDisplayName(m_app, world, Span(buf), i);
bool show = entity_filter.pass(buf);
if (show && ImGui::Selectable(buf))
{
m_editor.setProperty(m_cmp_type, m_array, m_index, prop.name, m_entities, i);
ImGui::CloseCurrentPopup();
}
ImGui::PopID();
}
Expand Down
104 changes: 19 additions & 85 deletions src/editor/studio_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
#include <imgui/imgui_freetype.h>
#include <imgui/imgui_internal.h>

#include "core/default_allocator.h"
#include "audio/audio_module.h"
#include "core/associative_array.h"
#include "core/atomic.h"
#include "core/color.h"
#include "core/command_line_parser.h"
#include "core/debug.h"
#include "engine/file_system.h"
#include "core/default_allocator.h"
#include "core/geometry.h"
#include "core/hash.h"
#include "core/job_system.h"
#include "core/log.h"
#include "core/os.h"
#include "core/path.h"
#include "core/profiler.h"

#include "audio/audio_module.h"
#include "editor/asset_browser.h"
#include "editor/asset_compiler.h"
#include "editor/entity_folders.h"
Expand All @@ -28,8 +26,9 @@
#include "editor/signal_editor.h"
#include "editor/spline_editor.h"
#include "editor/world_editor.h"
#include "engine/engine.h"
#include "engine/engine_hash_funcs.h"
#include "engine/engine.h"
#include "engine/file_system.h"
#include "engine/input_system.h"
#include "engine/reflection.h"
#include "engine/resource_manager.h"
Expand Down Expand Up @@ -282,9 +281,23 @@ struct StudioAppImpl final : StudioApp {
editor.moveEntityToFolder(dropped_entity, folder_id);
editor.endCommandGroup();
}

if (auto* payload = ImGui::AcceptDragDropPayload("selected_entities")) {
const Array<EntityRef>& selected = editor.getSelectedEntities();
if (!selected.empty()) {
editor.beginCommandGroup("move_entities_to_folder_group");
for (EntityRef e : selected) {
editor.makeParent(INVALID_ENTITY, e);
editor.moveEntityToFolder(e, folder_id);
}
editor.endCommandGroup();
}
}

ImGui::EndDragDropTarget();
}


if (ImGui::IsMouseClicked(0) && ImGui::IsItemHovered()) {
folders.selectFolder(folder_id);
}
Expand Down Expand Up @@ -1077,62 +1090,6 @@ struct StudioAppImpl final : StudioApp {
insertAddCmpNode(*new_group, node);
}

void registerComponent(const char* icon, ComponentType cmp_type, const char* label, ResourceType resource_type, const char* property) {
struct Plugin final : IAddComponentPlugin {
void onGUI(bool create_entity, bool from_filter, EntityPtr parent, WorldEditor& editor) override {
const char* last = reverseFind(label, '/');
last = last && !from_filter ? last + 1 : label;
if (last[0] == ' ') ++last;
if (!ImGui::BeginMenu(last)) return;
Path path;
bool create_empty = ImGui::MenuItem(ICON_FA_BROOM " Empty");
static FilePathHash selected_res_hash;
if (asset_browser->resourceList(path, selected_res_hash, resource_type, true) || create_empty) {
editor.beginCommandGroup("createEntityWithComponent");
if (create_entity) {
EntityRef entity = editor.addEntity();
editor.selectEntities(Span(&entity, 1), false);
}

const Array<EntityRef>& selected_entites = editor.getSelectedEntities();
editor.addComponent(selected_entites, type);
if (!create_empty) {
editor.setProperty(type, "", -1, property, editor.getSelectedEntities(), path);
}
if (parent.isValid()) editor.makeParent(parent, selected_entites[0]);
editor.endCommandGroup();
editor.lockGroupCommand();
ImGui::CloseCurrentPopup();
}
ImGui::EndMenu();
}


const char* getLabel() const override { return label; }

PropertyGrid* property_grid;
AssetBrowser* asset_browser;
ComponentType type;
ResourceType resource_type;
StaticString<64> property;
char label[50];
};

Plugin* plugin = LUMIX_NEW(m_allocator, Plugin);
plugin->property_grid = m_property_grid.get();
plugin->asset_browser = m_asset_browser.get();
plugin->type = cmp_type;
plugin->property = property;
plugin->resource_type = resource_type;
copyString(plugin->label, label);
addPlugin(*plugin);

m_component_labels.insert(plugin->type, String(label, m_allocator));
if (icon && icon[0]) {
m_component_icons.insert(plugin->type, icon);
}
}

void registerComponent(const char* icon, const char* id, IAddComponentPlugin& plugin) override {
addPlugin(plugin);
m_component_labels.insert(reflection::getComponentType(id), String(plugin.getLabel(), m_allocator));
Expand Down Expand Up @@ -2544,30 +2501,7 @@ struct StudioAppImpl final : StudioApp {
const reflection::ComponentBase* r = cmp.cmp;

if (m_component_labels.find(r->component_type).isValid()) continue;

struct : reflection::IEmptyPropertyVisitor {
void visit(const reflection::Property<Path>& prop) override {
for (const reflection::IAttribute* attr : prop.attributes) {
if (attr->getType() == reflection::IAttribute::RESOURCE) {
is_res = true;
reflection::ResourceAttribute* a = (reflection::ResourceAttribute*)attr;
res_type = a->resource_type;
prop_name = prop.name;
}
}
}
bool is_res = false;
const char* prop_name;
ResourceType res_type;
} visitor;

r->visit(visitor);
if (visitor.is_res) {
registerComponent(r->icon, r->component_type, r->label, visitor.res_type, visitor.prop_name);
}
else {
registerComponent(r->icon, r->component_type, r->label);
}
registerComponent(r->icon, r->component_type, r->label);
}
PrefabSystem::createEditorPlugins(*this, m_editor->getPrefabSystem());
}
Expand Down

0 comments on commit 87f498f

Please sign in to comment.