Merge pull request #216 from SHADE-DP/SP3-4-Editor

Added controls to adjust editor camera movement speed and turn speed
This commit is contained in:
XiaoQiDigipen 2022-11-17 17:12:16 +08:00 committed by GitHub
commit c54c59a445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 87 additions and 40 deletions

View File

@ -143,6 +143,18 @@ namespace SHADE
return result; return result;
} }
AssetType SHAssetManager::GetType(AssetID id) noexcept
{
if (assetCollection.contains(id))
{
return assetCollection[id].type;
}
SHLOG_WARNING("AssetID {}, does not belong to an asset", id)
return AssetType::INVALID;
}
std::optional<SHADE::SHAsset> SHAssetManager::GetAsset(AssetID id) noexcept std::optional<SHADE::SHAsset> SHAssetManager::GetAsset(AssetID id) noexcept
{ {
if (assetCollection.contains(id)) if (assetCollection.contains(id))

View File

@ -52,6 +52,8 @@ namespace SHADE
static std::vector<SHAsset> GetAllAssets() noexcept; static std::vector<SHAsset> GetAllAssets() noexcept;
static std::optional<SHAsset> GetAsset(AssetID id) noexcept; static std::optional<SHAsset> GetAsset(AssetID id) noexcept;
static AssetType GetType(AssetID id) noexcept;
/**************************************************************************** /****************************************************************************
* \brief Create record for new resource. CAN ONLY CREATE FOR CUSTOM * \brief Create record for new resource. CAN ONLY CREATE FOR CUSTOM
* RESOURCES CREATED BY THE ENGINE. * RESOURCES CREATED BY THE ENGINE.

View File

@ -5,6 +5,7 @@
namespace SHADE namespace SHADE
{ {
bool SHDragDrop::hasDragDrop = false; bool SHDragDrop::hasDragDrop = false;
SHDragDrop::DragDropTag SHDragDrop::currentDragDropTag{};
bool SHDragDrop::BeginSource(ImGuiDragDropFlags const flags) bool SHDragDrop::BeginSource(ImGuiDragDropFlags const flags)
{ return ImGui::BeginDragDropSource(flags); } { return ImGui::BeginDragDropSource(flags); }
@ -16,6 +17,10 @@ namespace SHADE
{ return ImGui::BeginDragDropTarget(); } { return ImGui::BeginDragDropTarget(); }
void SHDragDrop::EndTarget() void SHDragDrop::EndTarget()
{ ImGui::EndDragDropTarget(); hasDragDrop = false;} {
ImGui::EndDragDropTarget();
hasDragDrop = false;
currentDragDropTag = {};
}
} }

View File

@ -19,9 +19,13 @@ namespace SHADE
static void EndSource(); static void EndSource();
template<typename T> template<typename T>
static bool SetPayload(std::string_view const type, T* object, ImGuiCond const cond = 0) static bool SetPayload(DragDropTag const& type, T* object, ImGuiCond const cond = 0)
{ {
hasDragDrop = ImGui::SetDragDropPayload(type.data(), static_cast<void*>(object), sizeof(T), cond); ImGui::SetDragDropPayload(type.data(), static_cast<void*>(object), sizeof(T), cond);
hasDragDrop = true;
currentDragDropTag = type;
return hasDragDrop; return hasDragDrop;
} }
@ -32,13 +36,16 @@ namespace SHADE
static void EndTarget(); static void EndTarget();
template<typename T> template<typename T>
static T* AcceptPayload(std::string_view const type, ImGuiDragDropFlags const flags = 0) static T* AcceptPayload(DragDropTag const& type, ImGuiDragDropFlags const flags = 0)
{ {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(type.data(), flags)) if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(type.data(), flags))
{
return static_cast<T*>(payload->Data); return static_cast<T*>(payload->Data);
}
return nullptr; return nullptr;
} }
static bool hasDragDrop; static bool hasDragDrop;
static DragDropTag currentDragDropTag;
}; };
} }

View File

@ -109,7 +109,7 @@ namespace SHADE
ImVec2 vertLineEnd = vertLineStart; ImVec2 vertLineEnd = vertLineStart;
for (auto const& subFolder : subFolders) for (auto const& subFolder : subFolders)
{ {
const float horizontalLineSize = 8.0f; const float horizontalLineSize = (subFolder->subFolders.empty() && subFolder->files.empty()) ? 25.0f : 8.0f;
const ImRect childRect = RecursivelyDrawTree(subFolder); const ImRect childRect = RecursivelyDrawTree(subFolder);
const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f;
drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1);
@ -117,7 +117,7 @@ namespace SHADE
} }
for (auto& file : files) for (auto& file : files)
{ {
const float horizontalLineSize = 25.0f; const float horizontalLineSize = (file.assetMeta && !file.assetMeta->subAssets.empty()) ? 8.0f : 25.0f;
const ImRect childRect = DrawFile(file); const ImRect childRect = DrawFile(file);
const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f;
drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1);
@ -182,7 +182,10 @@ namespace SHADE
return nodeRect; return nodeRect;
} }
if(file.assetMeta) if(file.assetMeta)
DrawAsset(file.assetMeta, file.ext); {
const ImRect childRect = DrawAsset(file.assetMeta, file.ext);
return childRect;
}
} }
ImRect SHAssetBrowser::DrawAsset(SHAsset const* const asset, FileExt const& ext /*= ""*/) noexcept ImRect SHAssetBrowser::DrawAsset(SHAsset const* const asset, FileExt const& ext /*= ""*/) noexcept

View File

@ -117,9 +117,12 @@ namespace SHADE
{ {
if(ImGui::IsDragDropActive()) if(ImGui::IsDragDropActive())
{ {
ParentSelectedEntities(MAX_EID, draggingEntities); if (SHDragDrop::currentDragDropTag == SHDragDrop::DRAG_EID)
draggingEntities.clear(); {
ImGui::ClearDragDrop(); ParentSelectedEntities(MAX_EID, draggingEntities);
draggingEntities.clear();
ImGui::ClearDragDrop();
}
} }
} }
ImGui::End(); ImGui::End();
@ -233,8 +236,9 @@ namespace SHADE
{ {
ParentSelectedEntities(eid, draggingEntities); ParentSelectedEntities(eid, draggingEntities);
draggingEntities.clear(); draggingEntities.clear();
SHDragDrop::EndTarget(); //ImGui::ClearDragDrop();
} }
SHDragDrop::EndTarget();
} }
//Context menu //Context menu
@ -342,17 +346,12 @@ namespace SHADE
SHEntityManager::CreateEntity(MAX_EID, "DefaultChild", parentEID); SHEntityManager::CreateEntity(MAX_EID, "DefaultChild", parentEID);
} }
void SHHierarchyPanel::ParentSelectedEntities(EntityID parentEID, std::vector<EntityID> const& entities) const noexcept void SHHierarchyPanel::ParentSelectedEntities(EntityID parentEID, std::vector<EntityID> const& entities) noexcept
{ {
auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph();
std::vector<EntityID> entitiesToParent{}; std::vector<EntityID> entitiesToParent = CleanUpEIDList(entities);
std::ranges::copy_if(entities, std::back_inserter(entitiesToParent), [&sceneGraph](EntityID const& eid)
{
if (sceneGraph.GetParent(eid)->GetEntityID() == MAX_EID)
return true;
return false;
});
//auto const editor = SHSystemManager::GetSystem<SHEditor>(); //auto const editor = SHSystemManager::GetSystem<SHEditor>();
SHEntityParentCommand::EntityParentData entityParentData; SHEntityParentCommand::EntityParentData entityParentData;
std::vector<EntityID> parentedEIDS; std::vector<EntityID> parentedEIDS;
@ -419,14 +418,7 @@ namespace SHADE
void SHHierarchyPanel::CopySelectedEntities() void SHHierarchyPanel::CopySelectedEntities()
{ {
const auto editor = SHSystemManager::GetSystem<SHEditor>(); const auto editor = SHSystemManager::GetSystem<SHEditor>();
auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); std::vector<EntityID> entitiesToCopy = CleanUpEIDList(editor->selectedEntities);
std::vector<EntityID> entitiesToCopy{};
std::ranges::copy_if(editor->selectedEntities, std::back_inserter(entitiesToCopy), [&sceneGraph](EntityID const& eid)
{
if(sceneGraph.GetParent(eid)->GetEntityID() == MAX_EID)
return true;
return false;
});
SHClipboardUtilities::WriteToClipboard(SHSerialization::SerializeEntitiesToString(entitiesToCopy)); SHClipboardUtilities::WriteToClipboard(SHSerialization::SerializeEntitiesToString(entitiesToCopy));
} }
@ -439,19 +431,25 @@ namespace SHADE
void SHHierarchyPanel::DeleteSelectedEntities() void SHHierarchyPanel::DeleteSelectedEntities()
{ {
const auto editor = SHSystemManager::GetSystem<SHEditor>(); const auto editor = SHSystemManager::GetSystem<SHEditor>();
std::vector<EntityID> entitiesToDelete = CleanUpEIDList(editor->selectedEntities);
SHCommandManager::PerformCommand(std::make_shared<SHDeleteEntitiesCommand>(entitiesToDelete));
}
std::vector<EntityID> SHHierarchyPanel::CleanUpEIDList(std::vector<EntityID> const& entities)
{
std::vector<EntityID> result;
auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph();
std::vector<EntityID> entitiesToDelete{}; std::ranges::copy_if(entities, std::back_inserter(result), [&sceneGraph, &entities](EntityID const& eid)
std::ranges::copy_if(editor->selectedEntities, std::back_inserter(entitiesToDelete), [&sceneGraph, &selectedEntities = editor->selectedEntities](EntityID const& eid)
{ {
EntityID parentEID = sceneGraph.GetParent(eid)->GetEntityID(); EntityID parentEID = sceneGraph.GetParent(eid)->GetEntityID();
if (parentEID == MAX_EID) if (parentEID == MAX_EID)
return true; return true;
else if(std::ranges::find(selectedEntities, parentEID) == selectedEntities.end()) if (std::ranges::find(entities, parentEID) == entities.end())
return true; return true;
return false; return false;
}); });
SHCommandManager::PerformCommand(std::make_shared<SHDeleteEntitiesCommand>(entitiesToDelete)); return result;
} }
}//namespace SHADE }//namespace SHADE

