Section 10: Outline and Glow Effects - Lecture 186

Swap pickup text
This commit is contained in:
charnet3d 2024-01-11 18:01:00 +01:00
parent 9e1d093008
commit 70d390a0de
99 changed files with 267 additions and 198 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/AnimStarterPack/BS_Jog.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/AnimStarterPack/Death_1.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/AnimStarterPack/Death_2.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/AnimStarterPack/Death_3.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/AnimStarterPack/Hit_React_1.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/AnimStarterPack/Hit_React_2.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/AnimStarterPack/Hit_React_3.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/AnimStarterPack/Hit_React_4.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/AnimStarterPack/Idle_Pistol.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/AnimStarterPack/Prone_Idle.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/AnimStarterPack/Showcase.umap (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Ammo/Ammo9mmBP.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/_Game/Character/Animations/EquipMontage.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/HUD/PickupWidgetBP.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/_Game/Maps/DefaultMap.umap (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

View File

@ -35,7 +35,8 @@ AItem::AItem() :
GlowAmount(150.f), GlowAmount(150.f),
FresnelExponent(3.f), FresnelExponent(3.f),
FresnelReflectFraction(4.f), FresnelReflectFraction(4.f),
SlotIndex(0) SlotIndex(0),
bCharacterInventoryFull(false)
{ {
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
@ -129,11 +130,18 @@ void AItem::setActiveStars()
} }
} }
void AItem::PlayPickupSound() void AItem::PlayPickupSound(bool bForcePlaySound)
{ {
if (Character) if (Character)
{ {
if (Character->ShouldPlayPickupSound()) if (bForcePlaySound)
{
if (PickupSound)
{
UGameplayStatics::PlaySound2D(this, PickupSound);
}
}
else if (Character->ShouldPlayPickupSound())
{ {
Character->StartPickupSoundTimer(); Character->StartPickupSoundTimer();
if (PickupSound) if (PickupSound)
@ -219,11 +227,15 @@ void AItem::DisableGlowMaterial()
} }
} }
void AItem::PlayEquipSound() void AItem::PlayEquipSound(bool bForcePlaySound)
{ {
if (Character) if (Character)
{ {
if (Character->ShouldPlayEquipSound()) if (bForcePlaySound)
{
UGameplayStatics::PlaySound2D(this, EquipSound);
}
else if (Character->ShouldPlayEquipSound())
{ {
Character->StartEquipSoundTimer(); Character->StartEquipSoundTimer();
if (EquipSound) if (EquipSound)
@ -462,7 +474,7 @@ void AItem::SetItemProperties(EItemState State)
} }
} }
void AItem::StartItemCurve(AShooterCharacter* Char) void AItem::StartItemCurve(AShooterCharacter* Char, bool bForcePlaySound)
{ {
// Store a handle to the Character // Store a handle to the Character
Character = Char; Character = Char;
@ -473,7 +485,7 @@ void AItem::StartItemCurve(AShooterCharacter* Char)
// Add 1 to the Item Count for this interp location struct // Add 1 to the Item Count for this interp location struct
Character->IncrementInterpLocItemCount(InterpLocIndex, 1); Character->IncrementInterpLocItemCount(InterpLocIndex, 1);
PlayPickupSound(); PlayPickupSound(bForcePlaySound);
// Store the initial locatino of the Item // Store the initial locatino of the Item
ItemInterpStartLocation = GetActorLocation(); ItemInterpStartLocation = GetActorLocation();

View File

@ -81,7 +81,7 @@ protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true))
USphereComponent* AreaSphere; USphereComponent* AreaSphere;
void PlayPickupSound(); void PlayPickupSound(bool bForcePlaySound = false);
virtual void InitializeCustomDepth(); virtual void InitializeCustomDepth();
@ -113,7 +113,7 @@ public:
FVector GetInterpLocation(); FVector GetInterpLocation();
// Called in AShooterCharacter::GetPickupItem // Called in AShooterCharacter::GetPickupItem
void PlayEquipSound(); void PlayEquipSound(bool bForcePlaySound = false);
private: private:
/* Skeletal mesh for the item */ /* Skeletal mesh for the item */
@ -252,6 +252,10 @@ private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true))
int32 SlotIndex; int32 SlotIndex;
/** True when the character's inventory is full */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true))
bool bCharacterInventoryFull;
public: public:
FORCEINLINE UWidgetComponent* GetPickupWidget() const { return PickupWidget; } FORCEINLINE UWidgetComponent* GetPickupWidget() const { return PickupWidget; }
@ -273,8 +277,12 @@ public:
FORCEINLINE int32 GetSlotIndex() const { return SlotIndex; } FORCEINLINE int32 GetSlotIndex() const { return SlotIndex; }
FORCEINLINE void SetSlotIndex(int32 Index) { SlotIndex = Index; } FORCEINLINE void SetSlotIndex(int32 Index) { SlotIndex = Index; }
FORCEINLINE void SetCharacter(AShooterCharacter* Char) { Character = Char; }
FORCEINLINE void SetCharacterInventoryFull(bool bFull) { bCharacterInventoryFull = bFull; }
/** Called from the AShooterCharacter class */ /** Called from the AShooterCharacter class */
void StartItemCurve(AShooterCharacter* Char); void StartItemCurve(AShooterCharacter* Char, bool bForcePlaySound = false);
virtual void EnableCustomDepth(); virtual void EnableCustomDepth();
virtual void DisableCustomDepth(); virtual void DisableCustomDepth();

