This commit is contained in:
Antoine Pilote
2023-08-02 12:16:33 -04:00
18 changed files with 333 additions and 87 deletions

View File

@@ -0,0 +1,73 @@
#pragma once
#include "ComponentPanel.h"
#include <src/Core/FileSystem.h>
#include <src/Core/Maths.h>
#include <src/Scene/Components/SpriteComponent.h>
#include <src/Scene/Entities/ImGuiHelper.h>
class SpritePanel : ComponentPanel
{
public:
SpritePanel() = default;
~SpritePanel() = default;
void Draw(Nuake::Entity entity) override
{
if (!entity.HasComponent<Nuake::SpriteComponent>())
{
return;
}
auto& component = entity.GetComponent<Nuake::SpriteComponent>();
BeginComponentTable(SPRITE, Nuake::SpriteComponent);
{
{
ImGui::Text("Sprite");
ImGui::TableNextColumn();
std::string path = component.SpritePath;
ImGui::Button(path.empty() ? "Drag image" : component.SpritePath.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0));
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Image"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 512);
path = Nuake::FileSystem::AbsoluteToRelative(std::move(fullPath));
component.SpritePath = path;
component.LoadSprite();
}
ImGui::EndDragDropTarget();
}
ImGui::TableNextColumn();
ComponentTableReset(component.LockYRotation, false);
}
ImGui::TableNextColumn();
{
ImGui::Text("Billboard");
ImGui::TableNextColumn();
ImGui::Checkbox("##billboard", &component.Billboard);
ImGui::TableNextColumn();
ComponentTableReset(component.Billboard, false);
}
ImGui::TableNextColumn();
{
ImGui::Text("Lock Y rotation");
ImGui::TableNextColumn();
ImGui::Checkbox("##lockYRotation", &component.LockYRotation);
ImGui::TableNextColumn();
ComponentTableReset(component.LockYRotation, false);
}
}
EndComponentTable();
}
};

View File

@@ -14,13 +14,6 @@
EditorSelectionPanel::EditorSelectionPanel()
{
mTransformPanel = TransformPanel();
mLightPanel = LightPanel();
mScriptPanel = ScriptPanel();
mQuakeMapPanel = QuakeMapPanel();
mCameraPanel = CameraPanel();
mRigidbodyPanel = RigidbodyPanel();
mBoxColliderPanel = BoxColliderPanel();
}
void EditorSelectionPanel::ResolveFile(Ref<Nuake::File> file)
@@ -100,6 +93,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
mTransformPanel.Draw(entity);
mLightPanel.Draw(entity);
mScriptPanel.Draw(entity);
mSpritePanel.Draw(entity);
mMeshPanel.Draw(entity);
mQuakeMapPanel.Draw(entity);
mCameraPanel.Draw(entity);
@@ -129,6 +123,7 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity)
MenuItemComponent("Camera", Nuake::CameraComponent)
MenuItemComponent("Light", Nuake::LightComponent)
MenuItemComponent("Model", Nuake::ModelComponent)
MenuItemComponent("Sprite", Nuake::SpriteComponent)
ImGui::Separator();
MenuItemComponent("Character Controller", Nuake::CharacterControllerComponent)
MenuItemComponent("Rigid body", Nuake::RigidBodyComponent)

View File

