diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index 8854bdf55..bd9c9af23 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -577,21 +577,7 @@ namespace Barotrauma.Items.Components return (average+100.0f)/2.0f; } - //public bool CheckFailure(Character Character) - //{ - // foreach (Skill skill in requiredSkills) - // { - // int characterLevel = Character.GetSkillLevel(skill.Name); - // if (characterLevel > skill.Level) continue; - - // item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, Character); - // //Item.ApplyStatusEffects(); - // return true; - - // } - - // return false; - //} + public virtual void FlipX() { } public bool HasRequiredContainedItems(bool addMessage) { diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index 50d8b968c..fe71a3d5d 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -470,6 +470,14 @@ namespace Barotrauma.Items.Components wireSprite.Depth + ((item.ID % 100) * 0.00001f)); } + public override void FlipX() + { + for (int i = 0; i < Nodes.Count; i++) + { + Nodes[i] = new Vector2(-Nodes[i].X, Nodes[i].Y); + } + } + public override XElement Save(XElement parentElement) { XElement componentElement = base.Save(parentElement); diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index de112c3d8..f85b87ebc 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -798,6 +798,16 @@ namespace Barotrauma } return true; + } + + public override void FlipX() + { + base.FlipX(); + + foreach (ItemComponent component in components) + { + component.FlipX(); + } } public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) diff --git a/Subsurface/Source/Map/LinkedSubmarine.cs b/Subsurface/Source/Map/LinkedSubmarine.cs index b70672f1d..aef2d6ccf 100644 --- a/Subsurface/Source/Map/LinkedSubmarine.cs +++ b/Subsurface/Source/Map/LinkedSubmarine.cs @@ -108,7 +108,7 @@ namespace Barotrauma { return Vector2.Distance(position, WorldPosition) < 50.0f; } - + public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) { if (!editing || wallVertices == null) return; @@ -212,8 +212,7 @@ namespace Barotrauma } return editingHUD; } - - + private bool Reload(GUIButton button, object obj) { var pathBox = obj as GUITextBox; diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 5265c0cf7..c608941e8 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -510,6 +510,20 @@ namespace Barotrauma entity.isSelected = true; selectedList.Add(entity); } + + public virtual void FlipX() + { + if (Submarine == null) + { + DebugConsole.ThrowError("Couldn't flip MapEntity \""+Name+"\", submarine==null"); + return; + } + + Vector2 relative = WorldPosition - Submarine.WorldPosition; + relative.Y = 0.0f; + + Move(-relative * 2.0f); + } public virtual void DrawEditing(SpriteBatch spriteBatch, Camera cam) {} diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 784d377e5..66648772f 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -496,22 +496,12 @@ namespace Barotrauma Item.UpdateHulls(); List bodyItems = Item.ItemList.FindAll(it => it.Submarine == this && it.body != null); - - List bodyPos = new List(); - for (int i = 0; i < bodyItems.Count; i++) - { - Vector2 relative = bodyItems[i].WorldPosition - WorldPosition; - relative.Y = 0.0f; - - bodyPos.Add(bodyItems[i].Position - relative*2.0f); - } - + foreach (MapEntity e in MapEntity.mapEntityList) { - if (e.MoveWithLevel || e.Submarine != this || e is Item || e is WayPoint) continue; - Vector2 relative = e.WorldPosition - WorldPosition; - relative.Y = 0.0f; - e.Move(-relative * 2.0f); + if (e.MoveWithLevel || e.Submarine != this || e is Item) continue; + + e.FlipX(); if (e is LinkedSubmarine) { @@ -526,26 +516,6 @@ namespace Barotrauma } } - /*foreach (Submarine sub in loaded) - { - if (sub != this && sub.Submarine == this && !parents.Contains(sub)) - { - Vector2 relative = sub.SubBody.Position - SubBody.Position; - relative.X = -relative.X; - sub.SetPosition(relative + SubBody.Position); - sub.FlipX(parents); - } - }*/ - - List subWayPoints = WayPoint.WayPointList.FindAll(wp => wp.Submarine == this); - foreach (WayPoint wp in subWayPoints) - { - Vector2 relative = wp.WorldPosition - WorldPosition; - relative.X = -relative.X * 2.0f; - relative.Y = 0.0f; - wp.Move(relative); - } - for (int i = 0; i < MapEntity.mapEntityList.Count; i++) { if (MapEntity.mapEntityList[i].Submarine != this) continue; @@ -573,30 +543,17 @@ namespace Barotrauma foreach (Item item in Item.ItemList) { - if (item.Submarine != this) continue; - - Items.Components.Wire wire = item.GetComponent(); - - if (wire != null) + if (bodyItems.Contains(item)) { - for (int i = 0; i < wire.Nodes.Count; i++) - { - wire.Nodes[i] = new Vector2(-wire.Nodes[i].X, wire.Nodes[i].Y); - } + item.Submarine = this; + if (Position == Vector2.Zero) item.Move(-HiddenSubPosition); + } + else if (item.Submarine != this) + { + continue; } - if (item.Submarine != this || bodyItems.Contains(item)) continue; - - Vector2 relative = item.WorldPosition - WorldPosition; - relative.Y = 0.0f; - - item.Move(-relative * 2.0f); - } - - for (int i = 0; i < bodyItems.Count; i++) - { - bodyItems[i].SetTransform(ConvertUnits.ToSimUnits(bodyPos[i]), bodyItems[i].body.Rotation); - bodyItems[i].Submarine = this; + item.FlipX(); } Item.UpdateHulls();