From bdcd894b83fde11dfcbaebe82a8fde61ed450227 Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Sat, 1 Oct 2016 16:41:16 -0300 Subject: [PATCH] Flipping sprites of staircases & engine --- Subsurface/Content/Items/Engine/engine.xml | 4 +- Subsurface/Content/Map/StructurePrefabs.xml | 16 ++--- .../Source/Events/Missions/CombatMission.cs | 2 +- Subsurface/Source/Items/Item.cs | 62 +++++++++++-------- Subsurface/Source/Items/ItemPrefab.cs | 10 +++ Subsurface/Source/Map/Structure.cs | 16 ++++- Subsurface/Source/Map/StructurePrefab.cs | 8 +++ Subsurface/Source/Map/Submarine.cs | 2 +- 8 files changed, 81 insertions(+), 39 deletions(-) diff --git a/Subsurface/Content/Items/Engine/engine.xml b/Subsurface/Content/Items/Engine/engine.xml index 43d1d64a6..eeac7b92a 100644 --- a/Subsurface/Content/Items/Engine/engine.xml +++ b/Subsurface/Content/Items/Engine/engine.xml @@ -8,7 +8,7 @@ pickthroughwalls="true" pickdistance="150"> - + @@ -36,7 +36,7 @@ pickthroughwalls="true" pickdistance="150"> - + diff --git a/Subsurface/Content/Map/StructurePrefabs.xml b/Subsurface/Content/Map/StructurePrefabs.xml index b17970684..5d045427b 100644 --- a/Subsurface/Content/Map/StructurePrefabs.xml +++ b/Subsurface/Content/Map/StructurePrefabs.xml @@ -49,19 +49,19 @@ - + - + - + - + - + - + - + - + diff --git a/Subsurface/Source/Events/Missions/CombatMission.cs b/Subsurface/Source/Events/Missions/CombatMission.cs index 341cfe143..9884becd1 100644 --- a/Subsurface/Source/Events/Missions/CombatMission.cs +++ b/Subsurface/Source/Events/Missions/CombatMission.cs @@ -67,7 +67,7 @@ namespace Barotrauma TeamASub = Submarine.MainSubs[0]; TeamBSub = Submarine.MainSubs[1]; TeamBSub.SetPosition(Level.Loaded.EndPosition - new Vector2(0.0f, 2000.0f)); - //TeamASub.FlipX(); + TeamBSub.FlipX(); foreach (Submarine submarine in Submarine.Loaded) { diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index f85b87ebc..2ee92427d 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -40,6 +40,8 @@ namespace Barotrauma public Hull CurrentHull; + public SpriteEffects SpriteEffects = SpriteEffects.None; + //components that determine the functionality of the item public List components; public List drawableComponents; @@ -798,16 +800,21 @@ namespace Barotrauma } return true; - } - - public override void FlipX() - { - base.FlipX(); - - foreach (ItemComponent component in components) + } + + public override void FlipX() + { + base.FlipX(); + + if (prefab.CanSpriteFlipX) { - component.FlipX(); - } + SpriteEffects ^= SpriteEffects.FlipHorizontally; + } + + foreach (ItemComponent component in components) + { + component.FlipX(); + } } public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) @@ -815,6 +822,9 @@ namespace Barotrauma Color color = (isSelected && editing) ? color = Color.Red : spriteColor; if (isHighlighted) color = Color.Orange; + SpriteEffects oldEffects = prefab.sprite.effects; + prefab.sprite.effects ^= SpriteEffects; + if (prefab.sprite != null) { float depth = Sprite.Depth; @@ -822,7 +832,7 @@ namespace Barotrauma if (body == null) { - if (prefab.ResizeHorizontal || prefab.ResizeVertical) + if (prefab.ResizeHorizontal || prefab.ResizeVertical || SpriteEffects.HasFlag(SpriteEffects.FlipHorizontally) || SpriteEffects.HasFlag(SpriteEffects.FlipVertically)) { prefab.sprite.DrawTiled(spriteBatch, new Vector2(DrawPosition.X-rect.Width/2, -(DrawPosition.Y+rect.Height/2)), new Vector2(rect.Width, rect.Height), color); } @@ -855,6 +865,8 @@ namespace Barotrauma } } + prefab.sprite.effects = oldEffects; + for (int i = 0; i < drawableComponents.Count; i++ ) { drawableComponents[i].Draw(spriteBatch, editing); @@ -1733,32 +1745,32 @@ namespace Barotrauma Condition = (float)message.ReadByte()/2.55f; Client sender = null; - if (GameMain.Server != null) - { - sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection); - if (sender == null || sender.Character == null || !sender.Character.CanAccessItem(this)) - { - return false; - } - } - + if (GameMain.Server != null) + { + sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection); + if (sender == null || sender.Character == null || !sender.Character.CanAccessItem(this)) + { + return false; + } + } + switch (type) { case NetworkEventType.DropItem: if (GameMain.Server != null) { Drop(sender.Character, false); - if (body != null) - { - body.TargetPosition = sender.Character.SimPosition; - body.MoveToTargetPosition(); + if (body != null) + { + body.TargetPosition = sender.Character.SimPosition; + body.MoveToTargetPosition(); } } - else + else { //client should not tell the server where the item should drop Drop(null, false); - if (body != null) + if (body != null) { body.ReadNetworkData(message, sendingTime); body.MoveToTargetPosition(); diff --git a/Subsurface/Source/Items/ItemPrefab.cs b/Subsurface/Source/Items/ItemPrefab.cs index b6de9ec3b..1c77e90ae 100644 --- a/Subsurface/Source/Items/ItemPrefab.cs +++ b/Subsurface/Source/Items/ItemPrefab.cs @@ -58,6 +58,8 @@ namespace Barotrauma private set; } + private bool canSpriteFlipX; + //if a matching itemprefab is not found when loading a sub, the game will attempt to find a prefab with a matching alias //(allows changing item names while keeping backwards compatibility with older sub files) public string[] Aliases @@ -116,6 +118,11 @@ namespace Barotrauma private set; } + public bool CanSpriteFlipX + { + get { return canSpriteFlipX; } + } + public Vector2 Size { get { return size; } @@ -281,6 +288,9 @@ namespace Barotrauma spriteFolder = Path.GetDirectoryName(filePath); } + if (ToolBox.GetAttributeBool(subElement, "canflipx", false)) + canSpriteFlipX = true; + sprite = new Sprite(subElement, spriteFolder); size = sprite.size; break; diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 1ae8facc9..18c789cfe 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -57,7 +57,9 @@ namespace Barotrauma bool isHorizontal; public float lastUpdate; - + + public SpriteEffects SpriteEffects = SpriteEffects.None; + public override Sprite Sprite { get { return prefab.sprite; } @@ -438,7 +440,10 @@ namespace Barotrauma Vector2.Zero, color, Point.Zero); } } - + + SpriteEffects oldEffects = prefab.sprite.effects; + prefab.sprite.effects ^= SpriteEffects; + if (back == prefab.sprite.Depth > 0.5f || editing) { foreach (WallSection s in sections) @@ -462,6 +467,8 @@ namespace Barotrauma prefab.sprite.DrawTiled(spriteBatch, new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), Vector2.Zero, color, offset); } } + + prefab.sprite.effects = oldEffects; } private bool OnWallCollision(Fixture f1, Fixture f2, Contact contact) @@ -747,6 +754,11 @@ namespace Barotrauma public override void FlipX() { base.FlipX(); + + if (prefab.CanSpriteFlipX) + { + SpriteEffects ^= SpriteEffects.FlipHorizontally; + } if (StairDirection != Direction.None) { diff --git a/Subsurface/Source/Map/StructurePrefab.cs b/Subsurface/Source/Map/StructurePrefab.cs index 53218ee18..e26609623 100644 --- a/Subsurface/Source/Map/StructurePrefab.cs +++ b/Subsurface/Source/Map/StructurePrefab.cs @@ -17,6 +17,7 @@ namespace Barotrauma private bool isPlatform; private Direction stairDirection; + private bool canSpriteFlipX; private float maxHealth; @@ -48,6 +49,11 @@ namespace Barotrauma get { return stairDirection; } } + public bool CanSpriteFlipX + { + get { return canSpriteFlipX; } + } + public Vector2 Size { get { return size; } @@ -107,6 +113,8 @@ namespace Barotrauma sp.sprite.effects = SpriteEffects.FlipHorizontally; if (ToolBox.GetAttributeBool(subElement, "flipvertical", false)) sp.sprite.effects = SpriteEffects.FlipVertically; + if (ToolBox.GetAttributeBool(subElement, "canflipx", false)) + sp.canSpriteFlipX = true; break; case "backgroundsprite": diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 655cd494b..343bd3f3d 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -562,7 +562,7 @@ namespace Barotrauma public void Update(float deltaTime) { - if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX(); + //if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX(); if (Level.Loaded == null) return;