Add Health and Gold Options to Level Up menu when there are no upgrades left
This commit is contained in:
parent
2d11a5c5bc
commit
804597fbff
@ -8,7 +8,6 @@
|
||||
#include "Components/ListView.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "UpgradeButtonDataObject.h"
|
||||
#include "EntitySystem/MovieSceneEntitySystemRunner.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "vampires/VampireCharacter.h"
|
||||
#include "vampires/Weapon.h"
|
||||
@ -25,11 +24,17 @@ void ULevelUpWidget::NativeConstruct()
|
||||
|
||||
if (UpgradesListView)
|
||||
{
|
||||
ACharacter* Player = Cast<AVampireCharacter>( UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||
if (!Player) return;
|
||||
ACharacter* Player = Cast<AVampireCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||
if (!Player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UWeaponInventoryComponent* InventoryComponent = Player->GetComponentByClass<UWeaponInventoryComponent>();
|
||||
if (!InventoryComponent) return;
|
||||
if (!InventoryComponent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TArray<AWeapon*> Inventory = InventoryComponent->GetInventory();
|
||||
TArray<UUpgradeButtonDataObject*> upgradeItems;
|
||||
@ -46,6 +51,23 @@ void ULevelUpWidget::NativeConstruct()
|
||||
}
|
||||
}
|
||||
|
||||
if (upgradeItems.Num() == 0)
|
||||
{
|
||||
UUpgradeButtonDataObject* tempHealth = NewObject<UUpgradeButtonDataObject>(this);
|
||||
tempHealth->SetData(FText::FromString("Health"),
|
||||
FText::FromString("Recover 10% of your health"),
|
||||
nullptr,
|
||||
this);
|
||||
upgradeItems.Add(tempHealth);
|
||||
|
||||
UUpgradeButtonDataObject* tempGold = NewObject<UUpgradeButtonDataObject>(this);
|
||||
tempGold->SetData(FText::FromString("Gold"),
|
||||
FText::FromString("Gain 10 gold"),
|
||||
nullptr,
|
||||
this);
|
||||
upgradeItems.Add(tempGold);
|
||||
}
|
||||
|
||||
UpgradesListView->SetListItems(upgradeItems);
|
||||
}
|
||||
SetIsFocusable(true);
|
||||
|
@ -26,3 +26,12 @@ void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget*
|
||||
Parent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
void UUpgradeButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon,
|
||||
UUserWidget* parent)
|
||||
{
|
||||
WeaponName = weaponName;
|
||||
Description = description;
|
||||
WeaponIcon = weaponIcon;
|
||||
Parent = parent;
|
||||
}
|
||||
|
@ -36,4 +36,5 @@ public:
|
||||
|
||||
void SetData(AWeapon* Weapon, UUserWidget* parent);
|
||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent);
|
||||
void SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, UUserWidget* parent);
|
||||
};
|
||||
|
@ -9,9 +9,10 @@
|
||||
#include "Components/Image.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
#include "vampires/Weapon.h"
|
||||
#include "UObject/UObjectBase.h"
|
||||
#include "vampires/GoldComponent.h"
|
||||
#include "vampires/HealthComponent.h"
|
||||
|
||||
void UUpgradeButtonWidget::NativeConstruct()
|
||||
{
|
||||
@ -31,14 +32,22 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
|
||||
if (Item->WeaponInstance != nullptr)
|
||||
{
|
||||
UpgradeType = EUpgradeType::Upgrade;
|
||||
UpgradeType = Upgrade;
|
||||
WeaponInstance = Item->WeaponInstance;
|
||||
}
|
||||
else if (Item->WeaponTemplate != nullptr)
|
||||
{
|
||||
UpgradeType = EUpgradeType::NewWeapon;
|
||||
UpgradeType = NewWeapon;
|
||||
WeaponTemplate = Item->WeaponTemplate;
|
||||
}
|
||||
else if (Item->WeaponName.ToString() == "Health")
|
||||
{
|
||||
UpgradeType = Health;
|
||||
}
|
||||
else if (Item->WeaponName.ToString() == "Gold")
|
||||
{
|
||||
UpgradeType = Gold;
|
||||
}
|
||||
|
||||
|
||||
if (Body)
|
||||
@ -48,26 +57,54 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
}
|
||||
|
||||
|
||||
switch (UpgradeType) {
|
||||
switch (UpgradeType)
|
||||
{
|
||||
case Upgrade:
|
||||
UpgradeTypeIcon->SetBrushFromTexture(UpgradeIcon);
|
||||
break;
|
||||
case NewWeapon:
|
||||
UpgradeTypeIcon->SetBrushFromTexture(NewWeaponIcon);
|
||||
break;
|
||||
case Health:
|
||||
UpgradeTypeIcon->SetBrushFromTexture(HealthIcon);
|
||||
break;
|
||||
case Gold:
|
||||
UpgradeTypeIcon->SetBrushFromTexture(GoldIcon);
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
void UUpgradeButtonWidget::OnClicked()
|
||||
{
|
||||
switch (UpgradeType) {
|
||||
APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
|
||||
switch (UpgradeType)
|
||||
{
|
||||
case Upgrade:
|
||||
WeaponInstance->UpgradeWeapon();
|
||||
break;
|
||||
case NewWeapon:
|
||||
// TODO: Spawn weapon
|
||||
break;
|
||||
case Health:
|
||||
if (playerController)
|
||||
{
|
||||
if (UHealthComponent* healthComponent = playerController->GetComponentByClass<UHealthComponent>())
|
||||
{
|
||||
healthComponent->RecoverHealth(healthComponent->GetMaxHealth() / 10.0f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Gold:
|
||||
if (playerController)
|
||||
{
|
||||
if (UGoldComponent* goldComponent = playerController->GetComponentByClass<UGoldComponent>())
|
||||
{
|
||||
goldComponent->IncrementGold(10);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
|
||||
@ -75,7 +112,7 @@ void UUpgradeButtonWidget::OnClicked()
|
||||
{
|
||||
Parent->RemoveFromParent();
|
||||
|
||||
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
if (playerController)
|
||||
{
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
||||
playerController->bShowMouseCursor = false;
|
||||
|
@ -13,7 +13,9 @@ UENUM(BlueprintType)
|
||||
enum EUpgradeType
|
||||
{
|
||||
Upgrade,
|
||||
NewWeapon
|
||||
NewWeapon,
|
||||
Health,
|
||||
Gold
|
||||
};
|
||||
|
||||
class UTextBlock;
|
||||
@ -47,6 +49,12 @@ public:
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> NewWeaponIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> HealthIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> GoldIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TEnumAsByte<EUpgradeType> UpgradeType;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user