Fixed wire drop/connect bugs, fixed powertransfer signal StackOverflowException, inventory icons

This commit is contained in:
Regalis
2015-07-19 17:34:48 +03:00
parent baa207985c
commit 2dd0a60bc4
8 changed files with 88 additions and 37 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

+62 -33
View File
@@ -13,16 +13,54 @@ namespace Subsurface
class CharacterInventory : Inventory class CharacterInventory : Inventory
{ {
private static Texture2D icons;
private Character character; private Character character;
private static LimbSlot[] limbSlots = new LimbSlot[] { private static LimbSlot[] limbSlots = new LimbSlot[] {
LimbSlot.Head, LimbSlot.Torso, LimbSlot.LeftHand, LimbSlot.RightHand, LimbSlot.Legs, LimbSlot.Head, LimbSlot.Torso, LimbSlot.Legs, LimbSlot.LeftHand, LimbSlot.RightHand,
LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any }; LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any, LimbSlot.Any };
private Vector2[] slotPositions;
public CharacterInventory(int capacity, Character character) public CharacterInventory(int capacity, Character character)
: base(capacity) : base(capacity)
{ {
this.character = character; this.character = character;
if (icons == null) icons = Game1.textureLoader.FromFile("Content/UI/inventoryIcons.png");
slotPositions = new Vector2[limbSlots.Length];
int rectWidth = 40, rectHeight = 40;
int spacing = 10;
for (int i = 0; i < slotPositions.Length; i++)
{
switch (i)
{
//head, torso, legs
case 0:
case 1:
case 2:
slotPositions[i] = new Vector2(
spacing,
Game1.GraphicsHeight - (spacing + rectHeight) * (3 - i));
break;
//lefthand, righthand
case 3:
case 4:
slotPositions[i] = new Vector2(
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 3),
Game1.GraphicsHeight - (spacing + rectHeight));
break;
default:
slotPositions[i] = new Vector2(
spacing * (4 + (i - 5)) + rectWidth * (3 + (i - 5)),
Game1.GraphicsHeight - (spacing + rectHeight));
break;
}
}
} }
protected override void DropItem(Item item) protected override void DropItem(Item item)
@@ -181,47 +219,38 @@ namespace Subsurface
doubleClickedItem = null; doubleClickedItem = null;
int rectWidth = 40, rectHeight = 40; int rectWidth = 40, rectHeight = 40;
int spacing = 10;
Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight); Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight);
Rectangle draggingItemSlot = slotRect; Rectangle draggingItemSlot = slotRect;
for (int i = 0; i < capacity; i++) for (int i = 0; i < capacity; i++)
{ {
int x, y; slotRect.X = (int)slotPositions[i].X;
switch (i) slotRect.Y = (int)slotPositions[i].Y;
{
//head if (i==1) //head
case 0: {
//legs spriteBatch.Draw(icons, new Vector2(slotRect.Center.X, slotRect.Center.Y),
case 4: new Rectangle(0,0,56,128), Color.White*0.7f, 0.0f,
x = spacing * 2 + rectWidth; new Vector2(28.0f, 64.0f), Vector2.One,
y = Game1.GraphicsHeight - (spacing + rectHeight) * ((i == 0) ? 3 : 1); SpriteEffects.None, 0.1f);
break; }
//lefthand else if (i==3 || i==4)
case 2: {
//torso spriteBatch.Draw(icons, new Vector2(slotRect.Center.X, slotRect.Center.Y),
case 1: new Rectangle(92, 41*(4-i), 36, 40), Color.White * 0.7f, 0.0f,
//righthand new Vector2(18.0f, 20.0f), Vector2.One,
case 3: SpriteEffects.None, 0.1f);
x = spacing; }
if (i == 1) x += (spacing + rectWidth); }
if (i == 3) x += (spacing + rectWidth) * 2;
y = Game1.GraphicsHeight - (spacing + rectHeight) * 2; for (int i = 0; i < capacity; i++)
break; {
default: slotRect.X = (int)slotPositions[i].X;
x = spacing * (4 + (i - 5)) + rectWidth * (3 + (i - 5)); slotRect.Y = (int)slotPositions[i].Y;
y = Game1.GraphicsHeight - (spacing + rectHeight);
break;
}
slotRect.X = x;
slotRect.Y = y;
UpdateSlot(spriteBatch, slotRect, i, items[i], false); UpdateSlot(spriteBatch, slotRect, i, items[i], false);
if (draggingItem!=null && draggingItem == items[i]) draggingItemSlot = slotRect; if (draggingItem!=null && draggingItem == items[i]) draggingItemSlot = slotRect;
} }
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition)) if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition))
@@ -141,9 +141,9 @@ namespace Subsurface.Items.Components
{ {
base.ReceiveSignal(signal, connection, sender, power); base.ReceiveSignal(signal, connection, sender, power);
if (connection.Name=="signal") if (connection.Name == "signal")
{ {
connection.SendSignal(signal, item, 0.0f); connection.SendSignal(signal, sender, 0.0f);
} }
} }
@@ -143,6 +143,7 @@ namespace Subsurface.Items.Components
Connection recipient = Wires[i].OtherConnection(this); Connection recipient = Wires[i].OtherConnection(this);
if (recipient == null) continue; if (recipient == null) continue;
if (recipient.item == this.item || recipient.item == sender) continue;
foreach (ItemComponent ic in recipient.item.components) foreach (ItemComponent ic in recipient.item.components)
{ {
+19 -1
View File
@@ -89,11 +89,22 @@ namespace Subsurface.Items.Components
if (connections[0] != null && connections[1] != null) if (connections[0] != null && connections[1] != null)
{ {
item.Drop(null, false); //List<Vector2> prevNodes = new List<Vector2>(Nodes);
foreach (ItemComponent ic in item.components)
{
if (ic == this) continue;
ic.Drop(null);
}
if (item.container != null) item.container.RemoveContained(this.item);
item.body.Enabled = false; item.body.Enabled = false;
isActive = false; isActive = false;
//Nodes = prevNodes;
CleanNodes(); CleanNodes();
} }
@@ -114,6 +125,13 @@ namespace Subsurface.Items.Components
isActive = false; isActive = false;
} }
public override void Drop(Character dropper)
{
ClearConnections();
isActive = false;
}
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
if (Nodes.Count == 0) return; if (Nodes.Count == 0) return;
+1 -1
View File
@@ -714,7 +714,7 @@ namespace Subsurface
if (Vector2.Distance(position, item.SimPosition) > item.prefab.PickDistance) continue; if (Vector2.Distance(position, item.SimPosition) > item.prefab.PickDistance) continue;
dist = Vector2.Distance(pickPosition, item.SimPosition); dist = Vector2.Distance(pickPosition, item.SimPosition);
if ((closest == null || dist < closestDist) && Submarine.CheckVisibility(position, item.SimPosition)==null) if ((closest == null || dist < closestDist))
{ {
closest = item; closest = item;
closestDist = dist; closestDist = dist;
+3
View File
@@ -404,6 +404,9 @@
<Content Include="Content\UI\caret.png"> <Content Include="Content\UI\caret.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\UI\inventoryIcons.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\UI\style.xml"> <Content Include="Content\UI\style.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> <SubType>Designer</SubType>
Binary file not shown.