From 228868604a0f7fbdb7a1ac1bf88bad3a3325c81f Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sun, 16 Oct 2022 14:20:35 +0800 Subject: [PATCH] Editor fixes Integration of mouse pick Add editor state Add editor layout --- Assets/Editor/Layouts/Default.ini | 42 +++++++++ .../src/Application/SBApplication.cpp | 17 +++- .../HierarchyPanel/SHHierarchyPanel.cpp | 31 ++++++- .../HierarchyPanel/SHHierarchyPanel.h | 2 + .../Inspector/SHEditorComponentView.hpp | 9 +- .../Inspector/SHEditorInspector.cpp | 2 +- .../EditorWindow/MenuBar/SHEditorMenuBar.cpp | 88 +++++++++++++++---- .../EditorWindow/MenuBar/SHEditorMenuBar.h | 1 + .../Profiling/SHEditorProfiler.cpp | 2 +- .../Editor/EditorWindow/SHEditorWindow.cpp | 16 +++- .../src/Editor/EditorWindow/SHEditorWindow.h | 7 +- .../EditorWindow/SHEditorWindowIncludes.h | 3 +- .../ViewportWindow/SHEditorViewport.cpp | 45 ++++++++++ .../ViewportWindow/SHEditorViewport.h | 28 ++++++ SHADE_Engine/src/Editor/SHEditor.cpp | 83 +++++++++++++---- SHADE_Engine/src/Editor/SHEditor.hpp | 21 ++++- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 8 +- .../MiddleEnd/Interface/SHMousePickSystem.cpp | 4 +- .../MiddleEnd/Interface/SHMousePickSystem.h | 2 +- 19 files changed, 349 insertions(+), 62 deletions(-) create mode 100644 Assets/Editor/Layouts/Default.ini create mode 100644 SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp create mode 100644 SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h diff --git a/Assets/Editor/Layouts/Default.ini b/Assets/Editor/Layouts/Default.ini new file mode 100644 index 00000000..b953b3a5 --- /dev/null +++ b/Assets/Editor/Layouts/Default.ini @@ -0,0 +1,42 @@ +[Window][MainStatusBar] +Pos=0,1060 +Size=1920,20 +Collapsed=0 + +[Window][SHEditorMenuBar] +Pos=0,24 +Size=1920,1036 +Collapsed=0 + +[Window][Hierarchy Panel] +Pos=0,89 +Size=286,971 +Collapsed=0 +DockId=0x00000004,0 + +[Window][Debug##Default] +Pos=60,60 +Size=400,400 +Collapsed=0 + +[Window][Inspector] +Pos=1494,24 +Size=426,1036 +Collapsed=0 +DockId=0x00000006,0 + +[Window][Profiler] +Pos=0,24 +Size=286,63 +Collapsed=0 +DockId=0x00000003,0 + +[Docking][Data] +DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,55 Size=1920,1036 Split=X + DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1492,1036 Split=X + DockNode ID=0x00000001 Parent=0x00000005 SizeRef=286,1036 Split=Y Selected=0xE096E5AE + DockNode ID=0x00000003 Parent=0x00000001 SizeRef=140,63 Selected=0x1E6EB881 + DockNode ID=0x00000004 Parent=0x00000001 SizeRef=140,971 Selected=0xE096E5AE + DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1204,1036 CentralNode=1 + DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=426,1036 Selected=0xE7039252 + diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 202a3852..d1d3e087 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -130,18 +130,29 @@ namespace Sandbox void SBApplication::Update(void) { SHGraphicsSystem* graphicsSystem = SHADE::SHSystemManager::GetSystem(); + SHEditor* editor = SHADE::SHSystemManager::GetSystem(); //TODO: Change true to window is open while (!window.WindowShouldClose()) { SHFrameRateController::UpdateFRC(); SHInputManager::UpdateInput(SHFrameRateController::GetRawDeltaTime()); SHSceneManager::UpdateSceneManager(); - SHSceneManager::SceneUpdate(0.016f); +#ifdef SHEDITOR + if(editor->editorState == SHEditor::State::PLAY) +#endif + SHSceneManager::SceneUpdate(0.016f); +#ifdef SHEDITOR + SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f); + if(auto editor = SHSystemManager::GetSystem()) + { + editor->PollPicking(); + } +#else SHSystemManager::RunRoutines(false, 0.016f); +#endif } - // Finish all graphics jobs first - graphicsSystem->AwaitGraphicsExecution(); + graphicsSystem->AwaitGraphicsExecution(); } diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp index 0f25175f..42c9da66 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp @@ -66,8 +66,8 @@ namespace SHADE editor->selectedEntities.clear(); } ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal); - ImGui::End(); } + ImGui::End(); } void SHHierarchyPanel::Exit() @@ -75,6 +75,11 @@ namespace SHADE SHEditorWindow::Exit(); } + void SHHierarchyPanel::SetScrollTo(EntityID eid) + { + scrollTo = eid; + } + //#==============================================================# //|| Private Member Functions || //#==============================================================# @@ -82,7 +87,20 @@ namespace SHADE { if (ImGui::BeginMenuBar()) { - if (ImGui::SmallButton(ICON_MD_ADD)) + + ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 35.0f); + if(ImGui::SmallButton(ICON_MD_DESELECT)) + { + auto editor = SHSystemManager::GetSystem(); + editor->selectedEntities.clear(); + } + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("Clear Selections"); + ImGui::EndTooltip(); + } + if (ImGui::SmallButton(ICON_MD_ADD_CIRCLE)) { SHEntityManager::CreateEntity(); } @@ -103,6 +121,13 @@ namespace SHADE //Get node data (Children, eid, selected) auto& children = currentNode->GetChildren(); EntityID eid = currentNode->GetEntityID(); + + if(scrollTo != MAX_EID && eid == scrollTo) + { + ImGui::SetScrollHereY(); + scrollTo = MAX_EID; + } + auto editor = SHSystemManager::GetSystem(); const bool isSelected = (std::ranges::find(editor->selectedEntities, eid) != editor->selectedEntities.end()); @@ -157,7 +182,7 @@ namespace SHADE } ImGui::EndPopup(); } - + //Handle node selection if (ImGui::IsItemHovered()) { diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h index 78e445fd..88983ca9 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h @@ -23,11 +23,13 @@ namespace SHADE void Init() override; void Update() override; void Exit() override; + void SetScrollTo(EntityID eid); private: void DrawMenuBar() const noexcept; ImRect RecursivelyDrawEntityNode(SHSceneNode*); void CreateChildEntity(EntityID parentEID) const noexcept; std::string filter; bool isAnyNodeSelected = false; + EntityID scrollTo = MAX_EID; };//class SHHierarchyPanel }//namespace SHADE diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 93f6984e..47fec730 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -207,8 +207,10 @@ namespace SHADE auto& colliders = component->GetColliders(); int const size = static_cast(colliders.size()); ImGui::BeginChild("Colliders", {0.0f, colliders.empty() ? 1.0f : 250.0f}, true); + std::optional colliderToDelete{std::nullopt}; for (int i{}; i < size; ++i) { + ImGui::PushID(i); SHCollider& collider = component->GetCollider(i); auto cursorPos = ImGui::GetCursorPos(); @@ -235,9 +237,14 @@ namespace SHADE } if(ImGui::Button(std::format("{} Remove Collider #{}", ICON_MD_REMOVE, i).data())) { - component->RemoveCollider(i); + colliderToDelete = i; } SHEditorWidgets::EndPanel(); + ImGui::PopID(); + } + if(colliderToDelete.has_value()) + { + component->RemoveCollider(colliderToDelete.value()); } ImGui::EndChild(); diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index a9b1c724..da09f345 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -99,8 +99,8 @@ namespace SHADE } } - ImGui::End(); } + ImGui::End(); } void SHEditorInspector::Exit() diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index a49af994..3cb6561d 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -36,6 +36,11 @@ namespace SHADE void SHEditorMenuBar::Init() { SHEditorWindow::Init(); + constexpr std::string_view path = "../../Assets/Editor/Layouts"; + for(auto const& entry : std::filesystem::directory_iterator(path)) + { + layoutPaths.push_back(entry.path()); + } } void SHEditorMenuBar::Update() @@ -87,20 +92,6 @@ namespace SHADE ImGui::EndDisabled(); ImGui::EndMenu(); } - if(ImGui::BeginMenu("Theme")) - { - auto styles = rttr::type::get().get_enumeration(); - auto values = styles.get_values(); - for (auto style : values) - { - if(ImGui::Selectable(style.to_string().c_str())) - { - if(auto editor = SHSystemManager::GetSystem()) - editor->SetStyle(style.convert()); - } - } - ImGui::EndMenu(); - } if (ImGui::BeginMenu("Scripts")) { if (ImGui::Selectable("Generate Visual Studio Project")) @@ -120,18 +111,79 @@ namespace SHADE } ImGui::EndMenu(); } + + if (ImGui::BeginMenu("Window")) + { + for (const auto& window : SHEditorWindowManager::editorWindows | std::views::values) + { + if (window.get() != this) + ImGui::Checkbox(window->windowName.data(), &window->isOpen); + } + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Theme")) + { + const auto styles = rttr::type::get().get_enumeration(); + auto values = styles.get_values(); + for (auto style : values) + { + if (ImGui::Selectable(style.to_string().c_str())) + { + if (auto editor = SHSystemManager::GetSystem()) + editor->SetStyle(style.convert()); + } + } + ImGui::EndMenu(); + } + if(ImGui::BeginMenu("Layout")) + { + for(auto const& entry : layoutPaths) + { + if(ImGui::Selectable(entry.stem().string().c_str())) + { + ImGui::LoadIniSettingsFromDisk(entry.string().c_str()); + } + } + ImGui::EndMenu(); + } ImGui::EndMainMenuBar(); } - const ImGuiID dockspace_id = ImGui::GetID("DockSpace"); - ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspaceFlags); + const ImGuiID dockspaceId = ImGui::GetID("DockSpace"); + ImGui::DockSpace(dockspaceId, ImVec2(0.0f, 0.0f), dockspaceFlags); ImGui::End(); } } void SHEditorMenuBar::DrawSecondaryBar() const noexcept { - + ImGuiViewport* viewport = ImGui::GetMainViewport(); + if(ImGui::BeginViewportSideBar("##SecondaryMenuBar", viewport, ImGuiDir_Up, ImGui::GetFrameHeight(), ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_MenuBar)) + { + ImGui::BeginMenuBar(); + ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x * 0.5f - 80.f); + const auto editor = SHSystemManager::GetSystem(); + ImGui::BeginDisabled(editor->editorState == SHEditor::State::PLAY); + if(ImGui::SmallButton(ICON_MD_PLAY_ARROW)) + { + editor->editorState = SHEditor::State::PLAY; + } + ImGui::EndDisabled(); + ImGui::BeginDisabled(editor->editorState == SHEditor::State::PAUSE); + if(ImGui::SmallButton(ICON_MD_PAUSE)) + { + editor->editorState = SHEditor::State::PAUSE; + } + ImGui::EndDisabled(); + ImGui::BeginDisabled(editor->editorState == SHEditor::State::STOP); + if(ImGui::SmallButton(ICON_MD_STOP)) + { + editor->editorState = SHEditor::State::STOP; + } + ImGui::EndDisabled(); + ImGui::EndMenuBar(); + } + ImGui::End(); } void SHEditorMenuBar::DrawStatusBar() const noexcept @@ -142,8 +194,8 @@ namespace SHADE if (ImGui::BeginViewportSideBar("MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, menuBarHeight, editorMenuBarFlags)) { ImGui::Text("Entity count: "); - ImGui::End(); } + ImGui::End(); ImGui::PopStyleVar(3); } diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.h b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.h index 616ba43e..7cbcd696 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.h +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.h @@ -18,5 +18,6 @@ namespace SHADE void DrawSecondaryBar() const noexcept; void DrawStatusBar() const noexcept; float menuBarHeight = 20.0f; + std::vector layoutPaths; };//class SHEditorMenuBar }//namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/EditorWindow/Profiling/SHEditorProfiler.cpp b/SHADE_Engine/src/Editor/EditorWindow/Profiling/SHEditorProfiler.cpp index 4b36fe5d..ef2ff8c0 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Profiling/SHEditorProfiler.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Profiling/SHEditorProfiler.cpp @@ -37,8 +37,8 @@ namespace SHADE if(Begin()) { ImGui::PlotLines("DT", frames.data(), static_cast(frames.size()), 0, nullptr, 0.0f, 16.0f); - ImGui::End(); } + ImGui::End(); } void SHEditorProfiler::Exit() diff --git a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.cpp b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.cpp index 2e2c820c..8f677be6 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.cpp @@ -19,7 +19,7 @@ namespace SHADE //|| Public Member Functions || //#==============================================================# SHEditorWindow::SHEditorWindow(std::string_view const& name, ImGuiWindowFlags const& inFlags) - : isOpen(true), windowName(name), windowFlags(inFlags), io(ImGui::GetIO()) + : windowName(name), windowFlags(inFlags), io(ImGui::GetIO()) { } @@ -40,7 +40,19 @@ namespace SHADE //#==============================================================# bool SHEditorWindow::Begin() { - return ImGui::Begin(windowName.data(), &isOpen, windowFlags); + bool result = ImGui::Begin(windowName.data(), &isOpen, windowFlags); + + auto wndSize = ImGui::GetWindowSize(); + if(size.x != wndSize.x || size.y != wndSize.y) + { + size = {wndSize.x, wndSize.y}; + OnResize(); + } + return result; + } + + void SHEditorWindow::OnResize() + { } }//namespace SHADE diff --git a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.h b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.h index 244ef677..78e1b6cb 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.h +++ b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindow.h @@ -5,6 +5,8 @@ //#==============================================================# #include +#include "Math/Vector/SHVec2.h" + //#==============================================================# //|| Forward Declarations || //#==============================================================# @@ -21,11 +23,14 @@ namespace SHADE virtual void Init(); virtual void Update(); virtual void Exit(); - bool isOpen = false; + bool isOpen; std::string_view windowName; protected: virtual bool Begin(); + virtual void OnResize(); ImGuiWindowFlags windowFlags = 0; ImGuiIO& io; + SHVec2 size; + SHVec2 pos; };//class SHEditorWindow }//namespace SHADE diff --git a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindowIncludes.h b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindowIncludes.h index d1ebfbf4..f0267b06 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindowIncludes.h +++ b/SHADE_Engine/src/Editor/EditorWindow/SHEditorWindowIncludes.h @@ -2,4 +2,5 @@ #include "MenuBar/SHEditorMenuBar.h" //Menu Bar #include "HierarchyPanel/SHHierarchyPanel.h" //Hierarchy Panel #include "Inspector/SHEditorInspector.h" //Inspector -#include "Profiling/SHEditorProfiler.h" //Profiler \ No newline at end of file +#include "Profiling/SHEditorProfiler.h" //Profiler +#include "ViewportWindow/SHEditorViewport.h" //Editor Viewport \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp new file mode 100644 index 00000000..99ca5067 --- /dev/null +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp @@ -0,0 +1,45 @@ +#include "SHpch.h" +#include "SHEditorViewport.h" + +namespace SHADE +{ + SHEditorViewport::SHEditorViewport() + :SHEditorWindow("Viewport", ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoScrollbar) + { + } + + void SHEditorViewport::Init() + { + SHEditorWindow::Init(); + + } + + void SHEditorViewport::Update() + { + SHEditorWindow::Update(); + if(Begin()) + { + DrawMenuBar(); + } + ImGui::End(); + } + + void SHEditorViewport::Exit() + { + SHEditorWindow::Exit(); + } + + void SHEditorViewport::OnResize() + { + SHEditorWindow::OnResize(); + //Get graphics system to resize swapchain image + } + + void SHEditorViewport::DrawMenuBar() const noexcept + { + if(ImGui::BeginMenuBar()) + { + ImGui::EndMenuBar(); + } + } +}//namespace SHADE diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h new file mode 100644 index 00000000..baee0941 --- /dev/null +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h @@ -0,0 +1,28 @@ +#pragma once +//#==============================================================# +//|| Library Includes || +//#==============================================================# +#include + +//#==============================================================# +//|| SHADE Includes || +//#==============================================================# +#include "imgui_internal.h" +#include "ECS_Base/SHECSMacros.h" +#include "Editor/EditorWindow/SHEditorWindow.h" + +namespace SHADE +{ + class SHEditorViewport final : public SHEditorWindow + { + public: + SHEditorViewport(); + void Init() override; + void Update() override; + void Exit() override; + protected: + virtual void OnResize() override; + private: + void DrawMenuBar() const noexcept; + };//class SHEditorViewport +}//namespace SHADE diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index d9fc8373..d0bf0c4f 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -43,6 +43,8 @@ #include #include +#include "Graphics/MiddleEnd/Interface/SHMousePickSystem.h" + RTTR_REGISTRATION { using namespace SHADE; @@ -73,6 +75,7 @@ namespace SHADE //#==============================================================# void SHEditor::Init() { + IMGUI_CHECKVERSION(); if(auto context = ImGui::CreateContext()) { @@ -82,11 +85,21 @@ namespace SHADE } } - ImGuiIO& io = ImGui::GetIO(); (void)io; + //Add editor windows + SHEditorWindowManager::CreateEditorWindow(); + SHEditorWindowManager::CreateEditorWindow(); + SHEditorWindowManager::CreateEditorWindow(); + SHEditorWindowManager::CreateEditorWindow(); + SHEditorWindowManager::CreateEditorWindow(); - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls - io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; //Enable for Multi-Viewports - io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; //Enable docking + io = &ImGui::GetIO(); + + io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; //Enable for Multi-Viewports + io->ConfigFlags |= ImGuiConfigFlags_DockingEnable; //Enable docking + io->IniFilename = "../../Assets/Editor/Layouts/UserLayout.ini"; + + InitLayout(); InitFonts(); @@ -98,11 +111,11 @@ namespace SHADE SetStyle(Style::SHADE); - //Add editor windows - SHEditorWindowManager::CreateEditorWindow(); - SHEditorWindowManager::CreateEditorWindow(); - SHEditorWindowManager::CreateEditorWindow(); - SHEditorWindowManager::CreateEditorWindow(); + + for (const auto& window : SHEditorWindowManager::editorWindows | std::views::values) + { + window->Init(); + } SHLOG_INFO("Successfully initialised SHADE Engine Editor") } @@ -116,7 +129,7 @@ namespace SHADE if(window->isOpen) window->Update(); } - + if(ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_Z)) { SHCommandManager::RedoCommand(); @@ -125,36 +138,46 @@ namespace SHADE { SHCommandManager::UndoCommand(); } - - + Render(); } void SHEditor::Render() { ImGui::Render(); - ImGuiIO& io = ImGui::GetIO(); - if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + if (io->ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { ImGui::UpdatePlatformWindows(); ImGui::RenderPlatformWindowsDefault(); } } + void SHEditor::InitLayout() noexcept + { + if(!std::filesystem::exists(io->IniFilename)) + { + std::filesystem::copy_file("../../Assets/Editor/Layouts/Default.ini", io->IniFilename); + } + //eventually load preferred layout here + } + void SHEditor::InitFonts() noexcept { - ImGuiIO& io = ImGui::GetIO(); - ImFont* mainFont = io.Fonts->AddFontFromFileTTF("../../Assets/Editor/Fonts/Segoe UI.ttf", 20.f);//TODO: Change to config based assets path + ImFont* mainFont = io->Fonts->AddFontFromFileTTF("../../Assets/Editor/Fonts/Segoe UI.ttf", 20.f);//TODO: Change to config based assets path - static const ImWchar icon_ranges[] = { ICON_MIN_MD, ICON_MAX_16_MD, 0 }; + constexpr ImWchar icon_ranges[] = { ICON_MIN_MD, ICON_MAX_16_MD, 0 }; ImFontConfig icons_config{}; icons_config.MergeMode = true; icons_config.GlyphOffset.y = 5.f; - ImFont* UIFont = io.Fonts->AddFontFromFileTTF("../../Assets/Editor/Fonts/MaterialIcons-Regular.ttf", 20.f, &icons_config, icon_ranges); //TODO: Change to config based assets path + ImFont* UIFont = io->Fonts->AddFontFromFileTTF("../../Assets/Editor/Fonts/MaterialIcons-Regular.ttf", 20.f, &icons_config, icon_ranges); //TODO: Change to config based assets path - io.Fonts->Build(); + io->Fonts->Build(); } void SHEditor::Exit() { + for (const auto& window : SHEditorWindowManager::editorWindows | std::views::values) + { + window->Init(); + } ImGui_ImplVulkan_Shutdown(); ImGui_ImplSDL2_Shutdown(); ImGui::DestroyContext(); @@ -309,6 +332,28 @@ namespace SHADE }); } + void SHEditor::PollPicking() + { + if (auto gfxSystem = SHSystemManager::GetSystem()) + { + if (!ImGui::IsAnyItemHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) + { + EntityID pickedEID = gfxSystem->GetMousePickSystem()->GetPickedEntity(); + if(pickedEID == MAX_EID) + return; + if (!ImGui::IsKeyDown(ImGuiKey_LeftCtrl)) + { + if (const auto hierarchyPanel = SHEditorWindowManager::GetEditorWindow()) + { + hierarchyPanel->SetScrollTo(pickedEID); + } + selectedEntities.clear(); + } + selectedEntities.push_back(pickedEID); + } + } + } + void SHEditor::NewFrame() { SDL_Event event; diff --git a/SHADE_Engine/src/Editor/SHEditor.hpp b/SHADE_Engine/src/Editor/SHEditor.hpp index d579a9b5..baa6324e 100644 --- a/SHADE_Engine/src/Editor/SHEditor.hpp +++ b/SHADE_Engine/src/Editor/SHEditor.hpp @@ -90,11 +90,11 @@ namespace SHADE return reinterpret_cast(editorWindows[GetEditorWindowID()].get()); } + static EditorWindowMap editorWindows; private: // Number of windows; used for Editor Window ID Generation static EditorWindowID windowCount; // Map of Editor Windows - static EditorWindowMap editorWindows; friend class SHEditor; }; @@ -110,10 +110,17 @@ namespace SHADE class SH_API EditorRoutine final : public SHSystemRoutine { public: - EditorRoutine() = default; + EditorRoutine():SHSystemRoutine("Editor routine", true) {}; void Execute(double dt) noexcept override final; }; + enum class State : uint8_t + { + PLAY, + PAUSE, + STOP + }; + /** * @brief Style options * @@ -162,9 +169,13 @@ namespace SHADE void SetSDLWindow(SDL_Window* inSDLWindow){sdlWindow = inSDLWindow;}; + void PollPicking(); + // List of selected entities std::vector selectedEntities; + State editorState = State::STOP; + private: /** * @brief Start new frame for editor @@ -177,7 +188,7 @@ namespace SHADE */ void Render(); - + void InitLayout() noexcept; void InitFonts() noexcept; @@ -186,6 +197,8 @@ namespace SHADE // Handle to command buffer used for ImGui Vulkan Backend Handle imguiCommandBuffer; - SDL_Window* sdlWindow; + SDL_Window* sdlWindow {nullptr}; + + ImGuiIO* io{nullptr}; };//class SHEditor }//namespace SHADE diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 09f1c93e..c31b8c4d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -571,7 +571,7 @@ namespace SHADE /* System Routine Functions - BeginRoutine */ /*-----------------------------------------------------------------------------------*/ SHGraphicsSystem::BeginRoutine::BeginRoutine() - : SHSystemRoutine("Graphics System Frame Set Up", false) + : SHSystemRoutine("Graphics System Frame Set Up", true) {} void SHGraphicsSystem::BeginRoutine::Execute(double) noexcept @@ -583,7 +583,7 @@ namespace SHADE /* System Routine Functions - RenderRoutine */ /*-----------------------------------------------------------------------------------*/ SHGraphicsSystem::RenderRoutine::RenderRoutine() - : SHSystemRoutine("Graphics System Render", false) + : SHSystemRoutine("Graphics System Render", true) {} void SHGraphicsSystem::RenderRoutine::Execute(double dt) noexcept @@ -595,7 +595,7 @@ namespace SHADE /* System Routine Functions - EndRoutine */ /*-----------------------------------------------------------------------------------*/ SHGraphicsSystem::EndRoutine::EndRoutine() - : SHSystemRoutine("Graphics System Frame Clean Up", false) + : SHSystemRoutine("Graphics System Frame Clean Up", true) {} void SHGraphicsSystem::EndRoutine::Execute(double) noexcept @@ -607,7 +607,7 @@ namespace SHADE /* System Routine Functions - BatcherDispatcherRoutine */ /*-----------------------------------------------------------------------------------*/ SHGraphicsSystem::BatcherDispatcherRoutine::BatcherDispatcherRoutine() - : SHSystemRoutine("Graphics System Batcher Dispatcher", false) + : SHSystemRoutine("Graphics System Batcher Dispatcher", true) {} void SHGraphicsSystem::BatcherDispatcherRoutine::Execute(double) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp index ee8665d5..8522a8d5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp @@ -11,8 +11,6 @@ namespace SHADE { void SHMousePickSystem::Init(Handle logicalDevice, std::span> cmdPools, Handle eidAttachment) noexcept { - pickedEID = 0; - // Create command buffers for (auto& pool : cmdPools) { @@ -34,7 +32,7 @@ namespace SHADE void SHMousePickSystem::Run(Handle queue, uint32_t frameIndex) noexcept { // if input detected - if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::LEFT_CTRL) && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) { afterCopyFence->Reset(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h index 080a192c..7ec193b4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h @@ -30,7 +30,7 @@ namespace SHADE Handle imageDataDstBuffer; //! eid picked from screen - EntityID pickedEID; + EntityID pickedEID = MAX_EID; public: /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */