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->uuid = this->ID;
|
||||
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()
|
||||
@@ -57,7 +61,10 @@ void UIResource::Draw()
|
||||
void UIResource::Resize(const Vector2& size)
|
||||
{
|
||||
framebuffer->QueueResize(size);
|
||||
canvas->ComputeLayout(size);
|
||||
if (canvas)
|
||||
{
|
||||
canvas->ComputeLayout(size);
|
||||
}
|
||||
}
|
||||
|
||||
void UIResource::Reload()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Component.h"
|
||||
#include "src/Core/Maths.h"
|
||||
#include "FieldTypes.h"
|
||||
#include "src/Core/Logger.h"
|
||||
#include "src/FileSystem/File.h"
|
||||
@@ -22,19 +23,32 @@ namespace Nuake
|
||||
|
||||
BindComponentField<&UIComponent::UIFilePath>("UIFilePath", "File Path");
|
||||
BindComponentField<&UIComponent::IsWorldSpace>("IsWorldspace", "Is Worldspace");
|
||||
BindComponentProperty<&UIComponent::SetResolution, &UIComponent::GetResolution>("Resolution", "Resolution");
|
||||
}
|
||||
|
||||
public:
|
||||
UUID UIResource = UUID(0);
|
||||
ResourceFile UIFilePath;
|
||||
bool IsWorldSpace;
|
||||
Vector3 Resolution = Vector3(1920, 1080, 0);
|
||||
// TODO: Z-Ordering
|
||||
|
||||
void SetResolution(const Vector3& newSize)
|
||||
{
|
||||
Resolution = newSize;
|
||||
}
|
||||
|
||||
Vector3 GetResolution()
|
||||
{
|
||||
return Resolution;
|
||||
}
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_RES_FILE(UIFilePath);
|
||||
SERIALIZE_VAL(IsWorldSpace);
|
||||
SERIALIZE_VEC3(Resolution)
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
@@ -42,6 +56,10 @@ namespace Nuake
|
||||
{
|
||||
DESERIALIZE_RES_FILE(UIFilePath);
|
||||
DESERIALIZE_VAL(IsWorldSpace);
|
||||
if (j.contains("Resolution"))
|
||||
{
|
||||
DESERIALIZE_VEC3(j["Resolution"], Resolution);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,6 +73,11 @@ namespace Nuake
|
||||
uis[uiViewComponent.UIResource]->Tick();
|
||||
}
|
||||
|
||||
if (uiViewComponent.IsWorldSpace)
|
||||
{
|
||||
uis[uiViewComponent.UIResource]->Resize(uiViewComponent.GetResolution());
|
||||
}
|
||||
|
||||
uis[uiViewComponent.UIResource]->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user