Skip to content

Commit

Permalink
Update Erebor to C++20
Browse files Browse the repository at this point in the history
Move most editor windows to Mahakam
  • Loading branch information
KredeGC committed Sep 8, 2024
1 parent bc2d5b2 commit f6458b7
Show file tree
Hide file tree
Showing 26 changed files with 260 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Erebor/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,6 @@ DockSpace ID=0x3FC20BEE Window=0x9A404470 Pos=0,45 Size=1920,995 Split=Y
DockNode ID=0x0000000A Parent=0x3FC20BEE SizeRef=1920,350 Split=X Selected=0xBF096F38
DockNode ID=0x0000000B Parent=0x0000000A SizeRef=381,324 Selected=0x50413B2F
DockNode ID=0x00000008 Parent=0x0000000A SizeRef=1537,324 Split=X Selected=0xBF096F38
DockNode ID=0x00000006 Parent=0x00000008 SizeRef=1048,350 Selected=0x49278EEE
DockNode ID=0x00000006 Parent=0x00000008 SizeRef=1048,350 Selected=0xBF096F38
DockNode ID=0x0000000C Parent=0x00000008 SizeRef=487,350 Selected=0x7EA89797

2 changes: 1 addition & 1 deletion Erebor/premake5.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project "Erebor"
kind "ConsoleApp"
language "C++"
cppdialect "C++17"
cppdialect "C++20"
staticruntime "off"
pic "on"

Expand Down
22 changes: 12 additions & 10 deletions Erebor/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#include "ebpch.h"
#include "EditorLayer.h"

#include "Panels/AssetManagerPanel.h"
#include "ConsoleLogSink.h"

#include "Panels/BuildPanel.h"
#include "Panels/ConsolePanel.h"
#include "Panels/ContentBrowserPanel.h"
#include "Panels/EnvironmentPanel.h"
#include "Panels/ImportWizardPanel.h"
#include "Panels/ProfilerPanel.h"
#include "Panels/RenderPassPanel.h"
#include "Panels/SceneHierarchyPanel.h"
#include "Panels/SceneViewPanel.h"
#include "Panels/StatsPanel.h"
#include "ConsoleLogSink.h"

#include "RenderPasses/BoundingBoxRenderPass.h"

#include <Mahakam/Editor/Windows/AssetManagerPanel.h>
#include <Mahakam/Editor/Windows/ContentBrowserPanel.h>
#include <Mahakam/Editor/Windows/EnvironmentPanel.h>
#include <Mahakam/Editor/Windows/ImportWizardPanel.h>
#include <Mahakam/Editor/Windows/ProfilerPanel.h>
#include <Mahakam/Editor/Windows/RenderPassPanel.h>
#include <Mahakam/Editor/Windows/SceneHierarchyPanel.h>
#include <Mahakam/Editor/Windows/SceneViewPanel.h>
#include <Mahakam/Editor/Windows/StatsPanel.h>

#include <fstream>
#include <filesystem>

Expand Down
10 changes: 5 additions & 5 deletions Erebor/src/Panels/BuildPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ namespace Mahakam::Editor

if (Runtime::HasRuntime(hasRun, hasStop, hasUpdate))
{
ImGui::Text(u8"\ueed7" " Runtime loaded correctly");
ImGui::Text(reinterpret_cast<const char*>(u8"\ueed7 Runtime loaded correctly"));

ImGui::Text("%s Run(Scene*)", hasRun ? u8"\ueed7" : u8"\ueedd");
ImGui::Text("%s Run(Scene*)", reinterpret_cast<const char*>(hasRun ? u8"\ueed7" : u8"\ueedd"));

ImGui::Text("%s Stop(Scene*)", hasStop ? u8"\ueed7" : u8"\ueedd");
ImGui::Text("%s Stop(Scene*)", reinterpret_cast<const char*>(hasStop ? u8"\ueed7" : u8"\ueedd"));

ImGui::Text("%s Update(Scene*, Timestep)", hasUpdate ? u8"\ueed7" : u8"\ueedd");
ImGui::Text("%s Update(Scene*, Timestep)", reinterpret_cast<const char*>(hasUpdate ? u8"\ueed7" : u8"\ueedd"));
}
else
{
ImGui::Text(u8"\ueedd" " Runtime not loaded");
ImGui::Text(reinterpret_cast<const char*>(u8"\ueedd Runtime not loaded"));
}

