Skip to content

Commit

Permalink
Continued work on WorldEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Dec 13, 2023
1 parent d13c445 commit d36de49
Show file tree
Hide file tree
Showing 17 changed files with 347 additions and 53 deletions.
58 changes: 58 additions & 0 deletions Volt/Sandbox/src/Sandbox/Modals/ConvertToWorldEngineModal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "sbpch.h"
#include "ConvertToWorldEngineModal.h"

#include <Volt/Asset/AssetManager.h>
#include <Volt/Scene/Scene.h>

#include <Volt/Utility/FileSystem.h>

#include <imgui.h>

ConvertToWorldEngineModal::ConvertToWorldEngineModal(const std::string& stringId)
: Modal(stringId)
{
}

ConvertToWorldEngineModal::~ConvertToWorldEngineModal()
{
}

void ConvertToWorldEngineModal::DrawModalContent()
{
ImGui::Text("Are you sure you want to convert to WorldEngine?");

ImGui::SameLine();

if (ImGui::Button("Convert"))
{
m_scene->GetSceneSettingsMutable().useWorldEngine = true;

const auto& metadata = Volt::AssetManager::GetMetadataFromHandle(m_scene->handle);
if (metadata.IsValid())
{
const std::filesystem::path directoryPath = Volt::AssetManager::GetFilesystemPath(metadata.filePath);
const std::filesystem::path layersPath = directoryPath / "Layers";

if (std::filesystem::exists(directoryPath) && std::filesystem::exists(layersPath))
{
FileSystem::MoveToRecycleBin(layersPath);
}
}

Volt::AssetManager::SaveAsset(m_scene.GetSharedPtr());
Close();
}

ImGui::SameLine();

if (ImGui::Button("Cancel"))
{
m_scene->GetSceneSettingsMutable().useWorldEngine = false;
Close();
}
}

void ConvertToWorldEngineModal::OnClose()
{
m_scene.Reset();
}
24 changes: 24 additions & 0 deletions Volt/Sandbox/src/Sandbox/Modals/ConvertToWorldEngineModal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "Sandbox/Modals/Modal.h"

namespace Volt
{
class Scene;
}

class ConvertToWorldEngineModal : public Modal
{
public:
ConvertToWorldEngineModal(const std::string& stringId);
~ConvertToWorldEngineModal();

inline void SetCurrentScene(Weak<Volt::Scene> scene) { m_scene = scene; }

protected:
void DrawModalContent() override;
void OnClose() override;

protected:
Weak<Volt::Scene> m_scene;
};
6 changes: 4 additions & 2 deletions Volt/Sandbox/src/Sandbox/Modals/Modal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <string>

typedef Volt::UUID ModalID;

class Modal
{
public:
Expand All @@ -14,7 +16,7 @@ class Modal
void Close();
bool Update();

inline const Volt::UUID GetID() const { return m_id; }
inline const ModalID GetID() const { return m_id; }

protected:
virtual void DrawModalContent() = 0;
Expand All @@ -26,6 +28,6 @@ class Modal

bool m_wasOpenLastFrame = false;

Volt::UUID m_id;
ModalID m_id;
std::string m_strId;
};
7 changes: 2 additions & 5 deletions Volt/Sandbox/src/Sandbox/Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "Sandbox/Window/Net/NetPanel.h"
#include "Sandbox/Window/Net/NetContractPanel.h"
#include "Sandbox/Window/BehaviourGraph/BehaviorPanel.h"
#include "Sandbox/Window/SceneSettingsPanel.h"
#include "Sandbox/VertexPainting/VertexPainterPanel.h"

#include "Sandbox/Utility/EditorResources.h"
Expand Down Expand Up @@ -117,9 +118,6 @@ void Sandbox::OnAttach()

NewScene();

// WIP Panels.
#ifndef VT_DIST

// Shelved Panels (So panel tab doesn't get cluttered up).
#ifdef VT_DEBUG
EditorLibrary::RegisterWithType<PrefabEditorPanel>("", Volt::AssetType::Prefab);
Expand All @@ -128,8 +126,6 @@ void Sandbox::OnAttach()
EditorLibrary::Register<TaigaPanel>("Advanced");
EditorLibrary::Register<ThemesPanel>("Advanced");
EditorLibrary::Register<CurveGraphPanel>("Advanced");
#endif

