GeorgeR
Topic Author
Posts: 39
Joined: 15 Mar 2018, 01:06

Ptr<SomeNonNoesisClass>

20 Apr 2018, 15:50

This doesn't work:
#include "StackSizeVisibilityConverter.h"

#include <NsCore/ReflectionImplement.h>
#include <NsCore/Boxing.h>
#include "ItemInstance.h"
#include "Item.h"
#include "NsGui/Enums.h"

using namespace Frontier::UI::Converters;
using namespace Noesis;

bool StackSizeVisibilityConverter::TryConvert(Noesis::BaseComponent* value, const Type* type, BaseComponent* parameter, Noesis::Ptr<BaseComponent>& result)
{
	NS_UNUSED(type, parameter);

	if (!Boxing::CanUnbox<Ptr<FItemInstance>>(value))
		result = Boxing::Box<Visibility>(Visibility::Visibility_Visible);

	auto itemInstance = Boxing::Unbox<Ptr<FItemInstance>>(value);

	result = Boxing::Box<Visibility>(itemInstance->GetItem()->bIsStackable && itemInstance->StackSize > 1
		? Visibility::Visibility_Visible
		: Visibility::Visibility_Collapsed);

	return true;
}

NS_IMPLEMENT_REFLECTION(StackSizeVisibilityConverter)
{
	NsMeta<TypeId>("Frontier.UI.Converters.StackSizeVisibilityConverter");
}
Apparently FItemInstance doesn't have AddReference. I tried unboxing to a regular pointer but that doesn't work either.
 
User avatar
jsantos
Site Admin
Posts: 2563
Joined: 20 Jan 2012, 17:18
Contact:

Re: Ptr<SomeNonNoesisClass>

23 Apr 2018, 18:09

As in C#, only struct types can be boxed, you cannot box or unbox an object in the heap, because in that case the object is already a BaseComponent and you don't need boxing. Similarly you only can have Ptr<> for types inheriting from BaseRefCounted.

Not sure to understand why you need to do that. I am sure hcpizzi will give you a better answer than me.
 
User avatar
hcpizzi
Site Admin
Posts: 213
Joined: 09 Feb 2012, 12:40

Re: Ptr<SomeNonNoesisClass>

23 Apr 2018, 18:22

What you're receiving is not a boxed FItemInstance, but a NoesisStructWrapper, which is a BaseComponent derived type that we use to wrap UStructs and make their properties accessible to Noesis, but it's not a BoxedValue, so CanUnbox/Unbox/Box won't work with them.

I could expose functions similar to those, as I have all the ingredients in place. However, as I mentioned in the bugtracker ticket you opened regarding two way bindings to UStructs, I'm in the process of revisiting that code and things may change. Nonetheless, there should be a way to get the UStruct from those BaseComponents, the same way you can get an UObject by using NoesisCreateUObjectForComponent. There's a NoesisCreateComponentForUStruct, but not the opposite. That would be the missing piece of the puzzle.
 
User avatar
hcpizzi
Site Admin
Posts: 213
Joined: 09 Feb 2012, 12:40

Re: Ptr<SomeNonNoesisClass>

21 May 2018, 11:00

Hi George,

I've implemented a function named NoesisGetUStructFromComponent that will allow you to extract the USTRUCT from the BaseComponent wrapper.

Please, let us know if this fits what you need.

Who is online

Users browsing this forum: No registered users and 3 guests