Fixed a bunch of sprites not being removed

This commit is contained in:
Regalis
2016-02-19 15:58:43 +02:00
parent c59a2b5207
commit 9cfbbb44ed
16 changed files with 68 additions and 30 deletions

View File

@@ -124,6 +124,8 @@ namespace Barotrauma
}
set
{
if (info != null && info != value) info.Remove();
info = value;
if (info != null) info.Character = this;
}
@@ -1685,6 +1687,8 @@ namespace Barotrauma
{
base.Remove();
if (info != null) info.Remove();
CharacterList.Remove(this);
if (controlled == this) controlled = null;

View File

@@ -325,5 +325,10 @@ namespace Barotrauma
parentElement.Add(charElement);
return charElement;
}
public void Remove()
{
if (headSprite != null) headSprite.Remove();
}
}
}

View File

@@ -286,7 +286,6 @@ namespace Barotrauma
damagedSpritePath = damagedSpritePath.Replace("[HEADID]", character.Info.HeadSpriteId.ToString());
}
damagedSprite = new Sprite(subElement, "", damagedSpritePath);
break;
case "attack":
@@ -546,6 +545,8 @@ namespace Barotrauma
public void Remove()
{
sprite.Remove();
if (damagedSprite != null) damagedSprite.Remove();
body.Remove();
if (bodyShapeTexture != null)

View File

@@ -349,16 +349,16 @@ namespace Barotrauma.Items.Components
UpdateConvexHulls();
}
public override void Remove()
protected override void RemoveComponentSpecific()
{
base.Remove();
base.RemoveComponentSpecific();
GameMain.World.RemoveBody(body.FarseerBody);
if (linkedGap!=null) linkedGap.Remove();
doorSprite.Remove();
weldedSprite.Remove();
if (weldedSprite != null) weldedSprite.Remove();
if (convexHull!=null) convexHull.Remove();
if (convexHull2 != null) convexHull2.Remove();

View File

@@ -470,12 +470,19 @@ namespace Barotrauma.Items.Components
return false;
}
public virtual void Remove()
public void Remove()
{
if (loopingSound!=null)
if (loopingSound != null)
{
Sounds.SoundManager.Stop(loopingSoundIndex);
}
RemoveComponentSpecific();
}
protected virtual void RemoveComponentSpecific()
{
}
public bool HasRequiredSkills(Character character)

View File

@@ -247,9 +247,9 @@ namespace Barotrauma.Items.Components
itemIds = null;
}
public override void Remove()
protected override void RemoveComponentSpecific()
{
base.Remove();
base.RemoveComponentSpecific();
foreach (Item item in Inventory.Items)
{

View File

@@ -321,6 +321,13 @@ namespace Barotrauma.Items.Components
new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen);
}
protected override void RemoveComponentSpecific()
{
if (pingCircle!=null) pingCircle.Remove();
if (screenOverlay != null) screenOverlay.Remove();
}
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
message.Write(IsActive);

View File

@@ -118,12 +118,7 @@ namespace Barotrauma.Items.Components
loadedConnections[i].wireId.CopyTo(Connections[i].wireId, 0);
}
}
public override void Remove()
{
base.Remove();
}
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
foreach (Connection c in Connections)

View File

@@ -145,9 +145,9 @@ namespace Barotrauma.Items.Components
//GUI.DrawLine(spriteBatch, center - Vector2.One * range, center + Vector2.One * range, lightColor);
}
public override void Remove()
protected override void RemoveComponentSpecific()
{
base.Remove();
base.RemoveComponentSpecific();
light.Remove();
}

View File

@@ -46,9 +46,9 @@ namespace Barotrauma.Items.Components
}
}
public override void Remove()
protected override void RemoveComponentSpecific()
{
base.Remove();
base.RemoveComponentSpecific();
list.Remove(this);
}

View File

@@ -461,11 +461,11 @@ namespace Barotrauma.Items.Components
}
public override void Remove()
protected override void RemoveComponentSpecific()
{
ClearConnections();
base.Remove();
base.RemoveComponentSpecific();
}
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)

