Added scripting interface for cursor visible.

Fixed collider offset undo/redo
Double click object to look at object
Display editor cam pitch/yaw/roll
This commit is contained in:
SHAM-DP 2023-03-01 17:06:53 +08:00
parent dd9eeac0d1
commit 98140aa797
8 changed files with 70 additions and 13 deletions

View File

@ -174,7 +174,6 @@ namespace Sandbox
SHSceneManager::InitSceneManager<SBMainScene>(editorConfig.workingSceneID);
#else
SHSceneManager::InitSceneManager<SBMainScene>(appConfig.startingSceneID);
window.SetMouseVisible(false);
#endif
SHFrameRateController::UpdateFRC();
@ -183,7 +182,6 @@ namespace Sandbox
auto clip = SHResourceManager::LoadOrGet<SHAnimationClip>(77816045);
auto rig = SHResourceManager::LoadOrGet<SHRig>(77816045);
int i = 0;
}
void SBApplication::Update(void)

View File

@ -31,6 +31,8 @@
#include "../AssetBrowser/SHAssetBrowser.h"
#include "Assets/SHAssetManager.h"
#include "Assets/Asset Types/SHPrefabAsset.h"
#include "Camera/SHCameraSystem.h"
#include "FRC/SHFramerateController.h"
namespace SHADE
@ -442,7 +444,24 @@ namespace SHADE
//Handle node selection
if (ImGui::IsItemHovered())
{
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left))
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
editor->selectedEntities.clear();
editor->selectedEntities.push_back(eid);
if(auto camSystem = SHSystemManager::GetSystem<SHCameraSystem>())
{
if(auto editorCam = camSystem->GetEditorCamera())
{
if(auto entityTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
{
editorCam->SetPosition(entityTransform->GetWorldPosition() + SHVec3(0.5f));
camSystem->CameraLookAt(*editorCam, entityTransform->GetWorldPosition());
camSystem->UpdateEditorCamera(SHFrameRateController::GetRawDeltaTime());
}
}
}
}
else if (ImGui::IsMouseReleased(ImGuiMouseButton_Left))
{
if (!isSelected)
{

View File

@ -387,14 +387,14 @@ namespace SHADE
}
SHEditorWidgets::BeginPanel("Offsets",{ ImGui::GetContentRegionAvail().x, 30.0f });
SHEditorWidgets::DragVec3("Position", { "X", "Y", "Z" }, [&collisionShape] {return collisionShape->GetPositionOffset(); }, [&collisionShape](SHVec3 const& vec) {collisionShape->SetPositionOffset(vec); });
SHEditorWidgets::DragVec3("Position", { "X", "Y", "Z" }, [collisionShape] {return collisionShape->GetPositionOffset(); }, [collisionShape](SHVec3 const& vec) {collisionShape->SetPositionOffset(vec); });
SHEditorWidgets::DragVec3("Rotation", { "X", "Y", "Z" },
[&collisionShape]
[collisionShape]
{
auto offset = collisionShape->GetRotationOffset();
return offset;
},
[&collisionShape](SHVec3 const& vec)
[collisionShape](SHVec3 const& vec)
{
collisionShape->SetRotationOffset(vec);
}, true);

View File

@ -157,16 +157,16 @@ namespace SHADE
if (ImGui::BeginViewportSideBar("MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, menuBarHeight, editorMenuBarFlags))
{
auto camSystem = SHSystemManager::GetSystem<SHCameraSystem>();
std::string editorCamPosText{};
std::string editorCamPosText{}, editorRotText{};
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);
editorRotText = std::format("[Pitch: {:.3f}, Yaw: {:.3f}, Roll: {:.3f}]", editorCam->GetPitch(), editorCam->GetYaw(), editorCam->GetRoll());
//ImGui::Text(editorCamPosText.data());
}
ImGui::Text("Entity count: %zu %s", SHEntityManager::GetEntityCount(), editorCamPosText.data());
ImGui::Text("Entity count: %zu | %s | %s", SHEntityManager::GetEntityCount(), editorCamPosText.data(), editorRotText.data());
if(ImGui::BeginPopupContextItem("EditorCamPosContext"))
{
if(editorCam)
@ -186,6 +186,20 @@ namespace SHADE
auto editorCamPos = editorCam->GetPosition();
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.z));
}
if (ImGui::Selectable("Copy Editor Cam Pitch"))
{
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCam->GetPitch()));
}
if (ImGui::Selectable("Copy Editor Cam Yaw"))
{
auto editorCamPos = editorCam->GetPosition();
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}",editorCam->GetYaw()));
}
if (ImGui::Selectable("Copy Editor Cam Roll"))
{
auto editorCamPos = editorCam->GetPosition();
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}",editorCam->GetRoll()));
}
}
ImGui::EndPopup();
}

View File

@ -183,9 +183,21 @@ namespace SHADE
return WindowSize(screenWidth, screenHeight);
}
bool SHWindow::GetMouseVisible()
{
CURSORINFO cursorInfo{};
cursorInfo.cbSize = sizeof(cursorInfo);
BOOL result = GetCursorInfo(&cursorInfo);
if(!result)
{
auto error = GetLastError();
SHLOG_ERROR("SHWindow: Failed to get cursor info")
}
return cursorInfo.flags != 0;
}
void SHWindow::SetMouseVisible(bool show)
{
if (GetActiveWindow() == wndHWND)
ShowCursor(show);
}

View File

@ -104,7 +104,8 @@ namespace SHADE
//Get size of display the window is in (whichever window contains the window origin)
WindowSize GetCurrentDisplaySize() const;
void SetMouseVisible(bool show);
static bool GetMouseVisible();
static void SetMouseVisible(bool show);
void SetMousePosition(int x = -1, int y = -1);

View File

@ -71,7 +71,14 @@ namespace SHADE
{
return SHGraphicsSystemInterface::SetFullscreen(value);
}*/
bool Application::IsCursorVisible::get()
{
return SHWindow::GetMouseVisible();
}
void Application::IsCursorVisible::set(bool value)
{
SHWindow::SetMouseVisible(value);
}
/*---------------------------------------------------------------------------------*/
/* Usage Functions */
/*---------------------------------------------------------------------------------*/

View File

@ -73,6 +73,12 @@ namespace SHADE
//void set(bool value);
}
static property bool IsCursorVisible
{
bool get();
void set(bool value);
}
/*-----------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------*/