From f7d1525e7e34ad67c41521bdf0168d378f19e675 Mon Sep 17 00:00:00 2001 From: charnet3d Date: Fri, 12 Jan 2024 08:21:38 +0100 Subject: [PATCH] Section 10: Outline and Glow Effects - Lecture 197 Set post process Highlight color from data table --- .../DataTable/ItemRarityDataTable.uasset | 3 + Content/_Game/HUD/PickupWidgetBP.uasset | 4 +- Content/_Game/Maps/DefaultMap.umap | 4 +- .../Weapons/BaseWeapon/BaseWeaponBP.uasset | 4 +- Source/Shooter/Item.cpp | 54 ++++++++++++-- Source/Shooter/Item.h | 70 +++++++++++++++---- 6 files changed, 115 insertions(+), 24 deletions(-) create mode 100644 Content/_Game/DataTable/ItemRarityDataTable.uasset diff --git a/Content/_Game/DataTable/ItemRarityDataTable.uasset b/Content/_Game/DataTable/ItemRarityDataTable.uasset new file mode 100644 index 00000000..f452da1c --- /dev/null +++ b/Content/_Game/DataTable/ItemRarityDataTable.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a7e5f1a8870d7c40f507efd733f3cf04f7c5d1920a6e337cb554dc8c7ff24e0 +size 4701 diff --git a/Content/_Game/HUD/PickupWidgetBP.uasset b/Content/_Game/HUD/PickupWidgetBP.uasset index 16f3e3c4..e1c008dc 100644 --- a/Content/_Game/HUD/PickupWidgetBP.uasset +++ b/Content/_Game/HUD/PickupWidgetBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:de1476ef3036c397c96db9c4fff414d3b703bcd99178337720405e7119b639a2 -size 212287 +oid sha256:fae0b3c432463b8e78576eb9644529d09042673d33c5e04447bf0b256900f8d1 +size 214640 diff --git a/Content/_Game/Maps/DefaultMap.umap b/Content/_Game/Maps/DefaultMap.umap index a756de68..7f778c8c 100644 --- a/Content/_Game/Maps/DefaultMap.umap +++ b/Content/_Game/Maps/DefaultMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:db7f0d65dbcc43086f8875cccce50e0f15f77c26e5000ecb41545f58f8321a17 -size 97981 +oid sha256:39d5bbb7caf4021ffd41a58d8db8a72a76a728cecddbbbdfa8e9f1ca68f31289 +size 109344 diff --git a/Content/_Game/Weapons/BaseWeapon/BaseWeaponBP.uasset b/Content/_Game/Weapons/BaseWeapon/BaseWeaponBP.uasset index 7f5a40e3..f4b2d574 100644 --- a/Content/_Game/Weapons/BaseWeapon/BaseWeaponBP.uasset +++ b/Content/_Game/Weapons/BaseWeapon/BaseWeaponBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:30b64b0c82ae7237b4c02006e662c29909a69f15d97b5573eeff30801944ac47 -size 53974 +oid sha256:ee2698a1cef17c60ec400f6124d8c7ba02dcf5ab7c68277ebd22802ae47d98a6 +size 53888 diff --git a/Source/Shooter/Item.cpp b/Source/Shooter/Item.cpp index 219acdaa..5010b238 100644 --- a/Source/Shooter/Item.cpp +++ b/Source/Shooter/Item.cpp @@ -171,13 +171,55 @@ void AItem::InitializeCustomDepth() void AItem::OnConstruction(const FTransform& Transform) { - if (MaterialInstance) - { - DynamicMaterialInstance = UMaterialInstanceDynamic::Create(MaterialInstance, this); - ItemMesh->SetMaterial(MaterialIndex, DynamicMaterialInstance); - } + // Path to the Item Rarity Data Table + FString RarityTablePath(TEXT("/Script/Engine.DataTable'/Game/_Game/DataTable/ItemRarityDataTable.ItemRarityDataTable'")); - EnableGlowMaterial(); + // Load the data in the table + UDataTable* RarityTableObject = Cast(StaticLoadObject(UDataTable::StaticClass(), nullptr, *RarityTablePath)); + if (RarityTableObject) + { + FItemRarityTable* RarityRow = nullptr; + switch (ItemRarity) + { + case EItemRarity::EIR_Common: + RarityRow = RarityTableObject->FindRow(FName("Common"), TEXT("")); + break; + case EItemRarity::EIR_Uncommon: + RarityRow = RarityTableObject->FindRow(FName("Uncommon"), TEXT("")); + break; + case EItemRarity::EIR_Rare: + RarityRow = RarityTableObject->FindRow(FName("Rare"), TEXT("")); + break; + case EItemRarity::EIR_Legendary: + RarityRow = RarityTableObject->FindRow(FName("Legendary"), TEXT("")); + break; + case EItemRarity::EIR_Damaged: + default: + RarityRow = RarityTableObject->FindRow(FName("Damaged"), TEXT("")); + } + + if (RarityRow) + { + GlowColor = RarityRow->GlowColor; + LightColor = RarityRow->LightColor; + DarkColor = RarityRow->DarkColor; + NumberOfStars = RarityRow->NumberOfStars; + IconBackground = RarityRow->IconBackground; + if (GetItemMesh()) + { + GetItemMesh()->SetCustomDepthStencilValue(RarityRow->CustomDepthStencil); + } + + if (MaterialInstance) + { + DynamicMaterialInstance = UMaterialInstanceDynamic::Create(MaterialInstance, this); + DynamicMaterialInstance->SetVectorParameterValue(TEXT("FresnelColor"), GlowColor); + ItemMesh->SetMaterial(MaterialIndex, DynamicMaterialInstance); + + EnableGlowMaterial(); + } + } + } } void AItem::UpdatePulse() diff --git a/Source/Shooter/Item.h b/Source/Shooter/Item.h index 2e924df0..46aa78a3 100644 --- a/Source/Shooter/Item.h +++ b/Source/Shooter/Item.h @@ -4,6 +4,8 @@ #include "CoreMinimal.h" #include "GameFramework/Actor.h" +#include "Engine/DataTable.h" + #include "Item.generated.h" class UBoxComponent; @@ -13,6 +15,7 @@ class UCurveFloat; class AShooterCharacter; class USoundCue; class UCurveVector; +class UDataTable; UENUM(BlueprintType) enum class EItemRarity : uint8 @@ -47,6 +50,30 @@ enum class EItemType : uint8 EIT_MAX UMETA(DisplayName = "DefaultMAX") }; +USTRUCT(BlueprintType) +struct FItemRarityTable : public FTableRowBase +{ + GENERATED_BODY() + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FLinearColor GlowColor; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FLinearColor LightColor; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FLinearColor DarkColor; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 NumberOfStars; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + UTexture2D* IconBackground; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 CustomDepthStencil; +}; + UCLASS() class SHOOTER_API AItem : public AActor { @@ -131,14 +158,6 @@ private: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties", meta = (AllowPrivateAccess = true)) int32 ItemCount; - /* Item rarity - determines number of stars in Pickup Widget */ - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) - EItemRarity ItemRarity; - - /* Item rarity - determines number of stars in Pickup Widget */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) - TArray ActiveStars; - /** State of the Item */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) EItemState ItemState; @@ -236,10 +255,6 @@ private: UPROPERTY(VisibleAnywhere, Category = "Item Properties", meta = (AllowPrivateAccess = true)) float FresnelReflectFraction; - /** Background for this item in the inventory */ - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) - UTexture2D* IconBackground; - /** Icon for this item in the inventory */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) UTexture2D* IconItem; @@ -256,6 +271,37 @@ private: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = true)) bool bCharacterInventoryFull; + /* Item rarity - determines number of stars in Pickup Widget */ + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) + EItemRarity ItemRarity; + + /* Item rarity - determines number of stars in Pickup Widget */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) + TArray ActiveStars; + + /** Item Rarity data table */ + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) + UDataTable* ItemRarityDataTable; + + /** Color in the glow material */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) + FLinearColor GlowColor; + + /** Light color in the pickup widget */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) + FLinearColor LightColor; + + /** Dark color in the pickup widget */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) + FLinearColor DarkColor; + + /** Number of stars in the pickup widget */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) + int32 NumberOfStars; + + /** Background icon for the inventory */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Rarity, meta = (AllowPrivateAccess = true)) + UTexture2D* IconBackground; public: FORCEINLINE UWidgetComponent* GetPickupWidget() const { return PickupWidget; }