mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-06 06:09:52 +03:00
Reorganized folder structure + using template concepts for security
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class EditorContext;
|
||||
|
||||
class IEditorWidget
|
||||
{
|
||||
protected:
|
||||
EditorContext& editorContext;
|
||||
|
||||
public:
|
||||
IEditorWidget(EditorContext& inContext) : editorContext(inContext) {}
|
||||
~IEditorWidget() {};
|
||||
|
||||
public:
|
||||
virtual void Update(float ts) = 0;
|
||||
virtual void Draw() = 0;
|
||||
};
|
||||
@@ -1255,7 +1255,7 @@ namespace Nuake {
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void EditorInterface::DrawSceneTree()
|
||||
{
|
||||
@@ -2741,11 +2741,10 @@ namespace Nuake {
|
||||
ImGuiWindowClass top_level_class;
|
||||
top_level_class.ClassId = ImHashStr("SceneEditor");
|
||||
top_level_class.DockingAllowUnclassed = false;
|
||||
|
||||
ImGui::DockSpace(ImGui::GetID("SceneEditorDockSpace"), {0, 0}, 0, &top_level_class);
|
||||
style.WindowMinSize.x = minWinSizeX;
|
||||
|
||||
ImGuiDockNode* node = (ImGuiDockNode*)GImGui->DockContext.Nodes.GetVoidPtr(ImGui::GetID("SceneEditorDockSpace"));
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 64);
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 32);
|
||||
if(ImGui::DockNodeBeginAmendTabBar(node))
|
||||
{
|
||||
ImGui::SetNextItemWidth(48);
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
#include <src/Scripting/ScriptingEngineNet.h>
|
||||
#include "ProjectSettings/ProjectSettingsWindow.h"
|
||||
#include "PrefabEditor/PrefabEditorWindow.h"
|
||||
#include "../../SceneEditorWindow.h"
|
||||
|
||||
#include "SceneEditor/SceneEditorWindow.h"
|
||||
|
||||
|
||||
using namespace NuakeEditor;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/Core/MulticastDelegate.h"
|
||||
#include "../../Actions/EditorSelection.h"
|
||||
|
||||
#include "src/Actions/EditorSelection.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
@@ -14,17 +14,20 @@ class EditorContext
|
||||
private:
|
||||
EditorSelection selection;
|
||||
Ref<Nuake::Scene> scene;
|
||||
std::string windowClass;
|
||||
|
||||
public:
|
||||
EditorContext() = default;
|
||||
~EditorContext() = default;
|
||||
|
||||
EditorContext(Ref<Nuake::Scene> inScene)
|
||||
: scene(inScene)
|
||||
EditorContext(Ref<Nuake::Scene> inScene, std::string inWindowClass) :
|
||||
scene(inScene),
|
||||
windowClass(inWindowClass)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
const std::string_view GetWindowClass() const { return windowClass; }
|
||||
MulticastDelegate<EditorSelection> OnSelectionChanged;
|
||||
|
||||
const EditorSelection& GetSelection() const { return selection; }
|
||||
@@ -1,16 +1,15 @@
|
||||
#include "SceneEditorWindow.h"
|
||||
|
||||
#include "SelectionPropertyWidget.h"
|
||||
#include "SceneHierarchyWidget.h"
|
||||
#include "Widgets/SceneHierarchyWidget.h"
|
||||
#include "Widgets/SelectionPropertyWidget.h"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_internal.h>
|
||||
#include <src/UI/ImUI.h>
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
SceneEditorWindow::SceneEditorWindow(Ref<Scene> inScene)
|
||||
{
|
||||
editorContext = EditorContext(inScene);
|
||||
editorContext = EditorContext(inScene, inScene->GetName());
|
||||
|
||||
RegisterWidget<SceneHierarchyWidget>();
|
||||
RegisterWidget<SelectionPropertyWidget>();
|
||||
@@ -30,9 +29,8 @@ void SceneEditorWindow::Draw()
|
||||
const std::string sceneName = scene->GetName();
|
||||
|
||||
// This is to prevent other windows of other scene editors to dock
|
||||
// into this window
|
||||
ImGuiWindowClass windowClass;
|
||||
windowClass.ClassId = ImHashStr("SceneEditor");
|
||||
windowClass.ClassId = ImHashStr(editorContext.GetWindowClass().data());
|
||||
windowClass.DockingAllowUnclassed = false;
|
||||
ImGui::SetNextWindowClass(&windowClass);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
#include "src/Core/Core.h"
|
||||
|
||||
#include "IEditorWidget.h"
|
||||
#include "EditorContext.h"
|
||||
|
||||
#include "Widgets/IEditorWidget.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <concepts>
|
||||
|
||||
// Forward declarations
|
||||
namespace Nuake
|
||||
@@ -14,7 +16,8 @@ namespace Nuake
|
||||
class Entity;
|
||||
}
|
||||
|
||||
class SceneHierarchyWidget;
|
||||
template <typename T>
|
||||
concept DerivedFromEditorWidget = std::derived_from<T, IEditorWidget>;
|
||||
|
||||
class SceneEditorWindow
|
||||
{
|
||||
@@ -33,10 +36,9 @@ public:
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
template<class T>
|
||||
template<DerivedFromEditorWidget T>
|
||||
inline void RegisterWidget()
|
||||
{
|
||||
widgets.push_back(CreateScope<T>(editorContext));
|
||||
}
|
||||
|
||||
};
|
||||
35
Editor/src/Windows/SceneEditor/Widgets/IEditorWidget.h
Normal file
35
Editor/src/Windows/SceneEditor/Widgets/IEditorWidget.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EditorContext.h"
|
||||
|
||||
#include "src/UI/ImUI.h"
|
||||
|
||||
class IEditorWidget
|
||||
{
|
||||
protected:
|
||||
EditorContext& editorContext;
|
||||
|
||||
public:
|
||||
IEditorWidget(EditorContext& inContext) : editorContext(inContext) {}
|
||||
virtual ~IEditorWidget() {};
|
||||
|
||||
public:
|
||||
virtual void Update(float ts) = 0;
|
||||
virtual void Draw() = 0;
|
||||
|
||||
bool BeginWidgetWindow(const std::string_view& name)
|
||||
{
|
||||
return BeginWidgetWindow(name.data());
|
||||
}
|
||||
|
||||
bool BeginWidgetWindow(const char* name)
|
||||
{
|
||||
ImGuiWindowClass windowClass;
|
||||
windowClass.ClassId = ImHashStr(editorContext.GetWindowClass().data());
|
||||
windowClass.DockingAllowUnclassed = false;
|
||||
ImGui::SetNextWindowClass(&windowClass);
|
||||
|
||||
std::string nameStr = std::string(name) + "##" + editorContext.GetScene()->GetName();
|
||||
return ImGui::Begin(nameStr.c_str());
|
||||
}
|
||||
};
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "src/Scene/Entities/Entity.h"
|
||||
#include "src/Scene/Components.h"
|
||||
|
||||
#include "SceneEditorWindow.h"
|
||||
|
||||
#include <src/Core/Input.h>
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
#include "Engine.h"
|
||||
@@ -16,27 +16,31 @@
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
SceneHierarchyWidget::SceneHierarchyWidget(EditorContext& inCtx) : IEditorWidget(inCtx)
|
||||
SceneHierarchyWidget::SceneHierarchyWidget(EditorContext& inCtx) :
|
||||
IEditorWidget(inCtx),
|
||||
isRenaming(false),
|
||||
searchQuery("")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SceneHierarchyWidget::Update(float ts)
|
||||
{
|
||||
//std::string searchQuery = "";
|
||||
//
|
||||
//ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 8, 8 });
|
||||
//ImGui::InputTextWithHint("##search", "Search entity", &searchQuery, 0, 0, 0);
|
||||
//ImGui::PopStyleVar();
|
||||
|
||||
}
|
||||
|
||||
void SceneHierarchyWidget::Draw()
|
||||
{
|
||||
DrawSearchBar();
|
||||
if (BeginWidgetWindow("Scene Hierarchy"))
|
||||
{
|
||||
DrawSearchBar();
|
||||
|
||||
DrawCreateEntityButton();
|
||||
DrawCreateEntityButton();
|
||||
|
||||
DrawEntityTree();
|
||||
DrawEntityTree();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
void SceneHierarchyWidget::DrawSearchBar()
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "SelectionPropertyWidget.h"
|
||||
|
||||
#include "src/UI/ImUI.h"
|
||||
|
||||
SelectionPropertyWidget::SelectionPropertyWidget(EditorContext& inCtx)
|
||||
: IEditorWidget(inCtx)
|
||||
{
|
||||
@@ -8,7 +10,11 @@ SelectionPropertyWidget::SelectionPropertyWidget(EditorContext& inCtx)
|
||||
|
||||
void SelectionPropertyWidget::Update(float ts)
|
||||
{
|
||||
|
||||
if (BeginWidgetWindow("Selection Properties"))
|
||||
{
|
||||
ImGui::Text("Selection Properties");
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectionPropertyWidget::Draw()
|
||||
Reference in New Issue
Block a user