View File

@ -27,12 +27,13 @@ namespace SHADE
void DrawMenuBar() const noexcept; void DrawMenuBar() const noexcept;
ImRect RecursivelyDrawEntityNode(SHSceneNode* const); ImRect RecursivelyDrawEntityNode(SHSceneNode* const);
void CreateChildEntity(EntityID parentEID) const noexcept; void CreateChildEntity(EntityID parentEID) const noexcept;
void ParentSelectedEntities(EntityID parentEID, std::vector<EntityID> const& entities) const noexcept; void ParentSelectedEntities(EntityID parentEID, std::vector<EntityID> const& entities) noexcept;
void SelectRangeOfEntities(EntityID beginEID, EntityID EndEID); void SelectRangeOfEntities(EntityID beginEID, EntityID EndEID);
void SelectAllEntities(); void SelectAllEntities();
void CopySelectedEntities(); void CopySelectedEntities();
void PasteEntities(EntityID parentEID = MAX_EID); void PasteEntities(EntityID parentEID = MAX_EID);
void DeleteSelectedEntities(); void DeleteSelectedEntities();
std::vector<EntityID> CleanUpEIDList(std::vector<EntityID> const& entities);
bool skipFrame = false; bool skipFrame = false;
std::string filter; std::string filter;
bool isAnyNodeSelected = false; bool isAnyNodeSelected = false;

