Components can be removed

master
Joey Pollack 3 years ago
parent f16ce840b2
commit 2bf786ac9d

@ -22,7 +22,7 @@ namespace lunarium { namespace editor
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// COMMON SECTIONS // 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 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()); 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)); ImU32 color = ImGui::ColorConvertFloat4ToU32(ImVec4(0.3f, 0.3f, 0.3f, 1.0f));
ImGui::GetWindowDrawList()->AddRectFilled(top_left, bot_right, color); ImGui::GetWindowDrawList()->AddRectFilled(top_left, bot_right, color);
ImGuiExt::TextCentered(title.c_str()); 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)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(3.0f, ImGui::GetStyle().ItemSpacing.y));
const int BUFFER_SIZE = 256; const int BUFFER_SIZE = 256;
@ -46,14 +51,16 @@ namespace lunarium { namespace editor
comp.Info = buffer; comp.Info = buffer;
ImGui::PopStyleVar(); ImGui::PopStyleVar();
return remove;
} }
/// This code taken from the Hazel engine /// This code taken from the Hazel engine
/// https://github.com/TheCherno/Hazel/blob/master/Hazelnut/src/Panels/SceneHierarchyPanel.cpp /// 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)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, ImGui::GetStyle().ItemSpacing.y + 10.0f));
DrawTitle("Transform Component"); remove = DrawTitle("Transform Component");
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGuiExt::Vec2Control("Translation", comp.Position, 0.0f, 85.0f); 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); ImGuiExt::FloatControl("Rotation", rotation.z, 0.0f, 85.0f);
comp.Rotation = glm::radians(rotation); comp.Rotation = glm::radians(rotation);
ImGuiExt::Vec2Control("Scale", comp.Scale, 1.0f, 85.0f); 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)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, ImGui::GetStyle().ItemSpacing.y + 10.0f));
DrawTitle("Velocity Component"); remove = DrawTitle("Velocity Component");
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGuiExt::Vec2Control("Velocity", comp.Velocity, 0.0f, 85.0f); 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)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, ImGui::GetStyle().ItemSpacing.y + 10.0f));
DrawTitle("Camera Component"); remove = DrawTitle("Camera Component");
ImGui::PopStyleVar(); ImGui::PopStyleVar();
glm::vec3 pos = comp.Camera.GetPosition(); glm::vec3 pos = comp.Camera.GetPosition();
@ -92,13 +105,16 @@ namespace lunarium { namespace editor
{ {
comp.Camera.SetRotation(rot); 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)); 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::PopStyleVar();
ImGui::Text("Block Color: "); ImGui::Text("Block Color: ");
@ -115,5 +131,8 @@ namespace lunarium { namespace editor
ImGui::Text("Render Layer: "); ImGui::Text("Render Layer: ");
ImGui::SameLine(); ImGui::SameLine();
ImGui::InputInt("##Render Layer", &comp.RenderLayer, 1, 10); ImGui::InputInt("##Render Layer", &comp.RenderLayer, 1, 10);
return remove;
} }
}} }}

@ -16,11 +16,11 @@ namespace lunarium { namespace editor
class CompGui class CompGui
{ {
public: public:
static void RenderTagComp(TagComponent& comp); static bool RenderTagComp(TagComponent& comp);
static void RenderTransformComp(TransformComponent& comp); static bool RenderTransformComp(TransformComponent& comp);
static void RenderVelocityComp(VelocityComponent& comp); static bool RenderVelocityComp(VelocityComponent& comp);
static void RenderCameraComp(CameraComponent& comp); static bool RenderCameraComp(CameraComponent& comp);
static void RenderBlockOutComp(BlockOutComponent& comp); static bool RenderBlockOutComp(BlockOutComponent& comp);
}; };
}} }}

@ -38,7 +38,10 @@ if (ImGui::Selectable(str_name)){\
if (mpSelectedEntity->HasComponent<type_name>()) \ if (mpSelectedEntity->HasComponent<type_name>()) \
{ \ { \
ImGui::PopStyleVar(); \ ImGui::PopStyleVar(); \
CompGui::func_name(mpSelectedEntity->GetComponent<type_name>()); \ if (CompGui::func_name(mpSelectedEntity->GetComponent<type_name>())) \
{\
mpSelectedEntity->RemoveComponent<type_name>();\
}\
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, spacing_y)); \ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, spacing_y)); \
ImGui::Separator(); \ ImGui::Separator(); \
} }
@ -172,17 +175,19 @@ namespace lunarium { namespace editor
// TODO: iterate through components // TODO: iterate through components
if (mpSelectedEntity->HasComponent<TagComponent>()) if (mpSelectedEntity->HasComponent<TagComponent>())
{ {
CompGui::RenderTagComp(mpSelectedEntity->GetComponent<TagComponent>()); if (CompGui::RenderTagComp(mpSelectedEntity->GetComponent<TagComponent>()))
{
mpSelectedEntity->RemoveComponent<TagComponent>();
}
ImGui::Separator(); ImGui::Separator();
} }
DRAW_COMP_GUI(TransformComponent, RenderTransformComp) DRAW_COMP_GUI(TransformComponent, RenderTransformComp)
DRAW_COMP_GUI(VelocityComponent, RenderVelocityComp) DRAW_COMP_GUI(VelocityComponent, RenderVelocityComp)
DRAW_COMP_GUI(CameraComponent, RenderCameraComp) DRAW_COMP_GUI(CameraComponent, RenderCameraComp)
DRAW_COMP_GUI(BlockOutComponent, RenderBlockOutComp) DRAW_COMP_GUI(BlockOutComponent, RenderBlockOutComp)
// After all components rendered // After all components rendered
if (ImGuiExt::ButtonCentered("Add Component")) if (ImGuiExt::ButtonCentered("Add Component"))
{ {

Loading…
Cancel
Save