Update Level Up UI to custom buttons
This commit is contained in:
parent
20dbb97b7c
commit
a0a3aaddff
BIN
Content/Widgets/LevelUp/BP_LevelUpWidget.uasset
(Stored with Git LFS)
BIN
Content/Widgets/LevelUp/BP_LevelUpWidget.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Widgets/LevelUp/BP_UpgradeButtonTemplate.uasset
(Stored with Git LFS)
BIN
Content/Widgets/LevelUp/BP_UpgradeButtonTemplate.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Widgets/MainMenu/BP_SelectWeaponWidget.uasset
(Stored with Git LFS)
BIN
Content/Widgets/MainMenu/BP_SelectWeaponWidget.uasset
(Stored with Git LFS)
Binary file not shown.
@ -202,9 +202,6 @@ void AVampirePlayerController::ShowLevelUpScreen(int Level)
|
||||
if (CurrentLevelUpUI)
|
||||
{
|
||||
CurrentLevelUpUI->AddToViewport();
|
||||
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentLevelUpUI,
|
||||
EMouseLockMode::LockInFullscreen);
|
||||
bShowMouseCursor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,13 @@
|
||||
|
||||
#include "LevelUpWidget.h"
|
||||
|
||||
#include "CustomButton.h"
|
||||
#include "Blueprint/WidgetBlueprintLibrary.h"
|
||||
#include "Components/Button.h"
|
||||
#include "Components/ListView.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "UpgradeButtonDataObject.h"
|
||||
#include "UpgradeButtonWidget.h"
|
||||
#include "Components/ScrollBox.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "vampires/VampireCharacter.h"
|
||||
#include "vampires/Weapon.h"
|
||||
@ -20,11 +22,10 @@ void ULevelUpWidget::NativeConstruct()
|
||||
if (ResumeButton)
|
||||
{
|
||||
ResumeButton->OnClicked.AddUniqueDynamic(this, &ULevelUpWidget::ResumeButtonClicked);
|
||||
ResumeButton->OnHovered.AddUniqueDynamic(this, &ULevelUpWidget::ResumeButtonOnHovered);
|
||||
ResumeButton->OnUnhovered.AddUniqueDynamic(this, &ULevelUpWidget::ResumeButtonOnUnhovered);
|
||||
ResumeButton->OnFocused.AddUniqueDynamic(this, &ULevelUpWidget::BackButtonFocused);
|
||||
}
|
||||
|
||||
if (UpgradesListView)
|
||||
if (UpgradesScrollBox && UpgradeButtonWidgetTemplate)
|
||||
{
|
||||
ACharacter* Player = Cast<AVampireCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||
if (!Player)
|
||||
@ -38,7 +39,7 @@ void ULevelUpWidget::NativeConstruct()
|
||||
return;
|
||||
}
|
||||
|
||||
UpgradesListView->ClearListItems();
|
||||
UpgradesScrollBox->ClearChildren();
|
||||
TArray<AWeapon*> Inventory = InventoryComponent->GetInventory();
|
||||
|
||||
// Get list of weapons that the player owns that can be upgraded
|
||||
@ -84,17 +85,34 @@ void ULevelUpWidget::NativeConstruct()
|
||||
for (int i = 0; i < 3 && UpgradeItems.Num() > 0; i++)
|
||||
{
|
||||
int Rand = FMath::RandRange(0, UpgradeItems.Num() - 1);
|
||||
UpgradesListView->AddItem(UpgradeItems[Rand]);
|
||||
UUpgradeButtonDataObject* Selection = UpgradeItems[Rand];
|
||||
UUpgradeButtonWidget* Widget = CreateWidget<UUpgradeButtonWidget>(
|
||||
GetWorld(), UpgradeButtonWidgetTemplate);
|
||||
Widget->SetData(Selection);
|
||||
UpgradesScrollBox->AddChild(Widget);
|
||||
UpgradeItems.RemoveAt(Rand);
|
||||
}
|
||||
|
||||
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
{
|
||||
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(PlayerController, UpgradesScrollBox->GetChildAt(0),
|
||||
EMouseLockMode::LockAlways);
|
||||
PlayerController->bShowMouseCursor = true;
|
||||
}
|
||||
}
|
||||
SetIsFocusable(true);
|
||||
|
||||
SetIsFocusable(false);
|
||||
}
|
||||
|
||||
FReply ULevelUpWidget::NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
|
||||
{
|
||||
CurrentFocus->SetKeyboardFocus();
|
||||
|
||||
return Super::NativeOnMouseButtonUp(InGeometry, InMouseEvent);
|
||||
}
|
||||
|
||||
void ULevelUpWidget::ResumeButtonClicked()
|
||||
{
|
||||
PlayClickedSound();
|
||||
|
||||
RemoveFromParent();
|
||||
|
||||
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
@ -107,14 +125,7 @@ void ULevelUpWidget::ResumeButtonClicked()
|
||||
SetIsFocusable(false);
|
||||
}
|
||||
|
||||
void ULevelUpWidget::ResumeButtonOnHovered()
|
||||
void ULevelUpWidget::BackButtonFocused(FFocusEvent InFocusEvent)
|
||||
{
|
||||
SetTextBlockHovered(ResumeTextBlock);
|
||||
PlayHoveredSound();
|
||||
}
|
||||
|
||||
void ULevelUpWidget::ResumeButtonOnUnhovered()
|
||||
{
|
||||
SetTextBlockUnhovered(ResumeTextBlock);
|
||||
PlayUnhoveredSound();
|
||||
SetCurrentFocus(ResumeButton);
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "VampireInteractiveWidget.h"
|
||||
#include "LevelUpWidget.generated.h"
|
||||
|
||||
class UUpgradeButtonWidget;
|
||||
class UScrollBox;
|
||||
class UUpgradeButtonDataObject;
|
||||
class UListView;
|
||||
class UButton;
|
||||
@ -17,23 +19,25 @@ class VAMPIRES_API ULevelUpWidget : public UVampireInteractiveWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
TObjectPtr<UButton> ResumeButton;
|
||||
TObjectPtr<UCustomButton> ResumeButton;
|
||||
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
TObjectPtr<UTextBlock> ResumeTextBlock;
|
||||
TObjectPtr<UScrollBox> UpgradesScrollBox;
|
||||
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
UListView* UpgradesListView;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSubclassOf<UUpgradeButtonWidget> UpgradeButtonWidgetTemplate;
|
||||
|
||||
protected:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
virtual FReply NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
|
||||
|
||||
private:
|
||||
UFUNCTION()
|
||||
void ResumeButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void ResumeButtonOnHovered();
|
||||
|
||||
UFUNCTION()
|
||||
void ResumeButtonOnUnhovered();
|
||||
void BackButtonFocused(FFocusEvent InFocusEvent);
|
||||
};
|
||||
|
@ -3,9 +3,9 @@
|
||||
|
||||
#include "UpgradeButtonWidget.h"
|
||||
|
||||
#include "LevelUpWidget.h"
|
||||
#include "UpgradeButtonDataObject.h"
|
||||
#include "Blueprint/WidgetBlueprintLibrary.h"
|
||||
#include "Components/Button.h"
|
||||
#include "Components/Image.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
@ -18,13 +18,16 @@
|
||||
void UUpgradeButtonWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
OnFocused.AddUniqueDynamic(this, &UUpgradeButtonWidget::SetFocusInParent);
|
||||
}
|
||||
|
||||
void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
void UUpgradeButtonWidget::SetData(UUpgradeButtonDataObject* ListItemObject)
|
||||
{
|
||||
if (UUpgradeButtonDataObject* Item = Cast<UUpgradeButtonDataObject>(ListItemObject))
|
||||
{
|
||||
WeaponNameTextBlock->SetText(Item->WeaponName);
|
||||
TextBlock->SetText(Item->WeaponName);
|
||||
ButtonText = Item->WeaponName;
|
||||
DescriptionTextBlock->SetText(Item->WeaponDescription);
|
||||
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
|
||||
Parent = Item->Parent;
|
||||
@ -47,13 +50,6 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
{
|
||||
UpgradeType = Gold;
|
||||
}
|
||||
|
||||
if (Body)
|
||||
{
|
||||
Body->OnClicked.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnClicked);
|
||||
Body->OnHovered.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnHoveredDelegate);
|
||||
Body->OnUnhovered.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnUnhoveredDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -75,9 +71,9 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
}
|
||||
}
|
||||
|
||||
void UUpgradeButtonWidget::OnClicked()
|
||||
void UUpgradeButtonWidget::OnButtonClicked()
|
||||
{
|
||||
PlayClickedSound();
|
||||
Super::OnButtonClicked();
|
||||
|
||||
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
|
||||
@ -136,16 +132,10 @@ void UUpgradeButtonWidget::OnClicked()
|
||||
}
|
||||
}
|
||||
|
||||
void UUpgradeButtonWidget::OnHoveredDelegate()
|
||||
void UUpgradeButtonWidget::SetFocusInParent(FFocusEvent InFocusEvent)
|
||||
{
|
||||
PlayHoveredSound();
|
||||
SetTextBlockHovered(WeaponNameTextBlock);
|
||||
SetTextBlockHovered(DescriptionTextBlock);
|
||||
}
|
||||
|
||||
void UUpgradeButtonWidget::OnUnhoveredDelegate()
|
||||
{
|
||||
PlayUnhoveredSound();
|
||||
SetTextBlockUnhovered(WeaponNameTextBlock);
|
||||
SetTextBlockUnhovered(DescriptionTextBlock);
|
||||
if (ULevelUpWidget* LevelUpMenu = Cast<ULevelUpWidget>(Parent))
|
||||
{
|
||||
LevelUpMenu->SetCurrentFocus(this);
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "VampireInteractiveWidget.h"
|
||||
#include "CustomButton.h"
|
||||
#include "Blueprint/IUserObjectListEntry.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "UpgradeButtonWidget.generated.h"
|
||||
|
||||
class UUpgradeButtonDataObject;
|
||||
class AWeapon;
|
||||
|
||||
UENUM(BlueprintType)
|
||||
@ -27,7 +28,7 @@ class UButton;
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class VAMPIRES_API UUpgradeButtonWidget : public UVampireInteractiveWidget, public IUserObjectListEntry
|
||||
class VAMPIRES_API UUpgradeButtonWidget : public UCustomButton, public IUserObjectListEntry
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
@ -45,16 +46,9 @@ protected:
|
||||
TObjectPtr<UTexture2D> GoldIcon;
|
||||
|
||||
private:
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UButton> Body;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UImage> WeaponIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UTextBlock> WeaponNameTextBlock;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UTextBlock> DescriptionTextBlock;
|
||||
|
||||
@ -70,22 +64,18 @@ private:
|
||||
UPROPERTY()
|
||||
TObjectPtr<UUserWidget> Parent;
|
||||
|
||||
private:
|
||||
UPROPERTY(meta=(BindWidget))
|
||||
UImage* UpgradeTypeIcon;
|
||||
|
||||
protected:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;
|
||||
public:
|
||||
virtual void SetData(UUpgradeButtonDataObject* ListItemObject);
|
||||
|
||||
private:
|
||||
UFUNCTION()
|
||||
virtual void OnClicked();
|
||||
virtual void OnButtonClicked() override;
|
||||
|
||||
UFUNCTION()
|
||||
void OnHoveredDelegate();
|
||||
|
||||
UFUNCTION()
|
||||
void OnUnhoveredDelegate();
|
||||
void SetFocusInParent(FFocusEvent InFocusEvent);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user