Skip to content

Commit

Permalink
Implementation of the UItemInventoryComponent
Browse files Browse the repository at this point in the history
Implementation of the UItemInventoryComponent.

This includes integration to the Sample Project via 2 Inventories, one for the Mouse to pickup Items and another for the Character Inventory which stores them. Implemented various User Interface Widgets to facilitate the usage of these 2 Inventory Components.

Various other improvements across the codebase.
  • Loading branch information
mattyman174 committed Feb 12, 2024
1 parent cffe4e7 commit b6ec3f5
Show file tree
Hide file tree
Showing 44 changed files with 760 additions and 17 deletions.
38 changes: 38 additions & 0 deletions Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,41 @@ ConnectionType=USBOnly
bUseManualIPAddress=False
ManualIPAddress=

[/Script/Engine.UserInterfaceSettings]
RenderFocusRule=NavigationOnly
HardwareCursors=()
SoftwareCursors=()
ApplicationScale=1.000000
UIScaleRule=ShortestSide
CustomScalingRuleClass=None
UIScaleCurve=(EditorCurveData=(Keys=((Time=480.000000,Value=0.444000),(Time=720.000000,Value=0.666000),(Time=1080.000000,Value=1.000000),(Time=8640.000000,Value=8.000000)),DefaultValue=340282346638528859811704183484516925440.000000,PreInfinityExtrap=RCCE_Constant,PostInfinityExtrap=RCCE_Constant),ExternalCurve=None)
bAllowHighDPIInGameMode=False
DesignScreenSize=(X=1920,Y=1080)
bLoadWidgetsOnDedicatedServer=True
bAuthorizeAutomaticWidgetVariableCreation=True
CustomFontDPI=96
FontDPIPreset=Unreal
bUseCustomFontDPI=False

[/Script/NavigationSystem.NavigationSystemV1]
DefaultAgentName=Default
CrowdManagerClass=/Script/AIModule.CrowdManager
bAutoCreateNavigationData=True
bSpawnNavDataInNavBoundsLevel=False
bAllowClientSideNavigation=False
bShouldDiscardSubLevelNavData=True
bTickWhilePaused=False
bInitialBuildingLocked=False
bSkipAgentHeightCheckWhenPickingNavData=False
GeometryExportTriangleCountWarningThreshold=200000
bGenerateNavigationOnlyAroundNavigationInvokers=False
ActiveTilesUpdateInterval=1.000000
DataGatheringMode=Instant
DirtyAreaWarningSizeThreshold=-1.000000
GatheringNavModifiersWarningLimitTime=-1.000000
+SupportedAgents=(Name="Default",Color=(B=0,G=75,R=38,A=164),DefaultQueryExtent=(X=50.000000,Y=50.000000,Z=250.000000),NavDataClass="/Script/NavigationSystem.RecastNavMesh",AgentRadius=42.000000,AgentHeight=96.000000,AgentStepHeight=-1.000000,NavWalkingSearchHeightScale=0.500000,PreferredNavData="/Script/NavigationSystem.RecastNavMesh",bCanCrouch=False,bCanJump=True,bCanWalk=True,bCanSwim=True,bCanFly=False)
SupportedAgentsMask=(bSupportsAgent0=True,bSupportsAgent1=True,bSupportsAgent2=True,bSupportsAgent3=True,bSupportsAgent4=True,bSupportsAgent5=True,bSupportsAgent6=True,bSupportsAgent7=True,bSupportsAgent8=True,bSupportsAgent9=True,bSupportsAgent10=True,bSupportsAgent11=True,bSupportsAgent12=True,bSupportsAgent13=True,bSupportsAgent14=True,bSupportsAgent15=True)

[/Script/NavigationSystem.RecastNavMesh]
RuntimeGeneration=Dynamic

Binary file modified Content/Itemization/BP_ItemChest.uasset
Binary file not shown.
Binary file modified Content/Itemization/BP_ItemDrop.uasset
Binary file not shown.
Binary file added Content/Itemization/GameMode/BP_Character.uasset
Binary file not shown.
Binary file added Content/Itemization/GameMode/BP_GameMode.uasset
Binary file not shown.
Binary file added Content/Itemization/GameMode/BP_HUD.uasset
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 added Content/Itemization/Inventories/ItemDrop.uasset
Binary file not shown.
Binary file added Content/Itemization/Inventories/ItemPickup.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/Itemization/ItemTables/Ammo.uasset
Binary file not shown.
Binary file modified Content/Itemization/ItemTables/Armor.uasset
Binary file not shown.
Binary file modified Content/Itemization/ItemTables/Misc.uasset
Binary file not shown.
Binary file modified Content/Itemization/ItemTables/Potions.uasset
Binary file not shown.
Binary file modified Content/Itemization/ItemTables/Weapons.uasset
Binary file not shown.
Binary file modified Content/Itemization/WBP_ItemDropDetails.uasset
Binary file not shown.
Binary file modified Content/Itemization/WBP_ItemDropTag.uasset
Binary file not shown.
Binary file modified Content/TopDown/Maps/TopDownMap.umap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public GenericItemization(ReadOnlyTargetRules Target) : base(Target)
"Core",
"StructUtils",
"GameplayTags",
"NetCore",
});

