Added Trenchbroom configurator window and some UI fixes
This commit is contained in:
194
Editor/TrenchbroomConfiguratorWindow.cpp
Normal file
194
Editor/TrenchbroomConfiguratorWindow.cpp
Normal file
@@ -0,0 +1,194 @@
|
||||
#include "TrenchbroomConfiguratorWindow.h"
|
||||
|
||||
#include <Engine.h>
|
||||
#include <src/UI/ImUI.h>
|
||||
#include <src/Core/OS.h>
|
||||
#include <src/Rendering/Textures/TextureManager.h>
|
||||
#include <src/Resource/Prefab.h>
|
||||
|
||||
void TrenchbroomConfiguratorWindow::Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TrenchbroomConfiguratorWindow::Draw()
|
||||
{
|
||||
auto& io = ImGui::GetIO();
|
||||
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(600, 400), ImVec2(1920, 1080));
|
||||
if (ImGui::Begin("Trenchbroom Configurator"))
|
||||
{
|
||||
ImGui::PushFont(FontManager::GetFont(Bold));
|
||||
ImGui::Text("What is this?");
|
||||
ImGui::PopFont();
|
||||
|
||||
ImGui::TextWrapped("The trenchbroom configurator is where you define your entities visible in trenchbroom. You can either define point entities from prefabs, or brush entities from scripts.");
|
||||
|
||||
ImGui::PushFont(FontManager::GetFont(Bold));
|
||||
ImGui::Text("Warning");
|
||||
ImGui::PopFont();
|
||||
|
||||
ImGui::TextWrapped("Make sure you have set your trenchbroom executable path in the project settings by click on your .project file in the file browser.");
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
auto project = Engine::GetProject();
|
||||
ImVec2 childSize = ImVec2();
|
||||
childSize.x = ImGui::GetContentRegionAvail().x;
|
||||
childSize.y = (ImGui::GetContentRegionAvail().y) - (ImGui::GetFontSize() * 2.0f + (16.0f * 2.0f));
|
||||
if (ImGui::BeginTabBar("##tabs", ImGuiTabBarFlags_None))
|
||||
{
|
||||
if(ImGui::BeginTabItem("Point Entities"))
|
||||
{
|
||||
ImGui::BeginChild("PointEntities", childSize, true);
|
||||
auto avail = ImGui::GetContentRegionAvail();
|
||||
const ImVec2 buttonSize = ImVec2(120, 120);
|
||||
int amount = avail.x / 110;
|
||||
if (amount <= 0)
|
||||
{
|
||||
amount = 1;
|
||||
}
|
||||
|
||||
if (ImGui::BeginTable("pointEntitiesUITable", amount))
|
||||
{
|
||||
|
||||
uint32_t itemIndex = 0;
|
||||
for (const auto& pe : project->EntityDefinitionsFile->PointEntities)
|
||||
{
|
||||
const auto& prefab = pe.Prefab;
|
||||
if (!prefab.empty())
|
||||
{
|
||||
DrawPrefabItem(pe);
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
itemIndex++;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Prefab"))
|
||||
{
|
||||
std::string fullPath = std::string(reinterpret_cast<char*>(payload->Data), 256);
|
||||
std::string relPath = FileSystem::AbsoluteToRelative(fullPath);
|
||||
|
||||
// Make sure file exists
|
||||
if (FileSystem::FileExists(relPath))
|
||||
{
|
||||
Ref<Prefab> prefab = Prefab::New(relPath);
|
||||
FGDPointEntity newPointEntity;
|
||||
newPointEntity.Name = prefab->DisplayName;
|
||||
newPointEntity.Prefab = relPath;
|
||||
newPointEntity.Description = prefab->DisplayName.empty() ? "No description provided" : prefab->DisplayName;
|
||||
project->EntityDefinitionsFile->PointEntities.push_back(std::move(newPointEntity));
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Log("Failed to import prefab file. File doesn't exists", "trenchbroom", CRITICAL);
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem("Brush Entities"))
|
||||
{
|
||||
ImGui::BeginChild("BushEntities", childSize, true);
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
|
||||
if (UI::PrimaryButton("Export"))
|
||||
{
|
||||
project->EntityDefinitionsFile->Export();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void TrenchbroomConfiguratorWindow::DrawPrefabItem(const Nuake::FGDPointEntity& pointEntity)
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
ImGui::PushFont(FontManager::GetFont(Icons));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
|
||||
const char* icon = ICON_FA_FOLDER;
|
||||
const std::string id = std::string("##") + pointEntity.Name;
|
||||
|
||||
ImVec2 prevCursor = ImGui::GetCursorPos();
|
||||
ImVec2 prevScreenPos = ImGui::GetCursorScreenPos();
|
||||
const bool selected = ImGui::Selectable(id.c_str(), false, ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick, ImVec2(100, 150));
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
ImGui::SetTooltip(pointEntity.Prefab.c_str());
|
||||
|
||||
|
||||
ImGui::SetCursorPos(prevCursor);
|
||||
ImGui::Image((ImTextureID)Nuake::TextureManager::Get()->GetTexture("Resources/Images/folder_icon.png")->GetID(), ImVec2(100, 100), ImVec2(0, 1), ImVec2(1, 0));
|
||||
|
||||
auto& imguiStyle = ImGui::GetStyle();
|
||||
|
||||
ImVec2 startOffset = ImVec2(imguiStyle.CellPadding.x / 2.0f, 0);
|
||||
ImVec2 offsetEnd = ImVec2(startOffset.x + imguiStyle. CellPadding.x / 2.0f, 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;
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(prevScreenPos + ImVec2(0, 100) - startOffset, prevScreenPos + ImVec2(100, 101) + offsetEnd, rectColor2, 0.0f);
|
||||
std::string visibleName = pointEntity.Name;
|
||||
const uint32_t MAX_CHAR_NAME = 35;
|
||||
if (visibleName.size() > MAX_CHAR_NAME)
|
||||
{
|
||||
visibleName = std::string(visibleName.begin(), visibleName.begin() + MAX_CHAR_NAME - 3) + "...";
|
||||
}
|
||||
|
||||
ImGui::TextWrapped(visibleName.c_str());
|
||||
|
||||
ImGui::SetCursorPosY(prevCursor.y + 150 - ImGui::GetTextLineHeight());
|
||||
ImGui::TextColored({ 1, 1, 1, 0.5f }, "Prefab");
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
|
||||
if (ImGui::BeginPopup(visibleName.c_str()))
|
||||
{
|
||||
if (ImGui::MenuItem("Remove"))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::BeginMenu("Copy"))
|
||||
{
|
||||
if (ImGui::MenuItem("Prefab Path"))
|
||||
{
|
||||
OS::CopyToClipboard(FileSystem::RelativeToAbsolute(pointEntity.Prefab));
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::MenuItem("Show in File Explorer"))
|
||||
{
|
||||
OS::OpenIn(FileSystem::RelativeToAbsolute(pointEntity.Prefab));
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::PopFont();
|
||||
}
|
||||
19
Editor/TrenchbroomConfiguratorWindow.h
Normal file
19
Editor/TrenchbroomConfiguratorWindow.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class FGDPointEntity;
|
||||
}
|
||||
|
||||
class TrenchbroomConfiguratorWindow
|
||||
{
|
||||
public:
|
||||
TrenchbroomConfiguratorWindow() = default;
|
||||
~TrenchbroomConfiguratorWindow() = default;
|
||||
|
||||
void Update();
|
||||
void Draw();
|
||||
void DrawPrefabItem(const Nuake::FGDPointEntity& pointEntity);
|
||||
private:
|
||||
|
||||
};
|
||||
@@ -38,7 +38,10 @@ void ScriptPanel::Draw(Nuake::Entity entity)
|
||||
{
|
||||
if(!component.Script.empty())
|
||||
{
|
||||
Nuake::OS::OpenIn(component.mWrenScript->GetFile()->GetAbsolutePath());
|
||||
if (component.mWrenScript)
|
||||
{
|
||||
Nuake::OS::OpenIn(component.mWrenScript->GetFile()->GetAbsolutePath());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1497,7 +1497,9 @@ namespace Nuake {
|
||||
ImVec4 color = ImVec4(1, 1, 1, 1.0);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, color);
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ImGui::GetColorU32(ImVec4(1, 1, 1, 0.0)), -1);
|
||||
ImGui::TextWrapped(l.message.c_str());
|
||||
|
||||
std::string displayMessage = l.message + "(" + std::to_string(l.count) + ")";
|
||||
ImGui::TextWrapped(displayMessage.c_str());
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
@@ -1740,14 +1742,26 @@ namespace Nuake {
|
||||
if (ImGui::MenuItem("Cut", "CTRL+X")) {}
|
||||
if (ImGui::MenuItem("Copy", "CTRL+C")) {}
|
||||
if (ImGui::MenuItem("Paste", "CTRL+V")) {}
|
||||
ImGui::Separator();
|
||||
|
||||
if(ImGui::MenuItem("Trenchbroom Configurator", NULL, m_ShowTrenchbroomConfigurator))
|
||||
{
|
||||
m_ShowTrenchbroomConfigurator = !m_ShowTrenchbroomConfigurator;
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("View"))
|
||||
{
|
||||
if (ImGui::MenuItem("Draw grid", NULL, m_DrawGrid))
|
||||
{
|
||||
m_DrawGrid = !m_DrawGrid;
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Draw Axis", NULL, m_DrawAxis))
|
||||
{
|
||||
m_DrawAxis = !m_DrawAxis;
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Draw collisions", NULL, m_DebugCollisions))
|
||||
{
|
||||
m_DebugCollisions = !m_DebugCollisions;
|
||||
@@ -1886,6 +1900,11 @@ namespace Nuake {
|
||||
|
||||
_audioWindow->Draw();
|
||||
|
||||
if (m_ShowTrenchbroomConfigurator)
|
||||
{
|
||||
m_TrenchhbroomConfigurator.Draw();
|
||||
}
|
||||
|
||||
DrawMenuBar();
|
||||
|
||||
pInterface.DrawEntitySettings();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "EditorSelectionPanel.h"
|
||||
#include "WelcomeWindow.h"
|
||||
#include "AudioWindow.h"
|
||||
#include "../../TrenchbroomConfiguratorWindow.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
@@ -27,6 +28,7 @@ namespace Nuake
|
||||
bool m_ShowOverlay = true;
|
||||
bool m_IsHoveringViewport = false;
|
||||
bool m_IsViewportFocused = false;
|
||||
bool m_ShowTrenchbroomConfigurator = false;
|
||||
|
||||
Vector2 m_ViewportPos = {0, 0};
|
||||
Vector2 m_ViewportSize = {};
|
||||
@@ -43,6 +45,7 @@ namespace Nuake
|
||||
FileSystemUI* filesystem;
|
||||
EditorSelection Selection;
|
||||
EditorSelectionPanel SelectionPanel;
|
||||
TrenchbroomConfiguratorWindow m_TrenchhbroomConfigurator;
|
||||
|
||||
EditorInterface();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <src/Scripting/WrenScript.h>
|
||||
|
||||
#include <Engine.h>
|
||||
#include <src/Resource/Prefab.h>
|
||||
|
||||
EditorSelectionPanel::EditorSelectionPanel()
|
||||
{
|
||||
@@ -59,7 +60,7 @@ void EditorSelectionPanel::Draw(EditorSelection selection)
|
||||
|
||||
if (!selection.File->IsValid())
|
||||
{
|
||||
std::string text = "File is invaluid";
|
||||
std::string text = "File is invalid";
|
||||
auto windowWidth = ImGui::GetWindowSize().x;
|
||||
auto windowHeight = ImGui::GetWindowSize().y;
|
||||
|
||||
@@ -175,18 +176,30 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity)
|
||||
void EditorSelectionPanel::DrawFile(Ref<Nuake::File> file)
|
||||
{
|
||||
using namespace Nuake;
|
||||
if (file->GetExtension() == ".material")
|
||||
{
|
||||
MaterialEditor matEditor;
|
||||
matEditor.Draw(std::static_pointer_cast<Material>(selectedResource));
|
||||
}
|
||||
if (file->GetExtension() == ".project")
|
||||
{
|
||||
DrawProjectPanel(Nuake::Engine::GetProject());
|
||||
}
|
||||
if (file->GetExtension() == ".wren")
|
||||
switch (file->GetFileType())
|
||||
{
|
||||
DrawWrenScriptPanel(CreateRef<WrenScript>(file, true));
|
||||
case FileType::Material:
|
||||
{
|
||||
MaterialEditor matEditor;
|
||||
matEditor.Draw(std::static_pointer_cast<Material>(selectedResource));
|
||||
break;
|
||||
}
|
||||
case FileType::Project:
|
||||
{
|
||||
DrawProjectPanel(Nuake::Engine::GetProject());
|
||||
break;
|
||||
}
|
||||
case FileType::Script:
|
||||
{
|
||||
DrawWrenScriptPanel(CreateRef<WrenScript>(file, true));
|
||||
break;
|
||||
}
|
||||
case FileType::Prefab:
|
||||
{
|
||||
//Ref<Prefab> prefab = CreateRef<Prefab>(file->GetRelativePath());
|
||||
//DrawPrefabPanel(prefab);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
struct ProjectSettings
|
||||
{
|
||||
bool ShowGizmos = true;
|
||||
bool ShowAxis = true;
|
||||
};
|
||||
|
||||
class Project : public ISerializable
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user