diff --git a/src/run_modes/editor/component_guis.cpp b/src/run_modes/editor/component_guis.cpp index 75798e3..3123aef 100644 --- a/src/run_modes/editor/component_guis.cpp +++ b/src/run_modes/editor/component_guis.cpp @@ -22,7 +22,7 @@ namespace lunarium { namespace editor ///////////////////////////////////////////////////////////////////// // COMMON SECTIONS ///////////////////////////////////////////////////////////////////// - static void DrawTitle(std::string title) + static bool DrawTitle(std::string title) { ImVec2 top_left(ImGui::GetWindowPos().x, ImGui::GetCursorScreenPos().y - ImGui::GetStyle().FramePadding.y); ImVec2 bot_right(top_left.x + ImGui::GetWindowSize().x, ImGui::GetCursorScreenPos().y + ImGui::GetFrameHeight()); @@ -30,11 +30,16 @@ namespace lunarium { namespace editor ImU32 color = ImGui::ColorConvertFloat4ToU32(ImVec4(0.3f, 0.3f, 0.3f, 1.0f)); ImGui::GetWindowDrawList()->AddRectFilled(top_left, bot_right, color); ImGuiExt::TextCentered(title.c_str()); + ImGui::SameLine(); + std::string label = "X##"; + label += title; + return ImGui::Button(label.c_str()); } - void CompGui::RenderTagComp(TagComponent& comp) + bool CompGui::RenderTagComp(TagComponent& comp) { - DrawTitle("Tag Component"); + bool remove = false; + remove = DrawTitle("Tag Component"); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(3.0f, ImGui::GetStyle().ItemSpacing.y)); const int BUFFER_SIZE = 256; @@ -46,14 +51,16 @@ namespace lunarium { namespace editor comp.Info = buffer; ImGui::PopStyleVar(); + return remove; } /// This code taken from the Hazel engine /// https://github.com/TheCherno/Hazel/blob/master/Hazelnut/src/Panels/SceneHierarchyPanel.cpp - void CompGui::RenderTransformComp(TransformComponent& comp) - { + bool CompGui::RenderTransformComp(TransformComponent& comp) + { + bool remove = false; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, ImGui::GetStyle().ItemSpacing.y + 10.0f)); - DrawTitle("Transform Component"); + remove = DrawTitle("Transform Component"); ImGui::PopStyleVar(); ImGuiExt::Vec2Control("Translation", comp.Position, 0.0f, 85.0f); @@ -62,23 +69,29 @@ namespace lunarium { namespace editor ImGuiExt::FloatControl("Rotation", rotation.z, 0.0f, 85.0f); comp.Rotation = glm::radians(rotation); ImGuiExt::Vec2Control("Scale", comp.Scale, 1.0f, 85.0f); + + return remove; } - void CompGui::RenderVelocityComp(VelocityComponent& comp) + bool CompGui::RenderVelocityComp(VelocityComponent& comp) { + bool remove = false; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, ImGui::GetStyle().ItemSpacing.y + 10.0f)); - DrawTitle("Velocity Component"); + remove = DrawTitle("Velocity Component"); ImGui::PopStyleVar(); ImGuiExt::Vec2Control("Velocity", comp.Velocity, 0.0f, 85.0f); + + return remove; } - void CompGui::RenderCameraComp(CameraComponent& comp) + bool CompGui::RenderCameraComp(CameraComponent& comp) { + bool remove = false; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, ImGui::GetStyle().ItemSpacing.y + 10.0f)); - DrawTitle("Camera Component"); + remove = DrawTitle("Camera Component"); ImGui::PopStyleVar(); glm::vec3 pos = comp.Camera.GetPosition(); @@ -92,13 +105,16 @@ namespace lunarium { namespace editor { comp.Camera.SetRotation(rot); } + + return remove; } - void CompGui::RenderBlockOutComp(BlockOutComponent& comp) + bool CompGui::RenderBlockOutComp(BlockOutComponent& comp) { + bool remove = false; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, ImGui::GetStyle().ItemSpacing.y + 10.0f)); - DrawTitle("Block Out Component"); + remove = DrawTitle("Block Out Component"); ImGui::PopStyleVar(); ImGui::Text("Block Color: "); @@ -115,5 +131,8 @@ namespace lunarium { namespace editor ImGui::Text("Render Layer: "); ImGui::SameLine(); ImGui::InputInt("##Render Layer", &comp.RenderLayer, 1, 10); + + + return remove; } }} \ No newline at end of file diff --git a/src/run_modes/editor/component_guis.h b/src/run_modes/editor/component_guis.h index 01f69f9..1b3a9a5 100644 --- a/src/run_modes/editor/component_guis.h +++ b/src/run_modes/editor/component_guis.h @@ -16,11 +16,11 @@ namespace lunarium { namespace editor class CompGui { public: - static void RenderTagComp(TagComponent& comp); - static void RenderTransformComp(TransformComponent& comp); - static void RenderVelocityComp(VelocityComponent& comp); - static void RenderCameraComp(CameraComponent& comp); - static void RenderBlockOutComp(BlockOutComponent& comp); + static bool RenderTagComp(TagComponent& comp); + static bool RenderTransformComp(TransformComponent& comp); + static bool RenderVelocityComp(VelocityComponent& comp); + static bool RenderCameraComp(CameraComponent& comp); + static bool RenderBlockOutComp(BlockOutComponent& comp); }; }} diff --git a/src/run_modes/editor/panels/properties_view.cpp b/src/run_modes/editor/panels/properties_view.cpp index 3fc2597..b71144e 100644 --- a/src/run_modes/editor/panels/properties_view.cpp +++ b/src/run_modes/editor/panels/properties_view.cpp @@ -38,7 +38,10 @@ if (ImGui::Selectable(str_name)){\ if (mpSelectedEntity->HasComponent()) \ { \ ImGui::PopStyleVar(); \ - CompGui::func_name(mpSelectedEntity->GetComponent()); \ + if (CompGui::func_name(mpSelectedEntity->GetComponent())) \ + {\ + mpSelectedEntity->RemoveComponent();\ + }\ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, spacing_y)); \ ImGui::Separator(); \ } @@ -172,17 +175,19 @@ namespace lunarium { namespace editor // TODO: iterate through components if (mpSelectedEntity->HasComponent()) { - CompGui::RenderTagComp(mpSelectedEntity->GetComponent()); + if (CompGui::RenderTagComp(mpSelectedEntity->GetComponent())) + { + mpSelectedEntity->RemoveComponent(); + } ImGui::Separator(); } - + DRAW_COMP_GUI(TransformComponent, RenderTransformComp) DRAW_COMP_GUI(VelocityComponent, RenderVelocityComp) DRAW_COMP_GUI(CameraComponent, RenderCameraComp) DRAW_COMP_GUI(BlockOutComponent, RenderBlockOutComp) - // After all components rendered if (ImGuiExt::ButtonCentered("Add Component")) {