diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/App.cpp | 8 | ||||
-rw-r--r-- | source/App.hpp | 8 | ||||
-rw-r--r-- | source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/EditorCore.hpp | 112 | ||||
-rw-r--r-- | source/EditorCorePrivate.cpp (renamed from source/EditorCore.cpp) | 8 | ||||
-rw-r--r-- | source/EditorCorePrivate.hpp | 111 | ||||
-rw-r--r-- | source/Ires.cpp | 10 | ||||
-rw-r--r-- | source/Ires.hpp | 10 | ||||
-rw-r--r-- | source/Material.cpp | 2 | ||||
-rw-r--r-- | source/Material.hpp | 2 | ||||
-rw-r--r-- | source/Shader.cpp | 2 | ||||
-rw-r--r-- | source/Shader.hpp | 2 | ||||
-rw-r--r-- | source/Sprite.cpp | 2 | ||||
-rw-r--r-- | source/Sprite.hpp | 2 | ||||
-rw-r--r-- | source/main.cpp | 1 |
15 files changed, 162 insertions, 120 deletions
diff --git a/source/App.cpp b/source/App.cpp index 15ffd27..9e8a298 100644 --- a/source/App.cpp +++ b/source/App.cpp @@ -65,11 +65,15 @@ bool App::IsEditorVisible() const { void App::SetEditorVisible(bool visible) { if (mEditorVisible != visible) { - mEditorVisible = visible; if (visible) { +#if BRUSSEL_ENABLE_EDITOR + mEditorVisible = true; if (mEditor == nullptr) { - mEditor = std::make_unique<EditorInstance>(this); + mEditor = IEditor::CreateInstance(this); } +#endif + } else { + mEditorVisible = false; } } } diff --git a/source/App.hpp b/source/App.hpp index 54e1fb5..c73c5a1 100644 --- a/source/App.hpp +++ b/source/App.hpp @@ -17,14 +17,11 @@ using KeyCaptureCallback = std::function<bool(int, int)>; -// TODO how should we split responsibilities between App and Editor? class App { - friend class EditorInstance; - private: std::deque<KeyCaptureCallback> mKeyCaptureCallbacks; PodVector<Player*> mPlayers; - std::unique_ptr<EditorInstance> mEditor; + std::unique_ptr<IEditor> mEditor; GameWorld mWorld; Renderer mWorldRenderer; Camera mMainCamera; @@ -37,8 +34,9 @@ public: App(); ~App(); - EditorInstance* GetEditor() { return mEditor.get(); } + IEditor* GetEditor() { return mEditor.get(); } GameWorld* GetWorld() { return &mWorld; } + Renderer* GetWorldRenderer() { return &mWorldRenderer; } Camera* GetActiveCamera() const; void BindActiveCamera(Camera* camera); diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index ba07566..6ca2cd5 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -6,7 +6,7 @@ PRIVATE EditorAccessories.cpp EditorAttachmentImpl.cpp EditorCommandPalette.cpp - EditorCore.cpp + EditorCorePrivate.cpp EditorGuizmo.cpp EditorNotification.cpp EditorUtils.cpp diff --git a/source/EditorCore.hpp b/source/EditorCore.hpp index b73152a..15bd100 100644 --- a/source/EditorCore.hpp +++ b/source/EditorCore.hpp @@ -1,114 +1,38 @@ #pragma once -#include "EditorAttachment.hpp" -#include "EditorCommandPalette.hpp" -#include "EditorUtils.hpp" -#include "GameObject.hpp" -#include "Ires.hpp" -#include "RcPtr.hpp" -#include "Sprite.hpp" -#include "World.hpp" - #include <memory> -#include <string> -// TODO move inspector drawing to this class -struct EditorInspector { +class App; +class SpriteDefinition; + +class IEditorInspector { +public: enum TargetType { ITT_GameObject, ITT_Ires, ITT_None, }; - std::string renamingScratchBuffer; - void* selectedItPtr = nullptr; - TargetType selectedItt = ITT_None; - bool renaming = false; - - void SelectTarget(TargetType type, void* object); -}; - -class EditorContentBrowser { -private: - enum Pane { - P_Settings, - P_Ires, - }; - - static constexpr float kSplitterThickness = 3.0f; - static constexpr float kPadding = 4.0f; - - // <root> - static constexpr float kLeftPaneMinWidth = 200.0f; - static constexpr float kRightPaneMinWidth = 200.0f; - - EditorInspector* mInspector; - Pane mPane = P_Settings; - float mBrowserHeight = 0.5f; - float mSplitterLeft = kLeftPaneMinWidth; - float mSplitterRight = 0.0f; - bool mDocked = true; - public: - EditorContentBrowser(EditorInspector* inspector); - ~EditorContentBrowser(); - - void Show(bool* open = nullptr); + virtual ~IEditorInspector() = default; + virtual void SelectTarget(TargetType type, void* object) = 0; }; -struct GuizmoState { - ImGuizmo::OPERATION currOperation = ImGuizmo::TRANSLATE; - ImGuizmo::MODE currMode = ImGuizmo::LOCAL; - glm::mat4 cubeMatrix; - float snap[3] = { 1.f, 1.f, 1.f }; - float boundsSnap[3] = { 0.1f, 0.1f, 0.1f }; - bool useSnap = false; - bool boundSizing = false; - bool boundSizingSnap = false; +class IEditorContentBrowser { +public: + virtual ~IEditorContentBrowser() = default; }; -// TODO editor undo stack -class App; -class EditorInstance { -private: - App* mApp; - GameObject* mPopupCurrent_GameObject = nullptr; - Camera mEditorCamera; - RcPtr<SpriteDefinition> mSpriteView_Instance; - EditorCommandPalette mEdCommandPalette; - EditorInspector mEdInspector; - EditorContentBrowser mEdContentBrowser; - GuizmoState mGuizmo; - glm::vec3 mDragCam_CamInitial; - ImVec2 mDragCam_CursorInitial; - int mSpriteView_Frame; - bool mSpriteView_OpenNextFrame = false; - bool mWindowVisible_ImGuiDemo = false; - bool mWindowVisible_CommandPalette = false; - bool mWindowVisible_Inspector = true; - bool mWindowVisible_ContentBrowser = true; - bool mWindowVisible_WorldStructure = true; - bool mWindowVisible_WorldProperties = true; - bool mDragCam_Happening = false; - bool mMoveCamKeyboard = false; - +class IEditor { public: - EditorInstance(App* app); - ~EditorInstance(); - - void OnGameStateChanged(bool running); - void Show(); - - EditorInspector& GetInspector() { return mEdInspector; } - EditorContentBrowser& GetContentBrowser() { return mEdContentBrowser; } - - void OpenSpriteViewer(SpriteDefinition* sprite); + static std::unique_ptr<IEditor> CreateInstance(App* app); + virtual ~IEditor() = default; -private: - void ShowWorldProperties(); + virtual void OnGameStateChanged(bool running) = 0; + virtual void Show() = 0; - void ShowInspector(IresObject* ires); - void ShowInspector(GameObject* object); + virtual IEditorInspector& GetInspector() = 0; + virtual IEditorContentBrowser& GetContentBrowser() = 0; - void ShowSpriteViewer(); + virtual void OpenSpriteViewer(SpriteDefinition* sprite) = 0; }; diff --git a/source/EditorCore.cpp b/source/EditorCorePrivate.cpp index 8bdec40..35378ce 100644 --- a/source/EditorCore.cpp +++ b/source/EditorCorePrivate.cpp @@ -1,4 +1,4 @@ -#include "EditorCore.hpp" +#include "EditorCorePrivate.hpp" #include "App.hpp" #include "AppConfig.hpp" @@ -307,6 +307,10 @@ struct CreatableGameObject { #undef GAMEOBJECT_CONSTRUCTOR } // namespace ProjectBrussel_UNITY_ID +std::unique_ptr<IEditor> IEditor::CreateInstance(App* app) { + return std::make_unique<EditorInstance>(app); +} + EditorInstance::EditorInstance(App* app) : mApp{ app } , mEdContentBrowser(&mEdInspector) { @@ -610,7 +614,7 @@ void EditorInstance::ShowInspector(GameObject* object) { glm::mat4 identityMatrix(1.00f); // TODO get rid of this massive hack: how to manage const better for intuitively read-only, but write doesn't-care data? - auto& lastFrameInfo = const_cast<RendererFrameInfo&>(mApp->mWorldRenderer.GetLastFrameInfo()); + auto& lastFrameInfo = const_cast<RendererFrameInfo&>(mApp->GetWorldRenderer()->GetLastFrameInfo()); auto& cameraViewMat = lastFrameInfo.matrixView; float* cameraView = &cameraViewMat[0][0]; auto& cameraProjMat = lastFrameInfo.matrixProj; diff --git a/source/EditorCorePrivate.hpp b/source/EditorCorePrivate.hpp new file mode 100644 index 0000000..566131b --- /dev/null +++ b/source/EditorCorePrivate.hpp @@ -0,0 +1,111 @@ +#pragma once + +#include "EditorCore.hpp" + +#include "App.hpp" +#include "EditorAttachment.hpp" +#include "EditorCommandPalette.hpp" +#include "EditorUtils.hpp" +#include "GameObject.hpp" +#include "Ires.hpp" +#include "RcPtr.hpp" +#include "Sprite.hpp" +#include "World.hpp" + +#include <memory> +#include <string> + +// TODO move inspector drawing to this class +class EditorInspector final : public IEditorInspector { +public: + std::string renamingScratchBuffer; + void* selectedItPtr = nullptr; + TargetType selectedItt = ITT_None; + bool renaming = false; + + void SelectTarget(TargetType type, void* object) override; +}; + +class EditorContentBrowser final : public IEditorContentBrowser { +private: + enum Pane { + P_Settings, + P_Ires, + }; + + static constexpr float kSplitterThickness = 3.0f; + static constexpr float kPadding = 4.0f; + + // <root> + static constexpr float kLeftPaneMinWidth = 200.0f; + static constexpr float kRightPaneMinWidth = 200.0f; + + EditorInspector* mInspector; + Pane mPane = P_Settings; + float mBrowserHeight = 0.5f; + float mSplitterLeft = kLeftPaneMinWidth; + float mSplitterRight = 0.0f; + bool mDocked = true; + +public: + EditorContentBrowser(EditorInspector* inspector); + ~EditorContentBrowser() override; + + void Show(bool* open = nullptr); +}; + +struct GuizmoState { + ImGuizmo::OPERATION currOperation = ImGuizmo::TRANSLATE; + ImGuizmo::MODE currMode = ImGuizmo::LOCAL; + glm::mat4 cubeMatrix; + float snap[3] = { 1.f, 1.f, 1.f }; + float boundsSnap[3] = { 0.1f, 0.1f, 0.1f }; + bool useSnap = false; + bool boundSizing = false; + bool boundSizingSnap = false; +}; + +// TODO editor undo stack +class EditorInstance : public IEditor { +private: + App* mApp; + GameObject* mPopupCurrent_GameObject = nullptr; + Camera mEditorCamera; + RcPtr<SpriteDefinition> mSpriteView_Instance; + EditorCommandPalette mEdCommandPalette; + EditorInspector mEdInspector; + EditorContentBrowser mEdContentBrowser; + GuizmoState mGuizmo; + glm::vec3 mDragCam_CamInitial; + ImVec2 mDragCam_CursorInitial; + int mSpriteView_Frame; + bool mSpriteView_OpenNextFrame = false; + bool mWindowVisible_ImGuiDemo = false; + bool mWindowVisible_CommandPalette = false; + bool mWindowVisible_Inspector = true; + bool mWindowVisible_ContentBrowser = true; + bool mWindowVisible_WorldStructure = true; + bool mWindowVisible_WorldProperties = true; + bool mDragCam_Happening = false; + bool mMoveCamKeyboard = false; + +public: + EditorInstance(App* app); + ~EditorInstance() override; + + void OnGameStateChanged(bool running) override; + void Show() override; + + EditorInspector& GetInspector() override { return mEdInspector; } + EditorContentBrowser& GetContentBrowser() override { return mEdContentBrowser; } + + void OpenSpriteViewer(SpriteDefinition* sprite) override; + +private: + void ShowWorldProperties(); + + void ShowInspector(IresObject* ires); + void ShowInspector(GameObject* object); + + void ShowSpriteViewer(); +}; diff --git a/source/Ires.cpp b/source/Ires.cpp index 0421a54..7a99be3 100644 --- a/source/Ires.cpp +++ b/source/Ires.cpp @@ -94,7 +94,7 @@ void IresObject::ShowName() const { } } -void IresObject::ShowReferenceSafe(EditorInstance& editor, IresObject* ires) { +void IresObject::ShowReferenceSafe(IEditor& editor, IresObject* ires) { if (ires) { ires->ShowReference(editor); } else { @@ -102,14 +102,14 @@ void IresObject::ShowReferenceSafe(EditorInstance& editor, IresObject* ires) { } } -void IresObject::ShowReferenceNull(EditorInstance& editor) { +void IresObject::ShowReferenceNull(IEditor& editor) { ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_ButtonHovered]); ImGui::Text("<null>"); ImGui::PopStyleColor(); ImGui::AddUnderLine(ImGui::GetStyle().Colors[ImGuiCol_Button]); } -void IresObject::ShowReference(EditorInstance& editor) { +void IresObject::ShowReference(IEditor& editor) { ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_ButtonHovered]); if (IsAnnoymous()) { ImGui::Text("<annoymous %p>", (void*)this); @@ -119,7 +119,7 @@ void IresObject::ShowReference(EditorInstance& editor) { ImGui::PopStyleColor(); if (ImGui::IsItemHovered()) { if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { - editor.GetInspector().SelectTarget(EditorInspector::ITT_Ires, this); + editor.GetInspector().SelectTarget(IEditorInspector::ITT_Ires, this); } ImGui::AddUnderLine(ImGui::GetStyle().Colors[ImGuiCol_ButtonHovered]); } else { @@ -127,7 +127,7 @@ void IresObject::ShowReference(EditorInstance& editor) { } } -void IresObject::ShowEditor(EditorInstance& editor) { +void IresObject::ShowEditor(IEditor& editor) { ImGui::Text("%s", ToString(mKind).data()); bool isAnnoymous = mName.empty(); diff --git a/source/Ires.hpp b/source/Ires.hpp index a4867da..83ca175 100644 --- a/source/Ires.hpp +++ b/source/Ires.hpp @@ -1,6 +1,7 @@ #pragma once #include "EditorAttachment.hpp" +#include "EditorCore.hpp" #include "RcPtr.hpp" #include "Uid.hpp" #include "Utils.hpp" @@ -12,7 +13,6 @@ #include <string_view> // Forward declarations -class EditorInstance; class IresManager; class IresWritingContext; class IresLoadingContext; @@ -56,11 +56,11 @@ public: static void ShowNameNull(); void ShowName() const; - static void ShowReferenceSafe(EditorInstance& editor, IresObject* ires); - static void ShowReferenceNull(EditorInstance& editor); - void ShowReference(EditorInstance& editor); + static void ShowReferenceSafe(IEditor& editor, IresObject* ires); + static void ShowReferenceNull(IEditor& editor); + void ShowReference(IEditor& editor); - virtual void ShowEditor(EditorInstance& editor); + virtual void ShowEditor(IEditor& editor); EditorAttachment* GetEditorAttachment() const { return mEditorAttachment.get(); } void SetEditorAttachment(EditorAttachment* attachment) { mEditorAttachment.reset(attachment); } diff --git a/source/Material.cpp b/source/Material.cpp index 3d227f6..e648970 100644 --- a/source/Material.cpp +++ b/source/Material.cpp @@ -337,7 +337,7 @@ void IresMaterial::InvalidateInstance() { mInstance->mIres = this; } -void IresMaterial::ShowEditor(EditorInstance& editor) { +void IresMaterial::ShowEditor(IEditor& editor) { using namespace Tags; IresObject::ShowEditor(editor); diff --git a/source/Material.hpp b/source/Material.hpp index eb05a73..f1cd7dd 100644 --- a/source/Material.hpp +++ b/source/Material.hpp @@ -118,7 +118,7 @@ public: Material* GetInstance() const; void InvalidateInstance(); - void ShowEditor(EditorInstance& editor) override; + void ShowEditor(IEditor& editor) override; void Write(IresWritingContext& ctx, rapidjson::Value& value, rapidjson::Document& root) const override; void Read(IresLoadingContext& ctx, const rapidjson::Value& value) override; diff --git a/source/Shader.cpp b/source/Shader.cpp index 2ab77af..48881f0 100644 --- a/source/Shader.cpp +++ b/source/Shader.cpp @@ -595,7 +595,7 @@ void IresShader::InvalidateInstance() { mInstance->mIres = this; } -void IresShader::ShowEditor(EditorInstance& editor) { +void IresShader::ShowEditor(IEditor& editor) { using namespace Tags; using namespace ProjectBrussel_UNITY_ID; diff --git a/source/Shader.hpp b/source/Shader.hpp index 602b0db..707e6cc 100644 --- a/source/Shader.hpp +++ b/source/Shader.hpp @@ -166,7 +166,7 @@ public: Shader* GetInstance() const; void InvalidateInstance(); - void ShowEditor(EditorInstance& editor) override; + void ShowEditor(IEditor& editor) override; void Write(IresWritingContext& ctx, rapidjson::Value& value, rapidjson::Document& root) const override; void Read(IresLoadingContext& ctx, const rapidjson::Value& value) override; diff --git a/source/Sprite.cpp b/source/Sprite.cpp index 0f1a3bb..2b4923c 100644 --- a/source/Sprite.cpp +++ b/source/Sprite.cpp @@ -175,7 +175,7 @@ int IresSpritesheet::GetFrameCount() const { } } -void IresSpritesheet::ShowEditor(EditorInstance& editor) { +void IresSpritesheet::ShowEditor(IEditor& editor) { IresObject::ShowEditor(editor); bool doInvalidateInstance = false; diff --git a/source/Sprite.hpp b/source/Sprite.hpp index 064aa30..e163a01 100644 --- a/source/Sprite.hpp +++ b/source/Sprite.hpp @@ -72,7 +72,7 @@ public: bool IsFrameCountOverriden() const; int GetFrameCount() const; - void ShowEditor(EditorInstance& editor) override; + void ShowEditor(IEditor& editor) override; void Write(IresWritingContext& ctx, rapidjson::Value& value, rapidjson::Document& root) const override; void Read(IresLoadingContext& ctx, const rapidjson::Value& value) override; diff --git a/source/main.cpp b/source/main.cpp index 0dec98f..1437c4f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,6 +2,7 @@ #include "AppConfig.hpp" #include "CommonVertexIndex.hpp" +#include "EditorGuizmo.hpp" #include "Ires.hpp" #include "Material.hpp" #include "Shader.hpp" |