From e29e4e5b325b5424f4fc3248b37949a634593749 Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 12 Jun 2025 23:17:00 +0100 Subject: [PATCH] Add placeholder select weapon widget --- Source/vampires/Widgets/MainMenuWidget.cpp | 34 +++++++++++++----- .../vampires/Widgets/SelectWeaponWidget.cpp | 36 +++++++++++++------ Source/vampires/Widgets/SelectWeaponWidget.h | 31 +++++++++++----- 3 files changed, 73 insertions(+), 28 deletions(-) diff --git a/Source/vampires/Widgets/MainMenuWidget.cpp b/Source/vampires/Widgets/MainMenuWidget.cpp index c7aaa30..57bf3fa 100644 --- a/Source/vampires/Widgets/MainMenuWidget.cpp +++ b/Source/vampires/Widgets/MainMenuWidget.cpp @@ -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( + 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() diff --git a/Source/vampires/Widgets/SelectWeaponWidget.cpp b/Source/vampires/Widgets/SelectWeaponWidget.cpp index 32e1dae..e43c998 100644 --- a/Source/vampires/Widgets/SelectWeaponWidget.cpp +++ b/Source/vampires/Widgets/SelectWeaponWidget.cpp @@ -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( + UGameplayStatics::GetPlayerController(GetWorld(), 0), PreviousWidget); + + if (selectWeaponWidget) + { + selectWeaponWidget->AddToViewport(); + } + } +} diff --git a/Source/vampires/Widgets/SelectWeaponWidget.h b/Source/vampires/Widgets/SelectWeaponWidget.h index 3cb5d3d..fda2271 100644 --- a/Source/vampires/Widgets/SelectWeaponWidget.h +++ b/Source/vampires/Widgets/SelectWeaponWidget.h @@ -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 PreviousWidget; + + virtual void NativeConstruct() override; + +private: + + UFUNCTION() + void BackButtonClicked(); - /** Constructs this widget with InArgs */ - void Construct(const FArguments& InArgs); };