Text Renderer Component serialization
This commit is contained in:
parent
c686954c77
commit
5d3603ac7d
Binary file not shown.
|
@ -0,0 +1,3 @@
|
||||||
|
Name: ALGER
|
||||||
|
ID: 182525173
|
||||||
|
Type: 10
|
Binary file not shown.
|
@ -81,6 +81,7 @@ namespace Sandbox
|
||||||
SHSystemManager::CreateSystem<SHUISystem>();
|
SHSystemManager::CreateSystem<SHUISystem>();
|
||||||
|
|
||||||
std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf");
|
std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf");
|
||||||
|
std::system("FontCompiler.exe ../../Assets/Fonts/ALGER.ttf");
|
||||||
|
|
||||||
SHSystemManager::CreateSystem<SHGraphicsSystem>();
|
SHSystemManager::CreateSystem<SHGraphicsSystem>();
|
||||||
SHGraphicsSystem* graphicsSystem = static_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem<SHGraphicsSystem>());
|
SHGraphicsSystem* graphicsSystem = static_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem<SHGraphicsSystem>());
|
||||||
|
|
|
@ -42,19 +42,6 @@ namespace Sandbox
|
||||||
void SBMainScene::Init()
|
void SBMainScene::Init()
|
||||||
{
|
{
|
||||||
sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID);
|
sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* TESTING CODE */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
//testText = SHEntityManager::CreateEntity<SHTransformComponent, SHTextRendererComponent>(MAX_EID, "Test Text");
|
|
||||||
//auto gfxSystem =SHSystemManager::GetSystem<SHGraphicsSystem>();
|
|
||||||
|
|
||||||
//auto textComp = SHComponentManager::GetComponent<SHTextRendererComponent>(testText);
|
|
||||||
|
|
||||||
//textComp->SetFont(gfxSystem->GetFontLibrary().GetFonts()[0]);
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* TESTING CODE */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBMainScene::Update(float dt)
|
void SBMainScene::Update(float dt)
|
||||||
|
|
|
@ -495,4 +495,52 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
static void DrawComponent(SHTextRendererComponent* component)
|
||||||
|
{
|
||||||
|
if (!component)
|
||||||
|
return;
|
||||||
|
ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHTextRendererComponent>());
|
||||||
|
const auto componentType = rttr::type::get(*component);
|
||||||
|
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active");
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::CollapsingHeader(componentType.get_name().data()))
|
||||||
|
{
|
||||||
|
DrawContextMenu(component);
|
||||||
|
Handle<SHFont> const& font = component->GetFont();
|
||||||
|
const auto FONT_NAME = SHResourceManager::GetAssetName<SHFont>(font).value_or("");
|
||||||
|
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Font", FONT_NAME, [component]()
|
||||||
|
{
|
||||||
|
Handle<SHFont> const& font = component->GetFont();
|
||||||
|
return SHResourceManager::GetAssetID<SHFont>(font).value_or(0);
|
||||||
|
},
|
||||||
|
[component](AssetID const& id)
|
||||||
|
{
|
||||||
|
if (SHAssetManager::GetType(id) != AssetType::FONT)
|
||||||
|
{
|
||||||
|
SHLOG_WARNING("Attempted to assign non font asset to TextRendererComponent Font property!")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
component->SetFont(SHResourceManager::LoadOrGet<SHFont>(id));
|
||||||
|
SHResourceManager::FinaliseChanges();
|
||||||
|
}, SHDragDrop::DRAG_RESOURCE);
|
||||||
|
|
||||||
|
SHEditorWidgets::InputText("Text",
|
||||||
|
[component](void)
|
||||||
|
{
|
||||||
|
return component->GetText();
|
||||||
|
},
|
||||||
|
[component](std::string const& val)
|
||||||
|
{
|
||||||
|
component->SetText(val);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawContextMenu(component);
|
||||||
|
}
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "UI/SHCanvasComponent.h"
|
#include "UI/SHCanvasComponent.h"
|
||||||
#include "SHEditorComponentView.h"
|
#include "SHEditorComponentView.h"
|
||||||
#include "AudioSystem/SHAudioListenerComponent.h"
|
#include "AudioSystem/SHAudioListenerComponent.h"
|
||||||
|
#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -144,6 +145,10 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
DrawComponent(uiComponent);
|
DrawComponent(uiComponent);
|
||||||
}
|
}
|
||||||
|
if (auto textRendererComponent = SHComponentManager::GetComponent_s<SHTextRendererComponent>(eid))
|
||||||
|
{
|
||||||
|
DrawComponent(textRendererComponent);
|
||||||
|
}
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
// Render Scripts
|
// Render Scripts
|
||||||
SHScriptEngine* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
|
SHScriptEngine* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
|
||||||
|
@ -162,6 +167,7 @@ namespace SHADE
|
||||||
DrawAddComponentWithEnforcedComponentButton<SHRenderable, SHTransformComponent>(eid);
|
DrawAddComponentWithEnforcedComponentButton<SHRenderable, SHTransformComponent>(eid);
|
||||||
DrawAddComponentWithEnforcedComponentButton<SHRigidBodyComponent, SHTransformComponent>(eid);
|
DrawAddComponentWithEnforcedComponentButton<SHRigidBodyComponent, SHTransformComponent>(eid);
|
||||||
DrawAddComponentWithEnforcedComponentButton<SHColliderComponent, SHTransformComponent>(eid);
|
DrawAddComponentWithEnforcedComponentButton<SHColliderComponent, SHTransformComponent>(eid);
|
||||||
|
DrawAddComponentWithEnforcedComponentButton<SHTextRendererComponent, SHTransformComponent>(eid);
|
||||||
|
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
|
|
|
@ -137,7 +137,6 @@ namespace SHADE
|
||||||
static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(SSAO_BLUR);
|
static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(SSAO_BLUR);
|
||||||
static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet<SHVkShaderModule>(TEXT_VS);
|
static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet<SHVkShaderModule>(TEXT_VS);
|
||||||
static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(TEXT_FS);
|
static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(TEXT_FS);
|
||||||
static constexpr AssetID SEGOE_UI_FONT = 176667660; testFont = SHResourceManager::LoadOrGet<SHFont>(SEGOE_UI_FONT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept
|
void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept
|
||||||
|
|
|
@ -58,6 +58,7 @@ namespace SHADE
|
||||||
void SHTextRendererComponent::SetFont(Handle<SHFont> font) noexcept
|
void SHTextRendererComponent::SetFont(Handle<SHFont> font) noexcept
|
||||||
{
|
{
|
||||||
fontHandle = font;
|
fontHandle = font;
|
||||||
|
MakeDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -76,4 +77,19 @@ namespace SHADE
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Handle<SHFont> SHTextRendererComponent::GetFont(void) const noexcept
|
||||||
|
{
|
||||||
|
return fontHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace rttr
|
||||||
|
{
|
||||||
|
RTTR_REGISTRATION
|
||||||
|
{
|
||||||
|
using namespace SHADE;
|
||||||
|
|
||||||
|
registration::class_<SHTextRendererComponent>("Text Renderer Component");
|
||||||
|
};
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
#include "ECS_Base/Components/SHComponent.h"
|
#include "ECS_Base/Components/SHComponent.h"
|
||||||
#include "Math/SHColour.h"
|
#include "Math/SHColour.h"
|
||||||
#include "Resource/SHHandle.h"
|
#include "Resource/SHHandle.h"
|
||||||
|
#include <rttr/registration>
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -53,9 +54,12 @@ namespace SHADE
|
||||||
void SetFont (Handle<SHFont> font) noexcept;
|
void SetFont (Handle<SHFont> font) noexcept;
|
||||||
|
|
||||||
std::string const& GetText (void) const noexcept;
|
std::string const& GetText (void) const noexcept;
|
||||||
|
Handle<SHFont> GetFont (void) const noexcept;
|
||||||
|
|
||||||
friend class SHTextRenderingSubSystem;
|
friend class SHTextRenderingSubSystem;
|
||||||
|
|
||||||
|
RTTR_ENABLE()
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,6 +211,7 @@ namespace SHADE
|
||||||
AddComponentToComponentNode<SHLightComponent>(components, eid);
|
AddComponentToComponentNode<SHLightComponent>(components, eid);
|
||||||
AddComponentToComponentNode<SHRigidBodyComponent>(components, eid);
|
AddComponentToComponentNode<SHRigidBodyComponent>(components, eid);
|
||||||
AddConvComponentToComponentNode<SHColliderComponent>(components, eid);
|
AddConvComponentToComponentNode<SHColliderComponent>(components, eid);
|
||||||
|
AddConvComponentToComponentNode<SHTextRendererComponent>(components, eid);
|
||||||
|
|
||||||
node[ComponentsNode] = components;
|
node[ComponentsNode] = components;
|
||||||
|
|
||||||
|
@ -262,6 +263,7 @@ namespace SHADE
|
||||||
AddComponentID<SHRigidBodyComponent>(componentIDList, componentsNode);
|
AddComponentID<SHRigidBodyComponent>(componentIDList, componentsNode);
|
||||||
AddComponentID<SHLightComponent>(componentIDList, componentsNode);
|
AddComponentID<SHLightComponent>(componentIDList, componentsNode);
|
||||||
AddComponentID<SHColliderComponent>(componentIDList, componentsNode);
|
AddComponentID<SHColliderComponent>(componentIDList, componentsNode);
|
||||||
|
AddComponentID<SHTextRendererComponent>(componentIDList, componentsNode);
|
||||||
|
|
||||||
return componentIDList;
|
return componentIDList;
|
||||||
}
|
}
|
||||||
|
@ -338,6 +340,7 @@ namespace SHADE
|
||||||
SHSerializationHelper::InitializeComponentFromNode<SHRigidBodyComponent>(componentsNode, eid);
|
SHSerializationHelper::InitializeComponentFromNode<SHRigidBodyComponent>(componentsNode, eid);
|
||||||
SHSerializationHelper::ConvertNodeToComponent<SHRenderable>(componentsNode, eid);
|
SHSerializationHelper::ConvertNodeToComponent<SHRenderable>(componentsNode, eid);
|
||||||
SHSerializationHelper::ConvertNodeToComponent<SHColliderComponent>(componentsNode, eid);
|
SHSerializationHelper::ConvertNodeToComponent<SHColliderComponent>(componentsNode, eid);
|
||||||
|
SHSerializationHelper::ConvertNodeToComponent<SHTextRendererComponent>(componentsNode, eid);
|
||||||
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
|
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
||||||
#include "SHSerializationTools.h"
|
#include "SHSerializationTools.h"
|
||||||
#include "Physics/Interface/SHColliderComponent.h"
|
#include "Physics/Interface/SHColliderComponent.h"
|
||||||
|
#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h"
|
||||||
|
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
using namespace SHADE;
|
using namespace SHADE;
|
||||||
|
@ -322,4 +325,45 @@ namespace YAML
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct convert<SHTextRendererComponent>
|
||||||
|
{
|
||||||
|
static constexpr std::string_view TEXT_YAML_TAG = "Text";
|
||||||
|
static constexpr std::string_view FONT_YAML_TAG = "Font";
|
||||||
|
|
||||||
|
static YAML::Node encode(SHTextRendererComponent const& rhs)
|
||||||
|
{
|
||||||
|
YAML::Node node;
|
||||||
|
node[TEXT_YAML_TAG.data()] = rhs.GetText();
|
||||||
|
auto font = rhs.GetFont();
|
||||||
|
if (font)
|
||||||
|
{
|
||||||
|
node[FONT_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHFont>(rhs.GetFont()).value_or(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
node[FONT_YAML_TAG.data()] = 0;
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
static bool decode(YAML::Node const& node, SHTextRendererComponent& rhs)
|
||||||
|
{
|
||||||
|
if (node[TEXT_YAML_TAG.data()].IsDefined())
|
||||||
|
{
|
||||||
|
rhs.SetText(node[TEXT_YAML_TAG.data()].as<std::string>());
|
||||||
|
}
|
||||||
|
if (node[FONT_YAML_TAG.data()].IsDefined())
|
||||||
|
{
|
||||||
|
|
||||||
|
// Temporarily, use default material
|
||||||
|
auto gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||||
|
if (!gfxSystem)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
rhs.SetFont(SHResourceManager::LoadOrGet<SHFont>(node[TEXT_YAML_TAG.data()].as<AssetID>()));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue