feat(editor): add select all scene objects
This commit is contained in:
parent
1d6e664d9f
commit
0444de7a42
@ -750,6 +750,16 @@ void MetaCoreReimportProjectAsset(MetaCoreEditorContext& editorContext, const Me
|
||||
!ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopup);
|
||||
}
|
||||
|
||||
void MetaCoreSelectAllSceneObjects(MetaCoreEditorContext& editorContext) {
|
||||
const std::vector<MetaCoreId> orderedIds = editorContext.GetScene().BuildHierarchyPreorder();
|
||||
if (orderedIds.empty()) {
|
||||
editorContext.ClearSelection();
|
||||
return;
|
||||
}
|
||||
|
||||
editorContext.SetSelection(orderedIds, orderedIds.back());
|
||||
}
|
||||
|
||||
void MetaCoreHandleGlobalEditorShortcuts(MetaCoreEditorContext& editorContext) {
|
||||
if (!MetaCoreCanHandleGlobalEditorShortcuts()) {
|
||||
return;
|
||||
@ -784,6 +794,11 @@ void MetaCoreHandleGlobalEditorShortcuts(MetaCoreEditorContext& editorContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctrlDown && ImGui::IsKeyPressed(ImGuiKey_A, false)) {
|
||||
MetaCoreSelectAllSceneObjects(editorContext);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Delete, false)) {
|
||||
(void)MetaCoreDeleteSelection(editorContext);
|
||||
return;
|
||||
@ -2588,6 +2603,10 @@ public:
|
||||
MetaCoreHandleRedo(editorContext);
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("全选", "Ctrl+A", false, !editorContext.GetScene().GetGameObjects().empty())) {
|
||||
MetaCoreSelectAllSceneObjects(editorContext);
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("复制", "Ctrl+D", false, !editorContext.GetSelectedObjectIds().empty())) {
|
||||
(void)MetaCoreDuplicateSelection(editorContext);
|
||||
}
|
||||
|
||||
@ -238,6 +238,11 @@ void MetaCoreTestSelectionStateMachine() {
|
||||
MetaCoreExpect(editorContext.IsObjectSelected(objectBId), "范围选择应包含中间对象 B");
|
||||
MetaCoreExpect(editorContext.IsObjectSelected(objectCId), "范围选择应包含终点 C");
|
||||
MetaCoreExpect(editorContext.GetActiveObjectId() == objectCId, "范围选择后 Active 应为终点 C");
|
||||
|
||||
const std::vector<MetaCore::MetaCoreId> allObjectIds = scene.BuildHierarchyPreorder();
|
||||
editorContext.SetSelection(allObjectIds, allObjectIds.back());
|
||||
MetaCoreExpect(editorContext.GetSelectedObjectIds().size() == allObjectIds.size(), "全选应包含场景中的所有对象");
|
||||
MetaCoreExpect(editorContext.GetActiveObjectId() == allObjectIds.back(), "全选后 Active 应为最后一个对象");
|
||||
}
|
||||
|
||||
void MetaCoreTestUndoRedo() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user