Fixed AIObjectiveGoto terminating if previous path was unreachable, BackGroundSpriteManager won't place a sprite if a suitable position isn't found, StatusEffect fire position fix, UI improvements, door convexhull fix, progress on Fabricators & Deconstructors, mapentities sorted by category in edit mode, item descriptions, TutorialMode refactoring to make it easier to add new types of tutorials
This commit is contained in:
@@ -261,14 +261,16 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (multiSlot) continue;
|
||||
|
||||
UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4);
|
||||
if (Items[i]!=null && slotRect.Contains(PlayerInput.MousePosition))
|
||||
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
toolTip = Items[i].Name;
|
||||
toolTip = string.IsNullOrEmpty(Items[i].Description) ? Items[i].Name : Items[i].Name + '\n' + Items[i].Description;
|
||||
highlightedSlot = slotRect;
|
||||
}
|
||||
|
||||
UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4);
|
||||
|
||||
if (draggingItem!=null && draggingItem == Items[i]) draggingItemSlot = slotRect;
|
||||
}
|
||||
@@ -305,6 +307,12 @@ namespace Barotrauma
|
||||
|
||||
if (!multiSlot) continue;
|
||||
|
||||
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
toolTip = string.IsNullOrEmpty(Items[i].Description) ? Items[i].Name : Items[i].Name + '\n' + Items[i].Description;
|
||||
highlightedSlot = slotRect;
|
||||
}
|
||||
|
||||
UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,8 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (convexHull == null) return;
|
||||
|
||||
if (rect.Height == 0)
|
||||
{
|
||||
convexHull.Enabled = false;
|
||||
@@ -219,8 +221,10 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
body.SetTransform(body.SimPosition + ConvertUnits.ToSimUnits(amount), 0.0f);
|
||||
|
||||
convexHull.Move(amount);
|
||||
if (convexHull2 != null) convexHull2.Move(amount);
|
||||
UpdateConvexHulls();
|
||||
|
||||
//convexHull.Move(amount);
|
||||
//if (convexHull2 != null) convexHull2.Move(amount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (guiFrame==null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error: the component "+name+" in "+item.Name+" doesn't have a guiFrame");
|
||||
DebugConsole.ThrowError("Error: the component "+name+" in "+item.Name+" doesn't have a GuiFrame component");
|
||||
guiFrame = new GUIFrame(new Rectangle(0, 0, 100, 100), Color.Black);
|
||||
}
|
||||
return guiFrame;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Barotrauma.Items.Components
|
||||
class ItemContainer : ItemComponent
|
||||
{
|
||||
List<RelatedItem> containableItems;
|
||||
public ItemInventory inventory;
|
||||
public ItemInventory Inventory;
|
||||
|
||||
private bool hasStatusEffects;
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Barotrauma.Items.Components
|
||||
public ItemContainer(Item item, XElement element)
|
||||
: base (item, element)
|
||||
{
|
||||
inventory = new ItemInventory(item, this, capacity, hudPos, slotsPerRow);
|
||||
Inventory = new ItemInventory(item, this, capacity, hudPos, slotsPerRow);
|
||||
containableItems = new List<RelatedItem>();
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
@@ -119,7 +119,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void RemoveContained(Item item)
|
||||
{
|
||||
inventory.RemoveItem(item);
|
||||
Inventory.RemoveItem(item);
|
||||
}
|
||||
|
||||
public bool CanBeContained(Item item)
|
||||
@@ -132,7 +132,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (!hasStatusEffects) return;
|
||||
|
||||
foreach (Item contained in inventory.Items)
|
||||
foreach (Item contained in Inventory.Items)
|
||||
{
|
||||
if (contained == null || contained.Condition <= 0.0f) continue;
|
||||
//if (contained.body != null) contained.body.Enabled = false;
|
||||
@@ -185,7 +185,7 @@ namespace Barotrauma.Items.Components
|
||||
currentRotation += item.body.Rotation;
|
||||
}
|
||||
|
||||
foreach (Item containedItem in inventory.Items)
|
||||
foreach (Item containedItem in Inventory.Items)
|
||||
{
|
||||
if (containedItem == null) continue;
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (!drawInventory && false) return;
|
||||
|
||||
inventory.Draw(spriteBatch);
|
||||
Inventory.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public override bool Pick(Character picker)
|
||||
@@ -217,7 +217,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (containableItems.Find(x => x.MatchesItem(item)) == null) return false;
|
||||
|
||||
if (inventory.TryPutItem(item))
|
||||
if (Inventory.TryPutItem(item))
|
||||
{
|
||||
IsActive = true;
|
||||
if (hideItems || (item.body!=null && !item.body.Enabled)) item.body.Enabled = false;
|
||||
@@ -239,7 +239,7 @@ namespace Barotrauma.Items.Components
|
||||
Item item = MapEntity.FindEntityByID(itemIds[i]) as Item;
|
||||
if (item == null) continue;
|
||||
|
||||
inventory.TryPutItem(item, i, false);
|
||||
Inventory.TryPutItem(item, i, false);
|
||||
}
|
||||
|
||||
itemIds = null;
|
||||
@@ -249,7 +249,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
base.Remove();
|
||||
|
||||
foreach (Item item in inventory.Items)
|
||||
foreach (Item item in Inventory.Items)
|
||||
{
|
||||
if (item == null) continue;
|
||||
item.Remove();
|
||||
@@ -280,10 +280,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
XElement componentElement = base.Save(parentElement);
|
||||
|
||||
string[] itemIdStrings = new string[inventory.Items.Length];
|
||||
for (int i = 0; i < inventory.Items.Length; i++)
|
||||
string[] itemIdStrings = new string[Inventory.Items.Length];
|
||||
for (int i = 0; i < Inventory.Items.Length; i++)
|
||||
{
|
||||
itemIdStrings[i] = (inventory.Items[i]==null) ? "0" : inventory.Items[i].ID.ToString();
|
||||
itemIdStrings[i] = (Inventory.Items[i]==null) ? "0" : Inventory.Items[i].ID.ToString();
|
||||
}
|
||||
|
||||
componentElement.Add(new XAttribute("contained", string.Join(",",itemIdStrings)));
|
||||
|
||||
109
Subsurface/Source/Items/Components/Machines/Deconstructor.cs
Normal file
109
Subsurface/Source/Items/Components/Machines/Deconstructor.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class Deconstructor : ItemComponent
|
||||
{
|
||||
GUIProgressBar progressBar;
|
||||
GUIButton activateButton;
|
||||
|
||||
float progressTimer;
|
||||
|
||||
ItemContainer container;
|
||||
|
||||
public Deconstructor(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
progressBar = new GUIProgressBar(new Rectangle(0,0,200,20), Color.Green, 0.0f, Alignment.BottomCenter, GuiFrame);
|
||||
|
||||
activateButton = new GUIButton(new Rectangle(0, 0, 200, 20), "Deconstruct", Alignment.TopCenter, GUI.Style, GuiFrame);
|
||||
activateButton.OnClicked = Activate;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (container == null || !container.Inventory.Items.Any(i=>i!=null))
|
||||
{
|
||||
progressBar.BarSize = 0.0f;
|
||||
//activateButton.Enabled = true;
|
||||
if (container != null) container.Inventory.Locked = false;
|
||||
IsActive = false;
|
||||
return;
|
||||
}
|
||||
|
||||
progressTimer += deltaTime;
|
||||
|
||||
var targetItem = container.Inventory.Items.FirstOrDefault(i => i != null);
|
||||
progressBar.BarSize = Math.Min(progressTimer / targetItem.Prefab.DeconstructTime, 1.0f);
|
||||
if (progressTimer>targetItem.Prefab.DeconstructTime)
|
||||
{
|
||||
var containers = item.GetComponents<ItemContainer>();
|
||||
if (containers.Count<2)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in Deconstructor.Update: Deconstructors must have two ItemContainer components!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string deconstructProduct in targetItem.Prefab.DeconstructItems)
|
||||
{
|
||||
var itemPrefab = ItemPrefab.list.FirstOrDefault(ip => ip.Name.ToLower() == deconstructProduct.ToLower()) as ItemPrefab;
|
||||
if (itemPrefab==null)
|
||||
{
|
||||
DebugConsole.ThrowError("Tried to deconstruct item ''"+targetItem.Name+"'' but couldn't find item prefab ''"+deconstructProduct+"''!");
|
||||
continue;
|
||||
}
|
||||
Item.Spawner.QueueItem(itemPrefab, containers[1].Inventory);
|
||||
}
|
||||
|
||||
container.Inventory.RemoveItem(targetItem);
|
||||
Item.Remover.QueueItem(targetItem);
|
||||
|
||||
activateButton.Text = "Deconstruct";
|
||||
progressBar.BarSize = 0.0f;
|
||||
progressTimer = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||
{
|
||||
GuiFrame.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
private bool Activate(GUIButton button, object obj)
|
||||
{
|
||||
container = item.GetComponent<ItemContainer>();
|
||||
if (container==null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in Deconstructor.Activate: Deconstructors must have two ItemContainer components");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsActive)
|
||||
{
|
||||
progressBar.BarSize = 0.0f;
|
||||
progressTimer = 0.0f;
|
||||
|
||||
activateButton.Text = "Deconstruct";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!container.Inventory.Items.Any(i => i != null)) return false;
|
||||
|
||||
activateButton.Text = "Cancel";
|
||||
}
|
||||
|
||||
IsActive = !IsActive;
|
||||
|
||||
container.Inventory.Locked = IsActive;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,17 +10,12 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
class FabricableItem
|
||||
{
|
||||
//public static List<FabricableItem> list = new List<FabricableItem>();
|
||||
|
||||
//public readonly string[] FabricatorTags;
|
||||
|
||||
public readonly ItemPrefab TargetItem;
|
||||
|
||||
public readonly List<ItemPrefab> RequiredItems;
|
||||
|
||||
public readonly float RequiredTime;
|
||||
|
||||
|
||||
|
||||
//ListOrSomething requiredLevels
|
||||
|
||||
public FabricableItem(XElement element)
|
||||
@@ -69,12 +64,12 @@ namespace Barotrauma.Items.Components
|
||||
if (subElement.Name.ToString() != "fabricableitem") continue;
|
||||
|
||||
FabricableItem fabricableItem = new FabricableItem(subElement);
|
||||
if (fabricableItem.TargetItem != null) fabricableItems.Add(fabricableItem);
|
||||
|
||||
if (fabricableItem.TargetItem != null) fabricableItems.Add(fabricableItem);
|
||||
}
|
||||
|
||||
int width = 500, height = 300;
|
||||
itemList = new GUIListBox(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style);
|
||||
GuiFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
|
||||
|
||||
itemList = new GUIListBox(new Rectangle(0,0,GuiFrame.Rect.Width/2-20,0), GUI.Style, GuiFrame);
|
||||
itemList.OnSelected = SelectItem;
|
||||
//structureList.CheckSelected = MapEntityPrefab.GetSelected;
|
||||
|
||||
@@ -98,17 +93,28 @@ namespace Barotrauma.Items.Components
|
||||
FabricableItem targetItem = obj as FabricableItem;
|
||||
if (targetItem == null) return false;
|
||||
|
||||
int width = 200, height = 150;
|
||||
selectedItemFrame = new GUIFrame(new Rectangle(itemList.Rect.Right - width - 20, GameMain.GraphicsHeight/2-height/2, width, height), Color.Black*0.8f);
|
||||
//selectedItemFrame.Padding = GUI.style.smallPadding;
|
||||
if (selectedItemFrame != null) GuiFrame.RemoveChild(selectedItemFrame);
|
||||
|
||||
//int width = 200, height = 150;
|
||||
selectedItemFrame = new GUIFrame(new Rectangle(0,0,(int)(GuiFrame.Rect.Width*0.4f),200), Color.Black*0.8f, Alignment.CenterY | Alignment.Right, null, GuiFrame);
|
||||
|
||||
selectedItemFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
|
||||
if (targetItem.TargetItem.sprite != null)
|
||||
{
|
||||
GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), targetItem.TargetItem.sprite, Alignment.CenterX, selectedItemFrame);
|
||||
GUIImage img = new GUIImage(new Rectangle(10, 0, 40, 40), targetItem.TargetItem.sprite, Alignment.TopLeft, selectedItemFrame);
|
||||
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
|
||||
img.Color = targetItem.TargetItem.SpriteColor;
|
||||
|
||||
string text = targetItem.TargetItem.Name + "\n";
|
||||
text += "Required items:\n";
|
||||
new GUITextBlock(
|
||||
new Rectangle(60, 0, 0, 25),
|
||||
targetItem.TargetItem.Name,
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.TopLeft,
|
||||
Alignment.TopLeft, null,
|
||||
selectedItemFrame, true);
|
||||
|
||||
string text = "Required items:\n";
|
||||
foreach (ItemPrefab ip in targetItem.RequiredItems)
|
||||
{
|
||||
text += " - " + ip.Name + "\n";
|
||||
@@ -116,11 +122,11 @@ namespace Barotrauma.Items.Components
|
||||
text += "Required time: "+targetItem.RequiredTime+" s";
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 0, 25),
|
||||
new Rectangle(0, 50, 0, 25),
|
||||
text,
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.CenterX | Alignment.CenterY,
|
||||
Alignment.Left, null,
|
||||
Alignment.TopLeft,
|
||||
Alignment.TopLeft, null,
|
||||
selectedItemFrame);
|
||||
|
||||
GUIButton button = new GUIButton(new Rectangle(0,0,100,20), "Create", Color.White, Alignment.CenterX | Alignment.Bottom, GUI.Style, selectedItemFrame);
|
||||
@@ -159,15 +165,22 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (timeUntilReady > 0.0f) return;
|
||||
|
||||
ItemContainer container = item.GetComponent<ItemContainer>();
|
||||
var containers = item.GetComponents<ItemContainer>();
|
||||
if (containers.Count<2)
|
||||
{
|
||||
DebugConsole.ThrowError("Error while fabricating a new item: fabricators must have two ItemContainer components");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (ItemPrefab ip in fabricatedItem.RequiredItems)
|
||||
{
|
||||
var requiredItem = container.inventory.Items.FirstOrDefault(it => it != null && it.Prefab == ip);
|
||||
container.inventory.RemoveItem(requiredItem);
|
||||
var requiredItem = containers[0].Inventory.Items.FirstOrDefault(it => it != null && it.Prefab == ip);
|
||||
containers[0].Inventory.RemoveItem(requiredItem);
|
||||
}
|
||||
|
||||
Item.Spawner.QueueItem(fabricatedItem.TargetItem, item.Position);
|
||||
|
||||
Item.Spawner.QueueItem(fabricatedItem.TargetItem, containers[1].Inventory);
|
||||
|
||||
itemList.Enabled = true;
|
||||
IsActive = false;
|
||||
fabricatedItem = null;
|
||||
}
|
||||
@@ -182,20 +195,23 @@ namespace Barotrauma.Items.Components
|
||||
ItemContainer container = item.GetComponent<ItemContainer>();
|
||||
foreach (ItemPrefab ip in targetItem.RequiredItems)
|
||||
{
|
||||
if (Array.Find(container.inventory.Items, it => it != null && it.Prefab == ip) != null) continue;
|
||||
if (Array.Find(container.Inventory.Items, it => it != null && it.Prefab == ip) != null) continue;
|
||||
selectedItemFrame.GetChild<GUIButton>().Enabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
itemList.Update(0.016f);
|
||||
itemList.Draw(spriteBatch);
|
||||
GuiFrame.Update((float)Physics.step);
|
||||
GuiFrame.Draw(spriteBatch);
|
||||
|
||||
if (selectedItemFrame != null)
|
||||
{
|
||||
selectedItemFrame.Update(0.016f);
|
||||
selectedItemFrame.Draw(spriteBatch);
|
||||
}
|
||||
//itemList.Update(0.016f);
|
||||
//itemList.Draw(spriteBatch);
|
||||
|
||||
//if (selectedItemFrame != null)
|
||||
//{
|
||||
// selectedItemFrame.Update(0.016f);
|
||||
// selectedItemFrame.Draw(spriteBatch);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,16 @@ namespace Barotrauma
|
||||
|
||||
protected int capacity;
|
||||
|
||||
|
||||
|
||||
private Vector2 centerPos;
|
||||
|
||||
protected int selectedSlot;
|
||||
|
||||
public Item[] Items;
|
||||
|
||||
public bool Locked;
|
||||
|
||||
public Vector2 CenterPos
|
||||
{
|
||||
get { return centerPos; }
|
||||
@@ -38,12 +48,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 centerPos;
|
||||
|
||||
protected int selectedSlot;
|
||||
|
||||
public Item[] Items;
|
||||
|
||||
public Inventory(Entity owner, int capacity, Vector2? centerPos = null, int slotsPerRow=5)
|
||||
{
|
||||
this.capacity = capacity;
|
||||
@@ -141,6 +145,8 @@ namespace Barotrauma
|
||||
|
||||
public void RemoveItem(Item item)
|
||||
{
|
||||
if (item == null) return;
|
||||
|
||||
//go through the inventory and remove the item from all slots
|
||||
for (int n = 0; n < capacity; n++)
|
||||
{
|
||||
@@ -224,8 +230,12 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle highlightedSlot)
|
||||
protected void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle highlightedSlot)
|
||||
{
|
||||
int maxWidth = 300;
|
||||
|
||||
toolTip = ToolBox.WrapText(toolTip, maxWidth, GUI.Font);
|
||||
|
||||
Vector2 textSize = GUI.Font.MeasureString(toolTip);
|
||||
Vector2 rectSize = textSize * 1.2f;
|
||||
|
||||
@@ -235,15 +245,15 @@ namespace Barotrauma
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, pos, rectSize, Color.Black * 0.8f, true);
|
||||
spriteBatch.DrawString(GUI.Font, toolTip,
|
||||
new Vector2((int)pos.X + rectSize.X * 0.5f, (int)pos.Y + rectSize.Y * 0.5f),
|
||||
new Vector2((int)(pos.X + rectSize.X * 0.5f), (int)(pos.Y + rectSize.Y * 0.5f)),
|
||||
Color.White, 0.0f,
|
||||
new Vector2((int)textSize.X * 0.5f, (int)textSize.Y * 0.5f),
|
||||
new Vector2((int)(textSize.X * 0.5f), (int)(textSize.Y * 0.5f)),
|
||||
1.0f, SpriteEffects.None, 0.0f);
|
||||
}
|
||||
|
||||
protected void UpdateSlot(SpriteBatch spriteBatch, Rectangle rect, int slotIndex, Item item, bool isSubSlot, bool drawItem=true)
|
||||
{
|
||||
bool mouseOn = rect.Contains(PlayerInput.MousePosition);
|
||||
bool mouseOn = rect.Contains(PlayerInput.MousePosition) && !Locked;
|
||||
|
||||
if (mouseOn)
|
||||
{
|
||||
@@ -292,7 +302,7 @@ namespace Barotrauma
|
||||
Rectangle subRect = rect;
|
||||
subRect.Height = 40;
|
||||
|
||||
selectedSlot = containerRect.Contains(PlayerInput.MousePosition) ? slotIndex : -1;
|
||||
selectedSlot = containerRect.Contains(PlayerInput.MousePosition) && !Locked ? slotIndex : -1;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, containerRect, Color.Black * 0.8f, true);
|
||||
GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace Barotrauma
|
||||
protected ItemPrefab prefab;
|
||||
|
||||
public static ItemSpawner Spawner = new ItemSpawner();
|
||||
public static ItemRemover Remover = new ItemRemover();
|
||||
|
||||
private List<string> tags;
|
||||
|
||||
@@ -72,6 +73,11 @@ namespace Barotrauma
|
||||
get { return prefab.Name; }
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get { return prefab.Description; }
|
||||
}
|
||||
|
||||
public override Sprite Sprite
|
||||
{
|
||||
get { return prefab.sprite; }
|
||||
@@ -211,7 +217,7 @@ namespace Barotrauma
|
||||
get
|
||||
{
|
||||
ItemContainer c = GetComponent<ItemContainer>();
|
||||
return (c == null) ? null : Array.FindAll(c.inventory.Items, i=>i!=null);
|
||||
return (c == null) ? null : Array.FindAll(c.Inventory.Items, i=>i!=null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,6 +302,7 @@ namespace Barotrauma
|
||||
break;
|
||||
case "trigger":
|
||||
case "sprite":
|
||||
case "deconstruct":
|
||||
break;
|
||||
case "aitarget":
|
||||
aiTarget = new AITarget(this);
|
||||
@@ -329,6 +336,17 @@ namespace Barotrauma
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public List<T> GetComponents<T>()
|
||||
{
|
||||
List<T> components = new List<T>();
|
||||
foreach (ItemComponent ic in this.components)
|
||||
{
|
||||
if (ic is T) components.Add((T)(object)ic);
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
public void RemoveContained(Item contained)
|
||||
{
|
||||
@@ -548,7 +566,7 @@ namespace Barotrauma
|
||||
{
|
||||
ic.Update(deltaTime, cam);
|
||||
|
||||
ic.PlaySound(ActionType.OnActive, WorldPosition);
|
||||
if (ic.IsActive) ic.PlaySound(ActionType.OnActive, WorldPosition);
|
||||
//ic.ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
||||
}
|
||||
else
|
||||
@@ -1306,8 +1324,8 @@ namespace Barotrauma
|
||||
break;
|
||||
case NetworkEventType.InventoryUpdate:
|
||||
var itemContainer = GetComponent<ItemContainer>();
|
||||
if (itemContainer == null || itemContainer.inventory == null) return false;
|
||||
return itemContainer.inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||
if (itemContainer == null || itemContainer.Inventory == null) return false;
|
||||
return itemContainer.Inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||
case NetworkEventType.ComponentUpdate:
|
||||
case NetworkEventType.ImportantComponentUpdate:
|
||||
|
||||
@@ -1385,8 +1403,8 @@ namespace Barotrauma
|
||||
case NetworkEventType.InventoryUpdate:
|
||||
|
||||
var itemContainer = GetComponent<ItemContainer>();
|
||||
if (itemContainer == null || itemContainer.inventory == null) return;
|
||||
itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message, sendingTime);
|
||||
if (itemContainer == null || itemContainer.Inventory == null) return;
|
||||
itemContainer.Inventory.ReadNetworkData(NetworkEventType.DropItem, message, sendingTime);
|
||||
break;
|
||||
case NetworkEventType.ComponentUpdate:
|
||||
case NetworkEventType.ImportantComponentUpdate:
|
||||
|
||||
@@ -38,6 +38,24 @@ namespace Barotrauma
|
||||
get { return configFile; }
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public List<string> DeconstructItems
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public float DeconstructTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public float PickDistance
|
||||
{
|
||||
get { return pickDistance; }
|
||||
@@ -48,7 +66,6 @@ namespace Barotrauma
|
||||
get { return pickThroughWalls; }
|
||||
}
|
||||
|
||||
|
||||
public override bool IsLinkable
|
||||
{
|
||||
get { return isLinkable; }
|
||||
@@ -83,8 +100,11 @@ namespace Barotrauma
|
||||
{
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
{
|
||||
new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this, Submarine.Loaded);
|
||||
var item = new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this, Submarine.Loaded);
|
||||
//constructor.Invoke(lobject);
|
||||
item.Submarine = Submarine.Loaded;
|
||||
item.SetTransform(ConvertUnits.ToSimUnits(item.Position - Submarine.Loaded.Position), 0.0f);
|
||||
item.FindHull();
|
||||
|
||||
placePosition = Vector2.Zero;
|
||||
|
||||
@@ -112,8 +132,13 @@ namespace Barotrauma
|
||||
|
||||
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
|
||||
{
|
||||
new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this, Submarine.Loaded);
|
||||
var item = new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this, Submarine.Loaded);
|
||||
placePosition = Vector2.Zero;
|
||||
|
||||
item.Submarine = Submarine.Loaded;
|
||||
item.SetTransform(ConvertUnits.ToSimUnits(item.Position - Submarine.Loaded.Position), 0.0f);
|
||||
item.FindHull();
|
||||
|
||||
//selected = null;
|
||||
return;
|
||||
}
|
||||
@@ -161,6 +186,8 @@ namespace Barotrauma
|
||||
name = ToolBox.GetAttributeString(element, "name", "");
|
||||
if (name == "") DebugConsole.ThrowError("Unnamed item in "+filePath+"!");
|
||||
|
||||
Description = ToolBox.GetAttributeString(element, "description", "");
|
||||
|
||||
pickThroughWalls = ToolBox.GetAttributeBool(element, "pickthroughwalls", false);
|
||||
pickDistance = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "pickdistance", 0.0f));
|
||||
|
||||
@@ -172,9 +199,13 @@ namespace Barotrauma
|
||||
focusOnSelected = ToolBox.GetAttributeBool(element, "focusonselected", false);
|
||||
|
||||
offsetOnSelected = ToolBox.GetAttributeFloat(element, "offsetonselected", 0.0f);
|
||||
|
||||
|
||||
FireProof = ToolBox.GetAttributeBool(element, "fireproof", false);
|
||||
|
||||
MapEntityCategory category;
|
||||
Enum.TryParse(ToolBox.GetAttributeString(element, "category", "Item"), out category);
|
||||
Category = category;
|
||||
|
||||
string spriteColorStr = ToolBox.GetAttributeString(element, "spritecolor", "1.0,1.0,1.0,1.0");
|
||||
SpriteColor = new Color(ToolBox.ParseToVector4(spriteColorStr));
|
||||
|
||||
@@ -182,6 +213,9 @@ namespace Barotrauma
|
||||
|
||||
Triggers = new List<Rectangle>();
|
||||
|
||||
DeconstructItems = new List<string>();
|
||||
DeconstructTime = 1.0f;
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLower())
|
||||
@@ -189,6 +223,15 @@ namespace Barotrauma
|
||||
case "sprite":
|
||||
sprite = new Sprite(subElement, Path.GetDirectoryName(filePath));
|
||||
size = sprite.size;
|
||||
break;
|
||||
case "deconstruct":
|
||||
DeconstructTime = ToolBox.GetAttributeFloat(subElement, "time", 10.0f);
|
||||
|
||||
foreach (XElement deconstructItem in subElement.Elements())
|
||||
{
|
||||
DeconstructItems.Add(ToolBox.GetAttributeString(deconstructItem, "name", "not found"));
|
||||
}
|
||||
|
||||
break;
|
||||
case "trigger":
|
||||
Rectangle trigger = new Rectangle(0, 0, 10,10);
|
||||
|
||||
@@ -8,30 +8,76 @@ namespace Barotrauma
|
||||
{
|
||||
class ItemSpawner
|
||||
{
|
||||
private Queue<Pair<ItemPrefab, Vector2>> spawnQueue;
|
||||
private Queue<Pair<ItemPrefab, object>> spawnQueue;
|
||||
|
||||
public ItemSpawner()
|
||||
{
|
||||
spawnQueue = new Queue<Pair<ItemPrefab, Vector2>>();
|
||||
spawnQueue = new Queue<Pair<ItemPrefab, object>>();
|
||||
}
|
||||
|
||||
public void QueueItem(ItemPrefab itemPrefab, Vector2 position)
|
||||
{
|
||||
var itemInfo = new Pair<ItemPrefab, Vector2>();
|
||||
var itemInfo = new Pair<ItemPrefab, object>();
|
||||
itemInfo.First = itemPrefab;
|
||||
itemInfo.Second = position;
|
||||
|
||||
spawnQueue.Enqueue(itemInfo);
|
||||
}
|
||||
|
||||
public void QueueItem(ItemPrefab itemPrefab, Inventory inventory)
|
||||
{
|
||||
var itemInfo = new Pair<ItemPrefab, object>();
|
||||
itemInfo.First = itemPrefab;
|
||||
itemInfo.Second = inventory;
|
||||
|
||||
spawnQueue.Enqueue(itemInfo);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
while (spawnQueue.Count>0)
|
||||
{
|
||||
var itemInfo = spawnQueue.Dequeue();
|
||||
|
||||
if (itemInfo.Second is Vector2)
|
||||
{
|
||||
new Item(itemInfo.First, (Vector2)itemInfo.Second - Submarine.HiddenSubPosition, null);
|
||||
}
|
||||
else if (itemInfo.Second is Inventory)
|
||||
{
|
||||
|
||||
var item = new Item(itemInfo.First, Vector2.Zero, null);
|
||||
|
||||
var inventory = itemInfo.Second as Inventory;
|
||||
inventory.TryPutItem(item, null, false);
|
||||
}
|
||||
//!!!!!!!!!!!!!!!!!!!!!!
|
||||
new Item(itemInfo.First, itemInfo.Second, null);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ItemRemover
|
||||
{
|
||||
private Queue<Item> removeQueue;
|
||||
|
||||
public ItemRemover()
|
||||
{
|
||||
removeQueue = new Queue<Item>();
|
||||
}
|
||||
|
||||
public void QueueItem(Item item)
|
||||
{
|
||||
removeQueue.Enqueue(item);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
while (removeQueue.Count > 0)
|
||||
{
|
||||
var item = removeQueue.Dequeue();
|
||||
|
||||
item.Remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user