Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaShared/Source/Items/ItemInventory.cs
T
juanjp600 4d225c65f2 Updated to MonoGame 3.6 + Directory refactor
- Barotrauma's projects are in the Barotrauma directory
- All libraries are in the Libraries directory
- MonoGame is now managed by NuGet, rather than referenced from the installed files (TODO: consider using PCL for easier cross-platform development?)
- NuGet libraries are not included in the repo, as getting the latest versions automatically should be preferred
- Removed Content/effects.mgfx as it didn't seem to be used anywhere
- Removed some references to Subsurface directory
- Renamed Launcher2 to Launcher
2017-06-27 09:52:57 -03:00

90 lines
2.5 KiB
C#

using Microsoft.Xna.Framework;
using Barotrauma.Items.Components;
namespace Barotrauma
{
class ItemInventory : Inventory
{
ItemContainer container;
public ItemInventory(Item owner, ItemContainer container, int capacity, Vector2? centerPos = null, int slotsPerRow = 5)
: base(owner, capacity, centerPos, slotsPerRow)
{
this.container = container;
}
public override int FindAllowedSlot(Item item)
{
for (int i = 0; i < capacity; i++)
{
//item is already in the inventory!
if (Items[i] == item) return -1;
}
if (!container.CanBeContained(item)) return -1;
for (int i = 0; i < capacity; i++)
{
if (Items[i] == null) return i;
}
return -1;
}
public override bool CanBePut(Item item, int i)
{
if (i < 0 || i >= Items.Length) return false;
return (item!=null && Items[i]==null && container.CanBeContained(item));
}
public override bool TryPutItem(Item item, System.Collections.Generic.List<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
{
bool wasPut = base.TryPutItem(item, allowedSlots, createNetworkEvent);
if (wasPut)
{
foreach (Character c in Character.CharacterList)
{
if (!c.HasSelectedItem(item)) continue;
item.Unequip(c);
break;
}
container.IsActive = true;
container.OnItemContained(item);
}
return wasPut;
}
public override bool TryPutItem(Item item, int i, bool allowSwapping, bool createNetworkEvent = true)
{
bool wasPut = base.TryPutItem(item, i, allowSwapping, createNetworkEvent);
if (wasPut)
{
foreach (Character c in Character.CharacterList)
{
if (!c.HasSelectedItem(item)) continue;
item.Unequip(c);
break;
}
container.IsActive = true;
container.OnItemContained(item);
}
return wasPut;
}
public override void RemoveItem(Item item)
{
base.RemoveItem(item);
container.OnItemRemoved(item);
}
}
}