Refine editor action shell and add regression tests

This commit is contained in:
2026-03-27 12:06:24 +08:00
parent c33404767e
commit 4b9a63098e
21 changed files with 838 additions and 308 deletions

View File

@@ -87,21 +87,11 @@ void HierarchyPanel::Render() {
for (auto* gameObject : rootEntities) {
RenderEntity(gameObject, filter);
}
if (ImGui::IsWindowHovered() && ImGui::IsMouseDown(0) && !ImGui::IsAnyItemHovered()) {
if (!m_renameState.IsActive()) {
m_context->GetSelectionManager().ClearSelection();
}
}
if (UI::BeginPopupContextWindow("HierarchyContextMenu", ImGuiPopupFlags_MouseButtonRight)) {
Actions::DrawHierarchyCreateActions(*m_context, nullptr);
UI::EndPopup();
}
ImGui::InvisibleButton("##DragTarget", ImVec2(-1, -1));
Actions::AcceptHierarchyEntityDropToRoot(*m_context);
Actions::HandleHierarchyBackgroundPrimaryClick(*m_context, m_renameState);
Actions::DrawHierarchyBackgroundContextPopup(*m_context);
Actions::DrawHierarchyRootDropTarget(*m_context);
}
void HierarchyPanel::RenderSearchBar() {
@@ -119,33 +109,18 @@ void HierarchyPanel::RenderSearchBar() {
buttonWidth + UI::ToolbarSearchTrailingSpacing());
ImGui::SameLine();
if (UI::ToolbarButton("...", false, ImVec2(buttonWidth, 0.0f))) {
ImGui::OpenPopup("HierarchyOptions");
Actions::RequestHierarchyOptionsPopup(m_optionsPopup);
}
if (UI::BeginPopup("HierarchyOptions")) {
const UI::MenuCommand commands[] = {
UI::MenuCommand::Action("Sort By Name", nullptr, m_sortMode == SortMode::Name),
UI::MenuCommand::Action("Sort By Component Count", nullptr, m_sortMode == SortMode::ComponentCount),
UI::MenuCommand::Action("Transform First", nullptr, m_sortMode == SortMode::TransformFirst)
};
UI::DrawMenuCommands(commands, [&](size_t index) {
switch (index) {
case 0:
m_sortMode = SortMode::Name;
break;
case 1:
m_sortMode = SortMode::ComponentCount;
break;
case 2:
m_sortMode = SortMode::TransformFirst;
break;
default:
break;
}
Actions::DrawHierarchySortOptionsPopup(
m_optionsPopup,
m_sortMode,
SortMode::Name,
SortMode::ComponentCount,
SortMode::TransformFirst,
[this](SortMode mode) {
m_sortMode = mode;
});
UI::EndPopup();
}
}
void HierarchyPanel::RenderEntity(::XCEngine::Components::GameObject* gameObject, const std::string& filter) {
@@ -193,11 +168,8 @@ void HierarchyPanel::RenderEntity(::XCEngine::Components::GameObject* gameObject
Actions::BeginHierarchyEntityDrag(gameObject);
Actions::AcceptHierarchyEntityDrop(*m_context, gameObject);
if (UI::BeginPopupContextItem("EntityContextMenu")) {
Actions::DrawHierarchyContextActions(*m_context, gameObject);
UI::EndPopup();
}
Actions::DrawHierarchyEntityContextPopup(*m_context, gameObject);
if (node.open) {
for (size_t i = 0; i < gameObject->GetChildCount(); i++) {
@@ -225,10 +197,7 @@ void HierarchyPanel::CommitRename() {
}
const uint64_t entityId = m_renameState.Item();
if (!m_renameState.Empty() && m_context->GetSceneManager().GetEntity(entityId)) {
Commands::RenameEntity(*m_context, entityId, m_renameState.Buffer());
}
Actions::CommitEntityRename(*m_context, entityId, m_renameState.Buffer());
CancelRename();
}