Limbs with no sprite don't cause the game to crash anymore, lightsources attached to a limb are drawn at the interpolated position (= DrawPosition) of the limb, lightTexture origin is flipped on the X-axis when parent limb flips
This commit is contained in:
@@ -372,7 +372,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
foreach (Limb limb in Limbs)
|
foreach (Limb limb in Limbs)
|
||||||
{
|
{
|
||||||
limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f;
|
if (limb.sprite != null)
|
||||||
|
limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f;
|
||||||
}
|
}
|
||||||
|
|
||||||
Limb torso = GetLimb(LimbType.Torso);
|
Limb torso = GetLimb(LimbType.Torso);
|
||||||
@@ -638,27 +639,31 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < Limbs.Length; i++)
|
foreach (Limb limb in Limbs)
|
||||||
{
|
{
|
||||||
if (Limbs[i] == null) continue;
|
if (limb == null) continue;
|
||||||
|
|
||||||
Vector2 spriteOrigin = Limbs[i].sprite.Origin;
|
if (limb.sprite != null)
|
||||||
spriteOrigin.X = Limbs[i].sprite.SourceRect.Width - spriteOrigin.X;
|
|
||||||
Limbs[i].sprite.Origin = spriteOrigin;
|
|
||||||
|
|
||||||
Limbs[i].Dir = Dir;
|
|
||||||
|
|
||||||
if (Limbs[i].LightSource != null)
|
|
||||||
{
|
{
|
||||||
Limbs[i].LightSource.SpriteEffect = (dir == Direction.Left) ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
Vector2 spriteOrigin = limb.sprite.Origin;
|
||||||
|
spriteOrigin.X = limb.sprite.SourceRect.Width - spriteOrigin.X;
|
||||||
|
limb.sprite.Origin = spriteOrigin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Limbs[i].pullJoint == null) continue;
|
limb.Dir = Dir;
|
||||||
|
|
||||||
Limbs[i].pullJoint.LocalAnchorA =
|
if (limb.LightSource != null)
|
||||||
new Vector2(
|
{
|
||||||
-Limbs[i].pullJoint.LocalAnchorA.X,
|
limb.LightSource.FlipX();
|
||||||
Limbs[i].pullJoint.LocalAnchorA.Y);
|
}
|
||||||
|
|
||||||
|
if (limb.pullJoint != null)
|
||||||
|
{
|
||||||
|
limb.pullJoint.LocalAnchorA =
|
||||||
|
new Vector2(
|
||||||
|
-limb.pullJoint.LocalAnchorA.X,
|
||||||
|
limb.pullJoint.LocalAnchorA.Y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -423,7 +423,6 @@ namespace Barotrauma
|
|||||||
if (LightSource != null)
|
if (LightSource != null)
|
||||||
{
|
{
|
||||||
LightSource.ParentSub = body.Submarine;
|
LightSource.ParentSub = body.Submarine;
|
||||||
LightSource.Position = Position;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!character.IsDead) damage = Math.Max(0.0f, damage-deltaTime*0.1f);
|
if (!character.IsDead) damage = Math.Max(0.0f, damage-deltaTime*0.1f);
|
||||||
@@ -504,6 +503,12 @@ namespace Barotrauma
|
|||||||
body.UpdateDrawPosition();
|
body.UpdateDrawPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LightSource != null)
|
||||||
|
{
|
||||||
|
LightSource.Position = body.DrawPosition;
|
||||||
|
LightSource.Rotation = body.DrawRotation;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (WearableSprite wearable in wearingItems)
|
foreach (WearableSprite wearable in wearingItems)
|
||||||
{
|
{
|
||||||
SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
||||||
@@ -528,29 +533,27 @@ namespace Barotrauma
|
|||||||
-body.DrawRotation,
|
-body.DrawRotation,
|
||||||
scale, spriteEffect, depth);
|
scale, spriteEffect, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (damage>0.0f && damagedSprite!=null && !hideLimb)
|
if (damage > 0.0f && damagedSprite != null && !hideLimb)
|
||||||
{
|
{
|
||||||
SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
SpriteEffects spriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
||||||
|
|
||||||
float depth = sprite.Depth - 0.0000015f;
|
float depth = sprite.Depth - 0.0000015f;
|
||||||
|
|
||||||
damagedSprite.Draw(spriteBatch,
|
damagedSprite.Draw(spriteBatch,
|
||||||
new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
|
new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
|
||||||
color*Math.Min(damage/50.0f,1.0f), sprite.Origin,
|
color * Math.Min(damage / 50.0f, 1.0f), sprite.Origin,
|
||||||
-body.DrawRotation,
|
-body.DrawRotation,
|
||||||
1.0f, spriteEffect, depth);
|
1.0f, spriteEffect, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GameMain.DebugDraw) return;
|
if (!GameMain.DebugDraw) return;
|
||||||
|
|
||||||
if (pullJoint!=null)
|
if (pullJoint != null)
|
||||||
{
|
{
|
||||||
Vector2 pos = ConvertUnits.ToDisplayUnits(pullJoint.WorldAnchorB);
|
Vector2 pos = ConvertUnits.ToDisplayUnits(pullJoint.WorldAnchorB);
|
||||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true);
|
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,8 @@ namespace Barotrauma.Lights
|
|||||||
if (NeedsHullUpdate)
|
if (NeedsHullUpdate)
|
||||||
{
|
{
|
||||||
var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub);
|
var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub);
|
||||||
chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
if (fullChList != null)
|
||||||
|
chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//light is outside, convexhull inside a sub
|
//light is outside, convexhull inside a sub
|
||||||
@@ -299,7 +300,7 @@ namespace Barotrauma.Lights
|
|||||||
if (ParentSub != null) drawPos += ParentSub.DrawPosition;
|
if (ParentSub != null) drawPos += ParentSub.DrawPosition;
|
||||||
|
|
||||||
drawPos.Y = -drawPos.Y;
|
drawPos.Y = -drawPos.Y;
|
||||||
|
|
||||||
if (range > 1.0f)
|
if (range > 1.0f)
|
||||||
{
|
{
|
||||||
if (overrideLightTexture == null)
|
if (overrideLightTexture == null)
|
||||||
@@ -326,6 +327,24 @@ namespace Barotrauma.Lights
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void FlipX()
|
||||||
|
{
|
||||||
|
SpriteEffect = SpriteEffect == SpriteEffects.None ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
||||||
|
if (LightSprite != null)
|
||||||
|
{
|
||||||
|
Vector2 lightOrigin = LightSprite.Origin;
|
||||||
|
lightOrigin.X = LightSprite.SourceRect.Width - lightOrigin.X;
|
||||||
|
LightSprite.Origin = lightOrigin;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overrideLightTexture != null)
|
||||||
|
{
|
||||||
|
Vector2 lightOrigin = overrideLightTexture.Origin;
|
||||||
|
lightOrigin.X = overrideLightTexture.SourceRect.Width - lightOrigin.X;
|
||||||
|
overrideLightTexture.Origin = lightOrigin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Remove()
|
public void Remove()
|
||||||
{
|
{
|
||||||
if (LightSprite != null) LightSprite.Remove();
|
if (LightSprite != null) LightSprite.Remove();
|
||||||
|
|||||||
@@ -425,6 +425,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
UpdateDrawPosition();
|
UpdateDrawPosition();
|
||||||
|
|
||||||
|
if (sprite == null) return;
|
||||||
|
|
||||||
SpriteEffects spriteEffect = (dir == 1.0f) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
SpriteEffects spriteEffect = (dir == 1.0f) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
||||||
|
|
||||||
if (GameMain.DebugDraw && !body.Awake)
|
if (GameMain.DebugDraw && !body.Awake)
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace Barotrauma
|
|||||||
texturePaths = new List<string>();
|
texturePaths = new List<string>();
|
||||||
foreach (Limb limb in editingCharacter.AnimController.Limbs)
|
foreach (Limb limb in editingCharacter.AnimController.Limbs)
|
||||||
{
|
{
|
||||||
if (texturePaths.Contains(limb.sprite.FilePath)) continue;
|
if (limb.sprite==null || texturePaths.Contains(limb.sprite.FilePath)) continue;
|
||||||
textures.Add(limb.sprite.Texture);
|
textures.Add(limb.sprite.Texture);
|
||||||
texturePaths.Add(limb.sprite.FilePath);
|
texturePaths.Add(limb.sprite.FilePath);
|
||||||
}
|
}
|
||||||
@@ -160,7 +160,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
foreach (Limb limb in editingCharacter.AnimController.Limbs)
|
foreach (Limb limb in editingCharacter.AnimController.Limbs)
|
||||||
{
|
{
|
||||||
if (limb.sprite.FilePath != texturePaths[i]) continue;
|
if (limb.sprite == null || limb.sprite.FilePath != texturePaths[i]) continue;
|
||||||
Rectangle rect = limb.sprite.SourceRect;
|
Rectangle rect = limb.sprite.SourceRect;
|
||||||
rect.X += x;
|
rect.X += x;
|
||||||
rect.Y += y;
|
rect.Y += y;
|
||||||
|
|||||||
Reference in New Issue
Block a user