(Feat) Add Main Menu + Music Manger
This commit is contained in:
@@ -33,6 +33,9 @@ void UConfirmDialogWidget::NativeConstruct()
|
||||
|
||||
void UConfirmDialogWidget::Open(const FText& InMessage)
|
||||
{
|
||||
// Une ouverture simple annule un rebours laisse par la precedente.
|
||||
StopCountdown();
|
||||
|
||||
if (MessageText)
|
||||
{
|
||||
MessageText->SetText(InMessage);
|
||||
@@ -45,11 +48,79 @@ void UConfirmDialogWidget::Open(const FText& InMessage)
|
||||
SetKeyboardFocus();
|
||||
}
|
||||
|
||||
void UConfirmDialogWidget::OpenWithCountdown(const FText& InMessageFormat, float Seconds)
|
||||
{
|
||||
StopCountdown();
|
||||
|
||||
CountdownMessageFormat = InMessageFormat;
|
||||
CountdownRemaining = FMath::Max(Seconds, 1.f);
|
||||
LastDisplayedSeconds = -1;
|
||||
|
||||
RefreshCountdownText();
|
||||
|
||||
SetVisibility(ESlateVisibility::Visible);
|
||||
SetKeyboardFocus();
|
||||
|
||||
CountdownTickerHandle = FTSTicker::GetCoreTicker().AddTicker(
|
||||
FTickerDelegate::CreateUObject(this, &UConfirmDialogWidget::TickCountdown));
|
||||
}
|
||||
|
||||
void UConfirmDialogWidget::Close()
|
||||
{
|
||||
StopCountdown();
|
||||
|
||||
SetVisibility(ESlateVisibility::Collapsed);
|
||||
}
|
||||
|
||||
void UConfirmDialogWidget::StopCountdown()
|
||||
{
|
||||
if (CountdownTickerHandle.IsValid())
|
||||
{
|
||||
FTSTicker::GetCoreTicker().RemoveTicker(CountdownTickerHandle);
|
||||
CountdownTickerHandle.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void UConfirmDialogWidget::RefreshCountdownText()
|
||||
{
|
||||
if (!MessageText)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// CeilToInt : on affiche "10" pendant la premiere seconde et "1" pendant la
|
||||
// derniere. Avec un arrondi classique on afficherait "0" une demi-seconde
|
||||
// avant que ca se declenche, ce qui donne l'impression d'un bug.
|
||||
const int32 Seconds = FMath::CeilToInt(CountdownRemaining);
|
||||
if (Seconds == LastDisplayedSeconds)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LastDisplayedSeconds = Seconds;
|
||||
MessageText->SetText(FText::Format(CountdownMessageFormat, FText::AsNumber(Seconds)));
|
||||
}
|
||||
|
||||
bool UConfirmDialogWidget::TickCountdown(float DeltaTime)
|
||||
{
|
||||
CountdownRemaining -= DeltaTime;
|
||||
|
||||
if (CountdownRemaining > 0.f)
|
||||
{
|
||||
RefreshCountdownText();
|
||||
|
||||
// true : on veut etre rappele a la frame suivante.
|
||||
return true;
|
||||
}
|
||||
|
||||
// On coupe le ticker AVANT de diffuser : un abonne qui rouvre une boite
|
||||
// dans son handler doit pouvoir relancer un rebours.
|
||||
StopCountdown();
|
||||
OnCancelled.Broadcast();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
FReply UConfirmDialogWidget::NativeOnKeyDown(const FGeometry& InGeometry, const FKeyEvent& InKeyEvent)
|
||||
{
|
||||
const FKey Key = InKeyEvent.GetKey();
|
||||
@@ -64,6 +135,7 @@ FReply UConfirmDialogWidget::NativeOnKeyDown(const FGeometry& InGeometry, const
|
||||
// reellement branchee.
|
||||
if (bCancelOnEscape && (Key == EKeys::Escape || Key == EKeys::Virtual_Gamepad_Back.GetVirtualKey()))
|
||||
{
|
||||
StopCountdown();
|
||||
OnCancelled.Broadcast();
|
||||
|
||||
// Handled et non Unhandled : sans ca la touche continue de remonter et
|
||||
@@ -73,6 +145,7 @@ FReply UConfirmDialogWidget::NativeOnKeyDown(const FGeometry& InGeometry, const
|
||||
|
||||
if (bConfirmOnEnter && (Key == EKeys::Enter || Key == EKeys::Virtual_Gamepad_Accept.GetVirtualKey()))
|
||||
{
|
||||
StopCountdown();
|
||||
OnConfirmed.Broadcast();
|
||||
return FReply::Handled();
|
||||
}
|
||||
@@ -82,16 +155,26 @@ FReply UConfirmDialogWidget::NativeOnKeyDown(const FGeometry& InGeometry, const
|
||||
|
||||
void UConfirmDialogWidget::HandleConfirmClicked()
|
||||
{
|
||||
// Le joueur a repondu : le rebours n'a plus lieu d'etre, et le laisser
|
||||
// tourner ferait arriver un OnCancelled apres coup.
|
||||
StopCountdown();
|
||||
|
||||
OnConfirmed.Broadcast();
|
||||
}
|
||||
|
||||
void UConfirmDialogWidget::HandleCancelClicked()
|
||||
{
|
||||
StopCountdown();
|
||||
|
||||
OnCancelled.Broadcast();
|
||||
}
|
||||
|
||||
void UConfirmDialogWidget::NativeDestruct()
|
||||
{
|
||||
// Le ticker du moteur survit au widget : sans ce retrait, il rappellerait
|
||||
// une methode sur un objet detruit.
|
||||
StopCountdown();
|
||||
|
||||
if (ConfirmButton)
|
||||
{
|
||||
ConfirmButton->OnClicked.RemoveDynamic(this, &UConfirmDialogWidget::HandleConfirmClicked);
|
||||
|
||||
Reference in New Issue
Block a user