diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index e7dcb857..eb7c9e38 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:65d9f1286e3e2a0afeb00fd61e2a4ad5d105f8c4ea61cf146761901c810ea4bb -size 42451 +oid sha256:b16d2dc2079c962cb71ea8ce5309aa078115d780d3dff8fe944447f9b39e2362 +size 62566 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 2bc21ec7..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:e84853e2ab5cb8653ef3686fdd8ce458fbadd1261807bdc73feb5212015290ce -size 17496 +oid sha256:78fa3a2622e7e2208ff72aebca44e7b2f57ae96c42dc2bb95ebeb1a87d6b696b +size 18080 diff --git a/EndlessVendetta/Content/Inventory/BP_Inventory.uasset b/EndlessVendetta/Content/Inventory/BP_Inventory.uasset deleted file mode 100644 index fcd21dcf..00000000 --- a/EndlessVendetta/Content/Inventory/BP_Inventory.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:72974c08342cd605641d080348b7871cb6ae40cb6057ca15daf6071195a9bc05 -size 27656 diff --git a/EndlessVendetta/Content/Inventory/BP_InventoryGrid.uasset b/EndlessVendetta/Content/Inventory/BP_InventoryGrid.uasset deleted file mode 100644 index 03c7d869..00000000 --- a/EndlessVendetta/Content/Inventory/BP_InventoryGrid.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:50072ca6628bee1c25749aa7a98ebdf1d06ba835595140aea8f8e3f672722707 -size 26373 diff --git a/EndlessVendetta/Content/Inventory/BP_InventoryItem.uasset b/EndlessVendetta/Content/Inventory/BP_InventoryItem.uasset deleted file mode 100644 index 1071edc7..00000000 --- a/EndlessVendetta/Content/Inventory/BP_InventoryItem.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bec37e4f48c1d422c6f9d506c98f65f4132318f29afeafe93f874c811eb42561 -size 18641 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/Source/EndlessVendetta/Inventory/BaseItem.cpp b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.cpp index 7418614d..b79e1425 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.cpp @@ -3,3 +3,27 @@ #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 index 3c6cc7a1..da7ed6d9 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.h +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/BaseItem.h @@ -10,7 +10,9 @@ struct FItemSize { GENERATED_BODY() + UPROPERTY(BlueprintReadOnly, Category = "ItemSize") int X; + UPROPERTY(BlueprintReadOnly, Category = "ItemSize") int Y; FItemSize(const int _X, const int _Y) @@ -29,14 +31,14 @@ struct FItemSize UENUM(BlueprintType) enum EItemRotation { - Horizontal UMETA(DisplayName = "Up"), - Vertical UMETA(DisplayName = "Down") + Horizontal UMETA(DisplayName = "Horizontal"), + Vertical UMETA(DisplayName = "Vertical") }; /** * */ -UCLASS(Abstract) +UCLASS(Abstract, Blueprintable) class ENDLESSVENDETTA_API UBaseItem : public UObject { GENERATED_BODY() @@ -50,14 +52,19 @@ public: FText Description; UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") FItemSize ItemSize = FItemSize(); - UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Instanced, Category = "Item") - UTexture2D* ItemTexture; - UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Instanced, Category = "Item") - UTexture2D* ItemTextureRotated; + 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 index 5378ddcb..5e8f39de 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.cpp @@ -4,6 +4,7 @@ #include "InventoryComponent.h" #include "BaseItem.h" +#include "Camera/CameraComponent.h" // Sets default values for this component's properties @@ -11,9 +12,15 @@ 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; } @@ -22,7 +29,9 @@ void UInventoryComponent::BeginPlay() { Super::BeginPlay(); - // ... + //FTimerHandle TraceTimerHandle; + //GetWorld()->GetTimerManager().SetTimer(TraceTimerHandle, this, &UInventoryComponent::ProjectTraceForItem, 0.1f, true); + InventoryItems.Init(nullptr, Columns * Rows); } @@ -31,16 +40,55 @@ void UInventoryComponent::TickComponent(float DeltaTime, ELevelTick TickType, FA { 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::LineTraceForItemCheck() +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() @@ -51,9 +99,9 @@ void UInventoryComponent::Pickup() bool UInventoryComponent::IsRoomAvailable(UBaseItem* Item, const int TopLeftIndex) { - for (int i = 0; i < IndexToTile(TopLeftIndex).X + (Item->ItemSize.X - 1); i++) + for (int i = IndexToTile(TopLeftIndex).X; i < IndexToTile(TopLeftIndex).X + Item->ItemSize.X; i++) { - for (int j = 0; j < IndexToTile(TopLeftIndex).Y + (Item->ItemSize.Y - 1); j++) + for (int j = IndexToTile(TopLeftIndex).Y; j < IndexToTile(TopLeftIndex).Y + Item->ItemSize.Y; j++) { FInventoryTile TileToCheck; TileToCheck.X = i; @@ -61,7 +109,7 @@ bool UInventoryComponent::IsRoomAvailable(UBaseItem* Item, const int TopLeftInde if (!IsTileValid(TileToCheck)) return false; const TTuple ItemAtIndex = GetItemAtIndex(TileToIndex(TileToCheck)); if (ItemAtIndex.Get<1>()) return false; - if (IsValid(ItemAtIndex.Get<0>())) return false; + if (IsValid(ItemAtIndex.Get<0>())) return true; } } return true; @@ -88,9 +136,9 @@ int UInventoryComponent::TileToIndex(const FInventoryTile InventoryTile) const void UInventoryComponent::AddItemAt(UBaseItem* Item, const int TopLeftIndex) { - for (int i = 0; i < IndexToTile(TopLeftIndex).X + (Item->ItemSize.X - 1); i++) + for (int i = IndexToTile(TopLeftIndex).X; i < IndexToTile(TopLeftIndex).X + Item->ItemSize.X; i++) { - for (int j = 0; j < IndexToTile(TopLeftIndex).Y + (Item->ItemSize.Y - 1); j++) + for (int j = IndexToTile(TopLeftIndex).Y; j < IndexToTile(TopLeftIndex).Y + Item->ItemSize.Y; j++) { FInventoryTile TileToCheck; TileToCheck.X = i; diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h index 608455c0..5ba7ba28 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h @@ -17,6 +17,7 @@ class ENDLESSVENDETTA_API UInventoryComponent : public UActorComponent public: // Sets default values for this component's properties UInventoryComponent(); + virtual void InitializeComponent() override; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Inventory") int Columns = 10; @@ -25,6 +26,7 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Inventory") float MaxPickupDistance = 200.0f; + protected: // Called when the game starts virtual void BeginPlay() override; @@ -33,10 +35,14 @@ 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 LineTraceForItemCheck(); + void ProjectTraceForItem(); UFUNCTION(BlueprintCallable, Category="Inventory") void Pickup(); UFUNCTION(BlueprintCallable, Category="Inventory") diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryStructs.h b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryStructs.h index 742bae19..6d0b93be 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryStructs.h +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryStructs.h @@ -14,7 +14,9 @@ struct FInventoryLine { GENERATED_BODY() + UPROPERTY(BlueprintReadWrite) FVector2D Start; + UPROPERTY(BlueprintReadWrite) FVector2D End; }; @@ -22,7 +24,9 @@ USTRUCT(BlueprintType) struct FInventoryTile { GENERATED_BODY() - + + UPROPERTY(BlueprintReadWrite) int X; + UPROPERTY(BlueprintReadWrite) int Y; };