From 0ce75eeec8c61f603420103cc5908c6a8e0f910b Mon Sep 17 00:00:00 2001 From: Arnau Alier Torres Date: Fri, 2 May 2025 16:39:54 +0200 Subject: [PATCH] Working on tree pannel implementation in angelscript --- Deer/Include/Deer/DataStore.h | 6 +- Deer/Include/Deer/EntryPoint.h | 4 +- Deer/Include/Deer/Log.h | 14 +- Deer/Include/DeerRender/UIEngine.h | 17 -- Deer/src/Deer/Core/Log.cpp | 8 +- Deer/src/Deer/DataStore/DataStore.cpp | 9 +- Deer/src/Deer/Scripting/ScriptEngine.cpp | 6 +- Deer/src/Deer/Voxels/VoxelData.cpp | 10 +- .../UIEngine/UIEngine_Functions.cpp | 131 ------------ .../DeerRender/UIEngine/UIEngine_Functions.h | 41 ---- .../UIEngine/UIEngine_RegisterFunctions.cpp | 128 ------------ Deer/src/DeerRender/Voxels/VoxelData.cpp | 16 +- .../Voxels/VoxelData_TextureAtlas.cpp | 6 +- Deer/src/Plattform/OpenGL/OpenGLContext.cpp | 1 - Deer/src/Plattform/OpenGL/OpenGLShader.cpp | 2 +- DeerStudio/Build.lua | 3 +- DeerStudio/src/DeerStudio/DeerStudio.cpp | 13 +- DeerStudio/src/DeerStudio/DeerStudio.h | 8 + .../Editor/MeshExplorer/MeshExplorer.cpp | 73 ------- .../Editor/MeshExplorer/MeshExplorer.h | 7 - .../src/DeerStudio/EditorEngine.h | 17 +- .../EditorEngine/API/EditorEngine_Button.h | 2 +- .../EditorEngine/API/EditorEngine_Column.h | 2 +- .../EditorEngine/API/EditorEngine_Directory.h | 30 +++ .../API/EditorEngine_Environment.h | 16 ++ .../EditorEngine/API/EditorEngine_Functions.h | 11 + .../EditorEngine/API/EditorEngine_Icon.h | 9 + .../EditorEngine/API/EditorEngine_Input.h | 2 +- .../EditorEngine/API/EditorEngine_MenuBar.h | 8 + .../EditorEngine/API/EditorEngine_Mesh.h | 9 + .../EditorEngine/API/EditorEngine_Text.h | 7 +- .../EditorEngine/API/EditorEngine_TreeNode.h | 11 + .../EditorEngine_Button.cpp | 11 + .../EditorEngine_Column.cpp | 28 +++ .../EditorEngine_Directory.cpp | 195 ++++++++++++++++++ .../EditorEngine_Environment.cpp | 7 + .../EditorEngine_Functions.cpp | 23 +++ .../API_Implementation/EditorEngine_Icon.cpp | 51 +++++ .../API_Implementation/EditorEngine_Input.cpp | 14 ++ .../EditorEngine_MenuBar.cpp | 10 + .../API_Implementation/EditorEngine_Mesh.cpp | 8 + .../API_Implementation/EditorEngine_Text.cpp | 30 +++ .../EditorEngine_TreeNode.cpp | 35 ++++ .../EditorEngine}/DockPanelObject.cpp | 61 +++++- .../EditorEngine}/DockPanelObject.h | 8 +- .../DeerStudio/EditorEngine/EditorEngine.cpp | 23 ++- .../EditorEngine/EditorEngine_ErrorHandle.cpp | 4 +- .../EditorEngine/EditorEngine_ErrorHandle.h | 10 +- .../EditorEngine_IconManagment.cpp | 4 +- .../EditorEngine/EditorEngine_LoadPanels.cpp | 10 +- .../EditorEngine/EditorEngine_LoadScripts.cpp | 12 +- .../EditorEngine_RegisterFunctions.cpp | 135 ++++++++++++ .../EditorEngine_RegisterStructs.cpp | 25 +++ roe/editor/mesh_explorer/mesh_explorer.as | 42 ++++ roe/editor/mesh_explorer/mesh_searcher.as | 28 --- roe/editor/tree_pannel/tree_pannel.as | 16 ++ roe/imgui.ini | 38 ++-- 57 files changed, 908 insertions(+), 547 deletions(-) delete mode 100644 Deer/Include/DeerRender/UIEngine.h delete mode 100644 Deer/src/DeerRender/UIEngine/UIEngine_Functions.cpp delete mode 100644 Deer/src/DeerRender/UIEngine/UIEngine_Functions.h delete mode 100644 Deer/src/DeerRender/UIEngine/UIEngine_RegisterFunctions.cpp delete mode 100644 DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.cpp delete mode 100644 DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.h rename Deer/src/DeerRender/UIEngine/UIEngine.h => DeerStudio/src/DeerStudio/EditorEngine.h (54%) rename Deer/src/DeerRender/UIEngine/Functions/UIEngine_ButtonFunctions.h => DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Button.h (79%) rename Deer/src/DeerRender/UIEngine/Functions/UIEngine_ColumnFunctions.h => DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Column.h (90%) create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Directory.h create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Environment.h create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Functions.h create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Icon.h rename Deer/src/DeerRender/UIEngine/Functions/UIEngine_InputFunctions.h => DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Input.h (90%) create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Mesh.h rename Deer/src/DeerRender/UIEngine/Functions/UIEngine_TextFunctions.h => DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Text.h (72%) create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Button.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Column.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Directory.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Environment.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Functions.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Icon.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Input.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_MenuBar.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Mesh.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Text.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_TreeNode.cpp rename {Deer/src/DeerRender/UIEngine => DeerStudio/src/DeerStudio/EditorEngine}/DockPanelObject.cpp (55%) rename {Deer/src/DeerRender/UIEngine => DeerStudio/src/DeerStudio/EditorEngine}/DockPanelObject.h (86%) rename Deer/src/DeerRender/UIEngine/UIEngine.cpp => DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp (72%) rename Deer/src/DeerRender/UIEngine/UIEngine_ErrorHandle.cpp => DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.cpp (96%) rename Deer/src/DeerRender/UIEngine/UIEngine_ErrorHandle.h => DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h (69%) rename Deer/src/DeerRender/UIEngine/UIEngine_IconManagment.cpp => DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_IconManagment.cpp (82%) rename Deer/src/DeerRender/UIEngine/UIEngine_LoadPanels.cpp => DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadPanels.cpp (77%) rename Deer/src/DeerRender/UIEngine/UIEngine_LoadScripts.cpp => DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadScripts.cpp (70%) create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterFunctions.cpp create mode 100644 DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterStructs.cpp create mode 100644 roe/editor/mesh_explorer/mesh_explorer.as delete mode 100644 roe/editor/mesh_explorer/mesh_searcher.as create mode 100644 roe/editor/tree_pannel/tree_pannel.as diff --git a/Deer/Include/Deer/DataStore.h b/Deer/Include/Deer/DataStore.h index b0e5901..ccae3b6 100755 --- a/Deer/Include/Deer/DataStore.h +++ b/Deer/Include/Deer/DataStore.h @@ -13,11 +13,11 @@ #define DEER_VOXEL_ASPECT_PATH "voxels/aspect" #define DEER_VOXEL_TEXTURE_PATH "voxels/textures" #define DEER_VOXEL_SHADER_PATH "voxels/shaders" -#define DEER_DOCK_PANEL_PATH "editor" -#define DEER_UI_SCRIPT_PATH DEER_DOCK_PANEL_PATH -#define DEER_UI_ICON_PATH DEER_DOCK_PANEL_PATH +#define DEER_EDITOR_PATH "editor" #define DEER_MESH_PATH "meshes" +#define DEER_MESH_EXTENSION ".dmesh" + #define DEER_BIN_PATH "bin" #define DEER_TEMP_PATH "tmp" #define DEER_NULL_PATH "null" diff --git a/Deer/Include/Deer/EntryPoint.h b/Deer/Include/Deer/EntryPoint.h index a4d89a8..9d04848 100755 --- a/Deer/Include/Deer/EntryPoint.h +++ b/Deer/Include/Deer/EntryPoint.h @@ -13,14 +13,14 @@ namespace Deer { Core::argv = argv; Log::init(); - DEER_CORE_TRACE("Initializing"); + DEER_CORE_INFO("Initializing"); Application* app = createApplication(argc, argv); int runResult = app->run(); delete app; - DEER_CORE_TRACE("Deinitializing"); + DEER_CORE_INFO("Deinitializing"); Log::shutdown(); return runResult; diff --git a/Deer/Include/Deer/Log.h b/Deer/Include/Deer/Log.h index e104906..11d49b7 100755 --- a/Deer/Include/Deer/Log.h +++ b/Deer/Include/Deer/Log.h @@ -26,15 +26,15 @@ namespace Deer { static inline Ref& getScriptLogger() { return scriptLogger; } - static inline Ref& getUiEngineLogger() { - return uiEngineLogger; + static inline Ref& getEditorEngineLogger() { + return EditorEngineLogger; } private: static Ref coreLogger; static Ref clientLogger; static Ref scriptLogger; - static Ref uiEngineLogger; + static Ref EditorEngineLogger; }; } // namespace Deer @@ -49,10 +49,10 @@ namespace Deer { #define DEER_SCRIPT_ERROR(...) Deer::Log::getScriptLogger()->error(__VA_ARGS__) -#define DEER_UI_ENGINE_TRACE(...) Deer::Log::getUiEngineLogger()->trace(__VA_ARGS__) -#define DEER_UI_ENGINE_INFO(...) Deer::Log::getUiEngineLogger()->info(__VA_ARGS__) -#define DEER_UI_ENGINE_WARN(...) Deer::Log::getUiEngineLogger()->warn(__VA_ARGS__) -#define DEER_UI_ENGINE_ERROR(...) Deer::Log::getUiEngineLogger()->error(__VA_ARGS__) +#define DEER_UI_ENGINE_TRACE(...) Deer::Log::getEditorEngineLogger()->trace(__VA_ARGS__) +#define DEER_UI_ENGINE_INFO(...) Deer::Log::getEditorEngineLogger()->info(__VA_ARGS__) +#define DEER_UI_ENGINE_WARN(...) Deer::Log::getEditorEngineLogger()->warn(__VA_ARGS__) +#define DEER_UI_ENGINE_ERROR(...) Deer::Log::getEditorEngineLogger()->error(__VA_ARGS__) #ifdef LINUX #define DEER_CORE_ASSERT(condition, ...) \ diff --git a/Deer/Include/DeerRender/UIEngine.h b/Deer/Include/DeerRender/UIEngine.h deleted file mode 100644 index 1f0fcfa..0000000 --- a/Deer/Include/DeerRender/UIEngine.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include - -namespace Deer { - // This namespace implements all interface ported from c++ ImGui to an easier lua aproach with simplifications - namespace UIEngine { - void initialize(); - void deinitialize(); - - void execute(); - - } - - namespace DataStore { - int getIconId(const std::string& name); - } -} \ No newline at end of file diff --git a/Deer/src/Deer/Core/Log.cpp b/Deer/src/Deer/Core/Log.cpp index 48483c0..94584ef 100755 --- a/Deer/src/Deer/Core/Log.cpp +++ b/Deer/src/Deer/Core/Log.cpp @@ -4,7 +4,7 @@ namespace Deer { std::shared_ptr Log::coreLogger; std::shared_ptr Log::clientLogger; std::shared_ptr Log::scriptLogger; - std::shared_ptr Log::uiEngineLogger; + std::shared_ptr Log::EditorEngineLogger; void Log::init() { @@ -13,19 +13,19 @@ namespace Deer { coreLogger = spdlog::stdout_color_mt("Core"); clientLogger = spdlog::stdout_color_mt("Client"); scriptLogger = spdlog::stdout_color_mt("Script"); - uiEngineLogger = spdlog::stdout_color_mt("UI Engine"); + EditorEngineLogger = spdlog::stdout_color_mt("UI Engine"); coreLogger->set_level(spdlog::level::level_enum::trace); clientLogger->set_level(spdlog::level::level_enum::trace); scriptLogger->set_level(spdlog::level::level_enum::trace); - uiEngineLogger->set_level(spdlog::level::level_enum::trace); + EditorEngineLogger->set_level(spdlog::level::level_enum::trace); } void Log::shutdown() { coreLogger.reset(); clientLogger.reset(); scriptLogger.reset(); - uiEngineLogger.reset(); + EditorEngineLogger.reset(); spdlog::drop_all(); } diff --git a/Deer/src/Deer/DataStore/DataStore.cpp b/Deer/src/Deer/DataStore/DataStore.cpp index 2487fe2..3d7daae 100755 --- a/Deer/src/Deer/DataStore/DataStore.cpp +++ b/Deer/src/Deer/DataStore/DataStore.cpp @@ -28,12 +28,9 @@ namespace Deer { return dirData_cache[dirId]; } - Path idPath = rootPath; - if (id != "") - idPath /= id; - Path searchPath = idPath; - if (subDir != "") - searchPath /= subDir; + Path idPath = rootPath / id; + + Path searchPath = idPath / subDir; DirectoryData& dirData = dirData_cache[dirId]; for (const auto& entry : std::filesystem::directory_iterator(searchPath)) { diff --git a/Deer/src/Deer/Scripting/ScriptEngine.cpp b/Deer/src/Deer/Scripting/ScriptEngine.cpp index 6ae0af8..5dd0631 100755 --- a/Deer/src/Deer/Scripting/ScriptEngine.cpp +++ b/Deer/src/Deer/Scripting/ScriptEngine.cpp @@ -129,7 +129,7 @@ namespace Deer { moduleName); try { - DEER_CORE_INFO("=== Loading Scripts ==="); + DEER_CORE_TRACE("Loading Scripts "); for (const auto& entry : fs::recursive_directory_iterator(modulePath)) { if (fs::is_regular_file(entry) && @@ -141,8 +141,8 @@ namespace Deer { "script and try again. {0}", entry.path().generic_string().c_str()); - DEER_CORE_TRACE(" {0}", - entry.path().filename().string().c_str()); + //DEER_CORE_TRACE(" {0}", + // entry.path().filename().string().c_str()); } } } catch (const fs::filesystem_error& e) { diff --git a/Deer/src/Deer/Voxels/VoxelData.cpp b/Deer/src/Deer/Voxels/VoxelData.cpp index 175956c..8ff90f9 100644 --- a/Deer/src/Deer/Voxels/VoxelData.cpp +++ b/Deer/src/Deer/Voxels/VoxelData.cpp @@ -34,8 +34,8 @@ namespace Deer { std::vector voxelsData; voxelsData = DataStore::getFiles(DEER_VOXEL_DATA_PATH, ".voxel"); - DEER_CORE_INFO("=== Loading voxels ==="); - DEER_CORE_TRACE(" default - air"); + DEER_CORE_TRACE("Loading voxels"); + //DEER_CORE_TRACE(" default - air"); for (Path& voxel : voxelsData) { VoxelInfo voxelData; @@ -61,9 +61,9 @@ namespace Deer { voxelData.name.c_str()); continue; } - DEER_CORE_TRACE(" {0} - {1}", - voxel.filename().generic_string().c_str(), - voxelData.name); + //DEER_CORE_TRACE(" {0} - {1}", + // voxel.filename().generic_string().c_str(), + // voxelData.name); uint32_t id = voxelsInfo.size(); diff --git a/Deer/src/DeerRender/UIEngine/UIEngine_Functions.cpp b/Deer/src/DeerRender/UIEngine/UIEngine_Functions.cpp deleted file mode 100644 index 710aa0c..0000000 --- a/Deer/src/DeerRender/UIEngine/UIEngine_Functions.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "DeerRender/UIEngine/UIEngine_Functions.h" -#include "DeerRender/UIEngine/UIEngine.h" -#include "DeerRender/UIEngine.h" -#include "DeerRender/UIEngine/DockPanelObject.h" -#include "Deer/Log.h" -#include "Deer/DataStore.h" - -#include "angelscript.h" -#include "imgui.h" - -namespace Deer { - namespace UIEngine { - int getMeshCount(std::string& dir) { - return DataStore::getDirData(DEER_MESH_PATH, dir, ".dmesh").elements.size(); - } - std::string getMeshPath(std::string& dir, int i) { - const DirectoryData& dirData = DataStore::getDirData(DEER_MESH_PATH, dir, ".dmesh"); - if (i < 0 || i >= dirData.elements.size()){ - DEER_UI_ENGINE_ERROR("Invalid id {0} calling getMeshPath(..), mas size {1}", i, dirData.dirs.size()); - if (currentDockPanelExecution) { - currentDockPanelExecution->invalidate(); - } - return ""; - } - return dirData.elements[i].string(); - } - std::string getMeshName(std::string& dir, int i) { - const DirectoryData& dirData = DataStore::getDirData(DEER_MESH_PATH, dir, ".dmesh"); - if (i < 0 || i >= dirData.elements.size()){ - DEER_UI_ENGINE_ERROR("Invalid id {0} calling getMeshName(..), mas size {1}", i, dirData.dirs.size()); - if (currentDockPanelExecution) { - currentDockPanelExecution->invalidate(); - } - return ""; - } - return dirData.elements[i].stem().string(); - } - - int getMeshDirCount(std::string& dir) { - return DataStore::getDirData(DEER_MESH_PATH, dir, ".dmesh").dirs.size(); - } - std::string getMeshDirPath(std::string& dir, int i) { - const DirectoryData& dirData = DataStore::getDirData(DEER_MESH_PATH, dir, ".dmesh"); - if (i < 0 || i >= dirData.dirs.size()){ - DEER_UI_ENGINE_ERROR("Invalid id {0} calling getMeshDirPath(..), mas size {1}", i, dirData.dirs.size()); - if (currentDockPanelExecution) { - currentDockPanelExecution->invalidate(); - } - return ""; - } - return dirData.dirs[i].string(); - } - std::string getMeshDirName(std::string& dir, int i) { - const DirectoryData& dirData = DataStore::getDirData(DEER_MESH_PATH, dir, ".dmesh"); - if (i < 0 || i >= dirData.dirs.size()){ - DEER_UI_ENGINE_ERROR("Invalid id {0} calling getMeshDirName(..), mas size {1}", i, dirData.dirs.size()); - if (currentDockPanelExecution) { - currentDockPanelExecution->invalidate(); - } - return ""; - } - return dirData.dirs[i].filename().string(); - } - - void textColor(float r, float g, float b, std::string& msg) { - ImGui::TextColored(ImVec4(r, g, b, 1.0f), "%s", msg.c_str()); - } - void text(std::string& msg) { - ImGui::Text("%s", msg.c_str()); - } - - void drawIcon(std::string& name, int size) { - int iconId = DataStore::getIconId(name); - - if (iconId < 0) { - DEER_UI_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); - if (currentDockPanelExecution) { - currentDockPanelExecution->invalidate(); - } - return; - } - - ImGui::Image((void*)(uint64_t)iconId, - ImVec2(size, size), ImVec2(0, 1), - ImVec2(1, 0)); - } - - // Interaction - bool isMouseClicked(int mouse) { - return ImGui::IsItemClicked(mouse); - } - - bool isMouseDoubleClicked(int mouse) { - return ImGui::IsMouseDoubleClicked(mouse); - } - - void setupAutomaticColumns(int pixelSize) { - float width = ImGui::GetWindowContentRegionWidth(); - - if (width < pixelSize) { - ImGui::Columns(); - return; - } - - int cols = (int)(width / (pixelSize)); - float componentWidth = width / (float)cols; - - ImGui::Columns(cols, 0, false); - } - - void endColumns() { - ImGui::Columns(); - } - - void nextColumn() { - ImGui::NextColumn(); - } - - void errorCallback(const asSMessageInfo *msg, void *param) { - if (msg->type == asMSGTYPE_WARNING) { - DEER_UI_ENGINE_WARN("{0} : ({1}, {2}) : {3}", msg->section, msg->row, msg->col, msg->message); - } else if( msg->type == asMSGTYPE_INFORMATION ) { - DEER_UI_ENGINE_ERROR("{0} : ({1}, {2}) : {3}", msg->section, msg->row, msg->col, msg->message); - } - } - - void print(std::string& msg) { - DEER_UI_ENGINE_INFO("{0}", msg.c_str()); - } - } -} \ No newline at end of file diff --git a/Deer/src/DeerRender/UIEngine/UIEngine_Functions.h b/Deer/src/DeerRender/UIEngine/UIEngine_Functions.h deleted file mode 100644 index 638d3f1..0000000 --- a/Deer/src/DeerRender/UIEngine/UIEngine_Functions.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once -#include - -#include "DeerRender/UIEngine/Functions/UIEngine_TextFunctions.h" -#include "DeerRender/UIEngine/Functions/UIEngine_ColumnFunctions.h" -#include "DeerRender/UIEngine/Functions/UIEngine_ButtonFunctions.h" -#include "DeerRender/UIEngine/Functions/UIEngine_ButtonFunctions.h" - -class asSMessageInfo; -namespace Deer { - namespace UIEngine { - // --- Mesh Data Store --- - - // Returns the count of meshes in the dir relative to the mesh root dir - int getMeshCount(std::string& dir); - // Returns the path to the mesh with id i - std::string getMeshPath(std::string& dir, int i); - // Returns the name of the mesh with id i - std::string getMeshName(std::string& dir, int i); - - // Returns the count of sub dirs in the dir relative to the mesh root dir - int getMeshDirCount(std::string& dir); - // Returns the path to the subDir in the dir relative to the mesh root dir - std::string getMeshDirPath(std::string& dir, int i); - // Returns the name of the subDir in the dir relative to the mesh root dir - std::string getMeshDirName(std::string& dir, int i); - - // --- RENDERING --- - - // TEXT - // Images - // TODO: Implement - void drawIcon(std::string& iconId, int size); - - - - void errorCallback(const asSMessageInfo *msg, void *param); - // Prints in console a mesage - void print(std::string& msg); - } -} \ No newline at end of file diff --git a/Deer/src/DeerRender/UIEngine/UIEngine_RegisterFunctions.cpp b/Deer/src/DeerRender/UIEngine/UIEngine_RegisterFunctions.cpp deleted file mode 100644 index edb4e6b..0000000 --- a/Deer/src/DeerRender/UIEngine/UIEngine_RegisterFunctions.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "DeerRender/UIEngine/UIEngine_Functions.h" -#include "DeerRender/UIEngine/UIEngine.h" -#include "DeerRender/UIEngine/UIEngine_ErrorHandle.h" - -namespace Deer { - void UIEngine::registerUIEngineFunctions() { - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void textColor(float, float, float, const string& in)", - asFUNCTION( - Deer::UIEngine::textColor - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void text(const string& in)", - asFUNCTION( - text - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void drawIcon(const string& in, int)", - asFUNCTION( - Deer::UIEngine::drawIcon - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "bool isMouseClicked(int)", - asFUNCTION( - isMouseClicked - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "bool isMouseDoubleClicked(int)", - asFUNCTION( - isMouseDoubleClicked - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void setupAutomaticColumns(int)", - asFUNCTION( - setupAutomaticColumns - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void endColumns()", - asFUNCTION( - endColumns - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void nextColumn()", - asFUNCTION( - nextColumn - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "void print(const string& in)", - asFUNCTION ( - Deer::UIEngine::print - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "int getMeshCount(const string& in)", - asFUNCTION( - Deer::UIEngine::getMeshCount - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "string getMeshPath(const string& in, int)", - asFUNCTION( - Deer::UIEngine::getMeshPath - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "string getMeshName(const string& in, int)", - asFUNCTION( - Deer::UIEngine::getMeshName - ), - asCALL_CDECL - )); - - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "int getMeshDirCount(const string& in)", - asFUNCTION( - Deer::UIEngine::getMeshDirCount - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "string getMeshDirPath(const string& in, int)", - asFUNCTION( - Deer::UIEngine::getMeshDirPath - ), - asCALL_CDECL - )); - - AS_CHECK(scriptEngine->RegisterGlobalFunction( - "string getMeshDirName(const string& in, int)", - asFUNCTION( - Deer::UIEngine::getMeshDirName - ), - asCALL_CDECL - )); - } -} \ No newline at end of file diff --git a/Deer/src/DeerRender/Voxels/VoxelData.cpp b/Deer/src/DeerRender/Voxels/VoxelData.cpp index 232c9ca..694c1a9 100644 --- a/Deer/src/DeerRender/Voxels/VoxelData.cpp +++ b/Deer/src/DeerRender/Voxels/VoxelData.cpp @@ -25,8 +25,8 @@ namespace Deer { voxelsAspect[0].definition.voxelName = VOXEL_INFO_TYPE_AIR; - DEER_CORE_INFO("=== Loading voxel aspect ==="); - DEER_CORE_TRACE(" default - air"); + DEER_CORE_TRACE("Loading voxel aspect "); + //DEER_CORE_TRACE(" default - air"); for (Path& voxelAspectPath : voxelsAspectPath) { uint32_t size; uint8_t* data = DataStore::readFile(voxelAspectPath, &size); @@ -56,14 +56,14 @@ namespace Deer { continue; } - DEER_CORE_TRACE(" {0} - {1}", - voxelAspectPath.filename().generic_string().c_str(), - aspectDefinition.voxelName.c_str()); + //DEER_CORE_TRACE(" {0} - {1}", + // voxelAspectPath.filename().generic_string().c_str(), + // aspectDefinition.voxelName.c_str()); voxelsAspect[voxelID].definition = aspectDefinition; } - DEER_CORE_INFO("=== Extracting textures ==="); + DEER_CORE_TRACE("Extracting textures "); for (VoxelAspect& voxelAspect : voxelsAspect) { if (voxelsInfo[DataStore::getVoxelID( voxelAspect.definition.voxelName)] @@ -93,8 +93,8 @@ namespace Deer { texturesIDs[faceTextureString] = textureID; voxelAspect.textureFacesIDs[i] = textureID; - DEER_CORE_TRACE(" texture {0} - id: {1}", - faceTextureString.c_str(), textureID); + //DEER_CORE_TRACE(" texture {0} - id: {1}", + // faceTextureString.c_str(), textureID); } } } diff --git a/Deer/src/DeerRender/Voxels/VoxelData_TextureAtlas.cpp b/Deer/src/DeerRender/Voxels/VoxelData_TextureAtlas.cpp index d92cf48..5b81b22 100644 --- a/Deer/src/DeerRender/Voxels/VoxelData_TextureAtlas.cpp +++ b/Deer/src/DeerRender/Voxels/VoxelData_TextureAtlas.cpp @@ -36,15 +36,15 @@ namespace Deer { stbi_set_flip_vertically_on_load(true); stbi_flip_vertically_on_write(true); - DEER_CORE_INFO("=== Creating Texture Atlas ==="); + DEER_CORE_TRACE("Creating Texture Atlas "); for (auto& texture : texturesIDs) { uint32_t size; uint8_t* fileData = DataStore::readFile( Path(DEER_VOXEL_TEXTURE_PATH) / (texture.first + ".png"), &size); - DEER_CORE_TRACE(" {0}.png - {1}", texture.first.c_str(), - texture.second); + //DEER_CORE_TRACE(" {0}.png - {1}", texture.first.c_str(), + // texture.second); if (fileData == nullptr) { DEER_CORE_ERROR("{0}.png does not exists", texture.first.c_str()); diff --git a/Deer/src/Plattform/OpenGL/OpenGLContext.cpp b/Deer/src/Plattform/OpenGL/OpenGLContext.cpp index eabfe01..37551c1 100755 --- a/Deer/src/Plattform/OpenGL/OpenGLContext.cpp +++ b/Deer/src/Plattform/OpenGL/OpenGLContext.cpp @@ -16,7 +16,6 @@ namespace Deer { } DEER_CORE_TRACE("OpenGL driver: {0}", (char*)glGetString(GL_VENDOR)); - DEER_CORE_TRACE("Initialized glad"); } void OpenGLContext::swapBuffers() { diff --git a/Deer/src/Plattform/OpenGL/OpenGLShader.cpp b/Deer/src/Plattform/OpenGL/OpenGLShader.cpp index fb19634..0e90119 100755 --- a/Deer/src/Plattform/OpenGL/OpenGLShader.cpp +++ b/Deer/src/Plattform/OpenGL/OpenGLShader.cpp @@ -210,7 +210,7 @@ namespace Deer { // Either of them. Don't leak shaders. glDeleteShader(vertexShader); - DEER_CORE_INFO(source); + DEER_CORE_TRACE(source); // Use the infoLog as you see fit. DEER_CORE_ERROR("Error compiling fragment shader. \n{0}", infoLog); diff --git a/DeerStudio/Build.lua b/DeerStudio/Build.lua index b7dd8bd..d465328 100755 --- a/DeerStudio/Build.lua +++ b/DeerStudio/Build.lua @@ -17,7 +17,8 @@ project "DeerStudio" "../Deer/vendor/imgui", "../Deer/vendor/glm", "../Deer/vendor/ImGuizmo", - "../Deer/vendor/entt/include" + "../Deer/vendor/entt/include", + "../Deer/vendor/angelScript/include" } links diff --git a/DeerStudio/src/DeerStudio/DeerStudio.cpp b/DeerStudio/src/DeerStudio/DeerStudio.cpp index 444091a..c6b9c6a 100755 --- a/DeerStudio/src/DeerStudio/DeerStudio.cpp +++ b/DeerStudio/src/DeerStudio/DeerStudio.cpp @@ -8,12 +8,11 @@ #include "Deer/Voxel.h" #include "Deer/VoxelWorld.h" #include "DeerRender/Mesh.h" -#include "DeerRender/UIEngine.h" +#include "DeerStudio/EditorEngine.h" #include "DeerStudio/Editor/Fonts.h" #include "DeerStudio/Editor/GamePanel.h" #include "DeerStudio/Editor/Icons.h" -#include "DeerStudio/Editor/MeshExplorer/MeshExplorer.h" #include "DeerStudio/Editor/PropertiesPanel.h" #include "DeerStudio/Editor/SceneExplorer.h" #include "DeerStudio/Editor/Terrain/TerrainEditor.h" @@ -31,7 +30,7 @@ namespace Deer { DataStore::loadVoxelsData(); DataStore::loadVoxelsAspect(); - UIEngine::initialize(); + EditorEngine::initialize(); return 0; } @@ -78,7 +77,7 @@ namespace Deer { ScriptEngine::shutdownScriptEngine(); Panels.clear(); - UIEngine::deinitialize(); + EditorEngine::deinitialize(); } void DeerStudioApplication::onRender(Timestep delta) { @@ -145,11 +144,9 @@ namespace Deer { } // ---- PanelS ----- - // sceneExplorer_onImGUI(); - UIEngine::execute(); + EditorEngine::execute(); TreePanel::onImgui(); PropertiesPanel::onImgui(); - MeshExplorer::onImGui(); TerrainEditor::onImGui(); viewport_onImGui(); // ---- PanelS ----- @@ -228,7 +225,7 @@ namespace Deer { if (ImGui::BeginMenu("Interface")) { if (ImGui::MenuItem("Reload interface")) { - UIEngine::initialize(); + EditorEngine::initialize(); } ImGui::EndMenu(); } diff --git a/DeerStudio/src/DeerStudio/DeerStudio.h b/DeerStudio/src/DeerStudio/DeerStudio.h index c916f80..ef34b09 100755 --- a/DeerStudio/src/DeerStudio/DeerStudio.h +++ b/DeerStudio/src/DeerStudio/DeerStudio.h @@ -7,6 +7,14 @@ #include "DeerStudio/Editor/ActiveEntity.h" #include "DeerStudio/Editor/EditorPanel.h" +#include + +class asIScriptEngine; +class asIScriptObject; +class asIScriptModule; +class asIScriptContext; + + namespace Deer { class DeerStudioApplication : public Deer::Application { public: diff --git a/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.cpp b/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.cpp deleted file mode 100644 index 670db41..0000000 --- a/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "MeshExplorer.h" - -#include "Deer/DataStore.h" -#include "Deer/Path.h" -#include "DeerStudio/Editor/EditorUtils.h" -#include "DeerStudio/Editor/Icons.h" -#include "imgui.h" - -namespace Deer { - namespace MeshExplorer { - Path m_meshExplorerPath(DEER_NULL_PATH); - void drawFolder(const Path& path); - } // namespace MeshExplorer - - void MeshExplorer::onImGui() { - if (m_meshExplorerPath == DEER_NULL_PATH) { - DataStore::createFolder(DataStore::rootPath / DEER_MESH_PATH); - m_meshExplorerPath = DEER_MESH_PATH; - } - - ImGui::Begin("Mesh Explorer", (bool*)0); // ImGuiWindowFlags_MenuBar - - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "%s", - m_meshExplorerPath.generic_string().c_str()); - - setupColumns(ICON_MIN_SIZE + 80); - - if (m_meshExplorerPath != DEER_MESH_PATH) { - drawFolder(".."); - - float cursorOffset = - (ICON_MIN_SIZE - ImGui::CalcTextSize("..").x) / 2; - ImGui::SetCursorPos(ImVec2(cursorOffset + ImGui::GetCursorPos().x, - ImGui::GetCursorPos().y)); - ImGui::Text(".."); - - ImGui::NextColumn(); - } - - for (const auto& entry : std::filesystem::directory_iterator( - DataStore::rootPath / m_meshExplorerPath)) { - if (entry.is_directory()) - drawFolder(entry.path()); - else { - } - - float cursorOffset = - (ICON_MIN_SIZE - - ImGui::CalcTextSize(entry.path().stem().string().c_str()).x) / - 2; - ImGui::SetCursorPos(ImVec2(cursorOffset + ImGui::GetCursorPos().x, - ImGui::GetCursorPos().y)); - ImGui::Text("%s", entry.path().stem().string().c_str()); - - ImGui::NextColumn(); - } - ImGui::Columns(); - ImGui::End(); - } - - void MeshExplorer::drawFolder(const Path& path) { - ImGui::Image((void*)(uint64_t)Icons::folder_icon->getTextureID(), - ImVec2(ICON_MIN_SIZE, ICON_MIN_SIZE), ImVec2(0, 1), - ImVec2(1, 0)); - - if (ImGui::IsItemClicked(0) && ImGui::IsMouseDoubleClicked(0)) { - if (path == "..") - m_meshExplorerPath = m_meshExplorerPath.parent_path(); - else - m_meshExplorerPath = path; - } - } -} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.h b/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.h deleted file mode 100644 index 3a0d3bd..0000000 --- a/DeerStudio/src/DeerStudio/Editor/MeshExplorer/MeshExplorer.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -namespace Deer { - namespace MeshExplorer { - void onImGui(); - } -} // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerRender/UIEngine/UIEngine.h b/DeerStudio/src/DeerStudio/EditorEngine.h similarity index 54% rename from Deer/src/DeerRender/UIEngine/UIEngine.h rename to DeerStudio/src/DeerStudio/EditorEngine.h index 63c9ff0..70b5f10 100644 --- a/Deer/src/DeerRender/UIEngine/UIEngine.h +++ b/DeerStudio/src/DeerStudio/EditorEngine.h @@ -1,15 +1,21 @@ #pragma once +#include #include class asIScriptEngine; -class asIScriptObject; class asIScriptModule; class asIScriptContext; namespace Deer { - namespace UIEngine { + // This namespace implements all interface ported from c++ ImGui to an easier lua aproach with simplifications + namespace EditorEngine { struct DockPanelObject; + void initialize(); + void deinitialize(); + + void execute(); + extern asIScriptEngine* scriptEngine; extern asIScriptModule* scriptModule; extern asIScriptContext* scriptContext; @@ -17,8 +23,13 @@ namespace Deer { extern DockPanelObject* currentDockPanelExecution; void loadScripts(); - void registerUIEngineFunctions(); + void registerEditorEngineFunctions(); + void registerEditorEngineStructs(); void registerDockPanel(); void extractDockPanels(); } + + namespace DataStore { + int getIconId(const std::string& name); + } } \ No newline at end of file diff --git a/Deer/src/DeerRender/UIEngine/Functions/UIEngine_ButtonFunctions.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Button.h similarity index 79% rename from Deer/src/DeerRender/UIEngine/Functions/UIEngine_ButtonFunctions.h rename to DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Button.h index 537ec6a..49c335a 100644 --- a/Deer/src/DeerRender/UIEngine/Functions/UIEngine_ButtonFunctions.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Button.h @@ -2,7 +2,7 @@ #include namespace Deer { - namespace UIEngine { + namespace EditorEngine { // TO IMPLEMENT bool button(std::string&); } diff --git a/Deer/src/DeerRender/UIEngine/Functions/UIEngine_ColumnFunctions.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Column.h similarity index 90% rename from Deer/src/DeerRender/UIEngine/Functions/UIEngine_ColumnFunctions.h rename to DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Column.h index 5735e0d..b9bc5b4 100644 --- a/Deer/src/DeerRender/UIEngine/Functions/UIEngine_ColumnFunctions.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Column.h @@ -1,7 +1,7 @@ #pragma once namespace Deer { - namespace UIEngine { + namespace EditorEngine { // Set up the colums to fit the pixelSize elements void setupAutomaticColumns(int pixelSize); // Iterates to the next column diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Directory.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Directory.h new file mode 100644 index 0000000..da650cb --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Directory.h @@ -0,0 +1,30 @@ +#pragma once +#include +#include + +namespace Deer { + namespace EditorEngine { + enum ResourceType : uint32_t { + NOTHING = 0, + MESH = 1 + }; + + // Returns the count of meshes in the dir relative to the mesh root dir + int getResourceCount(ResourceType, std::string& dir); + // Returns the path to the mesh with id i + std::string getResourceNameById(ResourceType, std::string& dir, int i); + // Returns the name of the mesh with id i + std::string getResourcePathById(ResourceType, std::string& dir, int i); + + // Returns the count of sub dirs in the dir relative to the mesh root dir + int getDirCount(ResourceType, std::string&); + // Returns the path to the subDir in the dir relative to the mesh root dir + std::string getDirPathById(ResourceType, std::string& dir, int i); + // Returns the name of the subDir in the dir relative to the mesh root dir + std::string getDirNameById(ResourceType, std::string& dir, int i); + + const char* getResourcePath(ResourceType); + const char* getResourceExtension(ResourceType); + const char* getResourceName(ResourceType); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Environment.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Environment.h new file mode 100644 index 0000000..e260116 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Environment.h @@ -0,0 +1,16 @@ +#pragma once +#include + +namespace Deer { + namespace EditorEngine { + struct EntityStruct { + uint16_t entityId; + }; + + EntityStruct getRoot(); + + int getChildCount(EntityStruct&); + EntityStruct getChild(EntityStruct&, int); + + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Functions.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Functions.h new file mode 100644 index 0000000..ce2a234 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Functions.h @@ -0,0 +1,11 @@ +#pragma once +#include + +class asSMessageInfo; +namespace Deer { + namespace EditorEngine { + void errorCallback(const asSMessageInfo *msg, void *param); + // Prints in console a mesage + void print(std::string& msg); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Icon.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Icon.h new file mode 100644 index 0000000..1bef780 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Icon.h @@ -0,0 +1,9 @@ +#pragma once +#include + +namespace Deer { + namespace EditorEngine { + void drawIcon(std::string& iconId, int size); + void drawIconCentered(std::string& iconId, int size); + } +} \ No newline at end of file diff --git a/Deer/src/DeerRender/UIEngine/Functions/UIEngine_InputFunctions.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Input.h similarity index 90% rename from Deer/src/DeerRender/UIEngine/Functions/UIEngine_InputFunctions.h rename to DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Input.h index 41b562d..2d2766a 100644 --- a/Deer/src/DeerRender/UIEngine/Functions/UIEngine_InputFunctions.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Input.h @@ -1,7 +1,7 @@ #pragma once namespace Deer { - namespace UIEngine { + namespace EditorEngine { // Returns if the specified mouse button is clicked on the last element bool isMouseClicked(int mouse); diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h new file mode 100644 index 0000000..27a7e9e --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h @@ -0,0 +1,8 @@ +#pragma once +#include + +namespace Deer { + namespace EditorEngine { + bool menuItem(std::string&); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Mesh.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Mesh.h new file mode 100644 index 0000000..b344d96 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Mesh.h @@ -0,0 +1,9 @@ +#pragma once +#include + +namespace Deer { + namespace EditorEngine { + + + } +} \ No newline at end of file diff --git a/Deer/src/DeerRender/UIEngine/Functions/UIEngine_TextFunctions.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Text.h similarity index 72% rename from Deer/src/DeerRender/UIEngine/Functions/UIEngine_TextFunctions.h rename to DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Text.h index ea5bf24..206e671 100644 --- a/Deer/src/DeerRender/UIEngine/Functions/UIEngine_TextFunctions.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_Text.h @@ -2,13 +2,16 @@ #include namespace Deer { - namespace UIEngine { - + namespace EditorEngine { + // Renders a text with the defined rgb values from range [0.0, 1.0] void textColor(float r, float g, float b, std::string& msg); // Renders a text void text(std::string& msg); + // Renders a text + void textCentered(std::string& msg); + } } \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h new file mode 100644 index 0000000..2eeeccb --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h @@ -0,0 +1,11 @@ +#pragma once +#include + +class asIScriptFunction; + +namespace Deer { + namespace EditorEngine { + void treeNode(std::string&); + void treeNode(std::string&, asIScriptFunction); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Button.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Button.cpp new file mode 100644 index 0000000..f7de871 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Button.cpp @@ -0,0 +1,11 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Button.h" +#include "imgui.h" +#include + +namespace Deer { + namespace EditorEngine { + bool button(std::string& txt) { + return ImGui::Button(txt.c_str()); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Column.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Column.cpp new file mode 100644 index 0000000..b9be098 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Column.cpp @@ -0,0 +1,28 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Column.h" +#include "imgui.h" + +namespace Deer { + namespace EditorEngine { + void setupAutomaticColumns(int pixelSize) { + float width = ImGui::GetWindowContentRegionWidth(); + + if (width < pixelSize) { + ImGui::Columns(); + return; + } + + int cols = (int)(width / (pixelSize)); + float componentWidth = width / (float)cols; + + ImGui::Columns(cols, 0, false); + } + + void endColumns() { + ImGui::Columns(); + } + + void nextColumn() { + ImGui::NextColumn(); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Directory.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Directory.cpp new file mode 100644 index 0000000..88ce34f --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Directory.cpp @@ -0,0 +1,195 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Directory.h" +#include "DeerStudio/EditorEngine.h" +#include "Deer/DataStore.h" +#include "DeerStudio/EditorEngine/DockPanelObject.h" +#include "Deer/Log.h" + +namespace Deer { + namespace EditorEngine { + + const char* getResourcePath(ResourceType resource) { + switch (resource) + { + case ResourceType::NOTHING: + return nullptr; + + case ResourceType::MESH : + return DEER_MESH_PATH; + } + + return nullptr; + } + + const char* getResourceExtension(ResourceType resource) { + switch (resource) + { + case ResourceType::NOTHING: + return nullptr; + + case ResourceType::MESH : + return ".dmesh"; + } + + return nullptr; + } + + const char* getResourceName(ResourceType resource) { + switch (resource) + { + case ResourceType::NOTHING: + return "???"; + + case ResourceType::MESH : + return "Mesh"; + } + + return nullptr; + } + + int getResourceCount(ResourceType type, std::string& dir) { + const char* resourcePath = getResourcePath(type); + const char* resourceExtension = getResourceExtension(type); + + if (!resourcePath || !resourceExtension) { + DEER_UI_ENGINE_ERROR("Invalid resource type calling getResourceCount(..)"); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return 0; + } + + return DataStore::getDirData(resourcePath, dir, resourceExtension).elements.size(); + } + + std::string getResourceNameById(ResourceType type, std::string& dir, int i) { + const char* resourcePath = getResourcePath(type); + const char* resourceExtension = getResourceExtension(type); + + if (!resourcePath || !resourceExtension) { + DEER_UI_ENGINE_ERROR("Invalid resource type calling getResourceNameById(..)"); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return ""; + } + + const DirectoryData& dirData = DataStore::getDirData(resourcePath, dir, resourceExtension); + if (i < 0 || i >= dirData.elements.size()) { + DEER_UI_ENGINE_ERROR("Invalid element id {3} calling getResourceNameById(..) for type {0} and path {1}, element count on that dir is {2}", + getResourceName(type), + dir.c_str(), + dirData.elements.size(), + i + ); + + if (currentDockPanelExecution) + currentDockPanelExecution->invalidate(); + return ""; + } + + return dirData.elements[i].stem().string(); + } + + std::string getResourcePathById(ResourceType type, std::string& dir, int i) { + const char* resourcePath = getResourcePath(type); + const char* resourceExtension = getResourceExtension(type); + + if (!resourcePath || !resourceExtension) { + DEER_UI_ENGINE_ERROR("Invalid resource type calling getResourcePathById(..)"); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return ""; + } + + const DirectoryData& dirData = DataStore::getDirData(resourcePath, dir, resourceExtension); + if (i < 0 || i >= dirData.elements.size()) { + DEER_UI_ENGINE_ERROR("Invalid element id {3} calling getResourcePathById(..) for type {0} and path {1}, element count on that dir is {2}", + getResourceName(type), + dir.c_str(), + dirData.elements.size(), + i + ); + + if (currentDockPanelExecution) + currentDockPanelExecution->invalidate(); + return ""; + } + + return dirData.elements[i].string(); + } + + int getDirCount(ResourceType type, std::string& dir) { + const char* resourcePath = getResourcePath(type); + const char* resourceExtension = getResourceExtension(type); + + if (!resourcePath || !resourceExtension) { + DEER_UI_ENGINE_ERROR("Invalid resource type calling getDirCount(..)"); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return 0; + } + + return DataStore::getDirData(resourcePath, dir, resourceExtension).dirs.size(); + } + + std::string getDirPathById(ResourceType type, std::string& dir, int i) { + const char* resourcePath = getResourcePath(type); + const char* resourceExtension = getResourceExtension(type); + + if (!resourcePath || !resourceExtension) { + DEER_UI_ENGINE_ERROR("Invalid resource type calling getDirPathById(..)"); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return ""; + } + + const DirectoryData& dirData = DataStore::getDirData(resourcePath, dir, resourceExtension); + if (i < 0 || i >= dirData.dirs.size()) { + DEER_UI_ENGINE_ERROR("Invalid element id {3} calling getDirPathById(..) for type {0} and path {1}, sub_dir count on that dir is {2}", + getResourceName(type), + dir.c_str(), + dirData.dirs.size(), + i) + ; + + if (currentDockPanelExecution) + currentDockPanelExecution->invalidate(); + return ""; + } + + return dirData.dirs[i].string(); + } + + std::string getDirNameById(ResourceType type, std::string& dir, int i) { + const char* resourcePath = getResourcePath(type); + const char* resourceExtension = getResourceExtension(type); + + if (!resourcePath || !resourceExtension) { + DEER_UI_ENGINE_ERROR("Invalid resource type calling getDirNameById(..)"); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return ""; + } + + const DirectoryData& dirData = DataStore::getDirData(resourcePath, dir, resourceExtension); + if (i < 0 || i >= dirData.dirs.size()) { + DEER_UI_ENGINE_ERROR("Invalid element id {3} calling getDirPathById(..) for type {0} and path {1}, sub_dir count on that dir is {2}", + getResourceName(type), + dir.c_str(), + dirData.dirs.size(), + i + ); + + if (currentDockPanelExecution) + currentDockPanelExecution->invalidate(); + return ""; + } + + return dirData.dirs[i].stem().string(); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Environment.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Environment.cpp new file mode 100644 index 0000000..a3f67dc --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Environment.cpp @@ -0,0 +1,7 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Environment.h" + +namespace Deer { + namespace EditorEngine { + + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Functions.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Functions.cpp new file mode 100644 index 0000000..5b841ea --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Functions.cpp @@ -0,0 +1,23 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Functions.h" +#include "Deer/Log.h" + +#include "angelscript.h" +#include "imgui.h" + +namespace Deer { + namespace EditorEngine { + + void errorCallback(const asSMessageInfo *msg, void *param) { + if (msg->type == asMSGTYPE_WARNING) { + DEER_UI_ENGINE_WARN("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message); + } else if( msg->type == asMSGTYPE_INFORMATION ) { + DEER_UI_ENGINE_ERROR("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message); + } + } + + void print(std::string& msg) { + DEER_UI_ENGINE_INFO("{0}", msg.c_str()); + } + + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Icon.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Icon.cpp new file mode 100644 index 0000000..dfad7da --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Icon.cpp @@ -0,0 +1,51 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Icon.h" +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/DockPanelObject.h" +#include "Deer/Log.h" +#include "Deer/DataStore.h" +#include "imgui.h" + +namespace Deer { + namespace EditorEngine { + void drawIcon(std::string& name, int size) { + int iconId = DataStore::getIconId(name); + + if (iconId < 0) { + DEER_UI_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return; + } + + ImGui::Image((void*)(uint64_t)iconId, + ImVec2(size, size), ImVec2(0, 1), + ImVec2(1, 0)); + } + + void drawIconCentered(std::string& name, int size) { + int iconId = DataStore::getIconId(name); + if (iconId < 0) { + DEER_UI_ENGINE_ERROR("Invalid icon name {0}", name.c_str()); + if (currentDockPanelExecution) { + currentDockPanelExecution->invalidate(); + } + return; + } + + float sizeX; + if (ImGui::GetColumnsCount() > 1) + sizeX = ImGui::GetColumnWidth(-1); + else + sizeX = ImGui::GetContentRegionAvail().x; + + float iconWidth = size; + float padding = (sizeX - iconWidth) * 0.5f; + + if (padding > 0.0f) + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); + + drawIcon(name, size); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Input.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Input.cpp new file mode 100644 index 0000000..6a2d661 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Input.cpp @@ -0,0 +1,14 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Input.h" +#include "imgui.h" + +namespace Deer { + namespace EditorEngine { + bool isMouseClicked(int mouse) { + return ImGui::IsItemClicked(mouse); + } + + bool isMouseDoubleClicked(int mouse) { + return ImGui::IsMouseDoubleClicked(mouse); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_MenuBar.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_MenuBar.cpp new file mode 100644 index 0000000..4d788c9 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_MenuBar.cpp @@ -0,0 +1,10 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h" +#include "imgui.h" + +namespace Deer { + namespace EditorEngine { + bool menuItem(std::string& txt) { + return ImGui::MenuItem(txt.c_str()); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Mesh.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Mesh.cpp new file mode 100644 index 0000000..f13e5db --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Mesh.cpp @@ -0,0 +1,8 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Mesh.h" + +namespace Deer { + namespace EditorEngine { + + + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Text.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Text.cpp new file mode 100644 index 0000000..318f296 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_Text.cpp @@ -0,0 +1,30 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Text.h" +#include "imgui.h" + +namespace Deer { + namespace EditorEngine { + void textColor(float r, float g, float b, std::string& msg) { + ImGui::TextColored(ImVec4(r, g, b, 1.0f), "%s", msg.c_str()); + } + + void text(std::string& msg) { + ImGui::Text("%s", msg.c_str()); + } + + void textCentered(std::string& msg) { + float sizeX; + if (ImGui::GetColumnsCount() > 1) + sizeX = ImGui::GetColumnWidth(-1); + else + sizeX = ImGui::GetContentRegionAvail().x; + + float textWidth = ImGui::CalcTextSize(msg.c_str(), nullptr, false).x; + float padding = (sizeX - textWidth) * 0.5f; + + if (padding > 0.0f) + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + padding); + + ImGui::Text("%s", msg.c_str()); + } + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_TreeNode.cpp b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_TreeNode.cpp new file mode 100644 index 0000000..8cc5b6f --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/API_Implementation/EditorEngine_TreeNode.cpp @@ -0,0 +1,35 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_TreeNode.h" +#include "DeerStudio/EditorEngine.h" +#include "angelscript.h" +#include "imgui.h" + +namespace Deer { + namespace EditorEngine { + void treeNode(std::string& txt) { + ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf | + ImGuiTreeNodeFlags_NoTreePushOnOpen | + ImGuiTreeNodeFlags_SpanFullWidth; + + ImGui::TreeNodeEx((void*)0, flags, "%s", txt.c_str()); + } + + void treeNode(std::string& txt, asIScriptFunction& func) { + ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnDoubleClick | + ImGuiTreeNodeFlags_OpenOnArrow | + ImGuiTreeNodeFlags_SpanFullWidth; + + if (ImGui::TreeNodeEx((void*)0, flags, "%s", txt.c_str())) { + + if (scriptContext && scriptContext->PushState() == asSUCCESS) { + + + scriptContext->PopState(); + } else { + ImGui::Text("Something failed"); + } + + ImGui::TreePop(); + } + } + } +} \ No newline at end of file diff --git a/Deer/src/DeerRender/UIEngine/DockPanelObject.cpp b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp similarity index 55% rename from Deer/src/DeerRender/UIEngine/DockPanelObject.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp index 385bc26..27f0131 100644 --- a/Deer/src/DeerRender/UIEngine/DockPanelObject.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.cpp @@ -1,6 +1,8 @@ -#include "DeerRender/UIEngine/DockPanelObject.h" -#include "DeerRender/UIEngine/UIEngine.h" -#include "DeerRender/UIEngine/UIEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine/DockPanelObject.h" +#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine.h" + +#include "Deer/Log.h" #include "angelscript.h" #include @@ -8,7 +10,7 @@ #include "imgui.h" namespace Deer { - UIEngine::DockPanelObject::DockPanelObject(asITypeInfo* _type) + EditorEngine::DockPanelObject::DockPanelObject(asITypeInfo* _type) : type (_type), isValid(false) { // Constructor @@ -44,19 +46,52 @@ namespace Deer { return; } + menuBarFunction = type->GetMethodByDecl("void onMenuBar()"); + isValid = true; } - UIEngine::DockPanelObject::~DockPanelObject() { + EditorEngine::DockPanelObject::~DockPanelObject() { if (object) object->Release(); } - void UIEngine::DockPanelObject::executeRender() { - ImGui::Begin(type->GetName()); + void EditorEngine::DockPanelObject::invalidate() { + DEER_UI_ENGINE_ERROR("Last error was caused executing {0}", type->GetName()); + isValid = false; + } + + void EditorEngine::DockPanelObject::executeRender() { + if (menuBarFunction) { + ImGui::Begin(type->GetName(), (bool*)0, ImGuiWindowFlags_MenuBar); + + if (ImGui::BeginMenuBar()) { + AS_CHECK_ADDITIONAL_INFO( + scriptContext->Prepare(menuBarFunction), + type->GetName() + ); + + AS_CHECK_ADDITIONAL_INFO( + scriptContext->SetObject(object), + type->GetName() + ); + + AS_CHECK_ADDITIONAL_INFO( + scriptContext->Execute(), + type->GetName() + ); + + ImGui::EndMenuBar(); + } + } else { + ImGui::Begin(type->GetName()); + } + if (!isValid) { - ImGui::TextColored(ImVec4(1, 0.3f, 0.3f, 1), "There was an error, please check the logs or reload the interface"); + ImGui::TextColored(ImVec4(1, 0.3f, 0.3f, 1), "There was a runtime error"); + ImGui::TextColored(ImVec4(1, 0.4f, 0.4f, 1), "Please check the log"); + ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1), "Plese restart the interface"); ImGui::End(); return; } @@ -79,28 +114,32 @@ namespace Deer { ImGui::End(); } - UIEngine::DockPanelObject::DockPanelObject(DockPanelObject&& other) noexcept - : isValid(other.isValid), renderFunction(other.renderFunction), type(other.type), object(other.object) { + EditorEngine::DockPanelObject::DockPanelObject(DockPanelObject&& other) noexcept + : isValid(other.isValid), renderFunction(other.renderFunction), type(other.type), object(other.object), menuBarFunction(other.menuBarFunction) { other.isValid = false; other.renderFunction = nullptr; other.type = nullptr; other.object = nullptr; + other.menuBarFunction = nullptr; } - UIEngine::DockPanelObject& UIEngine::DockPanelObject::operator=(UIEngine::DockPanelObject&& other) noexcept { + EditorEngine::DockPanelObject& EditorEngine::DockPanelObject::operator=(EditorEngine::DockPanelObject&& other) noexcept { if (this != &other) { isValid = other.isValid; renderFunction = other.renderFunction; type = other.type; object = other.object; + menuBarFunction = other.menuBarFunction; other.isValid = false; other.renderFunction = nullptr; other.type = nullptr; other.object = nullptr; + other.menuBarFunction = nullptr; } return *this; } + } \ No newline at end of file diff --git a/Deer/src/DeerRender/UIEngine/DockPanelObject.h b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.h similarity index 86% rename from Deer/src/DeerRender/UIEngine/DockPanelObject.h rename to DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.h index aaa52ae..ff7a626 100644 --- a/Deer/src/DeerRender/UIEngine/DockPanelObject.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/DockPanelObject.h @@ -4,14 +4,14 @@ class asIScriptObject; class asIScriptFunction; namespace Deer { - namespace UIEngine { + namespace EditorEngine { struct DockPanelObject { private: asITypeInfo* type = nullptr; asIScriptObject* object = nullptr; asIScriptFunction* renderFunction = nullptr; + asIScriptFunction* menuBarFunction = nullptr; bool isValid = false; - public: DockPanelObject(asITypeInfo*); @@ -22,9 +22,9 @@ namespace Deer { DockPanelObject(DockPanelObject&& other) noexcept; DockPanelObject& operator=(DockPanelObject&& other) noexcept; - + void executeRender(); - inline void invalidate() { isValid = false; } + void invalidate(); }; } } \ No newline at end of file diff --git a/Deer/src/DeerRender/UIEngine/UIEngine.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp similarity index 72% rename from Deer/src/DeerRender/UIEngine/UIEngine.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp index f7a943c..04be179 100644 --- a/Deer/src/DeerRender/UIEngine/UIEngine.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine.cpp @@ -1,8 +1,8 @@ -#include "DeerRender/UIEngine.h" -#include "DeerRender/UIEngine/UIEngine_ErrorHandle.h" -#include "DeerRender/UIEngine/UIEngine_Functions.h" -#include "DeerRender/UIEngine/UIEngine.h" -#include "DeerRender/UIEngine/DockPanelObject.h" +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Functions.h" +#include "DeerStudio/EditorEngine/DockPanelObject.h" +#include "DeerStudio/EditorEngine.h" #include "Deer/Log.h" #include @@ -12,7 +12,7 @@ #include "scriptstdstring.h" namespace Deer { - namespace UIEngine { + namespace EditorEngine { asIScriptEngine* scriptEngine = nullptr; asIScriptModule* scriptModule = nullptr; asIScriptContext* scriptContext = nullptr; @@ -23,7 +23,7 @@ namespace Deer { bool active = false; } - void UIEngine::initialize() { + void EditorEngine::initialize() { int err = 0; // If it exist we will reload it @@ -32,9 +32,10 @@ namespace Deer { scriptEngine = asCreateScriptEngine(); RegisterStdString(scriptEngine); - AS_RET_CHECK(scriptEngine->SetMessageCallback(asFUNCTION(Deer::UIEngine::errorCallback), 0, asCALL_CDECL)); + AS_RET_CHECK(scriptEngine->SetMessageCallback(asFUNCTION(Deer::EditorEngine::errorCallback), 0, asCALL_CDECL)); - registerUIEngineFunctions(); + registerEditorEngineStructs(); + registerEditorEngineFunctions(); registerDockPanel(); loadScripts(); @@ -46,7 +47,7 @@ namespace Deer { active = true; } - void UIEngine::deinitialize() { + void EditorEngine::deinitialize() { dockPanels.clear(); if (scriptContext) @@ -61,7 +62,7 @@ namespace Deer { active = false; } - void UIEngine::execute() { + void EditorEngine::execute() { if (!active) return; diff --git a/Deer/src/DeerRender/UIEngine/UIEngine_ErrorHandle.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.cpp similarity index 96% rename from Deer/src/DeerRender/UIEngine/UIEngine_ErrorHandle.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.cpp index e1e72d1..7df0652 100644 --- a/Deer/src/DeerRender/UIEngine/UIEngine_ErrorHandle.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.cpp @@ -1,9 +1,9 @@ -#include "DeerRender/UIEngine/UIEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" #include "angelscript.h" namespace Deer { - namespace UIEngine { + namespace EditorEngine { const char* getAngelScriptReturnCodeString(int code) { switch (code) diff --git a/Deer/src/DeerRender/UIEngine/UIEngine_ErrorHandle.h b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h similarity index 69% rename from Deer/src/DeerRender/UIEngine/UIEngine_ErrorHandle.h rename to DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h index dc74d45..e35d93b 100644 --- a/Deer/src/DeerRender/UIEngine/UIEngine_ErrorHandle.h +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h @@ -1,9 +1,9 @@ #pragma once #include "Deer/Log.h" -#include +#include "angelscript.h" namespace Deer { - namespace UIEngine { + namespace EditorEngine { const char* getAngelScriptReturnCodeString(int code); } } @@ -11,19 +11,19 @@ namespace Deer { #define AS_CHECK(f) { \ int __r = f; \ if (__r < 0) { \ - DEER_UI_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::UIEngine::getAngelScriptReturnCodeString(__r)); \ + DEER_UI_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::EditorEngine::getAngelScriptReturnCodeString(__r)); \ } \ } #define AS_CHECK_ADDITIONAL_INFO(f, i) { \ int __r = f; \ if (__r < 0) { \ - DEER_UI_ENGINE_ERROR("Error at line: {0}:{1} -> {2} \n {3}", __FILE__, __LINE__, Deer::UIEngine::getAngelScriptReturnCodeString(__r), i); \ + DEER_UI_ENGINE_ERROR("Error at line: {0}:{1} -> {2} \n {3}", __FILE__, __LINE__, Deer::EditorEngine::getAngelScriptReturnCodeString(__r), i); \ } \ } #define AS_RET_CHECK(f) { \ int __r = f; \ if (__r < 0) { \ - DEER_UI_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::UIEngine::getAngelScriptReturnCodeString(__r)); \ + DEER_UI_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::EditorEngine::getAngelScriptReturnCodeString(__r)); \ return; \ } \ } diff --git a/Deer/src/DeerRender/UIEngine/UIEngine_IconManagment.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_IconManagment.cpp similarity index 82% rename from Deer/src/DeerRender/UIEngine/UIEngine_IconManagment.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_IconManagment.cpp index 13aa560..940ce3a 100644 --- a/Deer/src/DeerRender/UIEngine/UIEngine_IconManagment.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_IconManagment.cpp @@ -1,4 +1,4 @@ -#include "DeerRender/UIEngine.h" +#include "DeerStudio/EditorEngine.h" #include "DeerRender/Render/Texture.h" #include "Deer/DataStore.h" @@ -16,7 +16,7 @@ namespace Deer { uint8_t* data; uint32_t size; - if (!DataStore::loadGlobalFileData(DEER_UI_ICON_PATH, name, &data, &size)) + if (!DataStore::loadGlobalFileData(DEER_EDITOR_PATH, name, &data, &size)) return -1; icons[name] = Texture2D::create(data, size); diff --git a/Deer/src/DeerRender/UIEngine/UIEngine_LoadPanels.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadPanels.cpp similarity index 77% rename from Deer/src/DeerRender/UIEngine/UIEngine_LoadPanels.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadPanels.cpp index 9a0ef86..82ec7cc 100644 --- a/Deer/src/DeerRender/UIEngine/UIEngine_LoadPanels.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadPanels.cpp @@ -1,16 +1,16 @@ #include "angelscript.h" -#include "DeerRender/UIEngine/UIEngine.h" -#include "DeerRender/UIEngine/DockPanelObject.h" -#include "DeerRender/UIEngine/UIEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/DockPanelObject.h" +#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" namespace Deer { - void UIEngine::registerDockPanel() { + void EditorEngine::registerDockPanel() { AS_RET_CHECK(scriptEngine->RegisterInterface("DockPanel")); AS_RET_CHECK(scriptEngine->RegisterInterfaceMethod("DockPanel", "void onRender()")); } - void UIEngine::extractDockPanels() { + void EditorEngine::extractDockPanels() { size_t nScripts = scriptModule->GetObjectTypeCount(); asITypeInfo* dockPanelType = scriptEngine->GetTypeInfoByName("DockPanel"); diff --git a/Deer/src/DeerRender/UIEngine/UIEngine_LoadScripts.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadScripts.cpp similarity index 70% rename from Deer/src/DeerRender/UIEngine/UIEngine_LoadScripts.cpp rename to DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadScripts.cpp index 2f4335e..c3bea56 100644 --- a/Deer/src/DeerRender/UIEngine/UIEngine_LoadScripts.cpp +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_LoadScripts.cpp @@ -1,5 +1,5 @@ -#include "DeerRender/UIEngine/UIEngine.h" -#include "DeerRender/UIEngine/UIEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" #include "Deer/Path.h" #include "Deer/DataStore.h" @@ -15,16 +15,16 @@ namespace fs = std::filesystem; namespace Deer { - void UIEngine::loadScripts() { - Path path = DataStore::rootPath / DEER_UI_SCRIPT_PATH; + void EditorEngine::loadScripts() { + Path path = DataStore::rootPath / DEER_EDITOR_PATH; CScriptBuilder builder; AS_RET_CHECK(builder.StartNewModule(scriptEngine, "DeerModule")); - DEER_UI_ENGINE_INFO("=== Extracting UI Engine Scripts ==="); + DEER_CORE_TRACE("Extracting UI Engine Scripts "); for (const auto& entry : fs::recursive_directory_iterator(path)) { if (entry.is_regular_file() && entry.path().extension() == ".as") { - DEER_UI_ENGINE_TRACE("\t{0}", entry.path().stem().string().c_str()); + //DEER_UI_ENGINE_TRACE("\t{0}", entry.path().stem().string().c_str()); // We add aditional info to check who caused the error AS_CHECK_ADDITIONAL_INFO( builder.AddSectionFromFile(entry.path().string().c_str());, diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterFunctions.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterFunctions.cpp new file mode 100644 index 0000000..3e40754 --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterFunctions.cpp @@ -0,0 +1,135 @@ +#include "DeerStudio/EditorEngine/API/EditorEngine_Functions.h" +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Button.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Column.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Directory.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Environment.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Environment.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Functions.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Functions.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Icon.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Input.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Mesh.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Text.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_MenuBar.h" + +#include "angelscript.h" + +namespace Deer { + void EditorEngine::registerEditorEngineFunctions() { + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool menuItem(const string& in)", + asFUNCTION(Deer::EditorEngine::menuItem), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void textColor(float, float, float, const string& in)", + asFUNCTION(Deer::EditorEngine::textColor), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void text(const string& in)", + asFUNCTION(text), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void drawIcon(const string& in, int)", + asFUNCTION(Deer::EditorEngine::drawIcon), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool isMouseClicked(int)", + asFUNCTION( + isMouseClicked + ), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "bool isMouseDoubleClicked(int)", + asFUNCTION( + isMouseDoubleClicked + ), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void setupAutomaticColumns(int)", + asFUNCTION( + setupAutomaticColumns + ), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void endColumns()", + asFUNCTION(endColumns), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void nextColumn()", + asFUNCTION(nextColumn), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void print(const string& in)", + asFUNCTION (Deer::EditorEngine::print), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void textCentered(const string& in)", + asFUNCTION(Deer::EditorEngine::textCentered), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "void drawIconCentered(const string& in, int)", + asFUNCTION(Deer::EditorEngine::drawIconCentered), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "int getResourceCount(ResourceType, const string& in)", + asFUNCTION(Deer::EditorEngine::getResourceCount), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "string getResourceNameById(ResourceType, const string& in, int)", + asFUNCTION(Deer::EditorEngine::getResourceNameById), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "string getResourcePathById(ResourceType, const string& in, int)", + asFUNCTION(Deer::EditorEngine::getResourcePathById), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "int getDirCount(ResourceType, const string& in)", + asFUNCTION(Deer::EditorEngine::getDirCount), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "string getDirPathById(ResourceType, const string& in, int)", + asFUNCTION(Deer::EditorEngine::getDirPathById), + asCALL_CDECL + )); + + AS_CHECK(scriptEngine->RegisterGlobalFunction( + "string getDirNameById(ResourceType, const string& in, int)", + asFUNCTION(Deer::EditorEngine::getDirNameById), + asCALL_CDECL + )); + } +} \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterStructs.cpp b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterStructs.cpp new file mode 100644 index 0000000..4d0bb5d --- /dev/null +++ b/DeerStudio/src/DeerStudio/EditorEngine/EditorEngine_RegisterStructs.cpp @@ -0,0 +1,25 @@ +#include "DeerStudio/EditorEngine.h" +#include "DeerStudio/EditorEngine/EditorEngine_ErrorHandle.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Mesh.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Environment.h" +#include "DeerStudio/EditorEngine/API/EditorEngine_Directory.h" +#include "angelscript.h" + +namespace Deer { + namespace EditorEngine { + void registerResourceTypeEnum() { + AS_RET_CHECK(scriptEngine->RegisterEnum("ResourceType")); + AS_CHECK(scriptEngine->RegisterEnumValue("ResourceType", "Mesh", (int)ResourceType::MESH)); + } + + void registerEntityStruct() { + AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityStruct), + asOBJ_VALUE | asOBJ_POD | asGetTypeTraits())); + + } + + void registerEditorEngineStructs() { + registerResourceTypeEnum(); + } + } +} \ No newline at end of file diff --git a/roe/editor/mesh_explorer/mesh_explorer.as b/roe/editor/mesh_explorer/mesh_explorer.as new file mode 100644 index 0000000..72cc309 --- /dev/null +++ b/roe/editor/mesh_explorer/mesh_explorer.as @@ -0,0 +1,42 @@ + +class MeshExplorer : DockPanel { + string currentPath = ""; + + void onRender() { + setupAutomaticColumns(128); + + // To avoid problems we will cache the current path + const string cache_currentPath = currentPath; + if (cache_currentPath != "") { + drawIconCentered("folder", 64); + if (isMouseClicked(0) and isMouseDoubleClicked(0)) { + currentPath = ""; + } + textCentered(cache_currentPath + "/.."); + nextColumn(); + } + + ResourceType resourceType = ResourceType::Mesh; + int dirCount = getDirCount(resourceType, cache_currentPath); + for (int i = 0; i < dirCount; i++) { + drawIconCentered("folder", 64); + + if (isMouseClicked(0) and isMouseDoubleClicked(0)) { + print(getDirPathById(ResourceType::Mesh, cache_currentPath, i)); + currentPath = getDirPathById(ResourceType::Mesh, cache_currentPath, i); + } + + textCentered(getDirNameById(ResourceType::Mesh, cache_currentPath, i)); + nextColumn(); + } + + int meshCount = getResourceCount(ResourceType::Mesh, cache_currentPath); + for (int i = 0; i < meshCount; i++) { + drawIconCentered("file", 64); + + textCentered(getResourceNameById(ResourceType::Mesh, cache_currentPath, i)); + nextColumn(); + } + endColumns(); + } +} \ No newline at end of file diff --git a/roe/editor/mesh_explorer/mesh_searcher.as b/roe/editor/mesh_explorer/mesh_searcher.as deleted file mode 100644 index 72dc979..0000000 --- a/roe/editor/mesh_explorer/mesh_searcher.as +++ /dev/null @@ -1,28 +0,0 @@ - -class MeshExplorer : DockPanel { - string currentPath = ""; - - void onRender() { - textColor(0.5, 0.5, 0.5, currentPath); - - setupAutomaticColumns(180); - - int dirCount = getMeshDirCount(currentPath); - for (int i = 0; i < dirCount; i++) { - - drawIcon("folder", 64); - text(getMeshDirName(currentPath, i)); - - nextColumn(); - } - - int meshCount = getMeshCount(currentPath); - for (int i = 0; i < meshCount; i++) { - drawIcon("file", 64); - text(getMeshName(currentPath, i)); - - nextColumn(); - } - endColumns(); - } -} \ No newline at end of file diff --git a/roe/editor/tree_pannel/tree_pannel.as b/roe/editor/tree_pannel/tree_pannel.as new file mode 100644 index 0000000..3e5e6ed --- /dev/null +++ b/roe/editor/tree_pannel/tree_pannel.as @@ -0,0 +1,16 @@ +class TreePannel : DockPanel { + void onMenuBar() { + if (menuItem("Hey!")) { + print("clicked"); + } + } + + void onRender() { + root = getRoot(); + renderEntity(root); + } + + void renderEntity(Entity entity) { + + } +} \ No newline at end of file diff --git a/roe/imgui.ini b/roe/imgui.ini index e816ef4..114e719 100644 --- a/roe/imgui.ini +++ b/roe/imgui.ini @@ -10,31 +10,31 @@ Collapsed=0 [Window][Properties] Pos=968,24 -Size=312,214 +Size=312,110 Collapsed=0 DockId=0x00000009,0 [Window][Game Window] Pos=304,24 -Size=662,368 +Size=662,392 Collapsed=0 DockId=0x00000006,1 [Window][Tree Panel] Pos=0,24 -Size=302,368 +Size=302,392 Collapsed=0 DockId=0x00000005,0 [Window][Terrain Editor] -Pos=968,240 -Size=312,152 +Pos=968,136 +Size=312,280 Collapsed=0 DockId=0x0000000A,0 [Window][Viewport] Pos=304,24 -Size=662,368 +Size=662,392 Collapsed=0 DockId=0x00000006,0 @@ -45,8 +45,8 @@ Collapsed=0 DockId=0x00000002,0 [Window][Mesh Explorer] -Pos=0,394 -Size=1280,326 +Pos=0,418 +Size=1280,302 Collapsed=0 DockId=0x00000008,0 @@ -57,21 +57,27 @@ Collapsed=0 DockId=0x00000008,1 [Window][MeshExplorer] -Pos=0,394 -Size=1280,326 +Pos=0,418 +Size=1280,302 Collapsed=0 -DockId=0x00000008,1 +DockId=0x00000008,0 + +[Window][TreePannel] +Pos=0,24 +Size=302,392 +Collapsed=0 +DockId=0x00000005,1 [Docking][Data] DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y - DockNode ID=0x00000007 Parent=0xA1672E74 SizeRef=1280,368 Split=Y + DockNode ID=0x00000007 Parent=0xA1672E74 SizeRef=1280,392 Split=Y DockNode ID=0x00000001 Parent=0x00000007 SizeRef=2560,363 Split=X Selected=0x13926F0B DockNode ID=0x00000003 Parent=0x00000001 SizeRef=966,779 Split=X Selected=0x13926F0B - DockNode ID=0x00000005 Parent=0x00000003 SizeRef=302,779 Selected=0xF278DC36 + DockNode ID=0x00000005 Parent=0x00000003 SizeRef=302,779 Selected=0xE45B9F93 DockNode ID=0x00000006 Parent=0x00000003 SizeRef=662,779 CentralNode=1 Selected=0x13926F0B DockNode ID=0x00000004 Parent=0x00000001 SizeRef=312,779 Split=Y Selected=0x199AB496 - DockNode ID=0x00000009 Parent=0x00000004 SizeRef=392,214 Selected=0x199AB496 - DockNode ID=0x0000000A Parent=0x00000004 SizeRef=392,152 Selected=0x2A2C795E + DockNode ID=0x00000009 Parent=0x00000004 SizeRef=392,110 Selected=0x199AB496 + DockNode ID=0x0000000A Parent=0x00000004 SizeRef=392,280 Selected=0x2A2C795E DockNode ID=0x00000002 Parent=0x00000007 SizeRef=2560,331 Selected=0xCF339702 - DockNode ID=0x00000008 Parent=0xA1672E74 SizeRef=1280,326 Selected=0xD962995A + DockNode ID=0x00000008 Parent=0xA1672E74 SizeRef=1280,302 Selected=0xD962995A