// TODO: Make button disabled in playmode
Expand Down
12 changes: 6 additions & 6 deletions Erebor/src/Panels/DockSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Mahakam::Editor
{
if (ImGui::BeginMenu("Project"))
{
if (ImGui::MenuItem(u8"\uec5b" " Open Project"))
if (ImGui::MenuItem(reinterpret_cast<const char*>(u8"\uec5b Open Project")))
{
std::filesystem::path projectPath = FileUtility::OpenDirectory();

Expand All @@ -54,7 +54,7 @@ namespace Mahakam::Editor
}
}

if (ImGui::MenuItem(u8"\uef1d" " Exit"))
if (ImGui::MenuItem(reinterpret_cast<const char*>(u8"\uef1d Exit")))
Application::GetInstance()->Close();

ImGui::EndMenu();
Expand All @@ -65,16 +65,16 @@ namespace Mahakam::Editor
// Disabling fullscreen would allow the window to be moved to the front of other windows,
// which we can't undo at the moment without finer window depth/z control.
//ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen_persistant);1
if (ImGui::MenuItem(u8"\uef10" " New Scene", "Ctrl+N"))
if (ImGui::MenuItem(reinterpret_cast<const char*>(u8"\uef10 New Scene"), "Ctrl+N"))
NewScene();

if (ImGui::MenuItem(u8"\uec5b" " Open Scene...", "Ctrl+O"))
if (ImGui::MenuItem(reinterpret_cast<const char*>(u8"\uec5b Open Scene..."), "Ctrl+O"))
OpenScene();

if (ImGui::MenuItem(u8"\uee00" " Save Scene...", "Ctrl+S"))
if (ImGui::MenuItem(reinterpret_cast<const char*>(u8"\uee00 Save Scene..."), "Ctrl+S"))
SaveScene();

if (ImGui::MenuItem(u8"\uee00" " Save Scene As...", "Ctrl+Shift+S"))
if (ImGui::MenuItem(reinterpret_cast<const char*>(u8"\uee00 Save Scene As..."), "Ctrl+Shift+S"))
SaveSceneAs();

ImGui::EndMenu();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ebpch.h"
#include "Mahakam/mhpch.h"
#include "AssetManagerPanel.h"

namespace Mahakam::Editor
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ebpch.h"
#include "Mahakam/mhpch.h"
#include "ContentBrowserPanel.h"

#include "ImportWizardPanel.h"
Expand Down
File renamed without changes.
201 changes: 201 additions & 0 deletions Mahakam/src/Mahakam/Editor/Windows/DockSpace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
#include "Mahakam/mhpch.h"
#include "DockSpace.h"

#include <imgui/imgui.h>

namespace Mahakam::Editor
{
void DockSpace::Begin()
{
// Render dockspace
ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;

ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->WorkPos);
ImGui::SetNextWindowSize(viewport->WorkSize);
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));

ImGui::Begin("DockSpace", nullptr, window_flags);

ImGui::PopStyleVar(3);

ImGuiIO& io = ImGui::GetIO();
ImGuiStyle& style = ImGui::GetStyle();
float minWidth = style.WindowMinSize.x;
style.WindowMinSize.x = 370.0f;
if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
ImGuiID dockspace_id = ImGui::GetID("DockSpace");
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
}
style.WindowMinSize.x = minWidth;

// File bar
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("Project"))
{
if (ImGui::MenuItem("\uec5b" " Open Project"))
{
std::filesystem::path projectPath = FileUtility::OpenDirectory();

if (projectPath != "")
{
Application::GetInstance()->GetWindow().SetTitle("Erebor " + projectPath.string());

FileUtility::SetProjectDirectory(projectPath);
}
}

if (ImGui::MenuItem("\uef1d" " Exit"))
Application::GetInstance()->Close();

ImGui::EndMenu();
}

if (ImGui::BeginMenu("Scene"))
{
// Disabling fullscreen would allow the window to be moved to the front of other windows,
// which we can't undo at the moment without finer window depth/z control.
//ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen_persistant);1
if (ImGui::MenuItem("\uef10" " New Scene", "Ctrl+N"))
NewScene();

if (ImGui::MenuItem("\uec5b" " Open Scene...", "Ctrl+O"))
OpenScene();

if (ImGui::MenuItem("\uee00" " Save Scene...", "Ctrl+S"))
SaveScene();

if (ImGui::MenuItem("\uee00" " Save Scene As...", "Ctrl+Shift+S"))
SaveSceneAs();

ImGui::EndMenu();
}

