Option to make wearable sprites use the depth of the sprite instead of using the depth of the limb it's attached to

This commit is contained in:
Joonas Rikkonen
2017-08-10 18:19:06 +03:00
parent b70f6fb3ca
commit fd844fd696
2 changed files with 21 additions and 15 deletions
@@ -88,15 +88,19 @@ namespace Barotrauma
Vector2 origin = wearable.Sprite.Origin; Vector2 origin = wearable.Sprite.Origin;
if (body.Dir == -1.0f) origin.X = wearable.Sprite.SourceRect.Width - origin.X; if (body.Dir == -1.0f) origin.X = wearable.Sprite.SourceRect.Width - origin.X;
float depth = wearable.Sprite.Depth;
float depth = sprite.Depth - 0.000001f; if (wearable.InheritLimbDepth)
if (wearable.DepthLimb != LimbType.None)
{ {
Limb depthLimb = character.AnimController.GetLimb(wearable.DepthLimb); depth = sprite.Depth - 0.000001f;
if (depthLimb != null) if (wearable.DepthLimb != LimbType.None)
{ {
depth = depthLimb.sprite.Depth - 0.000001f; Limb depthLimb = character.AnimController.GetLimb(wearable.DepthLimb);
if (depthLimb != null)
{
depth = depthLimb.sprite.Depth - 0.000001f;
}
} }
} }
@@ -8,18 +8,19 @@ namespace Barotrauma.Items.Components
{ {
class WearableSprite class WearableSprite
{ {
public Sprite Sprite; public readonly Sprite Sprite;
public bool HideLimb; public readonly bool HideLimb;
public LimbType DepthLimb; public readonly bool InheritLimbDepth;
public readonly LimbType DepthLimb;
public Wearable WearableComponent; public readonly Wearable WearableComponent;
public WearableSprite(Wearable item, Sprite sprite, bool hideLimb, LimbType depthLimb = LimbType.None) public WearableSprite(Wearable item, Sprite sprite, bool hideLimb, bool inheritLimbDepth = true, LimbType depthLimb = LimbType.None)
{ {
WearableComponent = item; WearableComponent = item;
Sprite = sprite; Sprite = sprite;
HideLimb = hideLimb; HideLimb = hideLimb;
InheritLimbDepth = inheritLimbDepth;
DepthLimb = depthLimb; DepthLimb = depthLimb;
} }
} }
@@ -88,9 +89,10 @@ 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);
wearableSprites[i] = new WearableSprite(this, sprite, ToolBox.GetAttributeBool(subElement, "hidelimb", false), wearableSprites[i] = new WearableSprite(this, sprite,
(LimbType)Enum.Parse(typeof(LimbType), ToolBox.GetAttributeBool(subElement, "hidelimb", false),
ToolBox.GetAttributeString(subElement, "depthlimb", "None"), true)); ToolBox.GetAttributeBool(subElement, "inheritlimbdepth", true),
(LimbType)Enum.Parse(typeof(LimbType), ToolBox.GetAttributeString(subElement, "depthlimb", "None"), true));
limbType[i] = (LimbType)Enum.Parse(typeof(LimbType), limbType[i] = (LimbType)Enum.Parse(typeof(LimbType),
ToolBox.GetAttributeString(subElement, "limb", "Head"), true); ToolBox.GetAttributeString(subElement, "limb", "Head"), true);