View File

@@ -294,9 +294,9 @@ namespace Barotrauma.Items.Components
return availablePower;
}
public override void Remove()
protected override void RemoveComponentSpecific()
{
base.Remove();
base.RemoveComponentSpecific();
barrelSprite.Remove();
}

View File

@@ -23,7 +23,7 @@ namespace Barotrauma.Items.Components
class Wearable : Pickable
{
WearableSprite[] wearableSprite;
WearableSprite[] wearableSprites;
LimbType[] limbType;
Limb[] limb;
@@ -62,7 +62,7 @@ namespace Barotrauma.Items.Components
var sprites = element.Elements().Where(x => x.Name.ToString() == "sprite").ToList();
int spriteCount = sprites.Count();
wearableSprite = new WearableSprite[spriteCount];
wearableSprites = new WearableSprite[spriteCount];
limbType = new LimbType[spriteCount];
limb = new Limb[spriteCount];
@@ -85,7 +85,7 @@ namespace Barotrauma.Items.Components
spritePath = Path.GetDirectoryName( item.Prefab.ConfigFile)+"/"+spritePath;
var sprite = new Sprite(subElement, "", spritePath);
wearableSprite[i] = new WearableSprite(sprite, ToolBox.GetAttributeBool(subElement, "hidelimb", false),
wearableSprites[i] = new WearableSprite(sprite, ToolBox.GetAttributeBool(subElement, "hidelimb", false),
(LimbType)Enum.Parse(typeof(LimbType),
ToolBox.GetAttributeString(subElement, "depthlimb", "None"), true));
@@ -99,7 +99,7 @@ namespace Barotrauma.Items.Components
public override void Equip(Character character)
{
picker = character;
for (int i = 0; i < wearableSprite.Length; i++ )
for (int i = 0; i < wearableSprites.Length; i++ )
{
Limb equipLimb = character.AnimController.GetLimb(limbType[i]);
if (equipLimb == null) continue;
@@ -118,7 +118,7 @@ namespace Barotrauma.Items.Components
limb[i] = equipLimb;
equipLimb.WearingItem = this;
equipLimb.WearingItemSprite = wearableSprite[i];
equipLimb.WearingItemSprite = wearableSprites[i];
}
}
@@ -135,7 +135,7 @@ namespace Barotrauma.Items.Components
public override void Unequip(Character character)
{
if (picker == null) return;
for (int i = 0; i < wearableSprite.Length; i++)
for (int i = 0; i < wearableSprites.Length; i++)
{
Limb equipLimb = character.AnimController.GetLimb(limbType[i]);
if (equipLimb == null) continue;
@@ -162,18 +162,28 @@ namespace Barotrauma.Items.Components
item.SetTransform(picker.SimPosition, 0.0f);
Item[] containedItems = item.ContainedItems;
ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker);
PlaySound(ActionType.OnWearing, picker.WorldPosition);
if (containedItems == null) return;
for (int j = 0; j<containedItems.Length; j++)
for (int j = 0; j < containedItems.Length; j++)
{
if (containedItems[j] == null) continue;
containedItems[j].ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker);
}
}
protected override void RemoveComponentSpecific()
{
base.RemoveComponentSpecific();
foreach (WearableSprite wearableSprite in wearableSprites)
{
if (wearableSprite != null && wearableSprite.Sprite != null) wearableSprite.Sprite.Remove();
}
}
}
}

View File

@@ -122,6 +122,8 @@ namespace Barotrauma.Lights
public void Remove()
{
if (LightSprite != null) LightSprite.Remove();
GameMain.LightManager.RemoveLight(this);
}
}

View File

@@ -62,6 +62,11 @@ namespace Barotrauma
get { return file; }
}
public override string ToString()
{
return FilePath + ": " + sourceRect;
}
public Sprite(XElement element, string path = "", string file = "")
{
if (file == "")
@@ -104,6 +109,8 @@ namespace Barotrauma
size.Y *= sourceRect.Height;
Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f);
list.Add(this);
}
public Sprite(string newFile, Vector2 newOrigin)