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
@@ -124,6 +124,8 @@ namespace Barotrauma
} }
set set
{ {
if (info != null && info != value) info.Remove();
info = value; info = value;
if (info != null) info.Character = this; if (info != null) info.Character = this;
} }
@@ -1685,6 +1687,8 @@ namespace Barotrauma
{ {
base.Remove(); base.Remove();
if (info != null) info.Remove();
CharacterList.Remove(this); CharacterList.Remove(this);
if (controlled == this) controlled = null; if (controlled == this) controlled = null;
@@ -325,5 +325,10 @@ namespace Barotrauma
parentElement.Add(charElement); parentElement.Add(charElement);
return charElement; return charElement;
} }
public void Remove()
{
if (headSprite != null) headSprite.Remove();
}
} }
} }
+2 -1
View File
@@ -286,7 +286,6 @@ namespace Barotrauma
damagedSpritePath = damagedSpritePath.Replace("[HEADID]", character.Info.HeadSpriteId.ToString()); damagedSpritePath = damagedSpritePath.Replace("[HEADID]", character.Info.HeadSpriteId.ToString());
} }
damagedSprite = new Sprite(subElement, "", damagedSpritePath); damagedSprite = new Sprite(subElement, "", damagedSpritePath);
break; break;
case "attack": case "attack":
@@ -546,6 +545,8 @@ namespace Barotrauma
public void Remove() public void Remove()
{ {
sprite.Remove(); sprite.Remove();
if (damagedSprite != null) damagedSprite.Remove();
body.Remove(); body.Remove();
if (bodyShapeTexture != null) if (bodyShapeTexture != null)
+3 -3
View File
@@ -349,16 +349,16 @@ namespace Barotrauma.Items.Components
UpdateConvexHulls(); UpdateConvexHulls();
} }
public override void Remove() protected override void RemoveComponentSpecific()
{ {
base.Remove(); base.RemoveComponentSpecific();
GameMain.World.RemoveBody(body.FarseerBody); GameMain.World.RemoveBody(body.FarseerBody);
if (linkedGap!=null) linkedGap.Remove(); if (linkedGap!=null) linkedGap.Remove();
doorSprite.Remove(); doorSprite.Remove();
weldedSprite.Remove(); if (weldedSprite != null) weldedSprite.Remove();
if (convexHull!=null) convexHull.Remove(); if (convexHull!=null) convexHull.Remove();
if (convexHull2 != null) convexHull2.Remove(); if (convexHull2 != null) convexHull2.Remove();
@@ -470,12 +470,19 @@ namespace Barotrauma.Items.Components
return false; return false;
} }
public virtual void Remove() public void Remove()
{ {
if (loopingSound!=null) if (loopingSound != null)
{ {
Sounds.SoundManager.Stop(loopingSoundIndex); Sounds.SoundManager.Stop(loopingSoundIndex);
} }
RemoveComponentSpecific();
}
protected virtual void RemoveComponentSpecific()
{
} }
public bool HasRequiredSkills(Character character) public bool HasRequiredSkills(Character character)
@@ -247,9 +247,9 @@ namespace Barotrauma.Items.Components
itemIds = null; itemIds = null;
} }
public override void Remove() protected override void RemoveComponentSpecific()
{ {
base.Remove(); base.RemoveComponentSpecific();
foreach (Item item in Inventory.Items) foreach (Item item in Inventory.Items)
{ {
@@ -321,6 +321,13 @@ namespace Barotrauma.Items.Components
new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen); 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) public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{ {
message.Write(IsActive); message.Write(IsActive);
@@ -119,11 +119,6 @@ namespace Barotrauma.Items.Components
} }
} }
public override void Remove()
{
base.Remove();
}
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message) public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{ {
foreach (Connection c in Connections) foreach (Connection c in Connections)
@@ -145,9 +145,9 @@ namespace Barotrauma.Items.Components
//GUI.DrawLine(spriteBatch, center - Vector2.One * range, center + Vector2.One * range, lightColor); //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(); light.Remove();
} }
@@ -46,9 +46,9 @@ namespace Barotrauma.Items.Components
} }
} }
public override void Remove() protected override void RemoveComponentSpecific()
{ {
base.Remove(); base.RemoveComponentSpecific();
list.Remove(this); list.Remove(this);
} }
@@ -461,11 +461,11 @@ namespace Barotrauma.Items.Components
} }
public override void Remove() protected override void RemoveComponentSpecific()
{ {
ClearConnections(); ClearConnections();
base.Remove(); base.RemoveComponentSpecific();
} }
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message) public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
+2 -2
View File
@@ -294,9 +294,9 @@ namespace Barotrauma.Items.Components
return availablePower; return availablePower;
} }
public override void Remove() protected override void RemoveComponentSpecific()
{ {
base.Remove(); base.RemoveComponentSpecific();
barrelSprite.Remove(); barrelSprite.Remove();
} }
+17 -7
View File
@@ -23,7 +23,7 @@ namespace Barotrauma.Items.Components
class Wearable : Pickable class Wearable : Pickable
{ {
WearableSprite[] wearableSprite; WearableSprite[] wearableSprites;
LimbType[] limbType; LimbType[] limbType;
Limb[] limb; Limb[] limb;
@@ -62,7 +62,7 @@ namespace Barotrauma.Items.Components
var sprites = element.Elements().Where(x => x.Name.ToString() == "sprite").ToList(); var sprites = element.Elements().Where(x => x.Name.ToString() == "sprite").ToList();
int spriteCount = sprites.Count(); int spriteCount = sprites.Count();
wearableSprite = new WearableSprite[spriteCount]; wearableSprites = new WearableSprite[spriteCount];
limbType = new LimbType[spriteCount]; limbType = new LimbType[spriteCount];
limb = new Limb[spriteCount]; limb = new Limb[spriteCount];
@@ -85,7 +85,7 @@ namespace Barotrauma.Items.Components
spritePath = Path.GetDirectoryName( item.Prefab.ConfigFile)+"/"+spritePath; spritePath = Path.GetDirectoryName( item.Prefab.ConfigFile)+"/"+spritePath;
var sprite = new Sprite(subElement, "", 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), (LimbType)Enum.Parse(typeof(LimbType),
ToolBox.GetAttributeString(subElement, "depthlimb", "None"), true)); ToolBox.GetAttributeString(subElement, "depthlimb", "None"), true));
@@ -99,7 +99,7 @@ namespace Barotrauma.Items.Components
public override void Equip(Character character) public override void Equip(Character character)
{ {
picker = 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]); Limb equipLimb = character.AnimController.GetLimb(limbType[i]);
if (equipLimb == null) continue; if (equipLimb == null) continue;
@@ -118,7 +118,7 @@ namespace Barotrauma.Items.Components
limb[i] = equipLimb; limb[i] = equipLimb;
equipLimb.WearingItem = this; 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) public override void Unequip(Character character)
{ {
if (picker == null) return; 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]); Limb equipLimb = character.AnimController.GetLimb(limbType[i]);
if (equipLimb == null) continue; if (equipLimb == null) continue;
@@ -168,12 +168,22 @@ namespace Barotrauma.Items.Components
PlaySound(ActionType.OnWearing, picker.WorldPosition); PlaySound(ActionType.OnWearing, picker.WorldPosition);
if (containedItems == null) return; 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; if (containedItems[j] == null) continue;
containedItems[j].ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker); 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();
}
}
} }
} }
@@ -122,6 +122,8 @@ namespace Barotrauma.Lights
public void Remove() public void Remove()
{ {
if (LightSprite != null) LightSprite.Remove();
GameMain.LightManager.RemoveLight(this); GameMain.LightManager.RemoveLight(this);
} }
} }
+7
View File
@@ -62,6 +62,11 @@ namespace Barotrauma
get { return file; } get { return file; }
} }
public override string ToString()
{
return FilePath + ": " + sourceRect;
}
public Sprite(XElement element, string path = "", string file = "") public Sprite(XElement element, string path = "", string file = "")
{ {
if (file == "") if (file == "")
@@ -104,6 +109,8 @@ namespace Barotrauma
size.Y *= sourceRect.Height; size.Y *= sourceRect.Height;
Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f); Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f);
list.Add(this);
} }
public Sprite(string newFile, Vector2 newOrigin) public Sprite(string newFile, Vector2 newOrigin)
Binary file not shown.