Quick widgets refactor
This commit is contained in:
parent
8d8da3ddc1
commit
ec818cfc55
@ -9,41 +9,41 @@ void UHUDWidget::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void UHUDWidget::UpdateEXPBar(float currentLevelPercent)
|
||||
void UHUDWidget::UpdateEXPBar(float CurrentLevelPercent)
|
||||
{
|
||||
EXPbar->SetPercent(currentLevelPercent);
|
||||
EXPbar->SetPercent(CurrentLevelPercent);
|
||||
}
|
||||
|
||||
void UHUDWidget::UpdateLevelBlock(int level)
|
||||
void UHUDWidget::UpdateLevelBlock(int Level)
|
||||
{
|
||||
LevelBlock->SetText(FText::FromString("LV" + FString::FromInt(level)));
|
||||
LevelBlock->SetText(FText::FromString("LV" + FString::FromInt(Level)));
|
||||
}
|
||||
|
||||
void UHUDWidget::UpdateTimerBlock(float deltaTime)
|
||||
void UHUDWidget::UpdateTimerBlock(float DeltaTime)
|
||||
{
|
||||
int timeSinceStart = FMath::FloorToInt(deltaTime);
|
||||
int TimeSinceStart = FMath::FloorToInt(DeltaTime);
|
||||
|
||||
FString mins = FString::FromInt(timeSinceStart / 60);
|
||||
if (timeSinceStart / 60 < 10)
|
||||
FString Mins = FString::FromInt(TimeSinceStart / 60);
|
||||
if (TimeSinceStart / 60 < 10)
|
||||
{
|
||||
mins = "0" + mins;
|
||||
Mins = "0" + Mins;
|
||||
}
|
||||
|
||||
FString secs = FString::FromInt(timeSinceStart % 60);
|
||||
if (timeSinceStart % 60 < 10)
|
||||
FString Secs = FString::FromInt(TimeSinceStart % 60);
|
||||
if (TimeSinceStart % 60 < 10)
|
||||
{
|
||||
secs = "0" + secs;
|
||||
Secs = "0" + Secs;
|
||||
}
|
||||
|
||||
TimerBLock->SetText(FText::FromString(mins + ":" + secs));
|
||||
TimerBLock->SetText(FText::FromString(Mins + ":" + Secs));
|
||||
}
|
||||
|
||||
void UHUDWidget::UpdateKillBlock(int killCount)
|
||||
void UHUDWidget::UpdateKillBlock(int KillCount)
|
||||
{
|
||||
KillBLock->SetText(FText::FromString("Kills: " + FString::FromInt(killCount)));
|
||||
KillBLock->SetText(FText::FromString("Kills: " + FString::FromInt(KillCount)));
|
||||
}
|
||||
|
||||
void UHUDWidget::UpdateGoldBlock(int goldCount)
|
||||
void UHUDWidget::UpdateGoldBlock(int GoldCount)
|
||||
{
|
||||
GoldBLock->SetText(FText::FromString("Gold: " + FString::FromInt(goldCount)));
|
||||
GoldBLock->SetText(FText::FromString("Gold: " + FString::FromInt(GoldCount)));
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ class VAMPIRES_API UHUDWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||
UProgressBar* EXPbar;
|
||||
|
||||
@ -35,19 +34,19 @@ public:
|
||||
|
||||
void Init();
|
||||
|
||||
public:
|
||||
UFUNCTION()
|
||||
void UpdateEXPBar(float currentLevelPercent);
|
||||
void UpdateEXPBar(float CurrentLevelPercent);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateLevelBlock(int level);
|
||||
void UpdateLevelBlock(int Level);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateTimerBlock(float deltaTime);
|
||||
void UpdateTimerBlock(float DeltaTime);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateKillBlock(int killCount);
|
||||
void UpdateKillBlock(int KillCount);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateGoldBlock(int goldCount);
|
||||
|
||||
void UpdateGoldBlock(int GoldCount);
|
||||
};
|
||||
|
@ -12,23 +12,23 @@ void UHealthbarWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
if (ACharacter* character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
|
||||
if (ACharacter* Character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
|
||||
{
|
||||
if (UHealthComponent* healthComponent = character->FindComponentByClass<UHealthComponent>())
|
||||
if (UHealthComponent* HealthComponent = Character->FindComponentByClass<UHealthComponent>())
|
||||
{
|
||||
healthComponent->OnDamaged.AddDynamic(this, &UHealthbarWidget::UpdateHealthBar);
|
||||
HealthComponent->OnDamaged.AddDynamic(this, &UHealthbarWidget::UpdateHealthBar);
|
||||
UpdateHealthBar({});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UHealthbarWidget::UpdateHealthBar(FDamageInfo damageInfo)
|
||||
void UHealthbarWidget::UpdateHealthBar(FDamageInfo DamageInfo)
|
||||
{
|
||||
if (ACharacter* character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
|
||||
if (ACharacter* Character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
|
||||
{
|
||||
if (UHealthComponent* healthComponent = character->FindComponentByClass<UHealthComponent>())
|
||||
if (UHealthComponent* HealthComponent = Character->FindComponentByClass<UHealthComponent>())
|
||||
{
|
||||
float percent = healthComponent->GetCurrentHealth() / healthComponent->GetMaxHealth();
|
||||
float percent = HealthComponent->GetCurrentHealth() / HealthComponent->GetMaxHealth();
|
||||
HealthBar->SetPercent(percent);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "HealthbarWidget.generated.h"
|
||||
|
||||
struct FDamageInfo;
|
||||
class UProgressBar;
|
||||
/**
|
||||
*
|
||||
@ -15,13 +16,13 @@ class VAMPIRES_API UHealthbarWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||
UProgressBar* HealthBar;
|
||||
TObjectPtr<UProgressBar> HealthBar;
|
||||
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
private:
|
||||
UFUNCTION()
|
||||
void UpdateHealthBar(FDamageInfo damageInfo);
|
||||
void UpdateHealthBar(FDamageInfo DamageInfo);
|
||||
};
|
||||
|
@ -40,50 +40,50 @@ void ULevelUpWidget::NativeConstruct()
|
||||
TArray<AWeapon*> Inventory = InventoryComponent->GetInventory();
|
||||
|
||||
// Get list of weapons that the player owns that can be upgraded
|
||||
TArray<UUpgradeButtonDataObject*> upgradeItems;
|
||||
for (AWeapon* weapon : Inventory)
|
||||
TArray<UUpgradeButtonDataObject*> UpgradeItems;
|
||||
for (AWeapon* Weapon : Inventory)
|
||||
{
|
||||
if (weapon->GetWeaponLevel() < weapon->GetUpgradeDescriptions().Num())
|
||||
if (Weapon->GetWeaponLevel() < Weapon->GetUpgradeDescriptions().Num())
|
||||
{
|
||||
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
|
||||
Temp->SetData(weapon, this);
|
||||
upgradeItems.Add(Temp);
|
||||
Temp->SetData(Weapon, this);
|
||||
UpgradeItems.Add(Temp);
|
||||
}
|
||||
}
|
||||
|
||||
// Get list of weapons that the player can still obtain
|
||||
TArray<TSubclassOf<AWeapon>> ObtainableWeapons = InventoryComponent->obtainableWeapons;
|
||||
for (TSubclassOf<AWeapon> weapon : ObtainableWeapons)
|
||||
for (TSubclassOf<AWeapon> Weapon : ObtainableWeapons)
|
||||
{
|
||||
UUpgradeButtonDataObject* Temp = NewObject<UUpgradeButtonDataObject>(this);
|
||||
Temp->SetData(weapon, this);
|
||||
upgradeItems.Add(Temp);
|
||||
Temp->SetData(Weapon, this);
|
||||
UpgradeItems.Add(Temp);
|
||||
}
|
||||
|
||||
// If no valid options exist, populate list with default options
|
||||
if (upgradeItems.Num() == 0)
|
||||
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* 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);
|
||||
UUpgradeButtonDataObject* TempGold = NewObject<UUpgradeButtonDataObject>(this);
|
||||
TempGold->SetData(FText::FromString("Gold"),
|
||||
FText::FromString("Gain 10 gold"),
|
||||
nullptr,
|
||||
this);
|
||||
UpgradeItems.Add(TempGold);
|
||||
}
|
||||
|
||||
// Select up to three random options from the list of options
|
||||
for (int i = 0; i < 3 && upgradeItems.Num() > 0; i++)
|
||||
for (int i = 0; i < 3 && UpgradeItems.Num() > 0; i++)
|
||||
{
|
||||
int rand = FMath::RandRange(0, upgradeItems.Num() - 1);
|
||||
UpgradesListView->AddItem(upgradeItems[rand]);
|
||||
upgradeItems.RemoveAt(rand);
|
||||
int Rand = FMath::RandRange(0, UpgradeItems.Num() - 1);
|
||||
UpgradesListView->AddItem(UpgradeItems[Rand]);
|
||||
UpgradeItems.RemoveAt(Rand);
|
||||
}
|
||||
}
|
||||
SetIsFocusable(true);
|
||||
@ -93,11 +93,11 @@ void ULevelUpWidget::ResumeButtonClicked()
|
||||
{
|
||||
RemoveFromParent();
|
||||
|
||||
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
{
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
||||
playerController->bShowMouseCursor = false;
|
||||
playerController->SetPause(false);
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
|
||||
PlayerController->bShowMouseCursor = false;
|
||||
PlayerController->SetPause(false);
|
||||
}
|
||||
|
||||
SetIsFocusable(false);
|
||||
|
@ -17,8 +17,7 @@ class VAMPIRES_API ULevelUpWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
|
||||
UButton* ResumeButton;
|
||||
|
||||
@ -28,7 +27,6 @@ public:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
private:
|
||||
|
||||
UFUNCTION()
|
||||
void ResumeButtonClicked();
|
||||
};
|
||||
|
@ -51,27 +51,14 @@ void UMainMenuWidget::NewGameButtonOnClicked()
|
||||
{
|
||||
RemoveFromParent();
|
||||
|
||||
UUserWidget* selectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
|
||||
UUserWidget* SelectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
|
||||
UGameplayStatics::GetPlayerController(GetWorld(), 0), NewGameMenuWidget);
|
||||
|
||||
if (selectWeaponWidget)
|
||||
if (SelectWeaponWidget)
|
||||
{
|
||||
selectWeaponWidget->AddToViewport();
|
||||
SelectWeaponWidget->AddToViewport();
|
||||
}
|
||||
}
|
||||
|
||||
// if (!NewGameLevel.IsNull())
|
||||
// {
|
||||
// UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NewGameLevel);
|
||||
// }
|
||||
//
|
||||
// if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
// {
|
||||
// PlayerController->bShowMouseCursor = false;
|
||||
// UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
|
||||
// }
|
||||
//
|
||||
// SetIsFocusable(false);
|
||||
}
|
||||
|
||||
void UMainMenuWidget::QuitButtonOnClicked()
|
||||
|
@ -17,7 +17,7 @@ class VAMPIRES_API UMainMenuWidget : public UVampireInteractiveWidget
|
||||
|
||||
// TODO: Add options menu
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||
TObjectPtr<UButton> NewGameButton;
|
||||
|
||||
@ -38,7 +38,7 @@ public:
|
||||
|
||||
private:
|
||||
UPROPERTY()
|
||||
TObjectPtr<UUserWidget> currentNewGameWidget;
|
||||
TObjectPtr<UUserWidget> CurrentNewGameWidget;
|
||||
|
||||
public:
|
||||
virtual void NativeConstruct() override;
|
||||
|
@ -27,11 +27,11 @@ void UPauseWidget::ResumeButtonClicked()
|
||||
{
|
||||
RemoveFromParent();
|
||||
|
||||
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
{
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
||||
playerController->bShowMouseCursor = false;
|
||||
playerController->SetPause(false);
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
|
||||
PlayerController->bShowMouseCursor = false;
|
||||
PlayerController->SetPause(false);
|
||||
}
|
||||
|
||||
SetIsFocusable(false);
|
||||
|
@ -16,7 +16,6 @@ class VAMPIRES_API UPauseWidget : public UUserWidget
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
|
||||
UButton* ResumeButton;
|
||||
|
||||
@ -25,7 +24,6 @@ public:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
private:
|
||||
|
||||
UFUNCTION()
|
||||
void ResumeButtonClicked();
|
||||
};
|
||||
|
@ -29,10 +29,10 @@ void USelectWeaponWidget::NativeConstruct()
|
||||
if (UpgradesListView)
|
||||
{
|
||||
// Get a list of weapons that the player owns that can be upgraded
|
||||
for (TSubclassOf<AWeapon> weapon : starterWeapons)
|
||||
for (TSubclassOf<AWeapon> Weapon : StarterWeapons)
|
||||
{
|
||||
UStarterWeaponButtonDataObject* Temp = NewObject<UStarterWeaponButtonDataObject>(this);
|
||||
Temp->SetData(weapon, this);
|
||||
Temp->SetData(Weapon, this);
|
||||
UpgradesListView->AddItem(Temp);
|
||||
}
|
||||
}
|
||||
@ -44,12 +44,12 @@ void USelectWeaponWidget::BackButtonClicked()
|
||||
{
|
||||
RemoveFromParent();
|
||||
|
||||
UUserWidget* selectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
|
||||
UUserWidget* SelectWeaponWidget = CreateWidget<UUserWidget, APlayerController*>(
|
||||
UGameplayStatics::GetPlayerController(GetWorld(), 0), PreviousWidget);
|
||||
|
||||
if (selectWeaponWidget)
|
||||
if (SelectWeaponWidget)
|
||||
{
|
||||
selectWeaponWidget->AddToViewport();
|
||||
SelectWeaponWidget->AddToViewport();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ UCLASS()
|
||||
class VAMPIRES_API USelectWeaponWidget : public UVampireInteractiveWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
protected:
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
|
||||
TObjectPtr<UButton> BackButton;
|
||||
@ -29,7 +29,7 @@ public:
|
||||
TObjectPtr<UListView> UpgradesListView;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
TArray<TSubclassOf<AWeapon>> starterWeapons;
|
||||
TArray<TSubclassOf<AWeapon>> StarterWeapons;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSubclassOf<class UUserWidget> PreviousWidget;
|
||||
|
@ -5,29 +5,29 @@
|
||||
|
||||
#include "vampires/Weapon.h"
|
||||
|
||||
void UStarterWeaponButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent)
|
||||
void UStarterWeaponButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* ParentWidget)
|
||||
{
|
||||
WeaponName = Weapon->GetWeaponName();
|
||||
Description = Weapon->GetDescription();
|
||||
WeaponDescription = Weapon->GetDescription();
|
||||
WeaponIcon = Weapon->GetIcon();
|
||||
WeaponInstance = Weapon;
|
||||
Parent = parent;
|
||||
Parent = ParentWidget;
|
||||
}
|
||||
|
||||
void UStarterWeaponButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent)
|
||||
void UStarterWeaponButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget)
|
||||
{
|
||||
if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon))
|
||||
{
|
||||
SetData(tempWeapon, parent);
|
||||
SetData(tempWeapon, ParentWidget);
|
||||
WeaponTemplate = Weapon;
|
||||
}
|
||||
}
|
||||
|
||||
void UStarterWeaponButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon,
|
||||
UUserWidget* parent)
|
||||
void UStarterWeaponButtonDataObject::SetData(FText NewWeaponName, FText NewWeaponDescription, TObjectPtr<UTexture2D> NewWeaponIcon,
|
||||
UUserWidget* ParentWidget)
|
||||
{
|
||||
WeaponName = weaponName;
|
||||
Description = description;
|
||||
WeaponIcon = weaponIcon;
|
||||
Parent = parent;
|
||||
WeaponName = NewWeaponName;
|
||||
WeaponDescription = NewWeaponDescription;
|
||||
WeaponIcon = NewWeaponIcon;
|
||||
Parent = ParentWidget;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
FText WeaponName;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FText Description;
|
||||
FText WeaponDescription;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UTexture2D> WeaponIcon;
|
||||
@ -33,7 +33,7 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UUserWidget> Parent;
|
||||
|
||||
void SetData(AWeapon* Weapon, UUserWidget* parent);
|
||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent);
|
||||
void SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, UUserWidget* parent);
|
||||
void SetData(AWeapon* Weapon, UUserWidget* ParentWidget);
|
||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget);
|
||||
void SetData(FText NewWeaponName, FText NewWeaponDescription, TObjectPtr<UTexture2D> NewWeaponIcon, UUserWidget* ParentWidget);
|
||||
};
|
||||
|
@ -18,12 +18,10 @@ void UStarterWeaponButtonWidget::NativeConstruct()
|
||||
|
||||
void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
{
|
||||
UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject);
|
||||
|
||||
if (Item)
|
||||
if (UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject))
|
||||
{
|
||||
WeaponNameTextBlock->SetText(Item->WeaponName);
|
||||
DescriptionTextBlock->SetText(Item->Description);
|
||||
DescriptionTextBlock->SetText(Item->WeaponDescription);
|
||||
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
|
||||
Parent = Item->Parent;
|
||||
WeaponTemplate = Item->WeaponTemplate;
|
||||
@ -43,13 +41,13 @@ void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObje
|
||||
|
||||
void UStarterWeaponButtonWidget::OnClicked()
|
||||
{
|
||||
if (UVampireGameInstance* gameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
|
||||
if (UVampireGameInstance* GameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
|
||||
{
|
||||
gameInstance->StarterWeapon = WeaponTemplate;
|
||||
GameInstance->StarterWeapon = WeaponTemplate;
|
||||
|
||||
if (!gameInstance->GameWorld.IsNull())
|
||||
if (!GameInstance->GameWorld.IsNull())
|
||||
{
|
||||
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), gameInstance->GameWorld);
|
||||
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), GameInstance->GameWorld);
|
||||
|
||||
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ class VAMPIRES_API UStarterWeaponButtonWidget : public UVampireInteractiveWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UButton> Body;
|
||||
|
||||
@ -39,7 +39,6 @@ public:
|
||||
UPROPERTY()
|
||||
TObjectPtr<UUserWidget> Parent;
|
||||
|
||||
protected:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;
|
||||
|
@ -5,32 +5,32 @@
|
||||
|
||||
#include "vampires/Weapon.h"
|
||||
|
||||
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent)
|
||||
void UUpgradeButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* ParentWidget)
|
||||
{
|
||||
WeaponName = Weapon->GetWeaponName();
|
||||
WeaponIcon = Weapon->GetIcon();
|
||||
WeaponInstance = Weapon;
|
||||
Parent = parent;
|
||||
Parent = ParentWidget;
|
||||
|
||||
if (Weapon->GetUpgradeDescriptions().Num() > Weapon->GetWeaponLevel())
|
||||
{
|
||||
Description = Weapon->GetUpgradeDescriptions()[Weapon->GetWeaponLevel()];
|
||||
WeaponDescription = Weapon->GetUpgradeDescriptions()[Weapon->GetWeaponLevel()];
|
||||
}
|
||||
}
|
||||
|
||||
void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent)
|
||||
void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget)
|
||||
{
|
||||
if (AWeapon* tempWeapon = NewObject<AWeapon>(this, Weapon))
|
||||
{
|
||||
SetData(tempWeapon, parent);
|
||||
SetData(tempWeapon, ParentWidget);
|
||||
}
|
||||
}
|
||||
|
||||
void UUpgradeButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon,
|
||||
UUserWidget* parent)
|
||||
void UUpgradeButtonDataObject::SetData(FText NewWeaponName, FText NewDescription, TObjectPtr<UTexture2D> NewWeaponIcon,
|
||||
UUserWidget* ParentWidget)
|
||||
{
|
||||
WeaponName = weaponName;
|
||||
Description = description;
|
||||
WeaponIcon = weaponIcon;
|
||||
Parent = parent;
|
||||
WeaponName = NewWeaponName;
|
||||
WeaponDescription = NewDescription;
|
||||
WeaponIcon = NewWeaponIcon;
|
||||
Parent = ParentWidget;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
FText WeaponName;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FText Description;
|
||||
FText WeaponDescription;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UTexture2D> WeaponIcon;
|
||||
@ -34,7 +34,7 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TObjectPtr<UUserWidget> Parent;
|
||||
|
||||
void SetData(AWeapon* Weapon, UUserWidget* parent);
|
||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent);
|
||||
void SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, UUserWidget* parent);
|
||||
void SetData(AWeapon* Weapon, UUserWidget* ParentWidget);
|
||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* ParentWidget);
|
||||
void SetData(FText NewWeaponName, FText NewDescription, TObjectPtr<UTexture2D> NewWeaponIcon, UUserWidget* ParentWidget);
|
||||
};
|
||||
|
@ -22,12 +22,10 @@ void UUpgradeButtonWidget::NativeConstruct()
|
||||
|
||||
void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
{
|
||||
UUpgradeButtonDataObject* Item = Cast<UUpgradeButtonDataObject>(ListItemObject);
|
||||
|
||||
if (Item)
|
||||
if (UUpgradeButtonDataObject* Item = Cast<UUpgradeButtonDataObject>(ListItemObject))
|
||||
{
|
||||
WeaponNameTextBlock->SetText(Item->WeaponName);
|
||||
DescriptionTextBlock->SetText(Item->Description);
|
||||
DescriptionTextBlock->SetText(Item->WeaponDescription);
|
||||
WeaponIcon->SetBrushFromTexture(Item->WeaponIcon);
|
||||
Parent = Item->Parent;
|
||||
|
||||
@ -83,7 +81,7 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
||||
|
||||
void UUpgradeButtonWidget::OnClicked()
|
||||
{
|
||||
APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
|
||||
switch (UpgradeType)
|
||||
{
|
||||
@ -92,8 +90,7 @@ 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);
|
||||
@ -101,22 +98,21 @@ void UUpgradeButtonWidget::OnClicked()
|
||||
break;
|
||||
|
||||
case Health:
|
||||
if (playerController)
|
||||
if (PlayerController)
|
||||
{
|
||||
if (UHealthComponent* healthComponent = playerController->GetPawn()->GetComponentByClass<
|
||||
UHealthComponent>())
|
||||
if (UHealthComponent* HealthComponent = PlayerController->GetPawn()->GetComponentByClass<UHealthComponent>())
|
||||
{
|
||||
healthComponent->RecoverHealth(healthComponent->GetMaxHealth() / 10.0f);
|
||||
HealthComponent->RecoverHealth(HealthComponent->GetMaxHealth() / 10.0f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Gold:
|
||||
if (playerController)
|
||||
if (PlayerController)
|
||||
{
|
||||
if (UGoldComponent* goldComponent = playerController->GetPawn()->GetComponentByClass<UGoldComponent>())
|
||||
if (UGoldComponent* GoldComponent = PlayerController->GetPawn()->GetComponentByClass<UGoldComponent>())
|
||||
{
|
||||
goldComponent->IncrementGold(10);
|
||||
GoldComponent->IncrementGold(10);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -129,11 +125,11 @@ void UUpgradeButtonWidget::OnClicked()
|
||||
{
|
||||
Parent->RemoveFromParent();
|
||||
|
||||
if (playerController)
|
||||
if (PlayerController)
|
||||
{
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
||||
playerController->bShowMouseCursor = false;
|
||||
playerController->SetPause(false);
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
|
||||
PlayerController->bShowMouseCursor = false;
|
||||
PlayerController->SetPause(false);
|
||||
}
|
||||
|
||||
Parent->SetIsFocusable(false);
|
||||
|
@ -31,7 +31,7 @@ class VAMPIRES_API UUpgradeButtonWidget : public UVampireInteractiveWidget, publ
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||
TObjectPtr<UButton> Body;
|
||||
|
||||
@ -86,5 +86,4 @@ private:
|
||||
|
||||
UFUNCTION()
|
||||
void OnUnhoveredDelegate() { SetTextBlockUnhovered(WeaponNameTextBlock); SetTextBlockUnhovered(DescriptionTextBlock); }
|
||||
|
||||
};
|
||||
|
@ -7,11 +7,11 @@
|
||||
#include "GameFramework/GameUserSettings.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
void UVampireInteractiveWidget::SetReturnScreen(UUserWidget* userWidget)
|
||||
void UVampireInteractiveWidget::SetReturnScreen(UUserWidget* UserWidget)
|
||||
{
|
||||
if (userWidget)
|
||||
if (UserWidget)
|
||||
{
|
||||
PreviousScreen = userWidget;
|
||||
PreviousScreen = UserWidget;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,7 @@ class VAMPIRES_API UVampireInteractiveWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TObjectPtr<USoundBase> ButtonHoveredSound;
|
||||
|
||||
@ -37,9 +36,8 @@ protected:
|
||||
TObjectPtr<UUserWidget> PreviousScreen;
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION()
|
||||
void SetReturnScreen(UUserWidget* userWidget);
|
||||
void SetReturnScreen(UUserWidget* UserWidget);
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
|
Loading…
x
Reference in New Issue
Block a user