diff --git a/Content/Blueprints/BP_Interaction.uasset b/Content/Blueprints/BP_Interaction.uasset index 024952c..36accd5 100644 --- a/Content/Blueprints/BP_Interaction.uasset +++ b/Content/Blueprints/BP_Interaction.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:14deaac2c8f6b6aa67592c8a806ed6059a566d3a767fbd18a092107b29913718 -size 27683 +oid sha256:4c7a00cbf616d22eba20079c3f1640b3d1c3ef86aee1bcfa4335ca32a5390a80 +size 27630 diff --git a/Content/Blueprints/BP_MyTempCharacter.uasset b/Content/Blueprints/BP_MyTempCharacter.uasset index 0594c08..ed9200f 100644 --- a/Content/Blueprints/BP_MyTempCharacter.uasset +++ b/Content/Blueprints/BP_MyTempCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7ab40229553278ecf914c2fb5a78609d1bff1d3c451797bf175ecf6a8948d3d5 -size 29619 +oid sha256:83b78bc2c32ead48fb4b3986da18675ab1673013673104c5232b504978a0c1ad +size 68346 diff --git a/Content/Blueprints/Items/BP_HealingJelly.uasset b/Content/Blueprints/Items/BP_HealingJelly.uasset new file mode 100644 index 0000000..65677e7 --- /dev/null +++ b/Content/Blueprints/Items/BP_HealingJelly.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79844600695e0e7790cb68584c0c58f21af18a8872904ccd645f1ec3108da22d +size 6681 diff --git a/Content/Blueprints/WBP_ItemDisplay.uasset b/Content/Blueprints/WBP_ItemDisplay.uasset new file mode 100644 index 0000000..748f45b --- /dev/null +++ b/Content/Blueprints/WBP_ItemDisplay.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3326b738a1a849cc33276c0a9c12c545dee4510e510848526cc225f939996d5 +size 81310 diff --git a/Content/Blueprints/WBP_PlayerInventory.uasset b/Content/Blueprints/WBP_PlayerInventory.uasset new file mode 100644 index 0000000..f05676b --- /dev/null +++ b/Content/Blueprints/WBP_PlayerInventory.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7df9350594b51cf2639b09ee43273d07e56f0328301b51d0c89b70c8edecf450 +size 90586 diff --git a/Content/Images/testimage.uasset b/Content/Images/testimage.uasset new file mode 100644 index 0000000..8691ea4 --- /dev/null +++ b/Content/Images/testimage.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:727645288d26ba910415d48a76aef277d0ba0840e5d5f859b58e11f0eaecbe0a +size 45103 diff --git a/Content/Levels/MerchantPrototype.umap b/Content/Levels/MerchantPrototype.umap index 5e6ba54..433a8e5 100644 --- a/Content/Levels/MerchantPrototype.umap +++ b/Content/Levels/MerchantPrototype.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b452da02d420447c486ed947537ab3030dddf2942de6533b784f7ec131498696 -size 23264 +oid sha256:659d40d87576c276667484be63bcb818039f4f8ac40525cdcea92c90eee7aaec +size 23245 diff --git a/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp b/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp new file mode 100644 index 0000000..8036177 --- /dev/null +++ b/Source/the_twilight_abyss/BaseItems/InventoryComponent.cpp @@ -0,0 +1,62 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "InventoryComponent.h" +#include "Items/BaseItem.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. + PrimaryComponentTick.bCanEverTick = true; + + MaxItemSlots = 10; +} + + +// Called when the game starts +void UInventoryComponent::BeginPlay() +{ + Super::BeginPlay(); + + for(auto & BaseItem : DefaultItems) + { + AddItem(BaseItem); + } +} + +bool UInventoryComponent::AddItem(class UBaseItem* BaseItem) +{ + //if the items is over the maxinventoryslots then it wont add the item + if (Items.Num() >= MaxItemSlots || !BaseItem) + { + return false; + } + + BaseItem->StoredItems = this; + BaseItem->World = GetWorld(); + Items.Add(BaseItem); + + //Update UI + OnInventoryUpdated.Broadcast(); + + return true; +} + +bool UInventoryComponent::Remove(UBaseItem* BaseItem) +{ + if(BaseItem) + { + BaseItem->StoredItems = nullptr; + BaseItem->World = nullptr; + Items.RemoveSingle(BaseItem); + OnInventoryUpdated.Broadcast(); // Updates UI + return true; + } + return false; +} + diff --git a/Source/the_twilight_abyss/BaseItems/InventoryComponent.h b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h new file mode 100644 index 0000000..d2fbb5a --- /dev/null +++ b/Source/the_twilight_abyss/BaseItems/InventoryComponent.h @@ -0,0 +1,41 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "InventoryComponent.generated.h" + +//OUR DELEGATE IS CALLED FONINVENTORYUPDATED +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnInventoryUpdated); + +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +class THE_TWILIGHT_ABYSS_API UInventoryComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UInventoryComponent(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + bool AddItem(class UBaseItem* BaseItem); //adds the item to the player + + bool Remove(class UBaseItem* BaseItem); //removes the item from the player + + UPROPERTY(EditDefaultsOnly, Instanced) + TArray DefaultItems; //Items you start the game with IF YOU WANT YOU CAN JUST NOT USE THIS + + UPROPERTY(EditDefaultsOnly, Category= "Inventory") + int32 MaxItemSlots; + + UPROPERTY(BlueprintAssignable, Category= "Inventory") + FOnInventoryUpdated OnInventoryUpdated; //This is our delegate + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Items") + TArray Items; // The items currently in the inventory +}; diff --git a/Source/the_twilight_abyss/BaseItems/Items/BaseItem.cpp b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.cpp new file mode 100644 index 0000000..2fac2d1 --- /dev/null +++ b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.cpp @@ -0,0 +1,16 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "BaseItem.h" + +//constructor +UBaseItem::UBaseItem() +{ + ItemDisplayName = FText::FromString("ItemName"); + ItemUseAction = FText::FromString("UseAction"); +} + +void UBaseItem::Use(ATempCharacter* Character) +{ + +} diff --git a/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h new file mode 100644 index 0000000..47cdbcc --- /dev/null +++ b/Source/the_twilight_abyss/BaseItems/Items/BaseItem.h @@ -0,0 +1,65 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "UObject/Object.h" +#include "BaseItem.generated.h" + + +/** + * + */ +UCLASS(Abstract, BlueprintType, Blueprintable, EditInlineNew, DefaultToInstanced) +class THE_TWILIGHT_ABYSS_API UBaseItem : public UObject +{ + GENERATED_BODY() + +public: + UBaseItem(); + + virtual class UWorld* GetWorld() const { return World; }; + + UPROPERTY(Transient) + class UWorld* World; + + //The text that will be displayed for using the item (Equip, Eat) + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + FText ItemUseAction; + + //The actual mesh of the item + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + class UStaticMesh* ItemMesh; + + //The picture of the item icon + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + class UTexture2D* ItemIcon; + + //The name of the item + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + FText ItemDisplayName; + + //The description of the item + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + FText ItemDescription; + + //The cost of the item + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item") + int32 ItemCostPrice; + + //ADD A HEALING ITEM VALUE? + + //reference to the UInventoryComponent script + UPROPERTY() + class UInventoryComponent* StoredItems; + + //The buy class to purchase the item + virtual void Buy(class UItemPurchaseComponent* PurchaseItem) PURE_VIRTUAL(UBaseItem); // WILL SET THIS UP LATER + + //The use Item class to use the item in the player Inventory + virtual void Use(class ATempCharacter* Character); + + //This is the same as the use item class but its in BP instead + UFUNCTION(BlueprintImplementableEvent) + void OnUse(class ATempCharacter* Character); +}; diff --git a/Source/the_twilight_abyss/BaseItems/Items/EatableItems.cpp b/Source/the_twilight_abyss/BaseItems/Items/EatableItems.cpp new file mode 100644 index 0000000..63956df --- /dev/null +++ b/Source/the_twilight_abyss/BaseItems/Items/EatableItems.cpp @@ -0,0 +1,15 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "EatableItems.h" + +#include "the_twilight_abyss/PlayerTemp/TempCharacter.h" + + +void UEatableItems::Use(ATempCharacter* Character) +{ + if(Character) + { + Character->Health += 10; + } +} diff --git a/Source/the_twilight_abyss/BaseItems/Items/EatableItems.h b/Source/the_twilight_abyss/BaseItems/Items/EatableItems.h new file mode 100644 index 0000000..127041f --- /dev/null +++ b/Source/the_twilight_abyss/BaseItems/Items/EatableItems.h @@ -0,0 +1,20 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BaseItem.h" +#include "EatableItems.generated.h" + +/** + * + */ +UCLASS() +class THE_TWILIGHT_ABYSS_API UEatableItems : public UBaseItem +{ + GENERATED_BODY() + +protected: + + virtual void Use(class ATempCharacter* Character) override; +}; diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp index df5bad3..237d6ee 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp @@ -12,7 +12,6 @@ AInteraction::AInteraction() { // 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; - WidgetBase = CreateDefaultSubobject(TEXT("Widget Base Class")); } // Called when the game starts or when spawned @@ -31,7 +30,7 @@ void AInteraction::Tick(float DeltaTime) void AInteraction::OnInteract() { - auto spawnedWidget = CreateWidget(GetWorld(), Widget); + UUserWidget* spawnedWidget = CreateWidget(GetWorld(), Widget); spawnedWidget->AddToViewport(0); } diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h index da9fd47..2fa21b1 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h @@ -22,12 +22,10 @@ protected: public: // Called every frame virtual void Tick(float DeltaTime) override; - - UPROPERTY(VisibleAnywhere) - class UWidgetComponent* WidgetBase; - + UPROPERTY(EditAnywhere) TSubclassOf Widget; virtual void OnInteract(); }; + diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index 87a07a9..d21da03 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -1,11 +1,9 @@ // Fill out your copyright notice in the Description page of Project Settings. #include "TempCharacter.h" -#include "UObject/SoftObjectPath.h" -#include "Dialogs/Dialogs.h" -#include "Engine/GameViewportClient.h" #include "Blueprint/UserWidget.h" -//#include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h" +#include "the_twilight_abyss/BaseItems/InventoryComponent.h" +#include "the_twilight_abyss/BaseItems/Items/BaseItem.h" #include "the_twilight_abyss/MerchantInteraction/Interaction.h" @@ -14,13 +12,15 @@ ATempCharacter::ATempCharacter() { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; + Inventory = CreateDefaultSubobject("Inventory"); + Inventory->MaxItemSlots = 10; } // Called when the game starts or when spawned void ATempCharacter::BeginPlay() { Super::BeginPlay(); - + Health = 100; } //Binds the input we made in the setup player component to the forward vector @@ -28,7 +28,6 @@ void ATempCharacter::ForwardInput(float Axis) { AddMovementInput(GetActorForwardVector() * Axis); } - //Binds the input we made in the setup player component to the right vector void ATempCharacter::RightMoveInput(float Axis) { @@ -42,7 +41,7 @@ void ATempCharacter::Tick(float DeltaTime) Super::Tick(DeltaTime); } -// Called to bind functionality to input +// Gives the character the functionality void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); @@ -51,14 +50,15 @@ void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompo PlayerInputComponent->BindAxis(TEXT("Turn Right / Left Mouse"), this, &ATempCharacter::AddControllerYawInput); PlayerInputComponent->BindAxis(TEXT("Look Up / Down Mouse"), this, &ATempCharacter::AddControllerPitchInput); PlayerInputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed); - // custom keybind Interact } +// When the player presses the E key void ATempCharacter::KeyPressed() { LineTraceLogic(); } +// Line trace logic void ATempCharacter::LineTraceLogic() { float GlobalTrace = TraceDistance; @@ -79,10 +79,18 @@ void ATempCharacter::LineTraceLogic() } if (AInteraction* MyInteractable = Cast(OutHit.GetActor())) { - DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f); MyInteractable->OnInteract(); UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); } } } + +void ATempCharacter::UseItem(class UBaseItem* Item) +{ + if(Item) + { + Item->Use(this); + Item->OnUse(this); //Blueprint Version + } +} diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index 3f170b4..7cafb29 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -11,6 +11,10 @@ class THE_TWILIGHT_ABYSS_API ATempCharacter : public ACharacter { GENERATED_BODY() + //Player inventory + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = "true")) + class UInventoryComponent* Inventory; //Using the InventoryComponent class + public: // Sets default values for this character's properties ATempCharacter(); @@ -35,4 +39,11 @@ public: float TraceDistance = 200; void LineTraceLogic(); + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Health") + float Health; + + //Using the item in the inventory + UFUNCTION(BlueprintCallable, Category= "Items") + void UseItem(class UBaseItem* Item); // Overriding the BaseItem Class };