#endif

myNavigationPanel = EditorLibrary::Register<NavigationPanel>("Advanced", myRuntimeScene);
Expand All @@ -148,6 +144,7 @@ void Sandbox::OnAttach()

EditorLibrary::Register<NetPanel>("Advanced");
EditorLibrary::Register<NetContractPanel>("Advanced");
EditorLibrary::Register<SceneSettingsPanel>("", myRuntimeScene);

if (userSettings.sceneSettings.lowMemoryUsage)
{
Expand Down
16 changes: 13 additions & 3 deletions Volt/Sandbox/src/Sandbox/Utility/ComponentPropertyUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ void ComponentPropertyUtility::DrawComponentDefaultMemberArray(Weak<Volt::Scene>
if (EditorUtils::Property(label, *reinterpret_cast<Volt::AssetHandle*>(elementData), arrayMember.assetType))
{
AddLocalChangeToEntity(entity, arrayMember.ownerTypeDesc->GetGUID(), arrayMember.name);
EditorUtils::MarkEntityAsEdited(entity);
}
return;
}
Expand All @@ -320,6 +321,7 @@ void ComponentPropertyUtility::DrawComponentDefaultMemberArray(Weak<Volt::Scene>
if (UI::PropertyColor(label, *reinterpret_cast<glm::vec3*>(elementData)))
{
AddLocalChangeToEntity(entity, arrayMember.ownerTypeDesc->GetGUID(), arrayMember.name);
EditorUtils::MarkEntityAsEdited(entity);
}
return;
}
Expand All @@ -329,6 +331,7 @@ void ComponentPropertyUtility::DrawComponentDefaultMemberArray(Weak<Volt::Scene>
if (UI::PropertyColor(label, *reinterpret_cast<glm::vec4*>(elementData)))
{
AddLocalChangeToEntity(entity, arrayMember.ownerTypeDesc->GetGUID(), arrayMember.name);
EditorUtils::MarkEntityAsEdited(entity);
}
return;
}
Expand All @@ -339,6 +342,7 @@ void ComponentPropertyUtility::DrawComponentDefaultMemberArray(Weak<Volt::Scene>
if (UI::PropertyEntity(label, scene, *reinterpret_cast<Volt::EntityID*>(elementData)))
{
AddLocalChangeToEntity(entity, arrayMember.ownerTypeDesc->GetGUID(), arrayMember.name);
EditorUtils::MarkEntityAsEdited(entity);
}
return;
}
Expand All @@ -351,6 +355,7 @@ void ComponentPropertyUtility::DrawComponentDefaultMemberArray(Weak<Volt::Scene>
if (s_propertyFunctions.at(typeIndex)(label, elementData, 0))
{
AddLocalChangeToEntity(entity, arrayMember.ownerTypeDesc->GetGUID(), arrayMember.name);
EditorUtils::MarkEntityAsEdited(entity);
}
}

Expand Down Expand Up @@ -383,6 +388,7 @@ void ComponentPropertyUtility::DrawComponentEnum(Weak<Volt::Scene> scene, Volt::
{
currentValue = indexToValueMap.at(currentValue);
AddLocalChangeToEntity(entity, member.ownerTypeDesc->GetGUID(), member.name);
EditorUtils::MarkEntityAsEdited(entity);
}
}

Expand Down Expand Up @@ -446,6 +452,8 @@ void ComponentPropertyUtility::DrawComponentArray(Weak<Volt::Scene> scene, Volt:
{
arrayDesc->EmplaceBack(arrayPtr, nullptr);
AddLocalChangeToEntity(entity, member.ownerTypeDesc->GetGUID(), member.name);

EditorUtils::MarkEntityAsEdited(entity);
}

ImGui::TreePop();
Expand Down Expand Up @@ -566,7 +574,6 @@ void ComponentPropertyUtility::DrawMonoMembers(Weak<Volt::Scene> scene, const Vo
if (EditorUtils::Property(displayName, value, field.type.assetType))
{
scriptInstance->SetField(name, &value);
AddLocalChangeToEntity(entity, scriptEntry.name, name);
}

continue;
Expand Down Expand Up @@ -713,7 +720,7 @@ void ComponentPropertyUtility::DrawMonoMembers(Weak<Volt::Scene> scene, const Vo
scriptInstance->SetField(name, str);
}

AddLocalChangeToEntity(entity, scriptEntry.name, name);
fieldChanged = true;
}
}
else if (field.type.IsEntity())
Expand Down Expand Up @@ -762,7 +769,6 @@ void ComponentPropertyUtility::DrawMonoMembers(Weak<Volt::Scene> scene, const Vo
if (scriptInstance && fieldChanged)
{
scriptInstance->SetField(name, currentField->data.As<void>());

AddLocalChangeToEntity(entity, scriptEntry.name, name);
}

Expand Down Expand Up @@ -816,6 +822,8 @@ void ComponentPropertyUtility::AddLocalChangeToEntity(Volt::Entity entity, const
auto& newChange = prefabComp.componentLocalChanges.emplace_back();
newChange.componentGUID = componentGuid;
newChange.memberName = strMemberName;

EditorUtils::MarkEntityAsEdited(entity);
}

void ComponentPropertyUtility::AddLocalChangeToEntity(Volt::Entity entity, const std::string& scriptName, std::string_view memberName)
Expand All @@ -841,4 +849,6 @@ void ComponentPropertyUtility::AddLocalChangeToEntity(Volt::Entity entity, const
auto& newChange = prefabComp.scriptLocalChanges.emplace_back();
newChange.scriptName = scriptName;
newChange.memberName = memberName;

EditorUtils::MarkEntityAsEdited(entity);
}
6 changes: 6 additions & 0 deletions Volt/Sandbox/src/Sandbox/Utility/EditorUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,9 @@ std::filesystem::path EditorUtils::GetThumbnailPathFromPath(const std::filesyste
{
return path.string() + ".vtthumb.png";
}

void EditorUtils::MarkEntityAsEdited(const Volt::Entity& entity)
{
auto scene = entity.GetScene();
scene->MarkEntityAsEdited(entity);
}
2 changes: 2 additions & 0 deletions Volt/Sandbox/src/Sandbox/Utility/EditorUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class EditorUtils
static bool HasThumbnail(const std::filesystem::path& path);
static std::filesystem::path GetThumbnailPathFromPath(const std::filesystem::path& path);

static void MarkEntityAsEdited(const Volt::Entity& entity);

private:
static bool AssetBrowserPopupInternal(const std::string& id, Volt::AssetHandle& assetHandle, bool startState, Volt::AssetType wantedType = Volt::AssetType::None);
struct DefaultFalse
Expand Down
22 changes: 19 additions & 3 deletions Volt/Sandbox/src/Sandbox/Window/PropertiesPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ void PropertiesPanel::UpdateMainContent()
if (firstEntity.HasComponent<Volt::TagComponent>())
{
auto& tag = firstEntity.GetComponent<Volt::TagComponent>();
UI::InputText("Name", tag.tag);
if (UI::InputText("Name", tag.tag))
{
EditorUtils::MarkEntityAsEdited(firstEntity);
}
}
}
else
Expand Down Expand Up @@ -110,6 +113,7 @@ void PropertiesPanel::UpdateMainContent()
if (entity.HasComponent<Volt::TagComponent>())
{
entity.GetComponent<Volt::TagComponent>().tag = inputText;
EditorUtils::MarkEntityAsEdited(entity);
}
}
}
Expand Down Expand Up @@ -146,6 +150,8 @@ void PropertiesPanel::UpdateMainContent()
Volt::Entity ent = myCurrentScene->GetEntityFromUUID(entId);
ent.SetLocalPosition(transform.position);
myCurrentScene->InvalidateEntityTransform(entId);

