Fix MVP menu startup and mouse flow

This commit is contained in:
2026-05-18 22:14:17 -07:00
parent 5566d846e1
commit 3aac902142
10 changed files with 321 additions and 35 deletions
@@ -18,6 +18,7 @@
#include "GameFramework/CharacterMovementComponent.h"
#include "InputMappingContext.h"
#include "Blueprint/UserWidget.h"
#include "TimerManager.h"
#include "AgrarianGame.h"
#include "Widgets/Input/SVirtualJoystick.h"
@@ -81,16 +82,18 @@ void AAgrarianGamePlayerController::BeginPlay()
if (IsLocalPlayerController())
{
if (!MvpFrontendWidgetClass)
if (MvpFrontendStartupDelaySeconds > 0.0f)
{
MvpFrontendWidgetClass = UAgrarianMvpFrontendWidget::StaticClass();
GetWorldTimerManager().SetTimer(
MvpFrontendStartupTimerHandle,
this,
&AAgrarianGamePlayerController::ShowMvpFrontend,
MvpFrontendStartupDelaySeconds,
false);
}
MvpFrontendWidget = CreateWidget<UAgrarianMvpFrontendWidget>(this, MvpFrontendWidgetClass);
if (MvpFrontendWidget)
else
{
MvpFrontendWidget->SetActiveScreen(EAgrarianMvpFrontendScreen::CharacterSelection);
MvpFrontendWidget->AddToPlayerScreen(10);
ShowMvpFrontend();
}
}
@@ -147,6 +150,30 @@ bool AAgrarianGamePlayerController::ShouldUseTouchControls() const
return SVirtualJoystick::ShouldDisplayTouchInterface() || bForceTouchControls;
}
void AAgrarianGamePlayerController::ShowMvpFrontend()
{
if (!IsLocalPlayerController() || MvpFrontendWidget)
{
return;
}
if (!MvpFrontendWidgetClass)
{
MvpFrontendWidgetClass = UAgrarianMvpFrontendWidget::StaticClass();
}
MvpFrontendWidget = CreateWidget<UAgrarianMvpFrontendWidget>(this, MvpFrontendWidgetClass);
if (!MvpFrontendWidget)
{
return;
}
MvpFrontendWidget->SetActiveScreen(EAgrarianMvpFrontendScreen::CharacterSelection);
MvpFrontendWidget->AddToPlayerScreen(10);
SetInputMode(FInputModeGameAndUI().SetWidgetToFocus(MvpFrontendWidget->TakeWidget()).SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock));
bShowMouseCursor = true;
}
void AAgrarianGamePlayerController::AgrarianGrantItem(FName ItemId, int32 Quantity)
{
if (ItemId == NAME_None || Quantity <= 0)