Added Screen space reflections and Editor UI refactoring

This commit is contained in:
antopilo
2022-01-31 13:54:58 -05:00
parent e216686272
commit b273a2fb8a
78 changed files with 2454 additions and 946 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
#pragma once
#include <src/Scene/Entities/Entity.h>
#include "src/Vendors/imgui/imgui.h"
#include <src/Vendors/imgui/ImGuizmo.h>
#include "src/Core/FileSystem.h"
#include "../Actions/EditorSelection.h"
#include "EditorSelectionPanel.h"
namespace Nuake {
class Material;
class FileSystemUI;
class EditorInterface
{
private:
FileSystemUI* filesystem;
bool m_DrawGrid = false;
bool m_ShowImGuiDemo = false;
bool m_DebugCollisions = false;
bool m_ShowOverlay = true;
ImGuizmo::OPERATION CurrentOperation = ImGuizmo::TRANSLATE;
ImGuizmo::MODE CurrentMode = ImGuizmo::WORLD;
Ref<Material> m_SelectedMaterial;
Ref<Directory> m_CurrentDirectory;
bool m_IsMaterialSelected = false;
public:
EditorSelection Selection;
EditorSelectionPanel SelectionPanel;
EditorInterface();
static ImFont* bigIconFont;
void BuildFonts();
void Init();
void Draw();
void DrawViewport();
void DrawEntityTree(Entity ent);
void DrawSceneTree();
void DrawEntityPropreties();
void DrawGizmos();
void DrawFileSystem();
void DrawDirectoryExplorer();
void DrawLogger();
void DrawDirectory(Ref<Directory> directory);
bool EntityContainsItself(Entity ent1, Entity ent2);
void DrawFile(Ref<File> file);
void DrawRessourceWindow();
void DrawInit();
void EditorInterfaceDrawFiletree(Ref<Directory> dir);
void Overlay();
void DrawMaterialEditor(Ref<Material> material);
};
}

View File