EditorUtils::MarkEntityAsEdited(ent);
}
}

Expand All @@ -169,6 +175,8 @@ void PropertiesPanel::UpdateMainContent()
Volt::Entity ent = myCurrentScene->GetEntityFromUUID(entId);
ent.SetLocalRotation(transform.rotation);
myCurrentScene->InvalidateEntityTransform(entId);

EditorUtils::MarkEntityAsEdited(ent);
}
}

Expand All @@ -188,6 +196,8 @@ void PropertiesPanel::UpdateMainContent()
Volt::Entity ent = myCurrentScene->GetEntityFromUUID(entId);
ent.SetLocalScale(transform.scale);
myCurrentScene->InvalidateEntityTransform(entId);

EditorUtils::MarkEntityAsEdited(ent);
}
}

Expand Down Expand Up @@ -316,9 +326,12 @@ void PropertiesPanel::AddComponentPopup()
{
for (auto& ent : SelectionManager::GetSelectedEntities())
{
if (!Volt::ComponentRegistry::Helpers::HasComponentWithGUID(compGuid, myCurrentScene->GetRegistry(), myCurrentScene->GetHandleFromUUID(ent)))
auto entity = myCurrentScene->GetEntityFromUUID(ent);
EditorUtils::MarkEntityAsEdited(entity);

if (!Volt::ComponentRegistry::Helpers::HasComponentWithGUID(compGuid, myCurrentScene->GetRegistry(), entity))
{
Volt::ComponentRegistry::Helpers::AddComponentWithGUID(compGuid, myCurrentScene->GetRegistry(), myCurrentScene->GetHandleFromUUID(ent));
Volt::ComponentRegistry::Helpers::AddComponentWithGUID(compGuid, myCurrentScene->GetRegistry(), entity);
}

if (newMonoScript)
Expand Down Expand Up @@ -394,6 +407,7 @@ void PropertiesPanel::AddMonoScriptPopup()
for (auto& id : SelectionManager::GetSelectedEntities())
{
Volt::Entity entity = myCurrentScene->GetEntityFromUUID(id);
EditorUtils::MarkEntityAsEdited(entity);

if (!entity.HasComponent<Volt::MonoScriptComponent>())
{
Expand Down Expand Up @@ -438,6 +452,7 @@ void PropertiesPanel::AddMonoScriptPopup()
for (auto& id : SelectionManager::GetSelectedEntities())
{
Volt::Entity entity = myCurrentScene->GetEntityFromUUID(id);
EditorUtils::MarkEntityAsEdited(entity);

if (!entity.HasComponent<Volt::MonoScriptComponent>())
{
Expand Down Expand Up @@ -506,6 +521,7 @@ void PropertiesPanel::AcceptMonoDragDrop()
for (auto& id : SelectionManager::GetSelectedEntities())
{
Volt::Entity entity = myCurrentScene->GetEntityFromUUID(id);
EditorUtils::MarkEntityAsEdited(entity);

if (!entity.HasComponent<Volt::MonoScriptComponent>())
{
Expand Down
30 changes: 30 additions & 0 deletions Volt/Sandbox/src/Sandbox/Window/SceneSettingsPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "sbpch.h"
#include "SceneSettingsPanel.h"

#include "Sandbox/Modals/ConvertToWorldEngineModal.h"
#include "Sandbox/UISystems/ModalSystem.h"

#include <Volt/Utility/UIUtility.h>

SceneSettingsPanel::SceneSettingsPanel(Ref<Volt::Scene>& editorScene)
: EditorWindow("Scene Settings"), m_editorScene(editorScene)
{
auto& modal = ModalSystem::AddModal<ConvertToWorldEngineModal>("Convert To World Engine##sceneSettings");
m_convertionModal = modal.GetID();
}

void SceneSettingsPanel::UpdateMainContent()
{
auto& sceneSettings = m_editorScene->GetSceneSettingsMutable();

if (UI::BeginProperties("sceneSettings"))
{
if (UI::Property("Use World Engine", sceneSettings.useWorldEngine))
{
ModalSystem::GetModal<ConvertToWorldEngineModal>(m_convertionModal).SetCurrentScene(m_editorScene);
ModalSystem::GetModal<ConvertToWorldEngineModal>(m_convertionModal).Open();
}

UI::EndProperties();
}
}
Loading

0 comments on commit d36de49

Please sign in to comment.