Added shortcut to open resource in component widgets

This commit is contained in:
antopilo
2024-11-21 22:14:14 -05:00
parent 4ab59bf7e8
commit 84b2b63ba9
7 changed files with 45 additions and 19 deletions

View File

@@ -123,7 +123,8 @@ namespace Nuake {
_NewProjectWindow = new NewProjectWindow(this);
_audioWindow = new AudioWindow();
m_ProjectSettingsWindow = new ProjectSettingsWindow();
SelectionPanel = new EditorSelectionPanel(this->Selection);
Logger::Log("Building fonts", "window", VERBOSE);
BuildFonts();
@@ -2623,7 +2624,7 @@ namespace Nuake {
//pInterface.DrawEntitySettings();
DrawViewport();
DrawSceneTree();
SelectionPanel.Draw(Selection);
SelectionPanel->Draw(Selection);
DrawLogger();
filesystem->Draw();
filesystem->DrawDirectoryExplorer();

View File

@@ -76,7 +76,7 @@ namespace Nuake
FileSystemUI* filesystem;
bool isNewProject = false;
static EditorSelection Selection;
EditorSelectionPanel SelectionPanel;
EditorSelectionPanel* SelectionPanel;
TrenchbroomConfiguratorWindow m_TrenchhbroomConfigurator;
MapImporterWindow m_MapImporter;

View File

@@ -1,6 +1,7 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include "EditorSelectionPanel.h"
#include "EditorInterface.h"
#include "../Misc/ImGuiTextHelper.h"
#include <src/Scene/Components.h>
#include "src/Scene/Components/FieldTypes.h"
@@ -25,8 +26,10 @@
using namespace Nuake;
EditorSelectionPanel::EditorSelectionPanel()
EditorSelectionPanel::EditorSelectionPanel(EditorSelection& inSelection)
{
selection = &inSelection;
virtualScene = CreateRef<Scene>();
virtualScene->SetName("Virtual Scene");
virtualScene->CreateEntity("Camera").AddComponent<CameraComponent>();
@@ -2075,6 +2078,8 @@ void EditorSelectionPanel::DrawFieldTypeResourceFile(entt::meta_data& field, ent
auto fieldValPtr = fieldVal.try_cast<ResourceFile>();
if (fieldValPtr != nullptr)
{
ImGui::SetNextItemAllowOverlap();
auto fieldValProxy = *fieldValPtr;
std::string filePath = fieldValProxy.file == nullptr ? "" : fieldValProxy.file->GetRelativePath();
std::string controlName = filePath + std::string("##") + displayName;
@@ -2092,6 +2097,27 @@ void EditorSelectionPanel::DrawFieldTypeResourceFile(entt::meta_data& field, ent
}
ImGui::EndDragDropTarget();
}
ImGui::SameLine();
bool showShortcutBtn = !filePath.empty();
const int shortcutBtnWidth = 30;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - shortcutBtnWidth - ImGui::GetStyle().ItemSpacing.x);
if(ImGui::Button(">", ImVec2(shortcutBtnWidth, 0)))
{
if (FileSystem::FileExists(filePath))
{
Ref<Nuake::File> file = FileSystem::GetFile(filePath);
if (file->GetFileType() == FileType::Map)
{
OS::OpenTrenchbroomMap(file->GetAbsolutePath());
}
else
{
*selection = EditorSelection(FileSystem::GetFile(filePath));
}
}
}
}
else
{

View File

@@ -33,13 +33,14 @@ class EditorSelectionPanel
private:
TransformPanel mTransformPanel;
MeshPanel meshPanel;
EditorSelection* selection = nullptr;
Ref<Nuake::File> currentFile;
Ref<Nuake::Resource> selectedResource;
Ref<Nuake::Scene> virtualScene;
public:
EditorSelectionPanel();
EditorSelectionPanel(EditorSelection& selection);
void Draw(EditorSelection selection, const std::string& id = "");

View File

@@ -305,7 +305,7 @@ void PrefabEditorWindow::Draw()
}
ImGui::End();
SelectionPanel.Draw(Selection, prefab->Path);
SelectionPanel->Draw(Selection, prefab->Path);
DrawViewportWindow();
}

View File

@@ -36,7 +36,7 @@ private:
bool isRenaming;
bool isInitialized = false;
EditorSelectionPanel SelectionPanel;
EditorSelectionPanel* SelectionPanel;
EditorSelection Selection;
Nuake::Entity QueueDeletion;
ImGuizmo::OPERATION CurrentOperation = ImGuizmo::TRANSLATE;