Fixed crash when canvas parser fails + added resolution settings for worldspace UI
This commit is contained in:
@@ -27,8 +27,12 @@ UIResource::UIResource(const std::string& path) :
|
|||||||
canvas = Canvas::New();
|
canvas = Canvas::New();
|
||||||
canvas->uuid = this->ID;
|
canvas->uuid = this->ID;
|
||||||
canvas = CanvasParser::Get().Parse(canvas, FileSystem::RelativeToAbsolute(path));
|
canvas = CanvasParser::Get().Parse(canvas, FileSystem::RelativeToAbsolute(path));
|
||||||
canvas->SetInputManager(inputManager);
|
|
||||||
canvas->ComputeLayout(defaultSize);
|
if (!canvas)
|
||||||
|
{
|
||||||
|
canvas->SetInputManager(inputManager);
|
||||||
|
canvas->ComputeLayout(defaultSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIResource::Tick()
|
void UIResource::Tick()
|
||||||
@@ -57,7 +61,10 @@ void UIResource::Draw()
|
|||||||
void UIResource::Resize(const Vector2& size)
|
void UIResource::Resize(const Vector2& size)
|
||||||
{
|
{
|
||||||
framebuffer->QueueResize(size);
|
framebuffer->QueueResize(size);
|
||||||
canvas->ComputeLayout(size);
|
if (canvas)
|
||||||
|
{
|
||||||
|
canvas->ComputeLayout(size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIResource::Reload()
|
void UIResource::Reload()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
|
#include "src/Core/Maths.h"
|
||||||
#include "FieldTypes.h"
|
#include "FieldTypes.h"
|
||||||
#include "src/Core/Logger.h"
|
#include "src/Core/Logger.h"
|
||||||
#include "src/FileSystem/File.h"
|
#include "src/FileSystem/File.h"
|
||||||
@@ -22,19 +23,32 @@ namespace Nuake
|
|||||||
|
|
||||||
BindComponentField<&UIComponent::UIFilePath>("UIFilePath", "File Path");
|
BindComponentField<&UIComponent::UIFilePath>("UIFilePath", "File Path");
|
||||||
BindComponentField<&UIComponent::IsWorldSpace>("IsWorldspace", "Is Worldspace");
|
BindComponentField<&UIComponent::IsWorldSpace>("IsWorldspace", "Is Worldspace");
|
||||||
|
BindComponentProperty<&UIComponent::SetResolution, &UIComponent::GetResolution>("Resolution", "Resolution");
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UUID UIResource = UUID(0);
|
UUID UIResource = UUID(0);
|
||||||
ResourceFile UIFilePath;
|
ResourceFile UIFilePath;
|
||||||
bool IsWorldSpace;
|
bool IsWorldSpace;
|
||||||
|
Vector3 Resolution = Vector3(1920, 1080, 0);
|
||||||
// TODO: Z-Ordering
|
// TODO: Z-Ordering
|
||||||
|
|
||||||
|
void SetResolution(const Vector3& newSize)
|
||||||
|
{
|
||||||
|
Resolution = newSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 GetResolution()
|
||||||
|
{
|
||||||
|
return Resolution;
|
||||||
|
}
|
||||||
|
|
||||||
json Serialize()
|
json Serialize()
|
||||||
{
|
{
|
||||||
BEGIN_SERIALIZE();
|
BEGIN_SERIALIZE();
|
||||||
SERIALIZE_RES_FILE(UIFilePath);
|
SERIALIZE_RES_FILE(UIFilePath);
|
||||||
SERIALIZE_VAL(IsWorldSpace);
|
SERIALIZE_VAL(IsWorldSpace);
|
||||||
|
SERIALIZE_VEC3(Resolution)
|
||||||
END_SERIALIZE();
|
END_SERIALIZE();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +56,10 @@ namespace Nuake
|
|||||||
{
|
{
|
||||||
DESERIALIZE_RES_FILE(UIFilePath);
|
DESERIALIZE_RES_FILE(UIFilePath);
|
||||||
DESERIALIZE_VAL(IsWorldSpace);
|
DESERIALIZE_VAL(IsWorldSpace);
|
||||||
|
if (j.contains("Resolution"))
|
||||||
|
{
|
||||||
|
DESERIALIZE_VEC3(j["Resolution"], Resolution);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -73,6 +73,11 @@ namespace Nuake
|
|||||||
uis[uiViewComponent.UIResource]->Tick();
|
uis[uiViewComponent.UIResource]->Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (uiViewComponent.IsWorldSpace)
|
||||||
|
{
|
||||||
|
uis[uiViewComponent.UIResource]->Resize(uiViewComponent.GetResolution());
|
||||||
|
}
|
||||||
|
|
||||||
uis[uiViewComponent.UIResource]->Draw();
|
uis[uiViewComponent.UIResource]->Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user