mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
MenuStack can now change the input mode, game pause and mouse visibility on enter & exit if required
This commit is contained in:
parent
167741cfbb
commit
52915aa105
@ -5,6 +5,7 @@
|
|||||||
#include "StevesUEHelpers.h"
|
#include "StevesUEHelpers.h"
|
||||||
#include "StevesUI/MenuBase.h"
|
#include "StevesUI/MenuBase.h"
|
||||||
#include "Framework/Application/SlateApplication.h"
|
#include "Framework/Application/SlateApplication.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
|
||||||
void UMenuStack::NativeConstruct()
|
void UMenuStack::NativeConstruct()
|
||||||
@ -25,6 +26,10 @@ void UMenuStack::NativeConstruct()
|
|||||||
GS->OnInputModeChanged.AddDynamic(this, &UMenuStack::InputModeChanged);
|
GS->OnInputModeChanged.AddDynamic(this, &UMenuStack::InputModeChanged);
|
||||||
LastInputMode = GS->GetLastInputModeUsed();
|
LastInputMode = GS->GetLastInputModeUsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApplyInputModeChange(InputModeSettingOnOpen);
|
||||||
|
ApplyMousePointerVisibility(MousePointerVisibilityOnOpen);
|
||||||
|
ApplyGamePauseChange(GamePauseSettingOnOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UMenuStack::NativeDestruct()
|
void UMenuStack::NativeDestruct()
|
||||||
@ -36,6 +41,56 @@ void UMenuStack::NativeDestruct()
|
|||||||
if (GS)
|
if (GS)
|
||||||
GS->OnInputModeChanged.RemoveDynamic(this, &UMenuStack::InputModeChanged);
|
GS->OnInputModeChanged.RemoveDynamic(this, &UMenuStack::InputModeChanged);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UMenuStack::ApplyInputModeChange(EInputModeChange Change) const
|
||||||
|
{
|
||||||
|
auto PC = GetOwningPlayer();
|
||||||
|
switch (Change)
|
||||||
|
{
|
||||||
|
case EInputModeChange::DoNotChange:
|
||||||
|
break;
|
||||||
|
case EInputModeChange::UIOnly:
|
||||||
|
PC->SetInputMode(FInputModeUIOnly());
|
||||||
|
break;
|
||||||
|
case EInputModeChange::GameAndUI:
|
||||||
|
PC->SetInputMode(FInputModeGameAndUI());
|
||||||
|
break;
|
||||||
|
case EInputModeChange::GameOnly:
|
||||||
|
PC->SetInputMode(FInputModeGameOnly());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UMenuStack::ApplyMousePointerVisibility(EMousePointerVisibilityChange Change) const
|
||||||
|
{
|
||||||
|
auto PC = GetOwningPlayer();
|
||||||
|
switch (Change)
|
||||||
|
{
|
||||||
|
case EMousePointerVisibilityChange::DoNotChange:
|
||||||
|
break;
|
||||||
|
case EMousePointerVisibilityChange::Visible:
|
||||||
|
PC->bShowMouseCursor = true;
|
||||||
|
break;
|
||||||
|
case EMousePointerVisibilityChange::Hidden:
|
||||||
|
PC->bShowMouseCursor = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UMenuStack::ApplyGamePauseChange(EGamePauseChange Change) const
|
||||||
|
{
|
||||||
|
switch (Change)
|
||||||
|
{
|
||||||
|
case EGamePauseChange::DoNotChange:
|
||||||
|
break;
|
||||||
|
case EGamePauseChange::Paused:
|
||||||
|
UGameplayStatics::SetGamePaused(GetWorld(), true);
|
||||||
|
break;
|
||||||
|
case EGamePauseChange::Unpaused:
|
||||||
|
UGameplayStatics::SetGamePaused(GetWorld(), false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +186,11 @@ void UMenuStack::LastMenuClosed(bool bWasCancel)
|
|||||||
{
|
{
|
||||||
RemoveFromParent();
|
RemoveFromParent();
|
||||||
OnClosed.Broadcast(this, bWasCancel);
|
OnClosed.Broadcast(this, bWasCancel);
|
||||||
|
|
||||||
|
ApplyInputModeChange(InputModeSettingOnClose);
|
||||||
|
ApplyMousePointerVisibility(MousePointerVisibilityOnClose);
|
||||||
|
ApplyGamePauseChange(GamePauseSettingOnClose);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UMenuStack::CloseAll(bool bWasCancel)
|
void UMenuStack::CloseAll(bool bWasCancel)
|
||||||
|
@ -10,3 +10,28 @@ enum class EInputMode : uint8
|
|||||||
Unknown
|
Unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UENUM(BlueprintType)
|
||||||
|
enum class EInputModeChange : uint8
|
||||||
|
{
|
||||||
|
DoNotChange UMETA(DisplayName="No Change"),
|
||||||
|
UIOnly UMETA(DisplayName="UI Only"),
|
||||||
|
GameAndUI UMETA(DisplayName="Game And UI"),
|
||||||
|
GameOnly UMETA(DisplayName="Game Only")
|
||||||
|
};
|
||||||
|
|
||||||
|
UENUM(BlueprintType)
|
||||||
|
enum class EMousePointerVisibilityChange : uint8
|
||||||
|
{
|
||||||
|
DoNotChange UMETA(DisplayName="No Change"),
|
||||||
|
Visible UMETA(DisplayName="Pointer Visible"),
|
||||||
|
Hidden UMETA(DisplayName="Pointer Hidden")
|
||||||
|
};
|
||||||
|
|
||||||
|
UENUM(BlueprintType)
|
||||||
|
enum class EGamePauseChange : uint8
|
||||||
|
{
|
||||||
|
DoNotChange UMETA(DisplayName="No Change"),
|
||||||
|
Paused UMETA(DisplayName="Pause Game"),
|
||||||
|
Unpaused UMETA(DisplayName="Unpause Game")
|
||||||
|
};
|
||||||
|
|
||||||
|
@ -8,34 +8,8 @@
|
|||||||
|
|
||||||
#include "MenuBase.generated.h"
|
#include "MenuBase.generated.h"
|
||||||
|
|
||||||
|
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnMenuClosed, UMenuBase*, Menu, bool, bWasCancelled);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnMenuClosed, UMenuBase*, Menu, bool, bWasCancelled);
|
||||||
|
|
||||||
UENUM(BlueprintType)
|
|
||||||
enum class EInputModeChange : uint8
|
|
||||||
{
|
|
||||||
DoNotChange UMETA(DisplayName="No Change"),
|
|
||||||
UIOnly UMETA(DisplayName="UI Only"),
|
|
||||||
GameAndUI UMETA(DisplayName="Game And UI"),
|
|
||||||
GameOnly UMETA(DisplayName="Game Only")
|
|
||||||
};
|
|
||||||
|
|
||||||
UENUM(BlueprintType)
|
|
||||||
enum class EMousePointerVisibilityChange : uint8
|
|
||||||
{
|
|
||||||
DoNotChange UMETA(DisplayName="No Change"),
|
|
||||||
Visible UMETA(DisplayName="Pointer Visible"),
|
|
||||||
Hidden UMETA(DisplayName="Pointer Hidden")
|
|
||||||
};
|
|
||||||
|
|
||||||
UENUM(BlueprintType)
|
|
||||||
enum class EGamePauseChange : uint8
|
|
||||||
{
|
|
||||||
DoNotChange UMETA(DisplayName="No Change"),
|
|
||||||
Paused UMETA(DisplayName="Pause Game"),
|
|
||||||
Unpaused UMETA(DisplayName="Unpause Game")
|
|
||||||
};
|
|
||||||
|
|
||||||
/// This class is a type of focusable panel designed for menus or other dialogs.
|
/// This class is a type of focusable panel designed for menus or other dialogs.
|
||||||
/// It can be added to a UMenuStack to put it in context of a larger navigable group,
|
/// It can be added to a UMenuStack to put it in context of a larger navigable group,
|
||||||
/// and if so represents one level in the chain of an assumed modal stack. Use UMenuStack::PushMenuByClass/Object
|
/// and if so represents one level in the chain of an assumed modal stack. Use UMenuStack::PushMenuByClass/Object
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "FocusableUserWidget.h"
|
#include "FocusableUserWidget.h"
|
||||||
#include "Framework/Application/IInputProcessor.h"
|
#include "Framework/Application/IInputProcessor.h"
|
||||||
#include "StevesHelperCommon.h"
|
#include "StevesHelperCommon.h"
|
||||||
#include "UObject/ObjectMacros.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include "MenuStack.generated.h"
|
#include "MenuStack.generated.h"
|
||||||
@ -49,10 +48,15 @@ protected:
|
|||||||
|
|
||||||
TSharedPtr<FUiInputPreprocessor> InputPreprocessor;
|
TSharedPtr<FUiInputPreprocessor> InputPreprocessor;
|
||||||
|
|
||||||
void LastMenuClosed(bool bWasCancel);
|
virtual void LastMenuClosed(bool bWasCancel);
|
||||||
|
|
||||||
virtual void NativeConstruct() override;
|
virtual void NativeConstruct() override;
|
||||||
virtual void NativeDestruct() override;
|
virtual void NativeDestruct() override;
|
||||||
|
|
||||||
|
virtual void ApplyInputModeChange(EInputModeChange Change) const;
|
||||||
|
virtual void ApplyMousePointerVisibility(EMousePointerVisibilityChange Change) const;
|
||||||
|
virtual void ApplyGamePauseChange(EGamePauseChange Change) const;
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
bool HandleKeyDownEvent(const FKeyEvent& InKeyEvent);
|
bool HandleKeyDownEvent(const FKeyEvent& InKeyEvent);
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
@ -70,6 +74,30 @@ public:
|
|||||||
UPROPERTY(BlueprintAssignable)
|
UPROPERTY(BlueprintAssignable)
|
||||||
FOnMenuStackClosed OnClosed;
|
FOnMenuStackClosed OnClosed;
|
||||||
|
|
||||||
|
/// How this stack should change the input mode when it opens (default no change)
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior")
|
||||||
|
EInputModeChange InputModeSettingOnOpen = EInputModeChange::DoNotChange;
|
||||||
|
|
||||||
|
/// How this stack should set the mouse pointer visibility when it opens (default no change)
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior")
|
||||||
|
EMousePointerVisibilityChange MousePointerVisibilityOnOpen = EMousePointerVisibilityChange::DoNotChange;
|
||||||
|
|
||||||
|
/// How this stack should set the game pause state when it opens (default no change)
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior")
|
||||||
|
EGamePauseChange GamePauseSettingOnOpen = EGamePauseChange::DoNotChange;
|
||||||
|
|
||||||
|
/// How this stack should change the input mode when it closes (default no change)
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior")
|
||||||
|
EInputModeChange InputModeSettingOnClose = EInputModeChange::DoNotChange;
|
||||||
|
|
||||||
|
/// How this stack should set the mouse pointer visibility when it closes (default no change)
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior")
|
||||||
|
EMousePointerVisibilityChange MousePointerVisibilityOnClose = EMousePointerVisibilityChange::DoNotChange;
|
||||||
|
|
||||||
|
/// How this stack should set the game pause state when it closes (default no change)
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Behavior")
|
||||||
|
EGamePauseChange GamePauseSettingOnClose = EGamePauseChange::DoNotChange;
|
||||||
|
|
||||||
/// Push a new menu level by class. This will instantiate the new menu, display it, and inform the previous menu that it's
|
/// Push a new menu level by class. This will instantiate the new menu, display it, and inform the previous menu that it's
|
||||||
/// been superceded. Use the returned instance if you want to cache it
|
/// been superceded. Use the returned instance if you want to cache it
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user