New UI framework stuff + lua

This commit is contained in:
Antoine Pilote
2021-05-25 21:38:22 -04:00
parent 1f1047d23b
commit 3843a3fe2d
34 changed files with 28609 additions and 73 deletions

View File

@@ -21,7 +21,7 @@
#include <src/Core/Logger.h>
ImFont* normalFont;
ImFont* bigIconFont;
ImFont* EditorInterface::bigIconFont;
void EditorInterface::Init()
{
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
@@ -33,6 +33,8 @@ void EditorInterface::Init()
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
ImGui::DockSpaceOverViewport(viewport, dockspace_flags);
this->filesystem = FileSystemUI();
}
void EditorInterface::DrawViewport()
@@ -532,35 +534,7 @@ void EditorInterface::DrawFileSystem()
Ref<Directory> rootDirectory = FileSystem::GetFileTree();
if (!rootDirectory)
return;
if(ImGui::Begin("Tree browser"))
{
if (ImGui::BeginPopupContextItem("item context menu"))
{
if (ImGui::Selectable("Set to zero"));
if (ImGui::Selectable("Set to PI"));
ImGui::SetNextItemWidth(-1);
ImGui::EndPopup();
}
ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth;
bool is_selected = m_CurrentDirectory == FileSystem::RootDirectory;
if (is_selected)
base_flags |= ImGuiTreeNodeFlags_Selected;
std::string icon = ICON_FA_FOLDER;
bool open = ImGui::TreeNodeEx((icon + " " + rootDirectory->name).c_str(), base_flags);
if (ImGui::IsItemClicked())
{
m_CurrentDirectory = FileSystem::RootDirectory;
}
if (open)
{
EditorInterfaceDrawFiletree(rootDirectory);
ImGui::TreePop();
}
}
ImGui::End();
}
@@ -697,7 +671,7 @@ void EditorInterface::DrawLogger()
{
for (auto l : Logger::GetLogs())
{
ImGui::Text(l.c_str());
ImGui::TextWrapped(l.c_str());
}
}
@@ -914,6 +888,18 @@ void OpenProject()
}
project->FullPath = projectPath;
Engine::LoadProject(project);
Ref<UI::UserInterface> userInterface = UI::UserInterface::New("test");
Ref<UI::Rect> rectangle = UI::Rect::New(0, 0, userInterface->Width, userInterface->Height);
userInterface->AddRect(rectangle);
Ref<UI::Rect> rect2 = rectangle->CutLeft(1280.f);
rect2->Props.BackgroundColor = Color(0, 1, 0, 1);
userInterface->AddRect(rect2);
Engine::GetCurrentScene()->AddInterface(userInterface);
}
void OpenScene()
@@ -964,7 +950,7 @@ void EditorInterface::Draw()
if (ImGui::MenuItem("Open...", "CTRL+O"))
{
OpenProject();
m_IsEntitySelected = false;
}
if (ImGui::MenuItem("Save", "CTRL+S"))
@@ -1080,7 +1066,7 @@ void EditorInterface::Draw()
}
DrawGizmos();
DrawRessourceWindow();
DrawViewport();
DrawSceneTree();
@@ -1088,6 +1074,10 @@ void EditorInterface::Draw()
DrawDirectoryExplorer();
DrawEntityPropreties();
DrawLogger();
// new stuff
filesystem.Draw();
if(m_ShowImGuiDemo)
ImGui::ShowDemoWindow();

View File

