diff --git a/editor/editor.cpp b/editor/editor.cpp index 4ef9ad6e..d4125a8e 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -455,9 +455,31 @@ Editor::SetupRendererData() renderer::VulkanRenderer::UpdateLineData(); } + void -Editor::ActionOnObject(Editor::ACTION action) +Editor::AddAnimationPoint(const glm::vec2& position) { + GetCamera().SetCameraAtPosition(position); + AddObject(ObjectType::ANIMATION_POINT); + SetRenderAnimationPoints(true); +} + +void +Editor::SelectAnimationPoint(const AnimationPoint& node) +{ + GetCamera().SetCameraAtPosition(node.m_end); + HandleObjectSelected(node.GetID(), true); + SetRenderAnimationPoints(true); +} + +void +Editor::ActionOnObject(Editor::ACTION action, const std::optional< Object::ID >& object) +{ + if (object) + { + HandleObjectSelected(object.value(), true); + } + switch (action) { case ACTION::UNSELECT: @@ -1002,8 +1024,6 @@ Editor::Update() } } - gui_.UpdateUI(); - auto& renderData = renderer::VulkanRenderer::GetRenderData(); renderData.viewMat = m_camera.GetViewMatrix(); renderData.projMat = m_camera.GetProjectionMatrix(); @@ -1074,14 +1094,16 @@ Editor::MainLoop() InputManager::PollEvents(); HandleCamera(); - updateReady_ = pool_.enqueue([this] { Update(); }); + // updateReady_ = pool_.enqueue([this] { Update(); }); + Update(); workQueue_.RunWorkUnits(); if (windowInFocus_) { const time::ScopedTimer renderTimer(&renderTime_); - renderReady_ = pool_.enqueue([this] { renderer::VulkanRenderer::Render(this); }); + renderer::VulkanRenderer::Render(this); + // renderReady_ = pool_.enqueue([this] { renderer::VulkanRenderer::Render(this); }); } timeLastFrame_ = watch.Stop(); diff --git a/editor/editor.hpp b/editor/editor.hpp index b9ef62a8..cfb59063 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -8,16 +8,18 @@ #include "logger.hpp" #include "object.hpp" #include "player.hpp" -#include "utils/time/time_step.hpp" #include "thread_pool.hpp" +#include "utils/time/time_step.hpp" #include +#include #include namespace looper { class Player; class Animatable; +struct AnimationPoint; class Editor : public Application { @@ -33,6 +35,12 @@ class Editor : public Application void MainLoop() override; + void + SelectAnimationPoint(const AnimationPoint& node); + + void + AddAnimationPoint(const glm::vec2& position); + [[nodiscard]] glm::vec2 GetWindowSize() const override; @@ -148,7 +156,7 @@ class Editor : public Application bool fromGUI = false); void - ActionOnObject(ACTION action); + ActionOnObject(ACTION action, const std::optional< Object::ID >& = {}); private: // [[nodiscard]] std::shared_ptr< EditorObject > diff --git a/editor/gui/editor_gui.cpp b/editor/gui/editor_gui.cpp index 68a33c37..3be34bdf 100644 --- a/editor/gui/editor_gui.cpp +++ b/editor/gui/editor_gui.cpp @@ -613,13 +613,14 @@ EditorGUI::RenderMainPanel() ImGui::SetNextWindowSize(ImVec2(windowWidth_, toolsWindowHeight_)); ImGui::Begin("Tools"); - if (ImGui::BeginTable("MainTable", 4)) + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0.0f, 0.0f)); + if (ImGui::BeginTable("MainTable", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { CreateActionRow( [this] { ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{0.0f, 0.5f, 0.0f, 0.8f}); ImGui::BeginDisabled(currentLevel_ == nullptr); - if (ImGui::Button(ICON_FA_PLAY "Play")) + if (ImGui::Button(ICON_FA_PLAY "Play", ImVec2(-FLT_MIN, -FLT_MIN))) { parent_.PlayLevel(); } @@ -628,7 +629,7 @@ EditorGUI::RenderMainPanel() }, [this] { - if (ImGui::Button("Save")) + if (ImGui::Button("Save", ImVec2(-FLT_MIN, -FLT_MIN))) { auto levelName = FileManager::FileDialog(LEVELS_DIR, {{"DGame Level file", "dgl"}}, true); @@ -641,7 +642,7 @@ EditorGUI::RenderMainPanel() }, [this] { - if (ImGui::Button("Load")) + if (ImGui::Button("Load", ImVec2(-FLT_MIN, -FLT_MIN))) { auto levelName = FileManager::FileDialog(LEVELS_DIR, {{"DGame Level file", "dgl"}}, false); @@ -653,13 +654,14 @@ EditorGUI::RenderMainPanel() }, [this] { - if (ImGui::Button("Create") or createPushed_) + if (ImGui::Button("Create", ImVec2(-FLT_MIN, -FLT_MIN)) or createPushed_) { createPushed_ = true; RenderCreateNewLevelWindow(); } }); } + ImGui::PopStyleVar(); ImGui::EndTable(); ImGui::End(); @@ -956,17 +958,14 @@ EditorGUI::RenderGameObjectMenu() // NOLINT ImGui::TableNextColumn(); if (ImGui::Selectable(label.c_str())) { - parent_.GetCamera().SetCameraAtPosition(node.m_end); - parent_.HandleObjectSelected(node.GetID(), true); - parent_.SetRenderAnimationPoints(true); + parent_.SelectAnimationPoint(node); } ImGui::TableNextColumn(); ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{1.0f, 0.0f, 0.0f, 1.0f}); if (ImGui::Selectable(fmt::format("{}##{}", ICON_FA_XMARK, i).c_str())) { - parent_.HandleObjectSelected(node.GetID(), true); - parent_.ActionOnObject(Editor::ACTION::REMOVE); + parent_.ActionOnObject(Editor::ACTION::REMOVE, node.GetID()); } ImGui::PopStyleColor(1); @@ -977,9 +976,7 @@ EditorGUI::RenderGameObjectMenu() // NOLINT if (ImGui::Button("New")) { - parent_.GetCamera().SetCameraAtPosition(newNodePosition); - parent_.AddObject(ObjectType::ANIMATION_POINT); - parent_.SetRenderAnimationPoints(true); + parent_.AddAnimationPoint(newNodePosition); } ImGui::EndChild(); @@ -1033,11 +1030,9 @@ EditorGUI::UpdateUI() windowSize_ = parent_.GetWindowSize(); windowWidth_ = windowSize_.x / 7; - toolsWindowHeight_ = 60; + toolsWindowHeight_ = windowSize_.y / 20; levelWindowHeight_ = windowSize_.y - toolsWindowHeight_; gameObjectWindowHeight_ = windowSize_.y; - debugWindowWidth_ = windowSize_.x - 2 * windowWidth_; - debugWindowHeight_ = 150; RenderMainPanel(); diff --git a/editor/gui/editor_gui.hpp b/editor/gui/editor_gui.hpp index c2f44ccb..a6117524 100644 --- a/editor/gui/editor_gui.hpp +++ b/editor/gui/editor_gui.hpp @@ -117,8 +117,6 @@ class EditorGUI : public InputListener float toolsWindowHeight_ = 0.0f; float gameObjectWindowHeight_ = 0.0f; float levelWindowHeight_ = 0.0f; - float debugWindowHeight_ = 0.0f; - float debugWindowWidth_ = 0.0f; bool createPushed_ = false;