I have this code:
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "FloatingCombatText.h"
#include "STextBlock.h"
#include "SConstraintCanvas.h"
#include "SFCTItem.h"
void SFCTItem::Construct(const FArguments& InArgs)
{
PositionDel.Bind(this, &SFCTItem::GetPosition);
AccumulatedLifeTime = 0;
ChildSlot
SNew(SConstraintCanvas)
+ SConstraintCanvas::Slot()
.AutoSize(true).Alignment(PositionDel)
SNew(STextBlock)
.Text(this, &SFCTItem::GetText)
]
];
}
void SFCTItem::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
{
FVector2D Pos;
Pos = Position;// AllottedGeometry.AbsoluteToLocal(Position);
LocalPos = Pos;
if (GetVisibility() == EVisibility::Visible)
{
AccumulatedLifeTime += InDeltaTime;
if (AccumulatedLifeTime > 3)
{
SetVisibility(EVisibility::Collapsed);
}
}
}
void SFCTItem::ShowWidget(const FVector& Location) const
{
FVector2D OutScreenPos;
if (PlayerController.IsValid())
{
PlayerController->ProjectWorldLocationToScreen(Location, OutScreenPos);
}
}
FText SFCTItem::GetText() const
{
return FText::FromString("Sample Text");
}
FVector2D SFCTItem::GetPosition() const
{
return LocalPos;
}
It’s widget I want to setup position in space.
And here is code for manager widget:
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "FloatingCombatText.h"
#include "SFCTContainer.h"
void SFCTContainer::Construct(const FArguments& InArgs)
{
PC = InArgs._PC;
PoolSize = InArgs._PoolSize;
//ItemCanvas = SNew(SCanvas);
for(int32 Idx = 0; Idx < PoolSize; Idx++)
{
TSharedPtr<SFCTItem> NewItem = SNew(SFCTItem);
GEngine->GameViewport->AddViewportWidgetContent(NewItem.ToSharedRef());
//ItemCanvas->AddSlot().AttachWidget(NewItem.ToSharedRef());
ItemsPool.Add(NewItem);
NewItem->SetVisibility(EVisibility::Collapsed);
}
//ItemCanvas->AddSlot().HAlign(HAlign_Fill).VAlign(VAlign_Fill);
//GEngine->GameViewport->AddViewportWidgetContent(ItemCanvas.ToSharedRef());
}
void SFCTContainer::ShowText(const FVector& Position, const FString& TextIn)
{
if(ItemsPool.Num() > 0)
{
FVector2D OutPosition;
PC->ProjectWorldLocationToScreen(Position, OutPosition);
FSlateRenderTransform NewTransform(5, OutPosition);
ItemsPool[0]->Position = OutPosition;
ItemsPool[0]->AccumulatedLifeTime = 0;
ItemsPool[0]->SetVisibility(EVisibility::Visible);
}
}
I want to set absolute position in viewport for SFCTItem . After 3 days of trying I can honestly say I have no idea what doing anymore.
I know it’s quite trivial to do in UMG, but I for the sake of science I want to do it in Slate.