Added display of editor camera position #368

Merged
srishamharan merged 6 commits from SP3-4-Editor into main 2023-02-27 11:59:58 +08:00
4 changed files with 140 additions and 23 deletions

View File

@ -96,30 +96,32 @@ namespace SHADE
} }
ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal); ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal);
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_A)) if (!ImGui::IsAnyItemFocused())
{ {
SelectAllEntities(); if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_A))
}
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_C))
{
CopySelectedEntities();
}
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && !ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V))
{
PasteEntities();
}
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V))
{
if (editor->selectedEntities.size() == 1)
{ {
PasteEntities(editor->selectedEntities.back()); SelectAllEntities();
}
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_C))
{
CopySelectedEntities();
}
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && !ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V))
{
PasteEntities();
}
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V))
{
if (editor->selectedEntities.size() == 1)
{
PasteEntities(editor->selectedEntities.back());
}
}
if (ImGui::IsKeyReleased(ImGuiKey_Delete))
{
DeleteSelectedEntities();
} }
} }
if (ImGui::IsKeyReleased(ImGuiKey_Delete))
{
DeleteSelectedEntities();
}
} }
if(ImGui::IsWindowHovered() && !ImGui::IsAnyItemHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) if(ImGui::IsWindowHovered() && !ImGui::IsAnyItemHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
{ {

View File

@ -26,6 +26,8 @@
#include "Serialization/Configurations/SHConfigurationManager.h" #include "Serialization/Configurations/SHConfigurationManager.h"
#include "Editor/EditorWindow/SHEditorWindowManager.h" #include "Editor/EditorWindow/SHEditorWindowManager.h"
#include "Physics/System/SHPhysicsDebugDrawSystem.h" #include "Physics/System/SHPhysicsDebugDrawSystem.h"
#include "Camera/SHCameraSystem.h"
#include "Tools/Utilities/SHClipboardUtilities.h"
const std::string LAYOUT_FOLDER_PATH{ std::string(ASSET_ROOT) + "/Editor/Layouts" }; const std::string LAYOUT_FOLDER_PATH{ std::string(ASSET_ROOT) + "/Editor/Layouts" };
@ -154,7 +156,39 @@ namespace SHADE
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]);
if (ImGui::BeginViewportSideBar("MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, menuBarHeight, editorMenuBarFlags)) if (ImGui::BeginViewportSideBar("MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, menuBarHeight, editorMenuBarFlags))
{ {
ImGui::Text("Entity count: %zu", SHEntityManager::GetEntityCount()); auto camSystem = SHSystemManager::GetSystem<SHCameraSystem>();
std::string editorCamPosText{};
auto editorCam = camSystem->GetEditorCamera();
if(editorCam)
{
auto editorCamPos = editorCam->GetPosition();
editorCamPosText = std::format("Editor Cam [X: {:.3f}, Y: {:.3f}, Z: {:.3f}]", editorCamPos.x, editorCamPos.y, editorCamPos.z);
//ImGui::Text(editorCamPosText.data());
}
ImGui::Text("Entity count: %zu %s", SHEntityManager::GetEntityCount(), editorCamPosText.data());
if(ImGui::BeginPopupContextItem("EditorCamPosContext"))
{
if(editorCam)
{
if(ImGui::Selectable("Copy Editor Cam Pos X"))
{
auto editorCamPos = editorCam->GetPosition();
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.x));
}
if (ImGui::Selectable("Copy Editor Cam Pos Y"))
{
auto editorCamPos = editorCam->GetPosition();
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.y));
}
if (ImGui::Selectable("Copy Editor Cam Pos Z"))
{
auto editorCamPos = editorCam->GetPosition();
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.z));
}
}
ImGui::EndPopup();
}
} }
ImGui::End(); ImGui::End();
ImGui::PopStyleColor(); ImGui::PopStyleColor();

View File

