Bugfix Inventory UI Not Refreshing on Dirty

This commit is contained in:
Philip W 2023-10-25 16:58:38 +01:00
parent 53ecbbb472
commit 58931ab222
39 changed files with 52 additions and 52 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -10,9 +10,9 @@ struct FItemSize
{ {
GENERATED_BODY() GENERATED_BODY()
UPROPERTY(BlueprintReadOnly, Category = "ItemSize") UPROPERTY(BlueprintReadWrite, Category = "ItemSize")
int X; int X;
UPROPERTY(BlueprintReadOnly, Category = "ItemSize") UPROPERTY(BlueprintReadWrite, Category = "ItemSize")
int Y; int Y;
FItemSize(const int _X, const int _Y) FItemSize(const int _X, const int _Y)

View File

@ -145,7 +145,7 @@ void UInventoryComponent::AddItemAt(UBaseItem* Item, const int TopLeftIndex)
TileToCheck.X = i; TileToCheck.X = i;
TileToCheck.Y = j; TileToCheck.Y = j;
if (!IsTileValid(TileToCheck)) return; if (!IsTileValid(TileToCheck)) return;
InventoryItems.Insert(Item, TileToIndex(TileToCheck)); InventoryItems[TileToIndex(TileToCheck)] = Item;
} }
} }
IsDirty = true; IsDirty = true;
@ -158,7 +158,7 @@ TMap<UBaseItem*, FInventoryTile> UInventoryComponent::GetAllItems()
{ {
UBaseItem* Item = InventoryItems[i]; UBaseItem* Item = InventoryItems[i];
if (!IsValid(Item)) continue; if (!IsValid(Item)) continue;
if (!Items.Contains(Item)) continue; if (Items.Contains(Item)) continue;
Items.Add(Item, IndexToTile(i)); Items.Add(Item, IndexToTile(i));
} }
return Items; return Items;
@ -171,7 +171,7 @@ void UInventoryComponent::RemoveItem(UBaseItem* Item)
{ {
if (InventoryItems[i] == Item) if (InventoryItems[i] == Item)
{ {
InventoryItems.RemoveAt(i); InventoryItems[i] = nullptr;
IsDirty = true; IsDirty = true;
} }
} }
@ -183,7 +183,7 @@ void UInventoryComponent::SpawnItem(UBaseItem* Item, FVector Location, FRotator
bool UInventoryComponent::IsTileValid(const FInventoryTile InventoryTile) const 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.Y < Columns && InventoryTile.Y <= Rows)
{ {
return true; return true;
} }