Merge branch 'master' into new-netcode

Conflicts:
	Subsurface/Source/Items/Components/Machines/Deconstructor.cs
	Subsurface/Source/Items/Components/Machines/Fabricator.cs
This commit is contained in:
Regalis
2017-03-23 18:58:18 +02:00
9 changed files with 156 additions and 89 deletions
@@ -36,6 +36,16 @@ namespace Barotrauma.Items.Components
}
}
[Editable, HasDefaultValue(1.0f, true)]
public float TextScale
{
get { return textBlock == null ? 1.0f : textBlock.TextScale; }
set
{
if (textBlock != null) textBlock.TextScale = MathHelper.Clamp(value, 0.1f, 10.0f);
}
}
private GUITextBlock TextBlock
{
get
@@ -49,6 +59,7 @@ namespace Barotrauma.Items.Components
textBlock.Font = GUI.SmallFont;
textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
textBlock.TextDepth = item.Sprite.Depth - 0.0001f;
textBlock.TextScale = TextScale;
}
return textBlock;
}
@@ -30,12 +30,9 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (container == null || !container.Inventory.Items.Any(i=>i!=null))
if (container == null || container.Inventory.Items.All(i => i == null))
{
progressBar.BarSize = 0.0f;
//activateButton.Enabled = true;
if (container != null) container.Inventory.Locked = false;
IsActive = false;
SetActive(false);
return;
}
@@ -51,10 +48,10 @@ namespace Barotrauma.Items.Components
if (progressTimer>targetItem.Prefab.DeconstructTime)
{
var containers = item.GetComponents<ItemContainer>();
if (containers.Count<2)
if (containers.Count < 2)
{
DebugConsole.ThrowError("Error in Deconstructor.Update: Deconstructors must have two ItemContainer components!");
return;
}
@@ -62,21 +59,32 @@ namespace Barotrauma.Items.Components
{
if (deconstructProduct.RequireFullCondition && targetItem.Condition < 100.0f) continue;
var itemPrefab = ItemPrefab.list.FirstOrDefault(ip => ip.Name.ToLowerInvariant() == deconstructProduct.ItemPrefabName.ToLowerInvariant()) as ItemPrefab;
if (itemPrefab==null)
var itemPrefab = MapEntityPrefab.list.FirstOrDefault(ip => ip.Name.ToLowerInvariant() == deconstructProduct.ItemPrefabName.ToLowerInvariant()) as ItemPrefab;
if (itemPrefab == null)
{
DebugConsole.ThrowError("Tried to deconstruct item \""+targetItem.Name+"\" but couldn't find item prefab \""+deconstructProduct+"\"!");
DebugConsole.ThrowError("Tried to deconstruct item \"" + targetItem.Name + "\" but couldn't find item prefab \"" + deconstructProduct + "\"!");
continue;
}
Item.Spawner.AddToSpawnQueue(itemPrefab, containers[1].Inventory);
//container full, drop the items outside the deconstructor
if (containers[1].Inventory.Items.All(i => i != null))
{
Entity.Spawner.AddToSpawnQueue(itemPrefab, item.Position, item.Submarine);
}
else
{
Entity.Spawner.AddToSpawnQueue(itemPrefab, containers[1].Inventory);
}
}
container.Inventory.RemoveItem(targetItem);
Item.Spawner.AddToRemoveQueue(targetItem);
Entity.Spawner.AddToRemoveQueue(targetItem);
activateButton.Text = "Deconstruct";
progressBar.BarSize = 0.0f;
progressTimer = 0.0f;
if (container.Inventory.Items.Any(i => i != null))
{
progressTimer = 0.0f;
progressBar.BarSize = 0.0f;
}
}
}
@@ -122,6 +130,8 @@ namespace Barotrauma.Items.Components
return;
}
if (container.Inventory.Items.All(i => i == null)) active = false;
IsActive = active;
if (!IsActive)
@@ -133,7 +143,6 @@ namespace Barotrauma.Items.Components
}
else
{
if (container.Inventory.Items.All(i => i == null)) return;
activateButton.Text = "Cancel";
}
@@ -360,25 +360,32 @@ namespace Barotrauma.Items.Components
if (timeUntilReady > 0.0f) return;
var containers = item.GetComponents<ItemContainer>();
if (containers.Count<2)
if (containers.Count < 2)
{
DebugConsole.ThrowError("Error while fabricating a new item: fabricators must have two ItemContainer components");
return;
}
foreach (Tuple<ItemPrefab,int> ip in fabricatedItem.RequiredItems)
foreach (Tuple<ItemPrefab, int> ip in fabricatedItem.RequiredItems)
{
for (int i = 0; i<ip.Item2; i++)
for (int i = 0; i < ip.Item2; i++)
{
var requiredItem = containers[0].Inventory.Items.FirstOrDefault(it => it != null && it.Prefab == ip.Item1);
if (requiredItem == null) continue;
Item.Spawner.AddToRemoveQueue(requiredItem);
Entity.Spawner.AddToRemoveQueue(requiredItem);
containers[0].Inventory.RemoveItem(requiredItem);
}
}
Item.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, containers[1].Inventory);
if (containers[1].Inventory.Items.All(i => i != null))
{
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, item.Position, item.Submarine);
}
else
{
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, containers[1].Inventory);
}
CancelFabricating();
}