Skip to content

Commit

Permalink
Last push
Browse files Browse the repository at this point in the history
  • Loading branch information
SrujanLokhande committed Sep 29, 2024
1 parent 358f414 commit 41623a5
Show file tree
Hide file tree
Showing 21 changed files with 194 additions and 17 deletions.
39 changes: 25 additions & 14 deletions .idea/.idea.InventorySystem/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Content/Assets/Characters/Mannequins/Animations/ABP_Manny.uasset
Binary file not shown.
Binary file modified Content/Assets/Characters/Mannequins/Meshes/SK_Mannequin.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/InventorySystem/Blueprints/BP_Tablet.uasset
Binary file not shown.
Binary file not shown.
Binary file modified Content/InventorySystem/ThirdPerson/Maps/LVL_MainMap.umap
Binary file not shown.
Binary file not shown.
Binary file modified Content/InventorySystem/UI/WBP_InventoryWidget.uasset
Binary file not shown.
Binary file added Content/Materials/M_RenderTargetDisplay.uasset
Binary file not shown.
Binary file added Content/Materials/RT_PlayerRenderTarget.uasset
Binary file not shown.
5 changes: 5 additions & 0 deletions InventorySystem.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=b59ab765_002De505_002D4643_002Dbda7_002De0c31a721019/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Solution /&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
35 changes: 35 additions & 0 deletions Source/InventorySystem/InventorySystemCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
#include "InputActionValue.h"
#include "DrawDebugHelpers.h"
#include "Actors/Pickup.h"
#include "Actors/Sword.h"
#include "Actors/Tablet.h"
#include "Blueprint/UserWidget.h"
#include "Components/InventoryComponent.h"
#include "Components/SceneCaptureComponent2D.h"
#include "Components/WidgetInteractionComponent.h"
#include "Engine/TextureRenderTarget2D.h"
#include "UserInterface/InventorySystemHUD.h"
#include "UserInterface/Inventory/DragItemVisual.h"
#include "UserInterface/Inventory/InventoryTooltip.h"
Expand Down Expand Up @@ -69,6 +72,11 @@ AInventorySystemCharacter::AInventorySystemCharacter()
PlayerInventory->SetSlotsCapacity(40);
PlayerInventory->SetWeightCapacity(60);

SceneCaptureComponent = CreateDefaultSubobject<USceneCaptureComponent2D>(TEXT("Scene Capture Component"));
SceneCaptureComponent->SetupAttachment(RootComponent);
SceneCaptureComponent->bCaptureEveryFrame = true;
SceneCaptureComponent->TextureTarget = PlayerRenderTarget;

InteractionCheckFrequency = 0.1;
InteractionCheckDistance = 225.f;

Expand Down Expand Up @@ -423,4 +431,31 @@ void AInventorySystemCharacter::DropItem(UItemBase* ItemToDrop, const int32 Quan
}
}

void AInventorySystemCharacter::EquipWeapon(UItemBase* WeaponItem)
{
if (WeaponItem)
{

if (SwordClass)
{
if (SwordWeapon)
{
SwordWeapon->Destroy();
}

FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.bNoFail = true;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;

// weapon spawn transform and location
FTransform SpawnTransform = GetMesh()->GetSocketTransform("WeaponSocket");
SwordWeapon = GetWorld()->SpawnActor<ASword>(SwordClass, SpawnTransform, SpawnParams);
SwordWeapon->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetIncludingScale, FName("WeaponSocket"));
PlayerInventory->RemoveSingleInstanceOfItem(WeaponItem);
PlayerInventory->OnInventoryUpdated.Broadcast();
}
}
}


17 changes: 16 additions & 1 deletion Source/InventorySystem/InventorySystemCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "InventorySystemCharacter.generated.h"


class ASword;
class UDragItemVisual;
class UInventoryTooltip;
class ATablet;
Expand Down Expand Up @@ -71,12 +72,17 @@ class AInventorySystemCharacter : public ACharacter
AInventorySystemCharacter();
FORCEINLINE bool IsInteracting() const { return GetWorldTimerManager().IsTimerActive(TimerHandleInteraction); }

FORCEINLINE UInventoryComponent* GetInventory() const { return PlayerInventory; }
FORCEINLINE UInventoryComponent* GetInventory() const { return PlayerInventory; }

void UpdateInteractionWidget() const;

void DropItem(UItemBase* ItemToDrop, const int32 QuantityToDrop);

void EquipWeapon(UItemBase* WeaponItem);

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Rendering")
UTextureRenderTarget2D* PlayerRenderTarget;

protected:

//=============================================================================
Expand All @@ -86,6 +92,9 @@ class AInventorySystemCharacter : public ACharacter
UPROPERTY()
AInventorySystemHUD* HUDRef;