@@ -0,0 +1,357 @@
#include "EditorSelectionPanel.h"
#include "src/Scene/Components/ImportComponents.h"
#include "../Misc/ImGuiTextHelper.h"
EditorSelectionPanel::EditorSelectionPanel()
{
mTransformPanel = TransformPanel();
mLightPanel = LightPanel();
mScriptPanel = ScriptPanel();
mQuakeMapPanel = QuakeMapPanel();
}
void EditorSelectionPanel::Draw(EditorSelection selection)
{
if (ImGui::Begin("Propreties"))
{
switch (selection.Type)
{
case EditorSelectionType::None:
{
DrawNone();
break;
}
case EditorSelectionType::Entity:
{
DrawEntity(selection.Entity);
break;
}
case EditorSelectionType::File:
{
DrawFile(selection.File.get());
break;
}
case EditorSelectionType::Resource:
{
DrawResource(selection.Resource);
break;
}
}
}
ImGui::End();
}
void EditorSelectionPanel::DrawNone()
{
std::string text = "No selection";
auto windowWidth = ImGui::GetWindowSize().x;
auto windowHeight = ImGui::GetWindowSize().y;
auto textWidth = ImGui::CalcTextSize(text.c_str()).x;
auto textHeight = ImGui::CalcTextSize(text.c_str()).y;
ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
ImGui::SetCursorPosY((windowHeight - textHeight) * 0.5f);
ImGui::Text(text.c_str());
}
void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
{
DrawAddComponentMenu(entity);
// Draw each component properties panels.
mTransformPanel.Draw(entity);
mLightPanel.Draw(entity);
mScriptPanel.Draw(entity);
mMeshPanel.Draw(entity);
mQuakeMapPanel.Draw(entity);
/*
if (Selection.Entity.HasComponent<MeshComponent>())
{
std::string icon = ICON_FA_MALE;
if (ImGui::CollapsingHeader((icon + " " + "Mesh").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Mesh properties");
auto& component = Selection.Entity.GetComponent<MeshComponent>();
// Path
std::string path = component.ModelPath;
char pathBuffer[256];
memset(pathBuffer, 0, sizeof(pathBuffer));
std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer));
std::string oldPath = component.ModelPath;
ImGui::Text("Model: ");
ImGui::SameLine();
if (ImGui::InputText("##ModelPath", pathBuffer, sizeof(pathBuffer)))
path = FileSystem::AbsoluteToRelative(std::string(pathBuffer));
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Model"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
path = FileSystem::AbsoluteToRelative(fullPath);
}
ImGui::EndDragDropTarget();
}
if (component.ModelPath != path)
{
component.ModelPath = path;
component.LoadModel();
}
ImGui::SameLine();
if (ImGui::Button("Reimport"))
{
component.LoadModel();
}
ImGui::Indent(16.0f);
if (ImGui::CollapsingHeader("Meshes"))
{
ImGui::Indent(16.0f);
uint16_t index = 0;
for (auto& m : component.meshes)
{
if (ImGui::CollapsingHeader(std::to_string(index).c_str()))
{
std::string materialName = "No material";
if (m->m_Material)
materialName = m->m_Material->GetName();
ImGui::Indent(16.0f);
if (ImGui::CollapsingHeader(materialName.c_str()))
{
//if (ImGui::BeginChild("Material child", ImVec2(0, 0), true, ImGuiWindowFlags_AlwaysAutoResize))
//{
ImGui::Indent(16.0f);
DrawMaterialEditor(m->m_Material);
//}
//ImGui::EndChild();
}
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Material"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
path = FileSystem::AbsoluteToRelative(fullPath);
}
ImGui::EndDragDropTarget();
}
}
index++;
}
}
ImGui::Separator();
}
}
if (Selection.Entity.HasComponent<WrenScriptComponent>()) {
std::string icon = ICON_FA_FILE;
if (ImGui::CollapsingHeader((icon + " " + "Wren Script").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Script properties");
auto& component = Selection.Entity.GetComponent<WrenScriptComponent>();
// Path
std::string path = component.Script;
char pathBuffer[256];
memset(pathBuffer, 0, sizeof(pathBuffer));
std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer));
ImGui::Text("Script: ");
ImGui::SameLine();
if (ImGui::InputText("##ScriptPath", pathBuffer, sizeof(pathBuffer)))
path = FileSystem::AbsoluteToRelative(std::string(pathBuffer));
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
path = FileSystem::AbsoluteToRelative(fullPath);
}
ImGui::EndDragDropTarget();
}
component.Script = path;
// Class
std::string module = component.Class;
char classBuffer[256];
memset(classBuffer, 0, sizeof(classBuffer));
std::strncpy(classBuffer, module.c_str(), sizeof(classBuffer));
ImGui::Text("Class: ");
ImGui::SameLine();
if (ImGui::InputText("##ScriptModule", classBuffer, sizeof(classBuffer)))
module = std::string(classBuffer);
component.Class = module;
ImGui::Separator();
}
}
if (Selection.Entity.HasComponent<CameraComponent>()) {
std::string icon = ICON_FA_LIGHTBULB;
if (ImGui::CollapsingHeader((icon + " " + "Camera").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Camera properties");
Selection.Entity.GetComponent<CameraComponent>().DrawEditor();
ImGui::Separator();
}
}
if (Selection.Entity.HasComponent<CharacterControllerComponent>())
{
if (ImGui::CollapsingHeader("Character controller", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Character controller properties");
auto& c = Selection.Entity.GetComponent<CharacterControllerComponent>();
ImGui::InputFloat("Height", &c.Height);
ImGui::InputFloat("Radius", &c.Radius);
ImGui::InputFloat("Mass", &c.Mass);
ImGui::Separator();
}
}
if (Selection.Entity.HasComponent<RigidBodyComponent>())
{
std::string icon = ICON_FA_BOWLING_BALL;
if (ImGui::CollapsingHeader((icon + " Rigidbody").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Rigidbody properties");
RigidBodyComponent& rbComponent = Selection.Entity.GetComponent<RigidBodyComponent>();
ImGui::DragFloat("Mass", &rbComponent.mass, 0.1, 0.0);
ImGui::Separator();
}
}
if (Selection.Entity.HasComponent<BoxColliderComponent>())
{
std::string icon = ICON_FA_BOX;
if (ImGui::CollapsingHeader((icon + " Box collider").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Box collider properties");
BoxColliderComponent& component = Selection.Entity.GetComponent<BoxColliderComponent>();
ImGuiHelper::DrawVec3("Size", &component.Size);
ImGui::Checkbox("Is trigger", &component.IsTrigger);
ImGui::Separator();
}
}
if (Selection.Entity.HasComponent<SphereColliderComponent>())
{
std::string icon = ICON_FA_CIRCLE;
if (ImGui::CollapsingHeader((icon + " Sphere collider").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Sphere properties");
SphereColliderComponent& component = Selection.Entity.GetComponent<SphereColliderComponent>();
ImGui::DragFloat("Radius", &component.Radius, 0.1f, 0.0f, 100.0f);
ImGui::Checkbox("Is trigger", &component.IsTrigger);
ImGui::Separator();
}
}
if (Selection.Entity.HasComponent<QuakeMapComponent>())
{
std::string icon = ICON_FA_BROOM;
if (ImGui::CollapsingHeader((icon + " " + "Quake map").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Quake map properties");
auto& component = Selection.Entity.GetComponent<QuakeMapComponent>();
std::string path = component.Path;
char pathBuffer[256];
memset(pathBuffer, 0, sizeof(pathBuffer));
std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer));
ImGui::Text("Map file: ");
ImGui::SameLine();
if (ImGui::InputText("##MapPath", pathBuffer, sizeof(pathBuffer)))
{
path = std::string(pathBuffer);
}
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Map"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
path = FileSystem::AbsoluteToRelative(fullPath);
}
ImGui::EndDragDropTarget();
}
component.Path = path;
ImGui::InputFloat("Scale factor", &component.ScaleFactor, 0.01f, 0.1f);
ImGui::Checkbox("Build collisions", &component.HasCollisions);
if (ImGui::Button("Build Geometry"))
{
QuakeMapBuilder mapBuilder;
mapBuilder.BuildQuakeMap(Selection.Entity);
}
ImGui::Separator();
}
}*/
}
void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity)
{
if (entity.HasComponent<Nuake::NameComponent>())
{
auto& entityName = entity.GetComponent<Nuake::NameComponent>().Name;
ImGuiTextSTD("##Name", entityName);
ImGui::SameLine();
if (ImGui::Button("Add Component"))
ImGui::OpenPopup("ComponentPopup");
if (ImGui::BeginPopup("ComponentPopup"))
{
MenuItemComponent("Wren Script", Nuake::WrenScriptComponent);
MenuItemComponent("Camera", Nuake::CameraComponent);
MenuItemComponent("Light", Nuake::LightComponent);
MenuItemComponent("Mesh", Nuake::MeshComponent);
MenuItemComponent("Rigid body", Nuake::RigidBodyComponent);
MenuItemComponent("Box collider", Nuake::BoxColliderComponent);
MenuItemComponent("Sphere collider", Nuake::SphereColliderComponent);
MenuItemComponent("Mesh collider", Nuake::MeshColliderComponent);
MenuItemComponent("Quake map", Nuake::QuakeMapComponent);
ImGui::EndPopup();
}
ImGui::Separator();
}
}
void EditorSelectionPanel::DrawFile(Nuake::File* file)
{
}
void EditorSelectionPanel::DrawResource(Nuake::Resource resource)
{
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "../Actions/EditorSelection.h"
#include "src/Scene/Entities/Entity.h"
#include "src/Core/FileSystem.h"
#include "../ComponentsPanel/TransformPanel.h"
#include "../ComponentsPanel/LightPanel.h"
#include "../ComponentsPanel/ScriptPanel.h"
#include "../ComponentsPanel/MeshPanel.h"
#include "../ComponentsPanel/QuakeMapPanel.h"
class EditorSelectionPanel {
private:
TransformPanel mTransformPanel;
LightPanel mLightPanel;
ScriptPanel mScriptPanel;
MeshPanel mMeshPanel;
QuakeMapPanel mQuakeMapPanel;
public:
EditorSelectionPanel();
void Draw(EditorSelection selection);
void DrawNone();
void DrawEntity(Nuake::Entity entity);
void DrawAddComponentMenu(Nuake::Entity entity);
void DrawFile(Nuake::File* file);
void DrawResource(Nuake::Resource resource);
};

View File

@@ -0,0 +1,378 @@
#include "FileSystemUI.h"
#include <src/Vendors/imgui/imgui.h>
#include <src/Vendors/imgui/imgui_internal.h>
#include "src/Resource/FontAwesome5.h"
#include "src/Scene/Components/ParentComponent.h"
#include "src/Rendering/Textures/Texture.h"
#include "src/Rendering/Textures/TextureManager.h"
#include "EditorInterface.h"
const std::string TEMPLATE_SCRIPT_BEGIN = "import \"Nuake:Engine\" for Engine \
import \"Nuake:ScriptableEntity\" for ScriptableEntity \
import \"Nuake:Input\" for Input \
import \"Nuake:Scene\" for Scene \
\
class ";
const std::string TEMPLATE_SCRIPT_END = " is ScriptableEntity {\
construct new(){\
_ReloadSpeed = 0.1\
_Intensity = 0.0\
}\
\
init() {\
}\
\
// Updates every frame\
update(ts) {\
\
}\
\
// Updates every tick\
fixedUpdate(ts) {\
\
}\
\
exit() {\
}\
}";
namespace Nuake {
// TODO: add filetree in same panel
void FileSystemUI::Draw()
{
}
void FileSystemUI::DrawDirectoryContent()
{
}
void FileSystemUI::DrawFiletree()
{
}
void FileSystemUI::EditorInterfaceDrawFiletree(Ref<Directory> dir)
{
ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth;
//if (is_selected)
std::string icon = ICON_FA_FOLDER;
if (m_CurrentDirectory == dir)
base_flags |= ImGuiTreeNodeFlags_Selected;
if (dir->Directories.size() <= 0)
base_flags = ImGuiTreeNodeFlags_Leaf;
bool open = ImGui::TreeNodeEx(dir->name.c_str(), base_flags);
if (ImGui::IsItemClicked())
m_CurrentDirectory = dir;
if (open)
{
if (dir->Directories.size() > 0)
for (auto& d : dir->Directories)
EditorInterfaceDrawFiletree(d);
ImGui::TreePop();
}
}
void FileSystemUI::DrawDirectory(Ref<Directory> directory)
{
ImGui::PushFont(EditorInterface::bigIconFont);
std::string id = 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);
std::string fileExtension = file->GetExtension();
if (fileExtension == ".png" || fileExtension == ".jpg")
{
Ref<Texture> texture = TextureManager::Get()->GetTexture(file->GetAbsolutePath());
ImGui::ImageButton((void*)texture->GetID(), ImVec2(100, 100), ImVec2(0, 1), ImVec2(1, 0));
}
else
{
const char* icon = ICON_FA_FILE;
if (fileExtension == ".shader" || fileExtension == ".wren")
icon = ICON_FA_FILE_CODE;
if (fileExtension == ".map")
icon = ICON_FA_BROOM;
if (fileExtension == ".ogg" || fileExtension == ".mp3" || fileExtension == ".wav")
icon = ICON_FA_FILE_AUDIO;
if (fileExtension == ".md3" || fileExtension == ".obj")
icon = ICON_FA_FILE_IMAGE;
std::string fullName = icon + std::string("##") + file->GetAbsolutePath();
if (ImGui::Button(fullName.c_str(), ImVec2(100, 100)))
{
Editor->Selection = EditorSelection(file);
}
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";
ImGui::SetDragDropPayload(dragType.c_str(), (void*)(pathBuffer), sizeof(pathBuffer));
ImGui::Text(file->GetName().c_str());
ImGui::EndDragDropSource();
}
}
ImGui::Text(file->GetName().c_str());
ImGui::PopFont();
}
bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f)
{
using namespace ImGui;
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
ImGuiID id = window->GetID("##Splitter");
ImRect bb;
bb.Min = window->DC.CursorPos + (split_vertically ? ImVec2(*size1, 0.0f) : ImVec2(0.0f, *size1));
bb.Max = bb.Min + CalcItemSize(split_vertically ? ImVec2(thickness, splitter_long_axis_size) : ImVec2(splitter_long_axis_size, thickness), 0.0f, 0.0f);
return SplitterBehavior(bb, id, split_vertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, min_size1, min_size2, 0.0f);
}
float h = 200;
static float sz1 = 300;
static float sz2 = 300;
void FileSystemUI::DrawDirectoryExplorer()
{
if (ImGui::Begin("File browser"))
{
Ref<Directory> rootDirectory = FileSystem::GetFileTree();
if (!rootDirectory)
return;
ImVec2 avail = ImGui::GetContentRegionAvail();
Splitter(true, 4.0f, &sz1, &sz2, 100, 8, avail.y);
if (ImGui::BeginChild("Tree browser", ImVec2(sz1, avail.y)))
{
ImGuiTreeNodeFlags base_flags = 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 + " " + "Project files").c_str(), base_flags);
if (ImGui::IsItemClicked())
{
m_CurrentDirectory = FileSystem::RootDirectory;
}
if (open)
{
for(auto& d : rootDirectory->Directories)
EditorInterfaceDrawFiletree(d);
ImGui::TreePop();
}
}
ImGui::EndChild();
ImGui::SameLine();
avail = ImGui::GetContentRegionAvail();
std::vector<Ref<Directory>> paths = std::vector<Ref<Directory>>();
Ref<Directory> currentParent = m_CurrentDirectory;
paths.push_back(m_CurrentDirectory);
while (currentParent != nullptr)
{
paths.push_back(currentParent);
currentParent = currentParent->Parent;
}
avail = ImGui::GetContentRegionAvail();
if (ImGui::BeginChild("Wrapper", avail))
{
avail.y = 30;
if (ImGui::BeginChild("Path", avail))
{
if (ImGui::Button("Refresh"))
{
FileSystem::Scan();
m_CurrentDirectory = FileSystem::RootDirectory;
}
ImGui::SameLine();
for (int i = paths.size() - 1; i > 0; i--)
{
if (i != paths.size())
ImGui::SameLine();
if (ImGui::Button(paths[i]->name.c_str()))
m_CurrentDirectory = paths[i];
ImGui::SameLine();
ImGui::Text("/");
}
ImGui::EndChild();
}
avail = ImGui::GetContentRegionAvail();
if (ImGui::BeginChild("Content", avail))
{
int width = avail.x;
ImVec2 buttonSize = ImVec2(80, 80);
int amount = (int)(width / 100);
if (amount <= 0) amount = 1;
int i = 1; // current amount of item per row.
if (ImGui::BeginTable("ssss", amount))
{
// Button to go up a level.
if (m_CurrentDirectory && m_CurrentDirectory != FileSystem::RootDirectory && m_CurrentDirectory->Parent)
{
ImGui::TableNextColumn();
if (ImGui::Button("..", ImVec2(100, 100)))
m_CurrentDirectory = m_CurrentDirectory->Parent;
ImGui::TableNextColumn();
i++;
}
if (m_CurrentDirectory && m_CurrentDirectory->Directories.size() > 0)
{
for (Ref<Directory>& 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++;
}
}
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::MenuItem("New Wren script"))
{
ImGui::OpenPopup("new_file");
}
if (ImGui::MenuItem("New interface script"))
{
}
if (ImGui::MenuItem("New Scene"))
{
}
if (ImGui::MenuItem("New folder"))
{
}
if (ImGui::MenuItem("New interface"))
{
}
if (ImGui::MenuItem("New stylesheet"))
{
}
ImGui::EndPopup();
}
if (ImGui::BeginPopup("new_file"))
{
static char name[32] = "NewWrenScript";
char buf[64];
sprintf(buf, "Button: %s###Button", name); // ### operator override ID ignoring the preceding label
ImGui::Text("Edit name:");
ImGui::InputText("##edit", name, IM_ARRAYSIZE(name));
if (ImGui::Button("Close"))
ImGui::CloseCurrentPopup();
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter)) && name != "")
{
FileSystem::BeginWriteFile(m_CurrentDirectory->fullPath + name + ".wren");
FileSystem::WriteLine(TEMPLATE_SCRIPT_BEGIN + name + TEMPLATE_SCRIPT_END);
FileSystem::EndWriteFile();
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
ImGui::EndTable();
}
}
ImGui::EndChild();
}
ImGui::EndChild();
}
ImGui::End();
}
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include <src/Core/FileSystem.h>
#include <src/Scene/Entities/Entity.h>
#include "EditorInterface.h"
namespace Nuake {
class FileSystemUI
{
private:
EditorInterface* Editor;
public:
Ref<Directory> m_CurrentDirectory;
FileSystemUI(EditorInterface* editor) {
m_CurrentDirectory = FileSystem::RootDirectory;
Editor = editor;
}
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,280 @@
#include "ProjectInterface.h"
#include <src/Vendors/imgui/imgui.h>
#include "Engine.h"
//#include "ImGuiTextHelper.h"
namespace Nuake {
void ProjectInterface::DrawProjectSettings()
{
if (ImGui::Begin("Project settings"))
{
char buffer[256];
memset(buffer, 0, sizeof(buffer));
std::strncpy(buffer, Engine::GetProject()->Name.c_str(), sizeof(buffer));
if (ImGui::InputText("##Name", buffer, sizeof(buffer)))
{
Engine::GetProject()->Name = std::string(buffer);
}
}
ImGui::End();
}
void ProjectInterface::DrawCreatePointEntity()
{
char buffer[256];
memset(buffer, 0, sizeof(buffer));
std::strncpy(buffer, Engine::GetProject()->Name.c_str(), sizeof(buffer));
if (ImGui::InputText("##Name", buffer, sizeof(buffer)))
{
Engine::GetProject()->Name = std::string(buffer);
}
}
FGDPointEntity newEntity;
const char* items[] = { "String", "Integer", "Float", "Boolean" };
void ProjectInterface::DrawEntitySettings()
{
if (!m_CurrentProject)
return;
if (ImGui::Begin("Entity definitions"))
{
ImGui::Text("This is the entity definition used by trenchbroom. This files allows you to see your entities inside Trenchbroom");
ImGui::Text("Trenchbroom path:");
ImGui::SameLine();
//ImGuiTextSTD("", m_CurrentProject->TrenchbroomPath);
ImGui::SameLine();
if (ImGui::Button("Browse"))
{
std::string path = FileDialog::OpenFile("*.exe");
if (path != "")
{
path += "/../";
m_CurrentProject->TrenchbroomPath = path;
}
}
Ref<FGDFile> file = Engine::GetProject()->EntityDefinitionsFile;
auto flags = ImGuiWindowFlags_NoTitleBar;
if (ImGui::BeginPopupModal("Create new point entity", NULL, flags))
{
//ImGuiTextSTD("Name", newEntity.Name);
//ImGuiTextMultiline("Description", newEntity.Description);
if (ImGui::BeginTable("DictCreate", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable))
{
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Type");
ImGui::TableHeadersRow();
ImGui::TableNextColumn();
int idx = 0;
for (auto& p : newEntity.Properties)
{
//ImGuiTextSTD("Name", p.name);
ImGui::TableNextColumn();
std::string current_item = NULL;
if (ImGui::BeginCombo(("TypeSelection" + std::to_string(idx)).c_str(), current_item.c_str()))
{
for (int n = 0; n < IM_ARRAYSIZE(items); n++)
{
bool is_selected = (p.type == (ClassPropertyType)n); // You can store your selection however you want, outside or inside your objects
if (ImGui::Selectable(items[n], is_selected))
if (is_selected)
{
p.type = (ClassPropertyType)n;
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
}
idx++;
ImGui::TableNextColumn();
}
if (ImGui::Button("Add new property"))
{
newEntity.Properties.push_back(ClassProperty());
}
ImGui::EndTable();
}
ImGui::Button("Create");
ImGui::SameLine();
if (ImGui::Button("Cancel"))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if (ImGui::Button("Export"))
{
file->Export();
}
ImGui::SameLine();
if (ImGui::Button("Save"))
{
file->Save();
}
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 100));
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
{
if (ImGui::BeginTabItem("Point entities"))
{
ImVec2 avail = ImGui::GetContentRegionAvail();
avail.y *= .8;
ImGui::BeginChild("table_child", avail, false);
if (ImGui::BeginTable("nested1", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable))
{
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Desciption");
ImGui::TableSetupColumn("Settings");
ImGui::TableSetupColumn("Prefab");
ImGui::TableHeadersRow();
ImGui::TableNextColumn();
int i = 0;
for (auto& pE : file->PointEntities)
{
//ImGuiTextSTD("##PName" + std::to_string(i), pE.Name);
for (int i = 0; i < pE.Name.size(); i++)
{
if (pE.Name[i] == ' ')
pE.Name[i] = '_';
}
ImGui::TableNextColumn();
//ImGuiTextSTD("Desc" + std::to_string(i), pE.Description);
ImGui::TableNextColumn();
ImGui::Button("Edit");
ImGui::TableNextColumn();
//ImGuiTextSTD("Prefab##" + std::to_string(i), pE.Prefab);
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Prefab"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
pE.Prefab = FileSystem::AbsoluteToRelative(fullPath);
}
ImGui::EndDragDropTarget();
}
ImGui::TableNextColumn();
i++;
}
ImGui::EndTable();
}
ImGui::EndChild();
if (ImGui::Button("Add new"))
{
file->PointEntities.push_back(FGDPointEntity("NewPointEntity"));
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Brush entities"))
{
ImVec2 avail = ImGui::GetContentRegionAvail();
avail.y *= .8;
ImGui::BeginChild("table_child", avail, false);
if (ImGui::BeginTable("nested1", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable))
{
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Desciption");
ImGui::TableSetupColumn("Settings");
ImGui::TableSetupColumn("Script");
ImGui::TableHeadersRow();
ImGui::TableNextColumn();
int i = 0;
for (auto& pE : file->BrushEntities)
{
//ImGuiTextSTD("##Name" + std::to_string(i), pE.Name);
ImGui::TableNextColumn();
//ImGuiTextSTD("Desc" + std::to_string(i), pE.Description);
ImGui::TableNextColumn();
ImGui::Checkbox(std::string("Visible##" + std::to_string(i)).c_str(), &pE.Visible);
ImGui::SameLine();
ImGui::Checkbox(std::string("Solid##" + std::to_string(i)).c_str(), &pE.Solid);
ImGui::SameLine();
ImGui::Checkbox(std::string("Trigger##" + std::to_string(i)).c_str(), &pE.IsTrigger);
ImGui::TableNextColumn();
//ImGuiTextSTD("Script##" + std::to_string(i), pE.Script);
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
pE.Script = FileSystem::AbsoluteToRelative(fullPath);
}
ImGui::EndDragDropTarget();
}
//ImGuiTextSTD("Class##" + std::to_string(i), pE.Class);
ImGui::TableNextColumn();
i++;
}
ImGui::TableNextColumn();
ImGui::EndTable();
if (ImGui::BeginPopupModal("CreateBrush", NULL, flags))
{
//ImGuiTextSTD("Name", newEntity.Name);
//ImGuiTextMultiline("Description", newEntity.Description);
bool isSolid = true;
bool isTrigger = false;
bool isVisible = true;
ImGui::Checkbox("Is Solid", &isSolid);
ImGui::Checkbox("Is Trigger", &isTrigger);
ImGui::Checkbox("Is Visible", &isVisible);
if (ImGui::Button("Create"))
{
}
ImGui::SameLine();
if (ImGui::Button("Cancel"))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if (ImGui::Button("Add new"))
{
file->BrushEntities.push_back(FGDBrushEntity("New brush"));
}
}
ImGui::EndChild();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
ImGui::PopStyleVar();
}
ImGui::End();
}
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "src/Core/Core.h"
#include "src/Resource/Project.h"
namespace Nuake {
class ProjectInterface
{
public:
Ref<Project> m_CurrentProject;
void DrawProjectSettings();
void DrawCreatePointEntity();
void DrawEntitySettings();
};
}

View File

@@ -0,0 +1,83 @@
#include "WelcomeWindow.h"
#include <src/Vendors/imgui/imgui.h>
#include "../Misc/InterfaceFonts.h"
#include <string>
#include <vector>
void WelcomeWindow::Draw()
{
std::vector<std::string> projects = {
"C:/Dev/Nuake-DemoProject/test.project"
};
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->GetWorkPos());
ImGui::SetNextWindowSize(viewport->GetWorkSize());
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(32.0f, 32.0f));
ImGui::Begin("AL:SDAL:SKd", 0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize);
{
{
UIFont boldfont = UIFont(Fonts::Title);
std::string text = "Nuake Engine";
auto windowWidth = ImGui::GetWindowSize().x;
auto textWidth = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
ImGui::Text(text.c_str());
}
{
UIFont boldfont = UIFont(Fonts::SubTitle);
std::string text = "An IdTech inspired game engine";
auto windowWidth = ImGui::GetWindowSize().x;
auto textWidth = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
ImGui::Text(text.c_str());
}
ImGui::Separator();
{
UIFont boldfont = UIFont(Fonts::SubTitle);
ImGui::Text("Projects recently opened");
}
ImVec2 projectsWindowSize = ImGui::GetContentRegionAvail();
projectsWindowSize.x *= 0.6f;
int idx = 0;
ImGui::BeginChild("Projects", projectsWindowSize, true);
{
for (int i = 0; i < 6; i++)
{
float cursorY = ImGui::GetCursorPosY();
std::string selectableName = "##My new project" + std::to_string(i);
ImGui::Selectable(selectableName.c_str(), false, 0, ImVec2(ImGui::GetContentRegionAvailWidth(), 100));
ImGui::SetCursorPosY(cursorY);
{
UIFont boldfont = UIFont(Fonts::LargeBold);
ImGui::Text("Name of project");
}
{
UIFont boldfont = UIFont(Fonts::Bold);
ImGui::Text("last modified on 10/20/2022");
}
{
UIFont boldfont = UIFont(Fonts::Normal);
ImGui::TextWrapped("Description lajsflkahjfklashklashgkASDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDlashglkashlkghalskghaslghaslkghaklsg");
//ImGui::Text("Description lajsflkahjfklashklashgklashglkashlkghalskghaslghaslkghaklsg");
}
ImGui::SetCursorPosY(cursorY + 100);
}
}
ImGui::EndChild();
}
ImGui::End();
ImGui::PopStyleVar();
ImGui::PopStyleVar();
}

View File

@@ -0,0 +1,9 @@
#pragma once
class WelcomeWindow {
public:
int SelectedProject = 0;
void Draw();
};