View File

@ -62,6 +62,7 @@ void UShooterAnimInstance::UpdateAnimationProperties(float DeltaTime)
bAiming = ShooterCharacter->GetAiming(); bAiming = ShooterCharacter->GetAiming();
bReloading = ShooterCharacter->GetCombatState() == ECombatState::ECS_Reloading; bReloading = ShooterCharacter->GetCombatState() == ECombatState::ECS_Reloading;
bCrouching = ShooterCharacter->IsCrouching(); bCrouching = ShooterCharacter->IsCrouching();
bEquipping = ShooterCharacter->GetCombatState() == ECombatState::ECS_Equipping;
if (bReloading) if (bReloading)
{ {
@ -148,7 +149,7 @@ void UShooterAnimInstance::TurnInPlace()
// Set the recoil weight // Set the recoil weight
if (bTurningInPlace) if (bTurningInPlace)
{ {
if (bReloading) if (bReloading || bEquipping)
{ {
RecoilWeight = 1.f; RecoilWeight = 1.f;
} }
@ -161,7 +162,7 @@ void UShooterAnimInstance::TurnInPlace()
{ {
if (bCrouching) if (bCrouching)
{ {
if (bReloading) if (bReloading || bEquipping)
{ {
RecoilWeight = 1.f; RecoilWeight = 1.f;
} }
@ -172,7 +173,7 @@ void UShooterAnimInstance::TurnInPlace()
} }
else else
{ {
if (bAiming || bReloading) if (bAiming || bReloading || bEquipping)
{ {
RecoilWeight = 1.f; RecoilWeight = 1.f;
} }

View File

@ -112,11 +112,15 @@ private:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Crouching", meta = (AllowPrivateAccess = true)) UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Crouching", meta = (AllowPrivateAccess = true))
bool bCrouching; bool bCrouching;
/** True when equipping */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Combat", meta = (AllowPrivateAccess = true))
bool bEquipping;
/** Change the recoil weight based on turning in place and aiming */ /** Change the recoil weight based on turning in place and aiming */
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Combat", meta = (AllowPrivateAccess = true)) UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Combat", meta = (AllowPrivateAccess = true))
float RecoilWeight; float RecoilWeight;
/** True when turning in place */ /** True when turning in place */
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Combat", meta = (AllowPrivateAccess = true)) UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Turn In Place", meta = (AllowPrivateAccess = true))
bool bTurningInPlace; bool bTurningInPlace;
}; };

View File

@ -152,6 +152,7 @@ void AShooterCharacter::BeginPlay()
EquipWeapon(SpawnDefaultWeapon()); EquipWeapon(SpawnDefaultWeapon());
Inventory.Add(EquippedWeapon); Inventory.Add(EquippedWeapon);
EquippedWeapon->SetSlotIndex(0); EquippedWeapon->SetSlotIndex(0);
EquippedWeapon->SetCharacter(this);
InitializeAmmoMap(); InitializeAmmoMap();
@ -413,7 +414,10 @@ void AShooterCharacter::Key5Pressed()
void AShooterCharacter::ExchangeInventoryItems(int32 CurrentItemIndex, int32 NewItemIndex) void AShooterCharacter::ExchangeInventoryItems(int32 CurrentItemIndex, int32 NewItemIndex)
{ {
if (CurrentItemIndex == NewItemIndex || NewItemIndex >= Inventory.Num()) return; if (CurrentItemIndex == NewItemIndex
|| NewItemIndex >= Inventory.Num()
|| CombatState != ECombatState::ECS_Unoccupied)
return;
auto OldEquippedWeapon = EquippedWeapon; auto OldEquippedWeapon = EquippedWeapon;
auto NewWeapon = Cast<AWeapon>(Inventory[NewItemIndex]); auto NewWeapon = Cast<AWeapon>(Inventory[NewItemIndex]);
@ -422,6 +426,15 @@ void AShooterCharacter::ExchangeInventoryItems(int32 CurrentItemIndex, int32 New
OldEquippedWeapon->SetItemState(EItemState::EIS_PickedUp); OldEquippedWeapon->SetItemState(EItemState::EIS_PickedUp);
NewWeapon->SetItemState(EItemState::EIS_Equipped); NewWeapon->SetItemState(EItemState::EIS_Equipped);
CombatState = ECombatState::ECS_Equipping;
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance && EquipMontage)
{
AnimInstance->Montage_Play(EquipMontage, 1.0f);
AnimInstance->Montage_JumpToSection(FName("Equip"));
}
NewWeapon->PlayEquipSound(true);
} }
int32 AShooterCharacter::GetInterpLocationIndex() int32 AShooterCharacter::GetInterpLocationIndex()
@ -762,6 +775,16 @@ void AShooterCharacter::TraceForItems()
TraceHitItem = nullptr; TraceHitItem = nullptr;
SetItemPickupWidgetVisibility(TraceHitItem, true); SetItemPickupWidgetVisibility(TraceHitItem, true);
if (Inventory.Num() >= INVENTORY_CAPACITY)
{
// Inventory is full
TraceHitItem->SetCharacterInventoryFull(true);
}
else
{
TraceHitItem->SetCharacterInventoryFull(false);
}
} }
else if (OldTraceHitItem) // Hide widget for the item from last frame else if (OldTraceHitItem) // Hide widget for the item from last frame
{ {
@ -841,9 +864,11 @@ void AShooterCharacter::DropWeapon()
void AShooterCharacter::SelectButtonPressed() void AShooterCharacter::SelectButtonPressed()
{ {
if (CombatState != ECombatState::ECS_Unoccupied) return;
if (TraceHitItem) if (TraceHitItem)
{ {
TraceHitItem->StartItemCurve(this); TraceHitItem->StartItemCurve(this, true);
TraceHitItem = nullptr; TraceHitItem = nullptr;
} }
} }
@ -1001,6 +1026,11 @@ void AShooterCharacter::FinishReloading()
} }
} }
void AShooterCharacter::FinishEquipping()
{
CombatState = ECombatState::ECS_Unoccupied;
}
bool AShooterCharacter::CarryingAmmo() bool AShooterCharacter::CarryingAmmo()
{ {
if (!EquippedWeapon) return false; if (!EquippedWeapon) return false;

View File

@ -24,6 +24,7 @@ enum class ECombatState : uint8
ECS_Unoccupied UMETA(DisplayName = "Unoccupied"), ECS_Unoccupied UMETA(DisplayName = "Unoccupied"),
ECS_FireTimerInProgress UMETA(DisplayName = "FireTimerInProgress"), ECS_FireTimerInProgress UMETA(DisplayName = "FireTimerInProgress"),
ECS_Reloading UMETA(DisplayName = "Reloading"), ECS_Reloading UMETA(DisplayName = "Reloading"),
ECS_Equipping UMETA(DisplayName = "Equipping"),
ECS_MAX UMETA(DisplayName = "DefaultMax") ECS_MAX UMETA(DisplayName = "DefaultMax")
}; };
@ -167,6 +168,9 @@ protected:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void FinishReloading(); void FinishReloading();
UFUNCTION(BlueprintCallable)
void FinishEquipping();
/** Check to see if we have ammo of the EquippedWeapon's ammo type */ /** Check to see if we have ammo of the EquippedWeapon's ammo type */
bool CarryingAmmo(); bool CarryingAmmo();
@ -382,6 +386,10 @@ private:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
UAnimMontage* ReloadMontage; UAnimMontage* ReloadMontage;
/* Montage for reloading the weapon */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
UAnimMontage* EquipMontage;
/* Transform of the clip when we first grab the clip during reloading */ /* Transform of the clip when we first grab the clip during reloading */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat, meta = (AllowPrivateAccess = true)) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat, meta = (AllowPrivateAccess = true))
FTransform ClipTransform; FTransform ClipTransform;