/****************************************************************************** * File - properties_view.h * Author - Joey Pollack * Date - 2022/01/26 (y/m/d) * Mod Date - 2022/01/26 (y/m/d) * Description - Displayes the properties and components(?) of the selected * object. ******************************************************************************/ #include "properties_view.h" #include "editor/editor.h" #include #include #include #include #include #include #include ///////////////////////////////////////////////////////////////////// // MACROS MACROS ///////////////////////////////////////////////////////////////////// #define PRESENT_COMP_CHOICE(str_name, type_name, pv) \ if (ImGui::Selectable(str_name)){\ if (pv->mpSelectedEntity->HasComponent()) {\ pv->OpenPopup(Popup::ADD_COMP_FAIL).LogIfFailed(Editor::LogCat);\ return false;\ }\ pv->mpSelectedEntity->AddComponent();\ if (!pv->mpSelectedEntity->HasComponent()) {\ Logger::Error(Editor::LogCat, "Component not added to entity - unknown error");\ }\ Logger::Info(Editor::LogCat, "Component added to entity: %ll", pv->mpSelectedEntity->GetUUID());\ return false;\ } #define DRAW_COMP_GUI(type_name, func_name) \ if (mpSelectedEntity->HasComponent()) \ { \ ImGui::PopStyleVar(); \ CompGui::func_name(mpSelectedEntity->GetComponent()); \ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, spacing_y)); \ ImGui::Separator(); \ } ///////////////////////////////////////////////////////////////////// // CLASS DEFINTION BEGIN ///////////////////////////////////////////////////////////////////// namespace lunarium { namespace editor { PropertiesView::PropertiesView(Editor* pEditor) : Panel("Properties", PanelDockZone::DDZ_RIGHT, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), mpSelectedAsset(nullptr), mpSelectedEntity(nullptr), mIsLocked(false), mpEditor(pEditor) { // ADD COMPONENT POPUP AddPopup(Popup::ADD_COMP, "Add Component", [](Panel* p) { PropertiesView* pv = (PropertiesView*)p; int is_hover = ImGui::IsWindowHovered(); // List components that can be added PRESENT_COMP_CHOICE("Tag Component", TagComponent, pv) PRESENT_COMP_CHOICE("Transform Component", TransformComponent, pv) PRESENT_COMP_CHOICE("Velocity Component", VelocityComponent, pv) PRESENT_COMP_CHOICE("Camera Component", CameraComponent, pv) PRESENT_COMP_CHOICE("Block Out Component", BlockOutComponent, pv) if ((ImGui::IsMouseClicked(ImGuiMouseButton_Left) && is_hover < 1)) { return false; } // ImGui::Text("Is Window Hovered? %d", is_hover); return true; }).LogIfFailed(Editor::LogCat); // ADD COMP FAILED POPUP AddPopup(Popup::ADD_COMP_FAIL, "Add Comp Fail", [] (Panel* p) { ImGui::Text("Can not add that component - Entity already has it"); if (ImGui::Button("OK") || (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !ImGui::IsWindowHovered())) { return false; } return true; }).LogIfFailed(Editor::LogCat); } ///////////////////////////////////////////////////////////////////// // RENDER METHOD ///////////////////////////////////////////////////////////////////// void PropertiesView::DoFrame() { ShowToolBar(); if (mpSelectedEntity) { ShowEntity(); } if (mpSelectedAsset) { ShowAsset(); } } ///////////////////////////////////////////////////////////////////// // INTERFACE METHODS ///////////////////////////////////////////////////////////////////// void PropertiesView::SetSelection(Entity* pEntity) { if (mIsLocked) { return; } mpSelectedAsset = nullptr; mpSelectedEntity = pEntity; } void PropertiesView::SetSelection(EditorAsset* pAsset) { if (mIsLocked) { return; } mpSelectedEntity = nullptr; mpSelectedAsset = pAsset; } ///////////////////////////////////////////////////////////////////// // HELPER METHODS HELPER METHODS ///////////////////////////////////////////////////////////////////// void PropertiesView::ShowToolBar() { ImGui::BeginChild("##PropsToolBar", ImVec2(0, ImGui::GetFrameHeightWithSpacing())); ImGui::Checkbox("Locked", &mIsLocked); ImGui::EndChild(); ImGui::Separator(); } void PropertiesView::ShowEntity() { ImGuiExt::TextCentered("Components"); float spacing_y = 12.0f; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, spacing_y)); ImGui::Separator(); // TODO: iterate through components if (mpSelectedEntity->HasComponent()) { CompGui::RenderTagComp(mpSelectedEntity->GetComponent()); 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")) { OpenPopup(Popup::ADD_COMP).LogIfFailed(Editor::LogCat); } ImGui::PopStyleVar(); } void PropertiesView::ShowAsset() { if (mpSelectedAsset) { if (mpSelectedAsset->DrawProperties()) { mpEditor->OnAssetUpdate(mpSelectedAsset); } } } }}