@@ -18,6 +18,8 @@
#include "../ComponentsPanel/SphereColliderPanel.h"
#include "../ComponentsPanel/MeshColliderPanel.h"
#include "../ComponentsPanel/CharacterControllerPanel.h"
#include "../ComponentsPanel/SpritePanel.h"
class EditorSelectionPanel {
private:
@@ -33,7 +35,7 @@ private:
MeshColliderPanel mMeshColliderPanel;
CapsuleColliderPanel mCapsuleColliderPanel;
CylinderColliderPanel mCylinderColliderPanel;
SpritePanel mSpritePanel;
CharacterControllerPanel mCharacterControllerPanel;
Ref<Nuake::File> currentFile;

View File

@@ -211,28 +211,42 @@ namespace Nuake
{
Editor->Selection = EditorSelection(file);
}
}
if (ImGui::BeginDragDropSource())
if (ImGui::BeginDragDropSource())
{
char pathBuffer[256];
std::strncpy(pathBuffer, file->GetAbsolutePath().c_str(), sizeof(pathBuffer));
std::string dragType;
if (fileExtension == ".wren")
{
dragType = "_Script";
}
else if (fileExtension == ".map")
{
dragType = "_Map";
}
else if (fileExtension == ".obj" || fileExtension == ".mdl" || fileExtension == ".gltf" || fileExtension == ".md3" || fileExtension == ".fbx")
{
dragType = "_Model";
}
else if (fileExtension == ".interface")
{
dragType = "_Interface";
}
else if (fileExtension == ".prefab")
{
dragType = "_Prefab";
}
else if (fileExtension == ".png" || fileExtension == ".jpg")
{
dragType = "_Image";
}
ImGui::SetDragDropPayload(dragType.c_str(), (void*)(pathBuffer), sizeof(pathBuffer));
ImGui::Text(file->GetName().c_str());
ImGui::EndDragDropSource();
}
}
const std::string hoverMenuId = std::string("item_hover_menu") + std::to_string(drawId);
if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(1))
@@ -532,8 +546,6 @@ namespace Nuake
ImGui::EndChild();
ImGui::SameLine();
avail = ImGui::GetContentRegionAvail();
std::vector<Ref<Directory>> paths = std::vector<Ref<Directory>>();
Ref<Directory> currentParent = m_CurrentDirectory;
@@ -581,12 +593,13 @@ namespace Nuake
}
const uint32_t numButtonAfterPathBrowser = 2;
const uint32_t searchBarSize = 6;
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_ChildBg, colors[ImGuiCol_TitleBgCollapsed]);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4));
ImGui::BeginChild("pathBrowser", ImVec2(ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth) - 4.0, 24));
ImGui::BeginChild("pathBrowser", ImVec2((ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth * searchBarSize)) - 4.0, 24));
for (int i = paths.size() - 1; i > 0; i--)
{
if (i != paths.size())
@@ -610,13 +623,23 @@ namespace Nuake
ImGui::SameLine();
ImGui::Text("/");
}
ImGui::EndChild();
ImGui::PopStyleVar();
ImGui::PopStyleVar();
ImGui::PopStyleColor();
ImGui::SameLine();
ImGui::BeginChild("searchBar", ImVec2(ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth), 24));
char buffer[256];
memset(buffer, 0, sizeof(buffer));
std::strncpy(buffer, m_searchKeyWord.c_str(), sizeof(buffer));
if (ImGui::InputTextEx("##Search", "Asset search & filter ..", buffer, sizeof(buffer), ImVec2(ImGui::GetContentRegionAvail().x, 24), ImGuiInputTextFlags_EscapeClearsAll))
{
m_searchKeyWord = std::string(buffer);
}
ImGui::EndChild();
ImGui::SameLine();
@@ -633,8 +656,9 @@ namespace Nuake
}
ImGui::PopStyleColor(); // Button color
ImGui::SameLine();
}
ImGui::EndChild();
ImDrawList* drawList = ImGui::GetWindowDrawList();
@@ -668,13 +692,16 @@ namespace Nuake
{
for (Ref<Directory>& d : m_CurrentDirectory->Directories)
{
if (i + 1 % amount != 0)
ImGui::TableNextColumn();
else
ImGui::TableNextRow();
if(String::Sanitize(d->name).find(String::Sanitize(m_searchKeyWord)) != std::string::npos)
{
if (i + 1 % amount != 0)
ImGui::TableNextColumn();
else
ImGui::TableNextRow();
DrawDirectory(d, i);
i++;
DrawDirectory(d, i);
i++;
}
}
}
@@ -682,13 +709,16 @@ namespace Nuake
{
for (auto f : m_CurrentDirectory->Files)
{
if (i - 1 % amount != 0 || i == 1)
ImGui::TableNextColumn();
else
ImGui::TableNextRow();
if(String::Sanitize(f->GetName()).find(String::Sanitize(m_searchKeyWord)) != std::string::npos)
{
if (i - 1 % amount != 0 || i == 1)
ImGui::TableNextColumn();
else
ImGui::TableNextRow();
DrawFile(f, i);
i++;
DrawFile(f, i);
i++;
}
}
}

View File

@@ -12,6 +12,7 @@ namespace Nuake {
public:
static Ref<Directory> m_CurrentDirectory;
bool m_hasClickedOnFile;
std::string m_searchKeyWord;
FileSystemUI(EditorInterface* editor)
{