@@ -3,13 +3,13 @@
#include "src/Vendors/imgui/imgui.h"
#include <src/Vendors/imgui/ImGuizmo.h>
#include "src/Core/FileSystem.h"
#include "FileSystemUI.h"
class Material;
class EditorInterface
{
private:
FileSystemUI filesystem;
Entity m_SelectedEntity;
bool m_IsEntitySelected = false;
bool m_DrawGrid = false;
@@ -23,9 +23,8 @@ private:
bool m_IsMaterialSelected = false;
public:
static ImFont* bigIconFont;
void BuildFonts();
void Init();
void Draw();

210
Editor/src/FileSystemUI.cpp Normal file
View File

@@ -0,0 +1,210 @@
#include "FileSystemUI.h"
#include <src/Vendors/imgui/imgui.h>
#include <src/Resource/FontAwesome5.h>
#include <src/Scene/Entities/Components/ParentComponent.h>
#include <src/Rendering/Textures/Texture.h>
#include <src/Core/TextureManager.h>
#include "EditorInterface.h"
// TODO: add filetree in same panel
void FileSystemUI::Draw()
{
Ref<Directory> rootDirectory = FileSystem::GetFileTree();
if (!rootDirectory)
return;
if (ImGui::Begin("Tree browser"))
{
if (ImGui::BeginPopupContextItem("item context menu"))
{
if (ImGui::Selectable("Set to zero"));
if (ImGui::Selectable("Set to PI"));
ImGui::SetNextItemWidth(-1);
ImGui::EndPopup();
}
ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth;
bool is_selected = m_CurrentDirectory == FileSystem::RootDirectory;
if (is_selected)
base_flags |= ImGuiTreeNodeFlags_Selected;
std::string icon = ICON_FA_FOLDER;
bool open = ImGui::TreeNodeEx((icon + " " + rootDirectory->name).c_str(), base_flags);
if (ImGui::IsItemClicked())
{
m_CurrentDirectory = FileSystem::RootDirectory;
}
if (open)
{
//EditorInterfaceDrawFiletree(rootDirectory);
ImGui::TreePop();
}
}
ImGui::End();
}
void FileSystemUI::DrawDirectoryContent()
{
}
void FileSystemUI::DrawFiletree()
{
}
void FileSystemUI::EditorInterfaceDrawFiletree(Ref<Directory> dir)
{
for (auto d : dir->Directories)
{
ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth;
bool is_selected = m_CurrentDirectory == d;
if (is_selected)
base_flags |= ImGuiTreeNodeFlags_Selected;
if (d->Directories.size() == 0)
{
base_flags = ImGuiTreeNodeFlags_Leaf;
}
std::string icon = ICON_FA_FOLDER;
if (is_selected)
icon = ICON_FA_FOLDER_OPEN;
bool open = ImGui::TreeNodeEx((icon + " " + d->name).c_str(), base_flags);
if (ImGui::IsItemClicked())
m_CurrentDirectory = d;
if (open)
{
if (d->Directories.size() > 0)
EditorInterfaceDrawFiletree(d);
ImGui::TreePop();
}
}
}
void FileSystemUI::DrawDirectory(Ref<Directory> directory)
{
ImGui::PushFont(EditorInterface::bigIconFont);
std::string id = ICON_FA_FOLDER + std::string("##") + directory->name;
if (ImGui::Button(id.c_str(), ImVec2(100, 100)))
m_CurrentDirectory = directory;
ImGui::Text(directory->name.c_str());
ImGui::PopFont();
}
bool FileSystemUI::EntityContainsItself(Entity source, Entity target)
{
ParentComponent& targeParentComponent = target.GetComponent<ParentComponent>();
if (!targeParentComponent.HasParent)
return false;
Entity currentParent = target.GetComponent<ParentComponent>().Parent;
while (currentParent != source)
{
if (currentParent.GetComponent<ParentComponent>().HasParent)
currentParent = currentParent.GetComponent<ParentComponent>().Parent;
else
return false;
if (currentParent == source)
return true;
}
return true;
}
void FileSystemUI::DrawFile(Ref<File> file)
{
ImGui::PushFont(EditorInterface::bigIconFont);
if (file->Type == ".png" || file->Type == ".jpg")
{
Ref<Texture> texture = TextureManager::Get()->GetTexture(file->fullPath);
ImGui::ImageButton((void*)texture->GetID(), ImVec2(100, 100), ImVec2(0, 1), ImVec2(1, 0));
}
else
{
const char* icon = ICON_FA_FILE;
if (file->Type == ".shader")
icon = ICON_FA_FILE_CODE;
if (file->Type == ".map")
icon = ICON_FA_BROOM;
if (file->Type == ".ogg" || file->Type == ".mp3" || file->Type == ".wav" || file->Type == ".flac")
icon = ICON_FA_FILE_AUDIO;
if (file->Type == ".cpp" || file->Type == ".h" || file->Type == ".cs" || file->Type == ".py" || file->Type == ".lua")
icon = ICON_FA_FILE_CODE;
if (ImGui::Button(icon, ImVec2(100, 100)))
{
if (ImGui::BeginPopupContextItem("item context menu"))
{
if (ImGui::Selectable("Set to zero"));
if (ImGui::Selectable("Set to PI"));
ImGui::EndPopup();
}
}
}
ImGui::Text(file->name.c_str());
ImGui::PopFont();
}
void FileSystemUI::DrawDirectoryExplorer()
{
if (ImGui::Begin("File browser"))
{
// Wrapping.
int width = ImGui::GetWindowWidth();
ImVec2 buttonSize = ImVec2(100, 100);
int amount = (width / 100); // -2 because button overflow width + ... button.
int i = 1; // current amount of item per row.
if (ImGui::BeginTable("ssss", amount))
{
// Button to go up a level.
if (m_CurrentDirectory != FileSystem::RootDirectory)
{
ImGui::TableNextColumn();
if (ImGui::Button("..", ImVec2(100, 100)))
m_CurrentDirectory = m_CurrentDirectory->Parent;
ImGui::TableNextColumn();
// Increment item per row tracker.
i++;
}
// Exit if no current directory.
if (!m_CurrentDirectory) {
ImGui::EndTable();
ImGui::End();
return;
}
if (m_CurrentDirectory && m_CurrentDirectory->Directories.size() > 0)
{
for (auto d : m_CurrentDirectory->Directories)
{
DrawDirectory(d);
if (i - 1 % amount != 0)
ImGui::TableNextColumn();
else
ImGui::TableNextRow();
i++;
}
}
if (m_CurrentDirectory && m_CurrentDirectory->Files.size() > 0)
{
for (auto f : m_CurrentDirectory->Files)
{
DrawFile(f);
if (i - 1 % amount != 0)
ImGui::TableNextColumn();
else
ImGui::TableNextRow();
i++;
}
}
ImGui::EndTable();
}
}
ImGui::End();
}

20
Editor/src/FileSystemUI.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include <src/Core/FileSystem.h>
#include <src/Scene/Entities/Entity.h>
class FileSystemUI
{
private:
Ref<Directory> m_CurrentDirectory;
public:
void Draw();
void DrawDirectoryContent();
void DrawFiletree();
void EditorInterfaceDrawFiletree(Ref<Directory> dir);
void DrawDirectory(Ref<Directory> directory);
bool EntityContainsItself(Entity source, Entity target);
void DrawFile(Ref<File> file);
void DrawDirectoryExplorer();
};

View File

@@ -0,0 +1,33 @@
#pragma once
class SelectableElement
{
virtual void Draw();
};
class SceneFile : public SelectableElement
{
void Draw() override;
};
class ProjectFile : public SelectableElement
{
void Draw() override;
};
class MaterialFile : public SelectableElement
{
void Draw() override;
};
class Entity : public SelectableElement
{
void Draw() override;
};
class PropretiesWindow
{
SelectableElement selected;
static void Draw();
};

1
Editor/src/SceneTree.h Normal file
View File

@@ -0,0 +1 @@
#pragma once

1
Editor/src/Toolbar.h Normal file
View File

@@ -0,0 +1 @@
#pragma once