-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWotUserWidget.cpp
53 lines (46 loc) · 1.34 KB
/
WotUserWidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "UI/WotUserWidget.h"
#include "Kismet/GameplayStatics.h"
#include "Blueprint/WidgetLayoutLibrary.h"
void UWotUserWidget::SetAttachTo(AActor* NewAttachTo)
{
AttachTo = NewAttachTo;
UpdatePosition();
}
void UWotUserWidget::SetOffset(const FVector& NewOffset)
{
Offset = NewOffset;
}
void UWotUserWidget::SetPosition(const FVector& NewPosition)
{
APlayerController* PC = GetOwningPlayer();
if (!PC) {
return;
}
FVector2D ScreenPosition;
UGameplayStatics::ProjectWorldToScreen(PC, NewPosition, ScreenPosition, false);
float ViewportScale = UWidgetLayoutLibrary::GetViewportScale(GetWorld());
SetRenderTranslation(ScreenPosition / ViewportScale);
}
void UWotUserWidget::SetDuration(float NewDuration)
{
Duration = NewDuration;
// now set a timer for destroying it
GetWorld()->GetTimerManager().SetTimer(TimerHandle_Remove, this, &UWotUserWidget::Remove_TimeElapsed, Duration);
}
void UWotUserWidget::Remove_TimeElapsed()
{
RemoveFromParent();
}
void UWotUserWidget::UpdatePosition()
{
if (AttachTo.IsValid()) {
// now draw it in the right place (based on location of AttachTo actor)
FVector Location = AttachTo->GetActorLocation() + Offset;
SetPosition(Location);
}
}
void UWotUserWidget::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
{
UpdatePosition();
Super::NativeTick(MyGeometry, InDeltaTime);
}