Create options menu widget class
This commit is contained in:
parent
145b497ed4
commit
738f4a2b8b
69
Source/vampires/Widgets/OptionsMenuWidget.cpp
Normal file
69
Source/vampires/Widgets/OptionsMenuWidget.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// Louis Hobbs | 2024-2025
|
||||||
|
|
||||||
|
|
||||||
|
#include "OptionsMenuWidget.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Components/Button.h"
|
||||||
|
#include "Components/ComboBoxString.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Kismet/KismetSystemLibrary.h"
|
||||||
|
|
||||||
|
|
||||||
|
void UOptionsMenuWidget::NativeConstruct()
|
||||||
|
{
|
||||||
|
Super::NativeConstruct();
|
||||||
|
|
||||||
|
GenerateResolutionOptions();
|
||||||
|
|
||||||
|
if (ReturnButton)
|
||||||
|
{
|
||||||
|
ReturnButton->OnClicked.AddUniqueDynamic(this, &UOptionsMenuWidget::ReturnButtonOnClicked);
|
||||||
|
ReturnButton->OnClicked.AddUniqueDynamic(this, &UOptionsMenuWidget::PlayClickedSound);
|
||||||
|
|
||||||
|
ReturnButton->OnHovered.AddUniqueDynamic(this, &UOptionsMenuWidget::PlayHoveredSound);
|
||||||
|
ReturnButton->OnHovered.AddUniqueDynamic(this, &UOptionsMenuWidget::ReturnTextBlockHoveredDelegate);
|
||||||
|
|
||||||
|
ReturnButton->OnUnhovered.AddUniqueDynamic(this, &UOptionsMenuWidget::ReturnTextBlockUnhoveredDelegate);
|
||||||
|
ReturnButton->OnUnhovered.AddUniqueDynamic(this, &UOptionsMenuWidget::PlayUnhoveredSound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UOptionsMenuWidget::GenerateResolutionOptions()
|
||||||
|
{
|
||||||
|
ResolutionComboBox->ClearOptions();
|
||||||
|
|
||||||
|
TArray<FIntPoint> Resolutions;
|
||||||
|
UKismetSystemLibrary::GetSupportedFullscreenResolutions(Resolutions);
|
||||||
|
for (FIntPoint Resolution : Resolutions)
|
||||||
|
{
|
||||||
|
ResolutionComboBox->AddOption(FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y));
|
||||||
|
}
|
||||||
|
|
||||||
|
FVector2D Resolution = FVector2D::ZeroVector;
|
||||||
|
GEngine->GameViewport->GetViewportSize(Resolution);
|
||||||
|
FString ResolutionString = FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y);
|
||||||
|
if (ResolutionComboBox->FindOptionIndex(ResolutionString) == -1)
|
||||||
|
{
|
||||||
|
ResolutionComboBox->AddOption(ResolutionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResolutionComboBox->SetSelectedOption(ResolutionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UOptionsMenuWidget::ReturnButtonOnClicked()
|
||||||
|
{
|
||||||
|
if (MainMenuMenuWidget)
|
||||||
|
{
|
||||||
|
RemoveFromParent();
|
||||||
|
|
||||||
|
UUserWidget* SelectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
|
||||||
|
UGameplayStatics::GetPlayerController(GetWorld(), 0), MainMenuMenuWidget);
|
||||||
|
|
||||||
|
if (SelectWeaponWidget)
|
||||||
|
{
|
||||||
|
SelectWeaponWidget->AddToViewport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
69
Source/vampires/Widgets/OptionsMenuWidget.h
Normal file
69
Source/vampires/Widgets/OptionsMenuWidget.h
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// Louis Hobbs | 2024-2025
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "VampireInteractiveWidget.h"
|
||||||
|
#include "OptionsMenuWidget.generated.h"
|
||||||
|
|
||||||
|
class UComboBoxString;
|
||||||
|
class UComboBox;
|
||||||
|
class UComboBox;
|
||||||
|
class UButton;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class VAMPIRES_API UOptionsMenuWidget : public UVampireInteractiveWidget
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UComboBoxString> ResolutionComboBox;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UTextBlock> ResolutionTextBlock;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UComboBoxString> WindowTypeComboBox;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UComboBoxString> VsyncComboBox;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UComboBoxString> RefreshRateComboBox;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UComboBoxString> DynamicResolutionComboBox;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UButton> ReturnButton;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UTextBlock> ReturnBlock;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UButton> ResetToDefaultsButton;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UTextBlock> ResetToDefaultsBlock;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, Category = "Widget Settings | New Game")
|
||||||
|
TSubclassOf<UUserWidget> MainMenuMenuWidget;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void NativeConstruct() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void GenerateResolutionOptions();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void ReturnButtonOnClicked();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void ReturnTextBlockHoveredDelegate() { SetTextBlockHovered(ReturnBlock); }
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void ReturnTextBlockUnhoveredDelegate() { SetTextBlockUnhovered(ReturnBlock); }
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user