From 15cce7496f8707a5444d87837995d5b080b74772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89meryc?= Date: Sat, 15 Jul 2023 22:19:57 -0400 Subject: [PATCH] display wren script in properties --- Editor/src/Windows/EditorSelectionPanel.cpp | 22 +++++++++++++++++++-- Editor/src/Windows/EditorSelectionPanel.h | 3 ++- Nuake/src/Scripting/WrenScript.cpp | 5 +++++ Nuake/src/Scripting/WrenScript.h | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index 8409401b..194a5111 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include EditorSelectionPanel::EditorSelectionPanel() @@ -60,7 +61,7 @@ void EditorSelectionPanel::Draw(EditorSelection selection) ResolveFile(selection.File); } - DrawFile(selection.File.get()); + DrawFile(selection.File); break; } case EditorSelectionType::Resource: @@ -140,7 +141,7 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity) } -void EditorSelectionPanel::DrawFile(Nuake::File* file) +void EditorSelectionPanel::DrawFile(Ref file) { using namespace Nuake; if (file->GetExtension() == ".material") @@ -151,6 +152,10 @@ void EditorSelectionPanel::DrawFile(Nuake::File* file) { DrawProjectPanel(Nuake::Engine::GetProject()); } + if (file->GetExtension() == ".wren") + { + DrawWrenScriptPanel(CreateRef(file, true)); + } } void EditorSelectionPanel::DrawResource(Nuake::Resource resource) @@ -415,3 +420,16 @@ void EditorSelectionPanel::DrawProjectPanel(Ref project) ImGui::InputText("Trenchbroom Path", &project->TrenchbroomPath); } +void EditorSelectionPanel::DrawWrenScriptPanel(Ref wrenFile) +{ + auto filePath = wrenFile->GetFile()->GetAbsolutePath(); + std::string fileContent = Nuake::FileSystem::ReadFile(filePath, true); + + ImGui::Text("Content"); + ImGui::Separator(); + ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetWindowWidth()); + ImGui::Text(fileContent.c_str(), ImGui::GetWindowWidth()); + + ImGui::PopTextWrapPos(); +} + diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index ff19422a..52e71657 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -46,11 +46,12 @@ public: void DrawEntity(Nuake::Entity entity); void DrawAddComponentMenu(Nuake::Entity entity); - void DrawFile(Nuake::File* file); + void DrawFile(Ref file); void DrawResource(Nuake::Resource resource); private: void ResolveFile(Ref file); void DrawMaterialPanel(Ref material); void DrawProjectPanel(Ref project); + void DrawWrenScriptPanel(Ref wrenFile); }; \ No newline at end of file diff --git a/Nuake/src/Scripting/WrenScript.cpp b/Nuake/src/Scripting/WrenScript.cpp index aadb1d8a..61bacc56 100644 --- a/Nuake/src/Scripting/WrenScript.cpp +++ b/Nuake/src/Scripting/WrenScript.cpp @@ -164,6 +164,11 @@ namespace Nuake WrenInterpretResult result = wrenCall(vm, handle); } + Ref WrenScript::GetFile() const + { + return mFile; + } + void WrenScript::SetScriptableEntityID(int id) { if (!m_HasCompiledSuccesfully) diff --git a/Nuake/src/Scripting/WrenScript.h b/Nuake/src/Scripting/WrenScript.h index 7a5c5009..8a3d03e8 100644 --- a/Nuake/src/Scripting/WrenScript.h +++ b/Nuake/src/Scripting/WrenScript.h @@ -40,6 +40,7 @@ namespace Nuake void RegisterMethod(const std::string& signature); void CallMethod(const std::string& signature); + Ref GetFile() const; void SetScriptableEntityID(int id); bool HasCompiledSuccesfully() const { return m_HasCompiledSuccesfully; }