UPROPERTY()
ASword* SwordWeapon;

/** Camera boom positioning the camera behind the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
USpringArmComponent* CameraBoom;
Expand Down Expand Up @@ -146,6 +155,12 @@ class AInventorySystemCharacter : public ACharacter

UPROPERTY(EditDefaultsOnly, Category = "Character | Tablet")
TSubclassOf<ATablet> TabletClass;

UPROPERTY(EditDefaultsOnly, Category = "Character | Tablet")
TSubclassOf<ASword> SwordClass;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera")
USceneCaptureComponent2D* SceneCaptureComponent;

float InteractionCheckFrequency;

Expand Down
2 changes: 1 addition & 1 deletion Source/InventorySystem/Private/Actors/Pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ APickup::APickup()
PrimaryActorTick.bCanEverTick = false;

PickupStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>("PickUp Actor Mesh");
PickupStaticMesh->SetSimulatePhysics(false);
PickupStaticMesh->SetSimulatePhysics(true);
SetRootComponent(PickupStaticMesh);
}

Expand Down
15 changes: 15 additions & 0 deletions Source/InventorySystem/Private/Actors/Sword.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "Actors/Sword.h"


// Sets default values
ASword::ASword()
{
PrimaryActorTick.bCanEverTick = false;

WeaponMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Tablet Mesh"));
SetRootComponent(WeaponMesh);
WeaponMesh->SetCollisionEnabled(ECollisionEnabled::Type::NoCollision);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "UserInterface/Actors/CharacterDisplayWidget.h"

#include "Components/Image.h"
#include "Engine/TextureRenderTarget2D.h"
#include "InventorySystem/InventorySystemCharacter.h"
#include "InventorySystem/DataStructure/ItemDataStructs.h"
#include "Items/ItemBase.h"
#include "UserInterface/Inventory/ItemDragDropOperation.h"

void UCharacterDisplayWidget::NativeConstruct()
{
Super::NativeConstruct();

PlayerCharacter = Cast<AInventorySystemCharacter>(GetOwningPlayerPawn());
}

bool UCharacterDisplayWidget::NativeOnDrop(const FGeometry& InGeometry, const FDragDropEvent& InDragDropEvent,
UDragDropOperation* InOperation)
{
const UItemDragDropOperation* ItemDragDrop = Cast<UItemDragDropOperation>(InOperation);

if(PlayerCharacter && ItemDragDrop->SourceItem)
{
if (ItemDragDrop->SourceItem->ItemType == EItemType::Weapons)
{
PlayerCharacter->EquipWeapon(ItemDragDrop->SourceItem);
return true;
}
}
return false;


}
20 changes: 20 additions & 0 deletions Source/InventorySystem/Public/Actors/Sword.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Sword.generated.h"

UCLASS()
class INVENTORYSYSTEM_API ASword : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor's properties
ASword();

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
UStaticMeshComponent* WeaponMesh;
};
2 changes: 2 additions & 0 deletions Source/InventorySystem/Public/Items/ItemBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include "CoreMinimal.h"
#include "Actors/Sword.h"
#include "UObject/Object.h"
#include "InventorySystem/DataStructure/ItemDataStructs.h"
#include "ItemBase.generated.h"
Expand Down Expand Up @@ -52,6 +53,7 @@ class INVENTORYSYSTEM_API UItemBase : public UObject
bool bIsPickup;

void ResetItemFlags();
TSubclassOf<ASword> GetWeaponClass() const { return this->GetClass(); }

// Constructor
UItemBase();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "CharacterDisplayWidget.generated.h"

class AInventorySystemCharacter;
class UImage;
/**
*
*/
UCLASS()
class INVENTORYSYSTEM_API UCharacterDisplayWidget : public UUserWidget
{
GENERATED_BODY()

public:

virtual void NativeConstruct() override;

protected:

virtual bool NativeOnDrop(const FGeometry& InGeometry, const FDragDropEvent& InDragDropEvent,
UDragDropOperation* InOperation) override;

UPROPERTY(meta=(BindWidget))
UImage* CharacterImage;

UPROPERTY()
AInventorySystemCharacter* PlayerCharacter;


};
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class INVENTORYSYSTEM_API AInventorySystemHUD : public AHUD

// Sets default values for this actor's properties
AInventorySystemHUD();


//void HideMenu();
//void ToggleMenu();
void ShowInteractionWidget();
void HideInteractionWidget();
void UpdateInteractionWidget(const FInteractableData* InteractableData) const;
Expand All @@ -59,4 +61,5 @@ class INVENTORYSYSTEM_API AInventorySystemHUD : public AHUD

// Called when the game starts or when spawned
virtual void BeginPlay() override;
//void DisplayMenu();
};

0 comments on commit 41623a5

Please sign in to comment.