Skip to content

Commit

Permalink
[#98]: Cleanup UI and move some functionality to Editor from gui
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Aug 2, 2023
1 parent 1f9c61f commit eac2d7e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
32 changes: 27 additions & 5 deletions editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1002,8 +1024,6 @@ Editor::Update()
}
}

gui_.UpdateUI();

auto& renderData = renderer::VulkanRenderer::GetRenderData();
renderData.viewMat = m_camera.GetViewMatrix();
renderData.projMat = m_camera.GetProjectionMatrix();
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 10 additions & 2 deletions editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <glm/matrix.hpp>
#include <optional>
#include <utility>

namespace looper {

class Player;
class Animatable;
struct AnimationPoint;

class Editor : public Application
{
Expand All @@ -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;

Expand Down Expand Up @@ -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 >
Expand Down
27 changes: 11 additions & 16 deletions editor/gui/editor_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
2 changes: 0 additions & 2 deletions editor/gui/editor_gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit eac2d7e

Please sign in to comment.