Add placeholder select weapon widget

This commit is contained in:
baz 2025-06-12 23:17:00 +01:00
parent 7d8c59d3fe
commit e29e4e5b32
3 changed files with 73 additions and 28 deletions

View File

@ -3,6 +3,7 @@
#include "MainMenuWidget.h" #include "MainMenuWidget.h"
#include "SelectWeaponWidget.h"
#include "Blueprint/WidgetBlueprintLibrary.h" #include "Blueprint/WidgetBlueprintLibrary.h"
#include "Components/Button.h" #include "Components/Button.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
@ -35,6 +36,8 @@ void UMainMenuWidget::NativeConstruct()
QuitButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuWidget::PlayUnhoveredSound); QuitButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuWidget::PlayUnhoveredSound);
} }
QuitButton->SetIsEnabled(false);
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{ {
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(PlayerController, this, EMouseLockMode::LockAlways); UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(PlayerController, this, EMouseLockMode::LockAlways);
@ -44,18 +47,31 @@ void UMainMenuWidget::NativeConstruct()
void UMainMenuWidget::NewGameButtonOnClicked() void UMainMenuWidget::NewGameButtonOnClicked()
{ {
if (!NewGameLevel.IsNull()) if (NewGameMenuWidget)
{ {
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NewGameLevel); RemoveFromParent();
UUserWidget* selectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
UGameplayStatics::GetPlayerController(GetWorld(), 0), NewGameMenuWidget);
if (selectWeaponWidget)
{
selectWeaponWidget->AddToViewport();
}
} }
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) // if (!NewGameLevel.IsNull())
{ // {
PlayerController->bShowMouseCursor = false; // UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NewGameLevel);
UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController); // }
} //
// if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
SetIsFocusable(false); // {
// PlayerController->bShowMouseCursor = false;
// UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
// }
//
// SetIsFocusable(false);
} }
void UMainMenuWidget::QuitButtonOnClicked() void UMainMenuWidget::QuitButtonOnClicked()

View File

@ -3,18 +3,32 @@
#include "SelectWeaponWidget.h" #include "SelectWeaponWidget.h"
#include "SlateOptMacros.h" #include "MainMenuWidget.h"
#include "Components/Button.h"
#include "Kismet/GameplayStatics.h"
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION void USelectWeaponWidget::NativeConstruct()
void SelectWeaponWidget::Construct(const FArguments& InArgs)
{ {
/* Super::NativeConstruct();
ChildSlot
[ if (BackButton)
// Populate the widget {
]; BackButton->OnClicked.AddUniqueDynamic(this, &USelectWeaponWidget::BackButtonClicked);
*/ }
} }
END_SLATE_FUNCTION_BUILD_OPTIMIZATION void USelectWeaponWidget::BackButtonClicked()
{
if (PreviousWidget)
{
RemoveFromParent();
UUserWidget* selectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
UGameplayStatics::GetPlayerController(GetWorld(), 0), PreviousWidget);
if (selectWeaponWidget)
{
selectWeaponWidget->AddToViewport();
}
}
}

View File

@ -3,20 +3,35 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h" #include "VampireInteractiveWidget.h"
#include "SelectWeaponWidget.generated.h"
class UListView;
class UButton;
/** /**
* *
*/ */
class VAMPIRES_API SelectWeaponWidget : public SCompoundWidget UCLASS()
class VAMPIRES_API USelectWeaponWidget : public UVampireInteractiveWidget
{ {
GENERATED_BODY()
public: public:
SLATE_BEGIN_ARGS(SelectWeaponWidget)
{
}
SLATE_END_ARGS() UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
UButton* BackButton;
UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
UListView* UpgradesListView;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<class UUserWidget> PreviousWidget;
virtual void NativeConstruct() override;
private:
UFUNCTION()
void BackButtonClicked();
/** Constructs this widget with InArgs */
void Construct(const FArguments& InArgs);
}; };