diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_PC.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_PC.uasset new file mode 100644 index 00000000..e3cbe293 --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_PC.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ed077fa7c656b64c3f81cb8812cc4fc339d8b4f470dbcb1426f799bb1977438 +size 109892 diff --git a/EndlessVendetta/Content/FirstPerson/GunMechanicWorld.uasset b/EndlessVendetta/Content/FirstPerson/GunMechanicWorld.uasset index 551d8f69..921b01db 100644 --- a/EndlessVendetta/Content/FirstPerson/GunMechanicWorld.uasset +++ b/EndlessVendetta/Content/FirstPerson/GunMechanicWorld.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:50316ead250bb810a80831ade33e194f2de7ccb433dc172e5217540998e2854e -size 19098 +oid sha256:f01d66661ebe4dc7038e9105e8c156e3186fdaeafea8e59cfbcbc7dde0741029 +size 19619 diff --git a/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Inventory.uasset b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Inventory.uasset new file mode 100644 index 00000000..385c9c5f --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Inventory.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab49ececebc9a9d1d7038a1901d08caef22732ffc625ab37a8f71f54846a4809 +size 1375 diff --git a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset index 6f9680cf..00f26444 100644 --- a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset +++ b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:574a8a6fe6bd0d9ee1e4e32e2fadfbaea00a337525907ac14aba3dd4bef1b164 -size 18076 +oid sha256:78fa3a2622e7e2208ff72aebca44e7b2f57ae96c42dc2bb95ebeb1a87d6b696b +size 18080 diff --git a/EndlessVendetta/Content/Inventory/M_Base.uasset b/EndlessVendetta/Content/Inventory/M_Base.uasset new file mode 100644 index 00000000..ff9c03b9 --- /dev/null +++ b/EndlessVendetta/Content/Inventory/M_Base.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46f740304c399e9d98a0a1744f320928201179685c6de52013d02fde640b0aa5 +size 21988 diff --git a/EndlessVendetta/Content/Inventory/MyBaseItem.uasset b/EndlessVendetta/Content/Inventory/MyBaseItem.uasset new file mode 100644 index 00000000..4c1d1f22 --- /dev/null +++ b/EndlessVendetta/Content/Inventory/MyBaseItem.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a60300e2d3a093d49cc47288fadddb35de6038282d0a4a9ede6d695cbd09b2e +size 6303 diff --git a/EndlessVendetta/Content/Inventory/UI_Inventory.uasset b/EndlessVendetta/Content/Inventory/UI_Inventory.uasset new file mode 100644 index 00000000..c2322151 --- /dev/null +++ b/EndlessVendetta/Content/Inventory/UI_Inventory.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3fa985cf21e27c882c72e15d3482c45829fcaefedf52ad4b287874b229287555 +size 87053 diff --git a/EndlessVendetta/Content/Inventory/UI_InventoryGrid.uasset b/EndlessVendetta/Content/Inventory/UI_InventoryGrid.uasset new file mode 100644 index 00000000..7d6cc8d5 --- /dev/null +++ b/EndlessVendetta/Content/Inventory/UI_InventoryGrid.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b7e8fc53c8f2ae5213bda1d4b5758ccfcc7255b8577b5bd6abaa0fbbb558430b +size 568064 diff --git a/EndlessVendetta/Content/Inventory/UI_ItemWidget.uasset b/EndlessVendetta/Content/Inventory/UI_ItemWidget.uasset new file mode 100644 index 00000000..6773c468 --- /dev/null +++ b/EndlessVendetta/Content/Inventory/UI_ItemWidget.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d6849ec4eed10578619d45a3633b4d8540ce11c4b56ef00bfca43fe2429b480 +size 148756 diff --git a/EndlessVendetta/Content/Inventory/zeldamus.uasset b/EndlessVendetta/Content/Inventory/zeldamus.uasset new file mode 100644 index 00000000..840e1137 --- /dev/null +++ b/EndlessVendetta/Content/Inventory/zeldamus.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5616afc778197366258235add689576f3323e03e78a5ec49000fbac40dd6674b +size 745780 diff --git a/EndlessVendetta/EndlessVendetta.uproject b/EndlessVendetta/EndlessVendetta.uproject index 8aea7a6c..1a1190f2 100644 --- a/EndlessVendetta/EndlessVendetta.uproject +++ b/EndlessVendetta/EndlessVendetta.uproject @@ -10,7 +10,8 @@ "LoadingPhase": "Default", "AdditionalDependencies": [ "Engine", - "AIModule" + "AIModule", + "CoreUObject" ] } ], diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.cpp b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.cpp new file mode 100644 index 00000000..b79e1425 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.cpp @@ -0,0 +1,29 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "BaseItem.h" + +void UBaseItem::RotateItem() +{ + if (CurrentItemRotation == Horizontal) + { + CurrentItemRotation = Vertical; + ItemSize = FItemSize(ItemSize.Y, ItemSize.X); + bIsRotated = true; + } + else + { + CurrentItemRotation = Horizontal; + ItemSize = FItemSize(ItemSize.Y, ItemSize.X); + bIsRotated = false; + } +} + +UMaterialInterface* UBaseItem::GetItemTexture() const +{ + if (bIsRotated) + { + return ItemTextureRotated; + } + return ItemTexture; +} diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.h b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.h new file mode 100644 index 00000000..da7ed6d9 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.h @@ -0,0 +1,70 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BaseItem.generated.h" + +USTRUCT(BlueprintType) +struct FItemSize +{ + GENERATED_BODY() + + UPROPERTY(BlueprintReadOnly, Category = "ItemSize") + int X; + UPROPERTY(BlueprintReadOnly, Category = "ItemSize") + int Y; + + FItemSize(const int _X, const int _Y) + { + X = _X; + Y = _Y; + } + + FItemSize() + { + X = 1; + Y = 1; + } +}; + +UENUM(BlueprintType) +enum EItemRotation +{ + Horizontal UMETA(DisplayName = "Horizontal"), + Vertical UMETA(DisplayName = "Vertical") +}; + +/** + * + */ +UCLASS(Abstract, Blueprintable) +class ENDLESSVENDETTA_API UBaseItem : public UObject +{ + GENERATED_BODY() + +public: + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + int ItemID; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + FName ItemName; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + FText Description; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + FItemSize ItemSize = FItemSize(); + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + UMaterialInterface* ItemTexture; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + UMaterialInterface* ItemTextureRotated; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + TEnumAsByte CurrentItemRotation = Horizontal; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + TSubclassOf ItemActor; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + bool bIsRotated = false; + + UFUNCTION(BlueprintCallable, Category = "Item") + void RotateItem(); + UFUNCTION(BlueprintCallable, Category = "Item") + UMaterialInterface* GetItemTexture() const; +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseWorldItem.cpp b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseWorldItem.cpp new file mode 100644 index 00000000..ffa855c9 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseWorldItem.cpp @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "BaseWorldItem.h" + + +// Sets default values +ABaseWorldItem::ABaseWorldItem() +{ + // 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; +} + +// Called when the game starts or when spawned +void ABaseWorldItem::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void ABaseWorldItem::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); +} + diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseWorldItem.h b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseWorldItem.h new file mode 100644 index 00000000..c83609d9 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseWorldItem.h @@ -0,0 +1,25 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "BaseWorldItem.generated.h" + +UCLASS() +class ENDLESSVENDETTA_API ABaseWorldItem : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + ABaseWorldItem(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.cpp b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.cpp new file mode 100644 index 00000000..5e8f39de --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.cpp @@ -0,0 +1,190 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "InventoryComponent.h" + +#include "BaseItem.h" +#include "Camera/CameraComponent.h" + + +// Sets default values for this component's properties +UInventoryComponent::UInventoryComponent() +{ + // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features + // off to improve performance if you don't need them. + bWantsInitializeComponent = true; + PrimaryComponentTick.bCanEverTick = true; +} + +void UInventoryComponent::InitializeComponent() +{ + Super::InitializeComponent(); + PlayerCharacter = Cast(GetOwner()); + ItemToPickup = nullptr; +} + + +// Called when the game starts +void UInventoryComponent::BeginPlay() +{ + Super::BeginPlay(); + + //FTimerHandle TraceTimerHandle; + //GetWorld()->GetTimerManager().SetTimer(TraceTimerHandle, this, &UInventoryComponent::ProjectTraceForItem, 0.1f, true); + InventoryItems.Init(nullptr, Columns * Rows); +} + + +// Called every frame +void UInventoryComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + if (IsDirty) + { + IsDirty = false; + OnInventoryUpdated.Broadcast(); + } +} + +bool UInventoryComponent::AddItem(UBaseItem* Item) +{ + if (!IsValid(Item)) return false; + for (int i = 0; i < InventoryItems.Num(); i++) + { + if (IsRoomAvailable(Item, i)) + { + AddItemAt(Item, i); + return true; + } + } + Item->RotateItem(); + for (int i = 0; i < InventoryItems.Num(); i++) + { + if (IsRoomAvailable(Item, i)) + { + AddItemAt(Item, i); + return true; + } + } + Item->RotateItem(); + return false; +} + +void UInventoryComponent::ProjectTraceForItem() +{ + if (!IsValid(PlayerCharacter)) return; + FVector StartLocation = Cast(PlayerCharacter->GetComponentByClass(UCameraComponent::StaticClass()))->GetComponentLocation(); + FVector EndLocation = StartLocation + Cast(PlayerCharacter->GetComponentByClass(UCameraComponent::StaticClass()))->GetForwardVector() * MaxPickupDistance; + FCollisionQueryParams CollisionQueryParams; + CollisionQueryParams.AddIgnoredActor(PlayerCharacter); + if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, CollisionQueryParams)) + { + if (Cast(HitResult.GetActor())) + { + ItemToPickup = HitResult.GetActor(); + Cast(ItemToPickup->GetComponentByClass(UStaticMeshComponent::StaticClass()))->SetRenderCustomDepth(true); + return; + } + } + if (!IsValid(ItemToPickup)) return; + Cast(ItemToPickup->GetComponentByClass(UStaticMeshComponent::StaticClass()))->SetRenderCustomDepth(false); +} + +void UInventoryComponent::Pickup() +{ + //TODO: Add pickup logic and create pickup Actor + if (!IsValid(ItemToPickup)) return; +} + +bool UInventoryComponent::IsRoomAvailable(UBaseItem* Item, const int TopLeftIndex) +{ + for (int i = IndexToTile(TopLeftIndex).X; i < IndexToTile(TopLeftIndex).X + Item->ItemSize.X; i++) + { + for (int j = IndexToTile(TopLeftIndex).Y; j < IndexToTile(TopLeftIndex).Y + Item->ItemSize.Y; j++) + { + FInventoryTile TileToCheck; + TileToCheck.X = i; + TileToCheck.Y = j; + if (!IsTileValid(TileToCheck)) return false; + const TTuple ItemAtIndex = GetItemAtIndex(TileToIndex(TileToCheck)); + if (ItemAtIndex.Get<1>()) return false; + if (IsValid(ItemAtIndex.Get<0>())) return true; + } + } + return true; +} + +FInventoryTile UInventoryComponent::IndexToTile(const int Index) const +{ + FInventoryTile Tile; + Tile.X = Index % Columns; + Tile.Y = Index / Columns; + return Tile; +} + +TTuple UInventoryComponent::GetItemAtIndex(const int Index) +{ + if (!InventoryItems.IsValidIndex(Index)) return MakeTuple(nullptr, false); + return MakeTuple(InventoryItems[Index], true); +} + +int UInventoryComponent::TileToIndex(const FInventoryTile InventoryTile) const +{ + return InventoryTile.X + InventoryTile.Y * Columns; +} + +void UInventoryComponent::AddItemAt(UBaseItem* Item, const int TopLeftIndex) +{ + for (int i = IndexToTile(TopLeftIndex).X; i < IndexToTile(TopLeftIndex).X + Item->ItemSize.X; i++) + { + for (int j = IndexToTile(TopLeftIndex).Y; j < IndexToTile(TopLeftIndex).Y + Item->ItemSize.Y; j++) + { + FInventoryTile TileToCheck; + TileToCheck.X = i; + TileToCheck.Y = j; + if (!IsTileValid(TileToCheck)) return; + InventoryItems.Insert(Item, TileToIndex(TileToCheck)); + } + } + IsDirty = true; +} + +TMap UInventoryComponent::GetAllItems() +{ + TMap Items; + for (int i = 0; i < InventoryItems.Num(); i++) + { + UBaseItem* Item = InventoryItems[i]; + if (!IsValid(Item)) continue; + if (!Items.Contains(Item)) continue; + Items.Add(Item, IndexToTile(i)); + } + return Items; +} + +void UInventoryComponent::RemoveItem(UBaseItem* Item) +{ + if (!IsValid(Item)) return; + for (int i = 0; i < InventoryItems.Num(); i++) + { + if (InventoryItems[i] == Item) + { + InventoryItems.RemoveAt(i); + IsDirty = true; + } + } +} + +void UInventoryComponent::SpawnItem(UBaseItem* Item, FVector Location, FRotator Rotation) +{ +} + +bool UInventoryComponent::IsTileValid(const FInventoryTile InventoryTile) const +{ + if (InventoryTile.X >= 0 && InventoryTile.Y >= 0 && InventoryTile.Y < Columns && InventoryTile.Y < Rows) + { + return true; + } + return false; +} diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h new file mode 100644 index 00000000..5ba7ba28 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h @@ -0,0 +1,75 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "InventoryStructs.h" +#include "EndlessVendetta/EndlessVendettaCharacter.h" +#include "InventoryComponent.generated.h" + + +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +class ENDLESSVENDETTA_API UInventoryComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UInventoryComponent(); + virtual void InitializeComponent() override; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Inventory") + int Columns = 10; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Inventory") + int Rows = 10; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Inventory") + float MaxPickupDistance = 200.0f; + + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + + DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnInventoryUpdated); + UPROPERTY(BlueprintAssignable, Category="Inventory") + FOnInventoryUpdated OnInventoryUpdated; + + UFUNCTION(BlueprintCallable, Category="Inventory") + bool AddItem(class UBaseItem* Item); + UFUNCTION(BlueprintCallable, Category="Inventory") + void ProjectTraceForItem(); + UFUNCTION(BlueprintCallable, Category="Inventory") + void Pickup(); + UFUNCTION(BlueprintCallable, Category="Inventory") + bool IsRoomAvailable(class UBaseItem* Item, const int TopLeftIndex); + UFUNCTION(BlueprintCallable, Category="Inventory") + FInventoryTile IndexToTile(const int Index) const; + //UFUNCTION(BlueprintCallable, Category="Inventory") + TTuple GetItemAtIndex(const int Index); + UFUNCTION(BlueprintCallable, Category="Inventory") + int TileToIndex(const FInventoryTile InventoryTile) const; + UFUNCTION(BlueprintCallable, Category="Inventory") + void AddItemAt(class UBaseItem* Item, const int TopLeftIndex); + UFUNCTION(BlueprintCallable, Category="Inventory") + TMap GetAllItems(); + UFUNCTION(BlueprintCallable, Category="Inventory") + void RemoveItem(class UBaseItem* Item); + UFUNCTION(BlueprintCallable, Category="Inventory") + void SpawnItem(class UBaseItem* Item, FVector Location, FRotator Rotation); + +private: + bool IsTileValid(const FInventoryTile InventoryTile) const; + + UPROPERTY() + AEndlessVendettaCharacter* PlayerCharacter; + UPROPERTY() + AActor* ItemToPickup; + bool IsDirty = false; + UPROPERTY() + TArray InventoryItems; +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryStructs.h b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryStructs.h new file mode 100644 index 00000000..6d0b93be --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryStructs.h @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "InventoryStructs.generated.h" + +/** + * + */ + +USTRUCT(BlueprintType) +struct FInventoryLine +{ + GENERATED_BODY() + + UPROPERTY(BlueprintReadWrite) + FVector2D Start; + UPROPERTY(BlueprintReadWrite) + FVector2D End; +}; + +USTRUCT(BlueprintType) +struct FInventoryTile +{ + GENERATED_BODY() + + UPROPERTY(BlueprintReadWrite) + int X; + UPROPERTY(BlueprintReadWrite) + int Y; +};