Added Copy/Paste of component values, scene name display, editor config #300

Merged
srishamharan merged 5 commits from SP3-4-Editor into main 2023-01-04 01:01:35 +08:00
9 changed files with 71 additions and 11 deletions
Showing only changes of commit 51c9058ab8 - Show all commits

View File

@ -67,6 +67,9 @@ namespace Sandbox
SHFileUtilities::SetWorkDirToExecDir();
WindowData wndData{};
auto& appConfig = SHConfigurationManager::LoadApplicationConfig(&wndData);
#if SHEDITOR
auto& editorConfig = SHConfigurationManager::LoadEditorConfig(&wndData);
#endif
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow, wndData);
// Create Systems
@ -158,8 +161,11 @@ namespace Sandbox
SHSystemManager::Init();
#if SHEDITOR
SHSceneManager::InitSceneManager<SBMainScene>(editorConfig.workingSceneID);
#else
SHSceneManager::InitSceneManager<SBMainScene>(appConfig.startingSceneID);
#endif
SHFrameRateController::UpdateFRC();
// Link up SHDebugDraw

View File

@ -183,7 +183,7 @@ namespace SHADE
//ImGui::InputScalar("Starting Scene", ImGuiDataType_U32, &appConfig.startingSceneID);
auto sceneAsset = SHAssetManager::GetData<SHSceneAsset>(appConfig.startingSceneID);
if(ImGui::BeginCombo("Starting Scne", sceneAsset ? sceneAsset->name.data() : ""))
if(ImGui::BeginCombo("Starting Scene", sceneAsset ? sceneAsset->name.data() : ""))
{
auto scenes = SHAssetManager::GetAllRecordOfType(AssetType::SCENE);
for(auto const& scene : scenes)

View File

@ -93,6 +93,8 @@ namespace SHADE
SHLOG_CRITICAL("Failed to create ImGui Context")
}
}
editorConfig = &SHConfigurationManager::LoadEditorConfig();
//Add editor windows
SHEditorWindowManager::CreateEditorWindow<SHEditorMenuBar>();
@ -122,7 +124,7 @@ namespace SHADE
InitBackend();
SetStyle(Style::SHADE);
SetStyle(static_cast<Style>(editorConfig->style));
for (const auto& window : SHEditorWindowManager::editorWindows | std::views::values)
@ -376,10 +378,14 @@ namespace SHADE
ImGui_ImplVulkan_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
editorConfig->startMaximized = shWindow->GetWindowData().isMaximised;
SHConfigurationManager::SaveEditorConfig();
}
void SHEditor::SetStyle(Style style)
{
editorConfig->style = static_cast<uint32_t>(style);
switch (style)
{
default:
@ -586,6 +592,7 @@ namespace SHADE
SHSceneManager::SetCurrentSceneName(newSceneName);
SHSceneManager::SetCurrentSceneAssetID(SHAssetManager::CreateNewAsset(AssetType::SCENE, newSceneName));
editorConfig->workingSceneID = SHSceneManager::GetCurrentSceneAssetID();
}
//Get data, if data is null, asset doesn't exist, prompt for a name and create a new asset with the name
@ -594,7 +601,7 @@ namespace SHADE
{
if(shWindow->IsUnsavedChanges())
shWindow->ToggleUnsavedChanges();
editorConfig->workingSceneID = SHSceneManager::GetCurrentSceneAssetID();
return true;
}
return false;
@ -675,6 +682,18 @@ namespace SHADE
ImGuizmo::BeginFrame();
}
void SHEditor::SetSHWindow(SHWindow* inWindow)
{
shWindow = inWindow;
shWindow->RegisterWindowSizeCallback([&](uint32_t width, uint32_t height)
{
if(width > 0 && height > 0)
{
auto [width, height] = shWindow->GetWindowSize();
editorConfig->windowSize = { static_cast<float>(width), static_cast<float>(height) };
}
});
}
void SHEditor::EditorRoutine::Execute(double dt) noexcept
{

View File

@ -20,6 +20,7 @@
#include "Events/SHEventDefines.h"
#include "Events/SHEvent.h"
#include "Graphics/Windowing/SHWindow.h"
#include "Serialization/Configurations/SHConfigurationManager.h"
//#==============================================================#
//|| Library Includes ||
@ -108,7 +109,7 @@ namespace SHADE
void InitBackend();
void SetSDLWindow(SDL_Window* inSDLWindow){sdlWindow = inSDLWindow;};
void SetSHWindow(SHWindow* inWindow){shWindow = inWindow;}
void SetSHWindow(SHWindow* inWindow);
void PollPicking();
@ -127,6 +128,8 @@ namespace SHADE
State editorState = State::STOP;
SHEditorConfig* editorConfig;
private:
/**
* @brief Start new frame for editor

View File

@ -160,7 +160,7 @@ namespace SHADE
template <typename T, std::size_t N>
static bool DragN(const std::string& label, std::vector<std::string>const& componentLabels,
std::vector<T*> values, float speed = 0.1f, const char* displayFormat = "", T valueMin = T(), T valueMax = T(),
std::vector<T*> values, float speed = 0.1f, const char* displayFormat = "%.3f", T valueMin = T(), T valueMax = T(),
ImGuiSliderFlags flags = 0, bool* isHovered = nullptr)
{
const ImGuiWindow* const window = ImGui::GetCurrentWindow();

View File

@ -115,6 +115,11 @@ namespace SHADE
SetFocus(wndHWND);
}
if(!wndData.isFullscreen && wndData.isMaximised)
{
Maximize();
}
if (!wndData.icoPath.empty())
{
//HICON hIcon = ::LoadIcon(nullptr, MAKEINTRESOURCE(wndData.icoPath.c_str()));
@ -208,10 +213,12 @@ namespace SHADE
if (!IsZoomed(wndHWND))
{
ShowWindow(wndHWND, SW_MAXIMIZE);
wndData.isMaximised = true;
}
else
{
ShowWindow(wndHWND, SW_RESTORE);
wndData.isMaximised = false;
}
}
@ -428,7 +435,9 @@ namespace SHADE
wndData.isMinimised = true;
}
else
{
wndData.isMinimised = false;
}
for (auto const& entry : windowResizeCallbacks)
{

View File

@ -64,6 +64,8 @@ namespace SHADE
bool isMinimised = false;
bool isMaximised = true;
std::wstring title = L"SHADE ENGINE";
std::wstring name = L"SHADEEngineApp";

View File

@ -52,15 +52,27 @@ namespace SHADE
SHFileIO::WriteStringToFile(editorConfigPath, out.c_str());
}
SHEditorConfig& SHConfigurationManager::LoadEditorConfig()
SHEditorConfig& SHConfigurationManager::LoadEditorConfig(WindowData* windowData)
{
if (!std::filesystem::exists(editorConfigPath))
{
SaveApplicationConfig();
return editorConfig;
}
auto const node = YAML::Load(SHFileIO::GetStringFromFile(editorConfigPath));
auto properties = rttr::type::get<SHApplicationConfig>().get_properties();
auto properties = rttr::type::get<SHEditorConfig>().get_properties();
for(auto const& property : properties)
{
if(node[property.get_name().data()].IsDefined())
SHSerializationHelper::InitializeProperty(&editorConfig, property, node[property.get_name().data()]);
}
if(windowData)
{
windowData->isMaximised = editorConfig.startMaximized;
windowData->width = static_cast<uint32_t>(editorConfig.windowSize.x);
windowData->height = static_cast<uint32_t>(editorConfig.windowSize.y);
}
return editorConfig;
}
@ -86,4 +98,10 @@ RTTR_REGISTRATION
.property("Starting Scene ID", &SHApplicationConfig::startingSceneID)
.property("Window Size", &SHApplicationConfig::windowSize)
.property("Window Title", &SHApplicationConfig::windowTitle);
registration::class_<SHEditorConfig>("Editor Config")
.property("Start Maximized", &SHEditorConfig::startMaximized)
.property("Working Scene ID", &SHEditorConfig::workingSceneID)
.property("Window Size", &SHEditorConfig::windowSize)
.property("Style", &SHEditorConfig::style);
}

View File

@ -7,7 +7,6 @@
namespace SHADE
{
struct SHApplicationConfig
{
bool startInFullScreen{ false };
@ -19,7 +18,11 @@ namespace SHADE
struct SHEditorConfig
{
bool startMaximized{true};
AssetID workingSceneID{};
SHVec2 windowSize {1920, 1080};
uint32_t style = 0;
RTTR_ENABLE()
};
class SH_API SHConfigurationManager
@ -33,7 +36,7 @@ namespace SHADE
static SHApplicationConfig applicationConfig;
#ifdef SHEDITOR
static void SaveEditorConfig();
static SHEditorConfig& LoadEditorConfig();
static SHEditorConfig& LoadEditorConfig(WindowData* windowData = nullptr);
static SHEditorConfig editorConfig;
private:
static void FetchEditorCameraData();