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

View File

@ -3,18 +3,32 @@
#include "SelectWeaponWidget.h"
#include "SlateOptMacros.h"
#include "MainMenuWidget.h"
#include "Components/Button.h"
#include "Kismet/GameplayStatics.h"
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SelectWeaponWidget::Construct(const FArguments& InArgs)
void USelectWeaponWidget::NativeConstruct()
{
/*
ChildSlot
[
// Populate the widget
];
*/
Super::NativeConstruct();
if (BackButton)
{
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
#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:
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);
};