From 8047197b62894cb1f7bb6a6871870e4b91fde992 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Fri, 8 Dec 2023 14:47:03 -0500 Subject: editor use delete key for removing entities --- editor/editor.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'editor') diff --git a/editor/editor.cpp b/editor/editor.cpp index c198bae..9b79155 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -1,6 +1,7 @@ #include "editor.hpp" +#include "ecs.hpp" #include "project.hpp" #include "thread_pool.hpp" #include "game.hpp" @@ -15,6 +16,7 @@ #include "vendor/tinyfiledialogs//tinyfiledialogs.h" #include "imgui.h" +#include #include #include #include @@ -38,6 +40,7 @@ const char* const dbgCtrl_CameraRot = "debug-camera-rot"; const char* const dbgCtrl_CameraButtonMask = "debug-camera-button-mask"; const char* const dbgCtrl_SelectHovered = "debug-select-hovered"; const char* const dbgCtrl_ClearSelection = "debug-clear-selection"; +const char* const dbgCtrl_DeleteSelectedItem = "debug-delete-selected-item"; ThreadPoolHandle threadPoolHandle = ThreadPoolHandle_MAX; @@ -374,6 +377,15 @@ void PkeEditor_Tick(double delta) { } } + holder = PkeInput_Query(dbgCtrl_DeleteSelectedItem); + if (holder.type != InputEventHash{0} && selectedEntity != EntityHandle_MAX) { + PkeKeyEvent *delSelectedItemEvent; + delSelectedItemEvent = static_cast(holder.ptr); + if (delSelectedItemEvent->isPressed == true) { + ECS_MarkForRemoval(selectedEntity); + selectedEntity = EntityHandle_MAX; + } + } } void RecordImGui_GLM(const char *label, glm::mat4 &mat) { @@ -456,6 +468,9 @@ void RecordImGuiEntityList() { ImGui::PushID(bucket); for (long row = 0; row < itemCount; row++) { auto *entity = &entities[row]; + if (entity->handle == EntityHandle_MAX) { + continue; + } ImGui::PushID(row); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); @@ -926,7 +941,7 @@ void PkeEditor_Teardown() { void PkeEditor_Init() { PkeInputSet debugControlsSet; debugControlsSet.title = "debug-editor-controls"; - debugControlsSet.actionCount = 12; + debugControlsSet.actionCount = 13; debugControlsSet.actions = Pke_New(debugControlsSet.actionCount); debugControlsSet.actions[0].name = dbgCtrl_CameraLeft; @@ -988,6 +1003,11 @@ void PkeEditor_Init() { .computedHash = PKE_INPUT_HASH_ALL_MOUSE_BUTTON_EVENTS, .button = GLFW_MOUSE_BUTTON_RIGHT, }; + debugControlsSet.actions[12].name = dbgCtrl_DeleteSelectedItem; + debugControlsSet.actions[12].primaryHash = PkeInputEventMask { + .computedHash = PKE_INPUT_HASH_ALL_KEY_EVENTS, + .button = GLFW_KEY_DELETE, + }; debugControlsHandle = PkeInput_RegisterSet(debugControlsSet); -- cgit v1.2.3