View File

@ -454,6 +454,11 @@ namespace SHADE
}, },
[component](AssetID const& id) [component](AssetID const& id)
{ {
if(SHAssetManager::GetType(id) != AssetType::MESH)
{
SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!")
return;
}
component->SetMesh(SHResourceManager::LoadOrGet<SHMesh>(id)); component->SetMesh(SHResourceManager::LoadOrGet<SHMesh>(id));
SHResourceManager::FinaliseChanges(); SHResourceManager::FinaliseChanges();
}, SHDragDrop::DRAG_RESOURCE); }, SHDragDrop::DRAG_RESOURCE);
@ -469,6 +474,11 @@ namespace SHADE
}, },
[component](AssetID const& id) [component](AssetID const& id)
{ {
if (SHAssetManager::GetType(id) != AssetType::MATERIAL)
{
SHLOG_WARNING("Attempted to assign non material asset to Renderable Mesh property!")
return;
}
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>(); auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
component->SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(SHResourceManager::LoadOrGet<SHMaterial>(id))); component->SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(SHResourceManager::LoadOrGet<SHMaterial>(id)));
}, SHDragDrop::DRAG_RESOURCE); }, SHDragDrop::DRAG_RESOURCE);

View File

@ -14,6 +14,7 @@
#include "Camera/SHCameraSystem.h" #include "Camera/SHCameraSystem.h"
#include "FRC/SHFramerateController.h" #include "FRC/SHFramerateController.h"
#include "../../SHEditorWidgets.hpp"
constexpr std::string_view windowName = "\xef\x80\x95 Viewport"; constexpr std::string_view windowName = "\xef\x80\x95 Viewport";
@ -193,6 +194,13 @@ namespace SHADE
if (isScale) if (isScale)
ImGui::PopStyleColor(); ImGui::PopStyleColor();
ImGui::EndDisabled(); ImGui::EndDisabled();
auto camSystem = SHSystemManager::GetSystem<SHCameraSystem>();
auto editorCamera = camSystem->GetEditorCamera();
//ImGui::SetNextItemWidth(10.0f);
SHEditorWidgets::SliderFloat("CamSpeed", 0.0f, 5.0f, [editorCamera] {return editorCamera->movementSpeed; }, [editorCamera](float const& value) {editorCamera->movementSpeed = value; });
SHEditorWidgets::DragVec3("TurnSpeed", { "X", "Y", "Z" }, [editorCamera] {return editorCamera->turnSpeed; }, [editorCamera](SHVec3 const& value) {editorCamera->turnSpeed = value; });
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
} }