@ -122,12 +122,22 @@ namespace SHADE
//auto pos = ImGui::GetCursorPos(); //auto pos = ImGui::GetCursorPos();
//windowCursorPos = {} //windowCursorPos = {}
if (beginContentRegionAvailable.x == 0 || beginContentRegionAvailable.y == 0) if (beginContentRegionAvailable.x == 0 || beginContentRegionAvailable.y == 0)
{ {
beginContentRegionAvailable = windowSize; beginContentRegionAvailable = windowSize;
} }
gfxSystem->PrepareResize(static_cast<uint32_t>(beginContentRegionAvailable.x), static_cast<uint32_t>(beginContentRegionAvailable.y));
//beginContentRegionAvailable = CalculateWindowSize(beginContentRegionAvailable);
SHVec2 viewportSize = CalculateWindowSize(beginContentRegionAvailable);
gfxSystem->PrepareResize(static_cast<uint32_t>(viewportSize.x), static_cast<uint32_t>(viewportSize.y));
shouldUpdateCamera = true; shouldUpdateCamera = true;
//if (aspectRatio != AspectRatio::FREE && (ImGui::IsMouseDown(ImGuiMouseButton_Left) || ImGui::IsMouseReleased(ImGuiMouseButton_Left)))
//{
// windowSize = CalculateWindowSize(windowSize);
// beginContentRegionAvailable = CalculateWindowSize(beginContentRegionAvailable);
// ImGui::SetWindowSize(windowName.data(), CalculateWindowSize(windowSize));
//}
} }
void SHEditorViewport::OnPosChange() void SHEditorViewport::OnPosChange()
@ -195,13 +205,73 @@ namespace SHADE
ImGui::PopStyleColor(); ImGui::PopStyleColor();
ImGui::EndDisabled(); ImGui::EndDisabled();
//TODO: Shift to constructor
auto arRTTRtype = rttr::type::get<SHEditorViewport::AspectRatio>();
auto enumAlign = arRTTRtype.get_enumeration();
auto names = enumAlign.get_names();
std::vector<const char*> arNames;
for (auto const& name : names)
{
arNames.push_back(name.data());
}
int currentAR = static_cast<int>(aspectRatio);
ImGui::SetNextItemWidth(80.0f);
if (ImGui::Combo("Aspect Ratio", &currentAR, arNames.data(), arNames.size()))
{
aspectRatio = static_cast<AspectRatio>(currentAR);
windowSize = CalculateWindowSize(windowSize);
ImGui::SetWindowSize(windowSize);
//beginContentRegionAvailable = CalculateWindowSize(beginContentRegionAvailable);
//OnResize();
}
auto camSystem = SHSystemManager::GetSystem<SHCameraSystem>(); auto camSystem = SHSystemManager::GetSystem<SHCameraSystem>();
auto editorCamera = camSystem->GetEditorCamera(); auto editorCamera = camSystem->GetEditorCamera();
//ImGui::SetNextItemWidth(10.0f); //ImGui::SetNextItemWidth(10.0f);
SHEditorWidgets::SliderFloat("CamSpeed", 0.0f, 5.0f, [editorCamera] {return editorCamera->movementSpeed; }, [editorCamera](float const& value) {editorCamera->movementSpeed = value; }); 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; }); SHEditorWidgets::DragVec3("TurnSpeed", { "X", "Y", "Z" }, [editorCamera] {return editorCamera->turnSpeed; }, [editorCamera](SHVec3 const& value) {editorCamera->turnSpeed = value; });
//if(ImGui::BeginCombo("Aspect Ratio", arNames[(uint8_t)aspectRatio].data()))
//{
// auto nameIt = names.begin();
// auto valueIt = values.end();
// while(nameIt != names.end() && valueIt != values.end())
// {
// if ImGui::Beg
// }
//}
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
} }
SHVec2 SHEditorViewport::CalculateWindowSize(SHVec2 const& rhs) noexcept
{
switch (aspectRatio)
{
case SHADE::SHEditorViewport::AspectRatio::FREE:
return rhs;
case SHADE::SHEditorViewport::AspectRatio::AR16_9:
return SHVec2(rhs.x, rhs.x * 0.5625f);
case SHADE::SHEditorViewport::AspectRatio::AR21_9:
return SHVec2(rhs.x, rhs.x * 0.42857f);
case SHADE::SHEditorViewport::AspectRatio::AR21_10:
return SHVec2(rhs.x, rhs.x * 0.47619f);
default:
return rhs;
}
}
}//namespace SHADE }//namespace SHADE
RTTR_REGISTRATION
{
using namespace rttr;
using namespace SHADE;
registration::enumeration<SHEditorViewport::AspectRatio>("AspectRatio")(
value("FREE", SHEditorViewport::AspectRatio::FREE),
value("16:9", SHEditorViewport::AspectRatio::AR16_9),
value("21:9", SHEditorViewport::AspectRatio::AR21_9),
value("21:10", SHEditorViewport::AspectRatio::AR21_10)
);
}

View File

@ -16,7 +16,15 @@ namespace SHADE
{ {
class SHEditorViewport final : public SHEditorWindow class SHEditorViewport final : public SHEditorWindow
{ {
public: public:
enum class AspectRatio : uint8_t
{
FREE,
AR16_9,
AR21_9,
AR21_10
};
SHEditorViewport(); SHEditorViewport();
void Init() override; void Init() override;
void Update() override; void Update() override;
@ -27,9 +35,12 @@ namespace SHADE
void OnPosChange() override; void OnPosChange() override;
private: private:
void DrawMenuBar() noexcept; void DrawMenuBar() noexcept;
SHVec2 beginCursorPos; SHVec2 CalculateWindowSize(SHVec2 const& rhs) noexcept;
bool shouldUpdateCamera = false; bool shouldUpdateCamera = false;
bool shouldUpdateCamArm = false; bool shouldUpdateCamArm = false;
AspectRatio aspectRatio {AspectRatio::FREE};
SHVec2 beginCursorPos;
SHVec3 targetPos; SHVec3 targetPos;
};//class SHEditorViewport };//class SHEditorViewport
}//namespace SHADE }//namespace SHADE