Simplify class
This commit is contained in:
parent
2768e84d66
commit
af60880d17
@ -51,12 +51,8 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
if (Body)
|
||||
{
|
||||
Body->OnClicked.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnClicked);
|
||||
|
||||
Body->OnHovered.AddUniqueDynamic(this, &UUpgradeButtonWidget::PlayHoveredSound);
|
||||
Body->OnHovered.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnHoveredDelegate);
|
||||
|
||||
Body->OnUnhovered.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnUnhoveredDelegate);
|
||||
Body->OnUnhovered.AddUniqueDynamic(this, &UUpgradeButtonWidget::PlayUnhoveredSound);
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,6 +77,8 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
|
||||
void UUpgradeButtonWidget::OnClicked()
|
||||
{
|
||||
PlayClickedSound();
|
||||
|
||||
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
|
||||
switch (UpgradeType)
|
||||
@ -90,7 +88,8 @@ void UUpgradeButtonWidget::OnClicked()
|
||||
break;
|
||||
|
||||
case NewWeapon:
|
||||
if (UWeaponInventoryComponent* Inventory = PlayerController->GetPawn()->GetComponentByClass<UWeaponInventoryComponent>())
|
||||
if (UWeaponInventoryComponent* Inventory = PlayerController->GetPawn()->GetComponentByClass<
|
||||
UWeaponInventoryComponent>())
|
||||
{
|
||||
Inventory->AddWeaponToInventory(WeaponTemplate);
|
||||
Inventory->ObtainableWeapons.Remove(WeaponTemplate);
|
||||
@ -100,7 +99,8 @@ void UUpgradeButtonWidget::OnClicked()
|
||||
case Health:
|
||||
if (PlayerController)
|
||||
{
|
||||
if (UHealthComponent* HealthComponent = PlayerController->GetPawn()->GetComponentByClass<UHealthComponent>())
|
||||
if (UHealthComponent* HealthComponent = PlayerController->GetPawn()->GetComponentByClass<
|
||||
UHealthComponent>())
|
||||
{
|
||||
HealthComponent->RecoverHealth(HealthComponent->GetMaxHealth() / 10.0f);
|
||||
}
|
||||
@ -135,3 +135,17 @@ void UUpgradeButtonWidget::OnClicked()
|
||||
Parent->SetIsFocusable(false);
|
||||
}
|
||||
}
|
||||
|
||||
void UUpgradeButtonWidget::OnHoveredDelegate()
|
||||
{
|
||||
PlayHoveredSound();
|
||||
SetTextBlockHovered(WeaponNameTextBlock);
|
||||
SetTextBlockHovered(DescriptionTextBlock);
|
||||
}
|
||||
|
||||
void UUpgradeButtonWidget::OnUnhoveredDelegate()
|
||||
{
|
||||
PlayUnhoveredSound();
|
||||
SetTextBlockUnhovered(WeaponNameTextBlock);
|
||||
SetTextBlockUnhovered(DescriptionTextBlock);
|
||||
}
|
||||
|
@ -32,6 +32,20 @@ class VAMPIRES_API UUpgradeButtonWidget : public UVampireInteractiveWidget, publ
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> UpgradeIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> NewWeaponIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> HealthIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> GoldIcon;
|
||||
|
||||
private:
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UButton> Body;
|
||||
|
||||
@ -44,25 +58,13 @@ protected:
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UTextBlock> DescriptionTextBlock;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> UpgradeIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> NewWeaponIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> HealthIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TObjectPtr<UTexture2D> GoldIcon;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TEnumAsByte<EUpgradeType> UpgradeType;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UPROPERTY()
|
||||
TSubclassOf<AWeapon> WeaponTemplate;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UPROPERTY()
|
||||
TObjectPtr<AWeapon> WeaponInstance;
|
||||
|
||||
UPROPERTY()
|
||||
@ -82,8 +84,8 @@ private:
|
||||
virtual void OnClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnHoveredDelegate() { SetTextBlockHovered(WeaponNameTextBlock); SetTextBlockHovered(DescriptionTextBlock); }
|
||||
void OnHoveredDelegate();
|
||||
|
||||
UFUNCTION()
|
||||
void OnUnhoveredDelegate() { SetTextBlockUnhovered(WeaponNameTextBlock); SetTextBlockUnhovered(DescriptionTextBlock); }
|
||||
void OnUnhoveredDelegate();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user