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:
Regalis
2015-12-28 13:21:24 +02:00
parent 8c032d8368
commit 92d396e6b2
69 changed files with 1264 additions and 455 deletions

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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)));

View 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;
}
}
}

View File

@@ -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);
//}
}
}
}