Merge remote-tracking branch 'origin/Inventory-System' into dev

# Conflicts:
#	EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset
#	EndlessVendetta/Content/Levels/TrainingFacility.umap
This commit is contained in:
Rafal Swierczek 2023-11-03 16:28:51 +00:00
commit a08f671114
48 changed files with 92 additions and 68 deletions

Binary file not shown.

Binary file not shown.

BIN
EndlessVendetta/Content/Inventory/M_Base_Rot.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
EndlessVendetta/Content/Inventory/UI/UI_Inventory.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
EndlessVendetta/Content/Inventory/UI/UI_InventoryGrid.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
EndlessVendetta/Content/Inventory/UI/UI_ItemWidget.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,13 @@
#include "BaseItem.h"
void UBaseItem::PostInitProperties()
{
Super::PostInitProperties();
ItemSize = FItemSize(DefaultItemSize.X, DefaultItemSize.Y);
}
void UBaseItem::RotateItem()
{
if (CurrentItemRotation == Horizontal)

View File

@ -10,9 +10,9 @@ struct FItemSize
{
GENERATED_BODY()
UPROPERTY(BlueprintReadOnly, Category = "ItemSize")
UPROPERTY(BlueprintReadWrite, Category = "ItemSize")
int X;
UPROPERTY(BlueprintReadOnly, Category = "ItemSize")
UPROPERTY(BlueprintReadWrite, Category = "ItemSize")
int Y;
FItemSize(const int _X, const int _Y)
@ -51,7 +51,9 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
FText Description;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
FItemSize ItemSize = FItemSize();
FVector2D DefaultItemSize = FVector2D(1);
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
FItemSize ItemSize;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
UMaterialInterface* ItemTexture;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
@ -63,6 +65,8 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
bool bIsRotated = false;
virtual void PostInitProperties() override;
UFUNCTION(BlueprintCallable, Category = "Item")
void RotateItem();
UFUNCTION(BlueprintCallable, Category = "Item")

View File

@ -107,9 +107,9 @@ bool UInventoryComponent::IsRoomAvailable(UBaseItem* Item, const int TopLeftInde
TileToCheck.X = i;
TileToCheck.Y = j;
if (!IsTileValid(TileToCheck)) return false;
const TTuple<UBaseItem*, bool> ItemAtIndex = GetItemAtIndex(TileToIndex(TileToCheck));
TTuple<UBaseItem*, bool> ItemAtIndex = GetItemAtIndex(TileToIndex(TileToCheck));
if (ItemAtIndex.Get<1>()) return false;
if (IsValid(ItemAtIndex.Get<0>())) return true;
if (IsValid(ItemAtIndex.Get<0>())) return false;
}
}
return true;
@ -126,6 +126,7 @@ FInventoryTile UInventoryComponent::IndexToTile(const int Index) const
TTuple<UBaseItem*, bool> UInventoryComponent::GetItemAtIndex(const int Index)
{
if (!InventoryItems.IsValidIndex(Index)) return MakeTuple(nullptr, false);
if (!IsValid(InventoryItems[Index])) return MakeTuple(nullptr, false);
return MakeTuple(InventoryItems[Index], true);
}
@ -144,7 +145,7 @@ void UInventoryComponent::AddItemAt(UBaseItem* Item, const int TopLeftIndex)
TileToCheck.X = i;
TileToCheck.Y = j;
if (!IsTileValid(TileToCheck)) return;
InventoryItems.Insert(Item, TileToIndex(TileToCheck));
InventoryItems[TileToIndex(TileToCheck)] = Item;
}
}
IsDirty = true;
@ -157,7 +158,7 @@ TMap<UBaseItem*, FInventoryTile> UInventoryComponent::GetAllItems()
{
UBaseItem* Item = InventoryItems[i];
if (!IsValid(Item)) continue;
if (!Items.Contains(Item)) continue;
if (Items.Contains(Item)) continue;
Items.Add(Item, IndexToTile(i));
}
return Items;
@ -170,19 +171,26 @@ void UInventoryComponent::RemoveItem(UBaseItem* Item)
{
if (InventoryItems[i] == Item)
{
InventoryItems.RemoveAt(i);
InventoryItems[i] = nullptr;
IsDirty = true;
}
}
}
void UInventoryComponent::SpawnItem(UBaseItem* Item, FVector Location, FRotator Rotation)
void UInventoryComponent::SpawnItem(UBaseItem* Item, FVector Location)
{
}
void UInventoryComponent::UpdateInventorySize_Implementation(const int _Columns, const int _Rows)
{
Columns = _Columns;
Rows = _Rows;
InventoryItems.SetNum(Columns * Rows);
}
bool UInventoryComponent::IsTileValid(const FInventoryTile InventoryTile) const
{
if (InventoryTile.X >= 0 && InventoryTile.Y >= 0 && InventoryTile.Y < Columns && InventoryTile.Y < Rows)
if (InventoryTile.X >= 0 && InventoryTile.Y >= 0 && InventoryTile.X < Columns && InventoryTile.Y < Columns && InventoryTile.Y <= Rows)
{
return true;
}

View File

@ -49,7 +49,6 @@ public:
bool IsRoomAvailable(class UBaseItem* Item, const int TopLeftIndex);
UFUNCTION(BlueprintCallable, Category="Inventory")
FInventoryTile IndexToTile(const int Index) const;
//UFUNCTION(BlueprintCallable, Category="Inventory")
TTuple<UBaseItem*, bool> GetItemAtIndex(const int Index);
UFUNCTION(BlueprintCallable, Category="Inventory")
int TileToIndex(const FInventoryTile InventoryTile) const;
@ -60,7 +59,10 @@ public:
UFUNCTION(BlueprintCallable, Category="Inventory")
void RemoveItem(class UBaseItem* Item);
UFUNCTION(BlueprintCallable, Category="Inventory")
void SpawnItem(class UBaseItem* Item, FVector Location, FRotator Rotation);
void SpawnItem(class UBaseItem* Item, FVector Location);
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Exec, Category = "Inventory")
void UpdateInventorySize(const int _Columns, const int _Rows);
virtual void UpdateInventorySize_Implementation(const int _Columns, const int _Rows);
private:
bool IsTileValid(const FInventoryTile InventoryTile) const;