PrivateDependencyModuleNames.AddRange(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#include "GenericItemizationInstanceTypes.h"
#include "ItemManagement/ItemInventoryComponent.h"

FItemInstance::FItemInstance()
{
ItemId = FGuid::NewGuid();
ItemSeed = -1;
ItemLevel = -1;
AffixLevel = -1;
}

bool FItemInstance::HasAnyAffixOfType(const FGameplayTag& AffixType) const
{
Expand All @@ -15,3 +24,113 @@ bool FItemInstance::HasAnyAffixOfType(const FGameplayTag& AffixType) const

return false;
}

bool FItemInstance::IsValid() const
{
return ItemSeed != -1;
}

void FFastItemInstancesContainer::PostReplicatedAdd(const TArrayView<int32>& AddedIndices, int32 FinalSize)
{
for (const int32& Index : AddedIndices)
{
const FFastItemInstance& FastItemInstance = ItemInstances[Index];
const FInstancedStruct& PostAddItemInstance = FastItemInstance.ItemInstance;
if (Owner)
{
Owner->OnAddedItemInstance(FastItemInstance);
}
}
}

void FFastItemInstancesContainer::PostReplicatedChange(const TArrayView<int32>& ChangedIndices, int32 FinalSize)
{

}

void FFastItemInstancesContainer::PreReplicatedRemove(const TArrayView<int32>& RemovedIndices, int32 FinalSize)
{
for (const int32& Index : RemovedIndices)
{
const FFastItemInstance& FastItemInstance = ItemInstances[Index];
const FInstancedStruct& PreRemoveItemInstance = FastItemInstance.ItemInstance;
if (Owner)
{
Owner->OnRemovedItemInstance(FastItemInstance);
}
}
}

void FFastItemInstancesContainer::Register(UItemInventoryComponent* InOwner)
{
if (Owner != InOwner && InOwner != nullptr)
{
Owner = InOwner;
bOwnerIsNetAuthority = Owner->HasAuthority();
}
}

void FFastItemInstancesContainer::AddItemInstance(const FInstancedStruct& ItemInstance, const FInstancedStruct& UserContextData)
{
if (!Owner)
{
return;
}

FFastItemInstance FastItemInstance;
FastItemInstance.ItemInstance = ItemInstance;
FastItemInstance.UserContextData = UserContextData;

ItemInstances.Add(FastItemInstance);
MarkItemDirty(FastItemInstance);

Owner->OnAddedItemInstance(FastItemInstance);
}

bool FFastItemInstancesContainer::RemoveItemInstance(const FGuid& ItemInstance)
{
for (int32 i = ItemInstances.Num() - 1; i >= 0; --i)
{
const FItemInstance* ItemInstancePtr = ItemInstances[i].ItemInstance.GetPtr<FItemInstance>();
if (ItemInstancePtr && ItemInstancePtr->IsValid() && ItemInstancePtr->ItemId == ItemInstance)
{
FFastItemInstance OldItemInstance = ItemInstances[i];
ItemInstances.RemoveAt(i);
MarkArrayDirty();

Owner->OnRemovedItemInstance(OldItemInstance);
return true;
}
}

return false;
}

void FFastItemInstancesContainer::GetItemInstances(TArray<FInstancedStruct>& OutItemInstances) const
{
OutItemInstances.Empty(ItemInstances.Num());

for (const FFastItemInstance& ItemInstance : ItemInstances)
{
OutItemInstances.Add(ItemInstance.ItemInstance);
}
}

bool FFastItemInstancesContainer::GetFastItemInstance(const FGuid& ItemInstance, FFastItemInstance& OutFastItemInstance) const
{
for (const FFastItemInstance& FastItemInstance : ItemInstances)
{
if (FastItemInstance.ItemInstance.IsValid() && FastItemInstance.ItemInstance.GetPtr<FItemInstance>() && FastItemInstance.ItemInstance.GetPtr<FItemInstance>()->ItemId == ItemInstance)
{
OutFastItemInstance = FastItemInstance;
return true;
}
}

return false;
}

int32 FFastItemInstancesContainer::GetNum() const
{
return ItemInstances.Num();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@ void AItemDrop::GetItemDefinitionStruct(FItemDefinition& OutItemDefinitionStruct
OutItemDefinitionStruct = ItemInstance.Get().ItemDefinition.Get();
}
}

bool AItemDrop::HasValidItemInstance() const
{
return ItemInstance.IsValid() && ItemInstance.Get().IsValid();
}

bool AItemDrop::CanTakeItem_Implementation(UItemInventoryComponent* InventoryComponent) const
{
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
UItemDropperComponent::UItemDropperComponent()
{
PrimaryComponentTick.bCanEverTick = false;
PrimaryComponentTick.bStartWithTickEnabled = false;

ItemDropClass = AItemDrop::StaticClass();
ContextProviderFunction = UItemInstancingContextFunction::StaticClass();
}

bool UItemDropperComponent::DropItems_Implementation(FInstancedStruct UserContextData, TArray<AItemDrop*>& ItemDrops)
{
if (!IsValid(GetOwner()) || !GetOwner()->HasAuthority())
{
return false;
}

if (!IsValid(ItemDropClass) || !IsValid(ContextProviderFunction))
{
return false;
Expand Down
Loading

0 comments on commit b6ec3f5

Please sign in to comment.