View File

@ -422,7 +422,7 @@ namespace SHADE
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.data()); ImGui::PushID(label.data());
TextLabel(label); TextLabel(label);
bool changed = ImGui::InputText("##", &text, ImGuiInputTextFlags_ReadOnly, nullptr, nullptr); bool changed = ImGui::InputText("##inputText", &text, ImGuiInputTextFlags_ReadOnly, nullptr, nullptr);
if(SHDragDrop::BeginTarget()) if(SHDragDrop::BeginTarget())
{ {
if(T* payload = SHDragDrop::AcceptPayload<T>(dragDropTag)) if(T* payload = SHDragDrop::AcceptPayload<T>(dragDropTag))
@ -454,7 +454,7 @@ namespace SHADE
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.data()); ImGui::PushID(label.data());
TextLabel(label); TextLabel(label);
const bool hasChange = ImGui::DragScalar("##", data_type, &value, speed, &p_min, &p_max, displayFormat, flags); const bool hasChange = ImGui::DragScalar("##dragScalar", data_type, &value, speed, &p_min, &p_max, displayFormat, flags);
static bool startRecording = false; static bool startRecording = false;
if (hasChange) if (hasChange)
{ {
@ -487,7 +487,7 @@ namespace SHADE
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.data()); ImGui::PushID(label.data());
TextLabel(label); TextLabel(label);
const bool hasChange = ImGui::DragFloat("##", &value, speed, p_min, p_max, displayFormat, flags); const bool hasChange = ImGui::DragFloat("##dragFloat", &value, speed, p_min, p_max, displayFormat, flags);
static bool startRecording = false; static bool startRecording = false;
if (hasChange) if (hasChange)
{ {
@ -520,7 +520,7 @@ namespace SHADE
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.data()); ImGui::PushID(label.data());
TextLabel(label); TextLabel(label);
const bool hasChange = ImGui::DragInt("##", &value, speed, p_min, p_max, displayFormat, flags); const bool hasChange = ImGui::DragInt("##dragInt", &value, speed, p_min, p_max, displayFormat, flags);
static bool startRecording = false; static bool startRecording = false;
if (hasChange) if (hasChange)
{ {
@ -553,7 +553,7 @@ namespace SHADE
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.data()); ImGui::PushID(label.data());
TextLabel(label); TextLabel(label);
bool const hasChange = ImGui::SliderScalar("##", data_type, &value, &min, &max, displayFormat, flags); bool const hasChange = ImGui::SliderScalar("##sliderScalar", data_type, &value, &min, &max, displayFormat, flags);
static bool startRecording = false; static bool startRecording = false;
if (hasChange) if (hasChange)
{ {
@ -587,7 +587,8 @@ namespace SHADE
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.data()); ImGui::PushID(label.data());
TextLabel(label); TextLabel(label);
bool const hasChange = ImGui::SliderFloat("##", &value, min, max, displayFormat, flags); ImGui::SetNextItemWidth(ImGui::CalcTextSize(displayFormat).x + ImGui::GetStyle().ItemInnerSpacing.x * 2.0f);
bool const hasChange = ImGui::SliderFloat("##sliderFloat", &value, min, max, displayFormat, flags);
static bool startRecording = false; static bool startRecording = false;
if (hasChange) if (hasChange)
{ {
@ -621,7 +622,7 @@ namespace SHADE
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.data()); ImGui::PushID(label.data());
TextLabel(label); TextLabel(label);
bool const hasChange = ImGui::SliderInt("##", &value, min, max, displayFormat, flags); bool const hasChange = ImGui::SliderInt("##sliderInt", &value, min, max, displayFormat, flags);
static bool startRecording = false; static bool startRecording = false;
if (hasChange) if (hasChange)
{ {

View File

@ -12,8 +12,8 @@
#include "Assets/Asset Types/SHSceneAsset.h" #include "Assets/Asset Types/SHSceneAsset.h"
#include "Camera/SHCameraComponent.h" #include "Camera/SHCameraComponent.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Physics/Interface/SHRigidBodyComponent.h" #include "Physics/Interface/SHRigidBodyComponent.h"
#include "ECS_Base/Managers/SHSystemManager.h" #include "ECS_Base/Managers/SHSystemManager.h"
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h"