Merge branch 'develop' of https://github.com/antopilo/nuake into develop

This commit is contained in:
Antoine Pilote
2024-09-17 12:32:48 -04:00
34 changed files with 550 additions and 137 deletions

View File

@@ -65,7 +65,7 @@ namespace NuakeEditor
"packageformat": { "extension": ".zip", "format": "zip" }
},
"textures": {
"root": "textures",
"root": "Textures",
"extensions": [ ".jpg", ".png", ".tga" ]
},
"entities": {

View File

@@ -10,6 +10,8 @@
#include "src/UI/NuakeUI.h"
#include "src/UI/UIInputManager.h"
void EditorApplication::OnInit()
{
using namespace Nuake;
@@ -73,6 +75,13 @@ void EditorApplication::OnInit()
}
});
m_Window->SetOnDragNDropCallback([&](Window& window, const std::vector<std::string>& paths) {
for (auto& layer : m_LayerStack)
{
layer->OnDragNDrop(paths);
}
});
PushLayer(CreateScope<EditorLayer>());
}

View File

@@ -10,6 +10,15 @@
using namespace NuakeEditor;
class DragNDropModule : public Nuake::IApplicationModule
{
public:
void OnInit() override
{
}
};
class EditorApplication : public Nuake::Application
{
private:

View File

@@ -79,4 +79,9 @@ void EditorLayer::OnDetach()
void EditorLayer::OnWindowFocused()
{
m_EditorInterface->OnWindowFocused();
}
}
void EditorLayer::OnDragNDrop(const std::vector<std::string>& paths)
{
m_EditorInterface->OnDragNDrop(paths);
}

View File

@@ -23,6 +23,7 @@ public:
virtual void OnDetach() override;
virtual void OnWindowFocused() override;
virtual void OnDragNDrop(const std::vector<std::string>& paths) override;
private:
CommandBuffer mCommandBuffer;

View File

