52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
// Copyright Pacificao. All Rights Reserved.
|
|
|
|
#include "AgrarianDemoNoticeActor.h"
|
|
|
|
#include "AgrarianDemoNoticeWidget.h"
|
|
#include "Blueprint/UserWidget.h"
|
|
#include "Engine/World.h"
|
|
#include "TimerManager.h"
|
|
|
|
AAgrarianDemoNoticeActor::AAgrarianDemoNoticeActor()
|
|
{
|
|
PrimaryActorTick.bCanEverTick = false;
|
|
NoticeWidgetClass = UAgrarianDemoNoticeWidget::StaticClass();
|
|
}
|
|
|
|
void AAgrarianDemoNoticeActor::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
if (!bAutoShowNotice)
|
|
{
|
|
return;
|
|
}
|
|
|
|
APlayerController* PlayerController = GetWorld() ? GetWorld()->GetFirstPlayerController() : nullptr;
|
|
if (!PlayerController || !NoticeWidgetClass)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ActiveNoticeWidget = CreateWidget<UAgrarianDemoNoticeWidget>(PlayerController, NoticeWidgetClass);
|
|
if (!ActiveNoticeWidget)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ActiveNoticeWidget->VersionLabel = VersionLabel;
|
|
ActiveNoticeWidget->DemoNotice = DemoNotice;
|
|
ActiveNoticeWidget->AddToViewport(100);
|
|
|
|
GetWorldTimerManager().SetTimer(RemoveNoticeTimerHandle, this, &AAgrarianDemoNoticeActor::RemoveNotice, NoticeDurationSeconds, false);
|
|
}
|
|
|
|
void AAgrarianDemoNoticeActor::RemoveNotice()
|
|
{
|
|
if (ActiveNoticeWidget)
|
|
{
|
|
ActiveNoticeWidget->RemoveFromParent();
|
|
ActiveNoticeWidget = nullptr;
|
|
}
|
|
}
|