if (ImGui::BeginMenu("View"))
{
auto& windowProps = EditorWindowRegistry::GetWindowProps();
for (auto& props : windowProps)
{
if (props.second.Viewable)
{
bool enabled = false;
if (props.second.Unique && props.second.Instance)
enabled = true;

if (ImGui::MenuItem(props.second.Name.c_str(), nullptr, enabled))
{
if (!enabled)
EditorWindowRegistry::OpenWindow(props.second.Name);
else if (props.second.Unique)
EditorWindowRegistry::CloseWindow(props.second.Instance);
}
}
}

ImGui::EndMenu();
}

if (ImGui::BeginMenu("Build"))
{
if (ImGui::MenuItem("Build Assets"))
{
// TODO: Build binary assets


}

if (ImGui::MenuItem("Build Executable"))
{
// TODO: Build executable in MH_STANDALONE
}

ImGui::EndMenu();
}

ImGui::EndMenuBar();
}
}

void DockSpace::End()
{
ImGui::End();
}

bool DockSpace::OnKeyPressed(KeyPressedEvent& event)
{
if (event.GetRepeatCount() > 0) return false;

// Shortcuts
bool controlPressed = Input::IsKeyPressed(Key::LEFT_CONTROL) || Input::IsKeyPressed(Key::RIGHT_CONTROL);
bool shiftPressed = Input::IsKeyPressed(Key::LEFT_SHIFT) || Input::IsKeyPressed(Key::RIGHT_SHIFT);

switch (event.GetKeyCode())
{
case Key::N:
if (controlPressed)
NewScene();
break;
case Key::O:
if (controlPressed)
OpenScene();
break;
case Key::S:
if (controlPressed && shiftPressed)
SaveSceneAs();
else if (controlPressed)
SaveScene();
break;
default:
break;
}

return false;
}

void DockSpace::NewScene()
{
Selection::SetSelectedEntity({});
Ref<Scene> scene = Scene::Create();
SceneManager::SetActiveScene(scene);
}

void DockSpace::OpenScene()
{
std::filesystem::path filepath = FileUtility::OpenFile("Mahakam Scene (*.mhk)\0*.mhk\0", FileUtility::GetWorkingDirectory() / FileUtility::ASSET_PATH);

if (!filepath.empty())
{
Selection::SetSelectedEntity({});
Ref<Scene> scene = Scene::Create();
SceneManager::SetActiveScene(scene);

SceneSerializer serializer(scene);
serializer.DeserializeFromPath(filepath);
}
}

void DockSpace::SaveScene()
{

}

void DockSpace::SaveSceneAs()
{
std::filesystem::path filepath = FileUtility::SaveFile("Mahakam Scene (*.mhk)\0*.mhk\0", FileUtility::GetWorkingDirectory() / FileUtility::ASSET_PATH);

if (!filepath.empty())
{
SceneSerializer serializer(SceneManager::GetActiveScene());
serializer.SerializeToPath(filepath);
}
}
}
21 changes: 21 additions & 0 deletions Mahakam/src/Mahakam/Editor/Windows/DockSpace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <Mahakam/Mahakam.h>

namespace Mahakam::Editor
{
class DockSpace
{
public:
void Begin();
void End();

bool OnKeyPressed(KeyPressedEvent& event);

private:
void NewScene();
void OpenScene();
void SaveScene();
void SaveSceneAs();
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ebpch.h"
#include "Mahakam/mhpch.h"
#include "EnvironmentPanel.h"

namespace Mahakam::Editor
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ebpch.h"
#include "Mahakam/mhpch.h"
#include "ImportWizardPanel.h"

namespace Mahakam::Editor
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ebpch.h"
#include "Mahakam/mhpch.h"
#include "ProfilerPanel.h"

namespace Mahakam::Editor
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ebpch.h"
#include "Mahakam/mhpch.h"
#include "RenderPassPanel.h"

namespace Mahakam::Editor
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ebpch.h"
#include "Mahakam/mhpch.h"
#include "SceneHierarchyPanel.h"

#include <imgui/imgui.h>
Expand All @@ -25,7 +25,7 @@ namespace Mahakam::Editor

// Use default icon
if (tagStream.tellp() == 0)
tagStream << u8"\ueea5"; // Archive icon
tagStream << reinterpret_cast<const char*>(u8"\ueea5"); // Archive icon

// Add tag at the end
tagStream << " " << tag.c_str();
Expand Down
File renamed without changes.
Loading

0 comments on commit f6458b7

Please sign in to comment.