Update Inventory Component for UI [WIP]
This commit is contained in:
parent
36daaaed16
commit
8cfe3b97a9
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BP_PC.uasset
(Stored with Git LFS)
Normal file
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BP_PC.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
EndlessVendetta/Content/FirstPerson/GunMechanicWorld.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/FirstPerson/GunMechanicWorld.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Inventory.uasset
(Stored with Git LFS)
Normal file
BIN
EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Inventory.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/Inventory/BP_Inventory.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/Inventory/BP_Inventory.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/Inventory/BP_InventoryGrid.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/Inventory/BP_InventoryGrid.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/Inventory/BP_InventoryItem.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/Inventory/BP_InventoryItem.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/Inventory/M_Base.uasset
(Stored with Git LFS)
Normal file
BIN
EndlessVendetta/Content/Inventory/M_Base.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
EndlessVendetta/Content/Inventory/MyBaseItem.uasset
(Stored with Git LFS)
Normal file
BIN
EndlessVendetta/Content/Inventory/MyBaseItem.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
EndlessVendetta/Content/Inventory/UI_Inventory.uasset
(Stored with Git LFS)
Normal file
BIN
EndlessVendetta/Content/Inventory/UI_Inventory.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
EndlessVendetta/Content/Inventory/UI_InventoryGrid.uasset
(Stored with Git LFS)
Normal file
BIN
EndlessVendetta/Content/Inventory/UI_InventoryGrid.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
EndlessVendetta/Content/Inventory/UI_ItemWidget.uasset
(Stored with Git LFS)
Normal file
BIN
EndlessVendetta/Content/Inventory/UI_ItemWidget.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
EndlessVendetta/Content/Inventory/zeldamus.uasset
(Stored with Git LFS)
Normal file
BIN
EndlessVendetta/Content/Inventory/zeldamus.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -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;
|
||||
}
|
||||
|
@ -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<EItemRotation> CurrentItemRotation = Horizontal;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
|
||||
TSubclassOf<AActor> ItemActor;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
|
||||
bool bIsRotated = false;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Item")
|
||||
void RotateItem();
|
||||
UFUNCTION(BlueprintCallable, Category = "Item")
|
||||
UMaterialInterface* GetItemTexture() const;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
@ -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<AEndlessVendettaCharacter>(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<UCameraComponent>(PlayerCharacter->GetComponentByClass(UCameraComponent::StaticClass()))->GetComponentLocation();
|
||||
FVector EndLocation = StartLocation + Cast<UCameraComponent>(PlayerCharacter->GetComponentByClass(UCameraComponent::StaticClass()))->GetForwardVector() * MaxPickupDistance;
|
||||
FCollisionQueryParams CollisionQueryParams;
|
||||
CollisionQueryParams.AddIgnoredActor(PlayerCharacter);
|
||||
if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, CollisionQueryParams))
|
||||
{
|
||||
if (Cast<UBaseItem>(HitResult.GetActor()))
|
||||
{
|
||||
ItemToPickup = HitResult.GetActor();
|
||||
Cast<UStaticMeshComponent>(ItemToPickup->GetComponentByClass(UStaticMeshComponent::StaticClass()))->SetRenderCustomDepth(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!IsValid(ItemToPickup)) return;
|
||||
Cast<UStaticMeshComponent>(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<UBaseItem*, bool> 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;
|
||||
|
@ -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")
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user