Add new weapon option to level up screen
This commit is contained in:
parent
318297e22c
commit
23d74eddfb
@ -15,6 +15,10 @@ class VAMPIRES_API UWeaponInventoryComponent : public UActorComponent
|
|||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
TArray<TSubclassOf<AWeapon>> obtainableWeapons;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
TArray<TSubclassOf<AWeapon>> initialInventory;
|
TArray<TSubclassOf<AWeapon>> initialInventory;
|
||||||
|
|
||||||
|
@ -51,6 +51,15 @@ void ULevelUpWidget::NativeConstruct()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TArray<TSubclassOf<AWeapon>> ObtainableWeapons = InventoryComponent->obtainableWeapons;
|
||||||
|
|
||||||
|
for (TSubclassOf<AWeapon> weapon : ObtainableWeapons)
|
||||||
|
{
|
||||||
|
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
|
||||||
|
Temp->SetData(weapon, this);
|
||||||
|
upgradeItems.Add(Temp);
|
||||||
|
}
|
||||||
|
|
||||||
if (upgradeItems.Num() == 0)
|
if (upgradeItems.Num() == 0)
|
||||||
{
|
{
|
||||||
UUpgradeButtonDataObject* tempHealth = NewObject<UUpgradeButtonDataObject>(this);
|
UUpgradeButtonDataObject* tempHealth = NewObject<UUpgradeButtonDataObject>(this);
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "UObject/UObjectBase.h"
|
#include "UObject/UObjectBase.h"
|
||||||
#include "vampires/GoldComponent.h"
|
#include "vampires/GoldComponent.h"
|
||||||
#include "vampires/HealthComponent.h"
|
#include "vampires/HealthComponent.h"
|
||||||
|
#include "vampires/WeaponInventoryComponent.h"
|
||||||
|
|
||||||
void UUpgradeButtonWidget::NativeConstruct()
|
void UUpgradeButtonWidget::NativeConstruct()
|
||||||
{
|
{
|
||||||
@ -49,7 +50,6 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
|||||||
UpgradeType = Gold;
|
UpgradeType = Gold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (Body)
|
if (Body)
|
||||||
{
|
{
|
||||||
Body->OnClicked.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnClicked);
|
Body->OnClicked.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnClicked);
|
||||||
@ -84,28 +84,39 @@ void UUpgradeButtonWidget::OnClicked()
|
|||||||
case Upgrade:
|
case Upgrade:
|
||||||
WeaponInstance->UpgradeWeapon();
|
WeaponInstance->UpgradeWeapon();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NewWeapon:
|
case NewWeapon:
|
||||||
// TODO: Spawn weapon
|
if (UWeaponInventoryComponent* Inventory = playerController->GetPawn()->GetComponentByClass<
|
||||||
|
UWeaponInventoryComponent>())
|
||||||
|
{
|
||||||
|
Inventory->AddWeaponToInventory(WeaponTemplate);
|
||||||
|
Inventory->obtainableWeapons.Remove(WeaponTemplate);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Health:
|
case Health:
|
||||||
if (playerController)
|
if (playerController)
|
||||||
{
|
{
|
||||||
if (UHealthComponent* healthComponent = playerController->GetComponentByClass<UHealthComponent>())
|
if (UHealthComponent* healthComponent = playerController->GetPawn()->GetComponentByClass<
|
||||||
|
UHealthComponent>())
|
||||||
{
|
{
|
||||||
healthComponent->RecoverHealth(healthComponent->GetMaxHealth() / 10.0f);
|
healthComponent->RecoverHealth(healthComponent->GetMaxHealth() / 10.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Gold:
|
case Gold:
|
||||||
if (playerController)
|
if (playerController)
|
||||||
{
|
{
|
||||||
if (UGoldComponent* goldComponent = playerController->GetComponentByClass<UGoldComponent>())
|
if (UGoldComponent* goldComponent = playerController->GetPawn()->GetComponentByClass<UGoldComponent>())
|
||||||
{
|
{
|
||||||
goldComponent->IncrementGold(10);
|
goldComponent->IncrementGold(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: ;
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Parent)
|
if (Parent)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user