@@ -27,6 +27,7 @@
#include <DetourDebugDraw.h>
#include <src/Scene/Components/BSPBrushComponent.h>
GizmoDrawer::GizmoDrawer(EditorInterface* editor)
{
m_LineShader = Nuake::ShaderManager::GetShader("Resources/Shaders/line.shader");
@@ -222,6 +223,8 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
{
using namespace Nuake;
auto camView = scene->m_Registry.view<TransformComponent, CameraComponent>();
RenderCommand::Enable(RendererEnum::DEPTH_TEST);
glLineWidth(3.0f);
@@ -459,6 +462,24 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
for (auto e : camView)
{
auto [transform, camera] = scene->m_Registry.get<TransformComponent, CameraComponent>(e);
const Quat& globalRotation = glm::normalize(transform.GetGlobalRotation());
const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation);
m_LineShader->Bind();
m_LineShader->SetUniform("u_Opacity", 1.f);
const float aspectRatio = camera.CameraInstance->AspectRatio;
const float fov = camera.CameraInstance->Fov;
Matrix4 clampedPerspective = glm::perspectiveFov(glm::radians(fov), 9.0f * aspectRatio, 9.0f, 0.05f, 3.0f);
m_LineShader->SetUniform("u_View", glm::translate(scene->m_EditorCamera->GetTransform(), Vector3(transform.GetGlobalTransform()[3])) * rotationMatrix * glm::inverse(clampedPerspective));
m_LineShader->SetUniform("u_Projection", scene->m_EditorCamera->GetPerspective());
m_BoxBuffer->Bind();
Nuake::RenderCommand::DrawLines(0, 26);
}
auto flatShader = ShaderManager::GetShader("Resources/Shaders/flat.shader");
flatShader->Bind();
flatShader->SetUniform("u_View", scene->m_EditorCamera->GetTransform());
@@ -484,7 +505,6 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
const Vector3 gizmoSize = Vector3(Engine::GetProject()->Settings.GizmoSize);
// Camera
auto camView = scene->m_Registry.view<TransformComponent, CameraComponent>();
for (auto e : camView)
{
gizmoShader->SetUniform("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/camera.png").get());

View File

@@ -736,6 +736,7 @@ namespace Nuake {
NameComponent& nameComponent = e.GetComponent<NameComponent>();
std::string name = nameComponent.Name;
ParentComponent& parent = e.GetComponent<ParentComponent>();
if (Selection.Type == EditorSelectionType::Entity && Selection.Entity == e)
@@ -767,9 +768,7 @@ namespace Nuake {
}
auto cursorPos = ImGui::GetCursorPos();
ImGui::SetNextItemAllowOverlap();
bool open = ImGui::TreeNodeEx(name.c_str(), base_flags);
if (m_IsRenaming)
@@ -904,6 +903,25 @@ namespace Nuake {
ImGui::TextColored(ImVec4(0.5, 0.5, 0.5, 1.0), GetEntityTypeName(e).c_str());
ImGui::TableNextColumn();
{
bool hasScript = e.HasComponent<NetScriptComponent>();
if (hasScript)
{
std::string scrollIcon = std::string(ICON_FA_SCROLL) + "##" + name;
ImGui::PushStyleColor(ImGuiCol_Button, { 0, 0, 0, 0 });
if (ImGui::Button(scrollIcon.c_str(), { 40, 0 }))
{
auto& scriptComponent = e.GetComponent<NetScriptComponent>();
if (!scriptComponent.ScriptPath.empty() && FileSystem::FileExists(scriptComponent.ScriptPath))
{
OS::OpenIn(FileSystem::RelativeToAbsolute(scriptComponent.ScriptPath));
}
}
ImGui::PopStyleColor();
}
}
ImGui::TableNextColumn();
{
bool& isVisible = e.GetComponent<VisibilityComponent>().Visible;
@@ -2139,10 +2157,11 @@ namespace Nuake {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 4, 4 });
if (ImGui::BeginChild("Scene tree", ImGui::GetContentRegionAvail(), false))
{
if (ImGui::BeginTable("entity_table", 3, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_SizingStretchProp))
if (ImGui::BeginTable("entity_table", 4, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_SizingStretchProp))
{
ImGui::TableSetupColumn(" Label", ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_IndentDisable | ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Script", ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_IndentDisable | ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Visibility ", ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_IndentDisable | ImGuiTableColumnFlags_WidthFixed);
ImGui::TableHeadersRow();
@@ -2427,6 +2446,11 @@ namespace Nuake {
void EditorInterface::Overlay()
{
if (Engine::GetGameState() == GameState::Playing)
{
return;
}
// FIXME-VIEWPORT: Select a default viewport
const float DISTANCE = 10.0f;
int corner = 0;
@@ -3271,6 +3295,27 @@ namespace Nuake {
}
void EditorInterface::OnDragNDrop(const std::vector<std::string>& paths)
{
if (Engine::GetProject())
{
for (const auto& path : paths)
{
if (!FileSystem::FileExists(path, true))
{
continue;
}
if (!FileSystem::DirectoryExists(FileSystemUI::m_CurrentDirectory->GetFullPath(), true))
{
return;
}
FileSystem::CopyFileAbsolute(path, FileSystemUI::m_CurrentDirectory->GetFullPath());
}
}
}
bool EditorInterface::LoadProject(const std::string& projectPath)
{
FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath));

View File

@@ -106,5 +106,6 @@ namespace Nuake
public:
void OnWindowFocused();
void OnDragNDrop(const std::vector<std::string>& paths);
};
}

View File

@@ -261,6 +261,8 @@ namespace Nuake
OS::OpenTrenchbroomMap(file->GetAbsolutePath());
break;
case FileType::NetScript:
case FileType::UI:
case FileType::CSS:
OS::OpenIn(file->GetAbsolutePath());
break;
case FileType::Scene:
@@ -383,17 +385,30 @@ namespace Nuake
textureImage = image;
}
}
else if (fileType == FileType::Solution)
{
textureImage = textureMgr->GetTexture("Resources/Images/sln_icon.png");
}
else if (fileType == FileType::Map)
{
textureImage = textureMgr->GetTexture("Resources/Images/trenchbroom_icon.png");
}
ImGui::SetCursorPos(prevCursor);
ImGui::Image(reinterpret_cast<ImTextureID>(textureImage->GetID()), ImVec2(100, 100), ImVec2(0, 1), ImVec2(1, 0));
ImGui::PopStyleVar();
auto imguiStyle = ImGui::GetStyle();
auto& imguiStyle = ImGui::GetStyle();
ImVec2 startOffset = ImVec2(imguiStyle.CellPadding.x / 2.0f, 0);
ImVec2 offsetEnd = ImVec2(startOffset.x, imguiStyle.CellPadding.y / 2.0f);
ImU32 rectColor = IM_COL32(255, 255, 255, 16);
ImGui::GetWindowDrawList()->AddRectFilled(prevScreenPos + ImVec2(0, 100) - startOffset, prevScreenPos + ImVec2(100, 150) + offsetEnd, rectColor, 1.0f);
ImU32 rectColor2 = UI::PrimaryCol;
Color fileTypeColor = GetColorByFileType(file->GetFileType());
ImGui::GetWindowDrawList()->AddRectFilled(prevScreenPos + ImVec2(0, 100) - startOffset, prevScreenPos + ImVec2(100, 101) + offsetEnd, IM_COL32(fileTypeColor.r * 255.f, fileTypeColor.g * 255.f, fileTypeColor.b * 255.f, fileTypeColor.a * 255.f), 0.0f);
std::string visibleName = file->GetName();
const uint32_t MAX_CHAR_NAME = 32;
if (file->GetName().size() >= MAX_CHAR_NAME)
@@ -670,6 +685,57 @@ namespace Nuake
Scan();
}
Color FileSystemUI::GetColorByFileType(FileType fileType)
{
switch (fileType)
{
case Nuake::FileType::Unknown:
break;
case Nuake::FileType::Image:
break;
case Nuake::FileType::Material:
break;
case Nuake::FileType::Mesh:
break;
case Nuake::FileType::Script:
return { 1.0, 0.0, 0.0, 1.0 };
break;
case Nuake::FileType::NetScript:
return { 1.0, 0.0, 0.0, 1.0 };
break;
case Nuake::FileType::Project:
return Engine::GetProject()->Settings.PrimaryColor;
break;
case Nuake::FileType::Prefab:
break;
case Nuake::FileType::Scene:
return { 0, 1.0f, 1.0, 1.0 };
break;
case Nuake::FileType::Wad:
break;
case Nuake::FileType::Map:
return { 0.0, 1.0, 0.0, 1.0 };
break;
case Nuake::FileType::Assembly:
break;
case Nuake::FileType::Solution:
break;
case Nuake::FileType::Audio:
return { 0.0, 0.0, 1.0, 1.0 };
break;
case Nuake::FileType::UI:
return { 1.0, 1.0, 0.0, 1.0 };
break;
case Nuake::FileType::CSS:
return { 1.0, 0.0, 1.0, 1.0 };
break;
default:
break;
}
return Color(0, 0, 0, 0);
}
void FileSystemUI::Scan()
{
if (!m_CurrentDirectory)
@@ -888,6 +954,11 @@ namespace Nuake
{
for (Ref<Directory>& d : m_CurrentDirectory->Directories)
{
if (d->GetName() == "bin" || d->GetName() == ".vs" || d->GetName() == "obj")
{
continue;
}
if(String::Sanitize(d->Name).find(String::Sanitize(m_SearchKeyword)) != std::string::npos)
{
if (i + 1 % amount != 0)
@@ -907,6 +978,11 @@ namespace Nuake
{
if(m_SearchKeyword.empty() || f->GetName().find(String::Sanitize(m_SearchKeyword)) != std::string::npos)
{
if (f->GetFileType() == FileType::Unknown || f->GetFileType() == FileType::Assembly)
{
continue;
}
if (i + 1 % amount != 0 || i == 1)
{
ImGui::TableNextColumn();
@@ -915,7 +991,7 @@ namespace Nuake
{
ImGui::TableNextRow();
}
DrawFile(f, i);
i++;
}

View File

@@ -33,6 +33,8 @@ namespace Nuake {
void DrawContextMenu();
void RefreshFileBrowser();
Color GetColorByFileType(FileType fileType);
void Scan();
};
}

View File

@@ -240,7 +240,7 @@ std::vector<std::string> MapImporterWindow::ScanUsedWads()
std::string MapImporterWindow::GetTransformedWadPath(const std::string& path)
{
const std::string& baseTextureDir = "/textures/";
const std::string& baseTextureDir = "/Textures/";
using namespace Nuake;
if (m_WadToMaterialMap.find(path) != m_WadToMaterialMap.end())
@@ -285,7 +285,7 @@ std::string MapImporterWindow::GetTransformedWadPath(const std::string& path)
if (entry.is_regular_file() && stem == upperInput)
{
std::filesystem::path relativePath = std::filesystem::relative(entry.path(), FileSystem::Root + "/textures/");
std::filesystem::path relativePath = std::filesystem::relative(entry.path(), FileSystem::Root + "/Textures/");
std::filesystem::path pathWithoutExtension = relativePath;
pathWithoutExtension = pathWithoutExtension.parent_path(); // Remove the file name