Cleaned up the flipping logic a bit, overridable MapEntity.FlipX method

This commit is contained in:
Regalis
2016-09-30 19:48:56 +03:00
parent 0da9f58325
commit 8e8a0e57f0
6 changed files with 47 additions and 73 deletions

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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)

View File

@@ -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;

View File

@@ -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) {}

View File

@@ -496,22 +496,12 @@ namespace Barotrauma
Item.UpdateHulls();
List<Item> bodyItems = Item.ItemList.FindAll(it => it.Submarine == this && it.body != null);
List<Vector2> bodyPos = new List<Vector2>();
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<WayPoint> 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<Items.Components.Wire>();
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();