From 12d1692bb5cae6ca71bd2c01c2ef584ffdbdaf0d Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Fri, 2 Mar 2018 11:13:11 +0200 Subject: [PATCH] Wearables can attach lightsources to limbs --- .../Content/Items/Diving/divinggear.xml | 6 +++++- .../Items/Components/Signal/LightComponent.cs | 12 +++++++---- .../Source/Items/Components/Wearable.cs | 20 ++++++++++++++++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml b/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml index b207683a0..00a8a928f 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Diving/divinggear.xml @@ -81,7 +81,11 @@ - + + + + + diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs index dcc4b8749..6c79d771f 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs @@ -21,6 +21,8 @@ namespace Barotrauma.Items.Components private bool castShadows; + public PhysicsBody ParentBody; + [Editable(0.0f, 2048.0f), Serialize(100.0f, true)] public float Range { @@ -133,15 +135,17 @@ namespace Barotrauma.Items.Components light.Color = Color.Transparent; return; } - light.Position = item.Position; + light.Position = ParentBody != null ? ParentBody.Position : item.Position; #endif - if (item.body != null) + PhysicsBody body = ParentBody ?? item.body; + + if (body != null) { #if CLIENT - light.Rotation = item.body.Dir > 0.0f ? item.body.Rotation : item.body.Rotation - MathHelper.Pi; + light.Rotation = body.Dir > 0.0f ? body.Rotation : body.Rotation - MathHelper.Pi; #endif - if (!item.body.Enabled) + if (!body.Enabled) { #if CLIENT light.Color = Color.Transparent; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Wearable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Wearable.cs index 41bd2b074..f70ebab2d 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Wearable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Wearable.cs @@ -15,6 +15,8 @@ namespace Barotrauma.Items.Components public readonly bool InheritLimbDepth; public readonly LimbType DepthLimb; + public LightComponent LightComponent; + public readonly Wearable WearableComponent; public readonly string Sound; @@ -80,6 +82,14 @@ namespace Barotrauma.Items.Components subElement.GetAttributeBool("inheritlimbdepth", true), (LimbType)Enum.Parse(typeof(LimbType), subElement.GetAttributeString("depthlimb", "None"), true), sound); + foreach (XElement lightElement in subElement.Elements()) + { + if (lightElement.Name.ToString().ToLowerInvariant() != "lightcomponent") continue; + wearableSprites[i].LightComponent = new LightComponent(item, lightElement); + wearableSprites[i].LightComponent.Parent = this; + item.components.Add(wearableSprites[i].LightComponent); + } + i++; break; case "damagemodifier": @@ -98,8 +108,11 @@ namespace Barotrauma.Items.Components if (equipLimb == null) continue; item.body.Enabled = false; - IsActive = true; + if (wearableSprites[i].LightComponent != null) + { + wearableSprites[i].LightComponent.ParentBody = equipLimb.body; + } limb[i] = equipLimb; if (!equipLimb.WearingItems.Contains(wearableSprites[i])) @@ -127,6 +140,11 @@ namespace Barotrauma.Items.Components Limb equipLimb = character.AnimController.GetLimb(limbType[i]); if (equipLimb == null) continue; + if (wearableSprites[i].LightComponent != null) + { + wearableSprites[i].LightComponent.ParentBody = null; + } + equipLimb.WearingItems.RemoveAll(w => w != null && w == wearableSprites[i]); limb[i] = null;