diff --git a/Subsurface/Content/Map/StructurePrefabs.xml b/Subsurface/Content/Map/StructurePrefabs.xml index 7fc9df42a..c34bb78f2 100644 --- a/Subsurface/Content/Map/StructurePrefabs.xml +++ b/Subsurface/Content/Map/StructurePrefabs.xml @@ -1,167 +1,239 @@ - + + + - + + + - - - - - - - + + + - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + - + + + + - + + + + - + + + + - + + + + - + + + - + + + - + + + - + + + - - - + + + - - - - + + + - + + + - + + + - + + + - + + + - + + + - + + + - + + + - + + + - + + + - - + + + - + + + - + + + - + + + - - + + + - + + + - + + + - + + + - - - - - - - - - - - - - - - - - - - + + + \ No newline at end of file diff --git a/Subsurface/Content/Map/structures2.png b/Subsurface/Content/Map/structures2.png index 14866b4e6..06704256e 100644 Binary files a/Subsurface/Content/Map/structures2.png and b/Subsurface/Content/Map/structures2.png differ diff --git a/Subsurface/Content/Map/testroom.png b/Subsurface/Content/Map/testroom.png index 2c6332335..6f00f0edb 100644 Binary files a/Subsurface/Content/Map/testroom.png and b/Subsurface/Content/Map/testroom.png differ diff --git a/Subsurface/Content/Map/walldamage.png b/Subsurface/Content/Map/walldamage.png index 4938b9a8f..d713180be 100644 Binary files a/Subsurface/Content/Map/walldamage.png and b/Subsurface/Content/Map/walldamage.png differ diff --git a/Subsurface/Content/damageshader.fx b/Subsurface/Content/damageshader.fx index 3736cf220..6b67aacd7 100644 --- a/Subsurface/Content/damageshader.fx +++ b/Subsurface/Content/damageshader.fx @@ -6,8 +6,11 @@ Texture xStencil; sampler StencilSampler = sampler_state { Texture = ; }; -float cutoff; -float multiplier; +float aCutoff; +float aMultiplier; + +float cCutoff; +float cMultiplier; float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0 { @@ -15,14 +18,15 @@ float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoor float4 stencilColor = tex2D(StencilSampler, texCoord); - float a = stencilColor.a - cutoff; + float aDiff = stencilColor.a - aCutoff; - clip(a); + clip(aDiff); - a = min(a * multiplier, 1.0f); - c = lerp(c, stencilColor, 1.0f - a); + float cDiff = stencilColor.a - cCutoff; - return c * a; + return float4( + lerp(stencilColor.rgb, c.rgb, clamp(cDiff * cMultiplier, 0.0f, 1.0f)), + min(aDiff * aMultiplier, c.a)); } technique StencilShader diff --git a/Subsurface/Content/damageshader.xnb b/Subsurface/Content/damageshader.xnb index efa2c33c0..88484654f 100644 Binary files a/Subsurface/Content/damageshader.xnb and b/Subsurface/Content/damageshader.xnb differ diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 1e22344a0..5265c0cf7 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -86,6 +86,30 @@ namespace Barotrauma { get { return null; } } + + public virtual bool DrawBelowWater + { + get + { + return Sprite != null && Sprite.Depth > 0.5f; + } + } + + public virtual bool DrawOverWater + { + get + { + return !DrawBelowWater; + } + } + + public virtual bool DrawDamageEffect + { + get + { + return false; + } + } public virtual bool IsLinkable { @@ -203,6 +227,8 @@ namespace Barotrauma public virtual void Draw(SpriteBatch spriteBatch, bool editing, bool back=true) {} + public virtual void DrawDamage(SpriteBatch spriteBatch, Effect damageEffect) {} + public override void Remove() { base.Remove(); diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 33171d373..54578367f 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -43,7 +43,7 @@ namespace Barotrauma class Structure : MapEntity, IDamageable { - public static int wallSectionSize = 100; + public static int wallSectionSize = 96; public static List WallList = new List(); List convexHulls; @@ -105,6 +105,30 @@ namespace Barotrauma get { return prefab.MaxHealth; } } + public override bool DrawBelowWater + { + get + { + return base.DrawBelowWater || prefab.BackgroundSprite != null; + } + } + + public override bool DrawOverWater + { + get + { + return !DrawDamageEffect; + } + } + + public override bool DrawDamageEffect + { + get + { + return prefab.HasBody; + } + } + public override Rectangle Rect { get @@ -371,12 +395,19 @@ namespace Barotrauma public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) { + if (prefab.sprite == null) return; + Draw(spriteBatch, editing, back, null); } + public override void DrawDamage(SpriteBatch spriteBatch, Effect damageEffect) + { + Draw(spriteBatch, false, false, damageEffect); + } + private static float prevCutoff; - public void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null) + private void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null) { if (prefab.sprite == null) return; @@ -389,69 +420,48 @@ namespace Barotrauma } Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition; - if (sections.Length == 1) - { - prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), Vector2.Zero, color, Point.Zero); - return; - } - foreach (WallSection s in sections) + if (back && damageEffect == null) { - if (damageEffect != null) + if (prefab.BackgroundSprite != null) { - float newCutoff = Math.Min((s.damage / prefab.MaxHealth)*0.5f - 0.2f, 0.1f); - - if (Math.Abs(newCutoff - prevCutoff) > 0.01f) + prefab.BackgroundSprite.DrawTiled( + spriteBatch, + new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), + new Vector2(rect.Width, rect.Height), + Vector2.Zero, color, Point.Zero); + } + } + + if (back == prefab.sprite.Depth > 0.5f || editing) + { + foreach (WallSection s in sections) + { + if (damageEffect != null) { - damageEffect.Parameters["cutoff"].SetValue(newCutoff); + float newCutoff = Math.Min((s.damage / prefab.MaxHealth), 0.65f); - damageEffect.CurrentTechnique.Passes[0].Apply(); + if (Math.Abs(newCutoff - prevCutoff) > 0.01f) + { + damageEffect.Parameters["aCutoff"].SetValue(newCutoff); + damageEffect.Parameters["cCutoff"].SetValue(newCutoff*1.2f); - prevCutoff = newCutoff; + damageEffect.CurrentTechnique.Passes[0].Apply(); + + prevCutoff = newCutoff; + } } - } - Point offset = new Point(Math.Abs(rect.Location.X - s.rect.Location.X), Math.Abs(rect.Location.Y - s.rect.Location.Y)); - if (sections.Length != 1) + Point offset = new Point(Math.Abs(rect.Location.X - s.rect.Location.X), Math.Abs(rect.Location.Y - s.rect.Location.Y)); 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); - - - if (s.isHighLighted) - { - GUI.DrawRectangle(spriteBatch, - new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), - new Color((s.damage / prefab.MaxHealth), 1.0f - (s.damage / prefab.MaxHealth), 0.0f, 1.0f), true); + + s.isHighLighted = false; } - - s.isHighLighted = false; - - //if (s.damage < 0.01f) continue; - - //GUI.DrawRectangle(spriteBatch, - // new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), - // Color.Black * (s.damage / prefab.MaxHealth), true); } - /* - if(_convexHulls == null) return; - var rand = new Random(32434324); - foreach (var hull in _convexHulls) - { - if (sections.Count(x => x.hull == hull) <= 1) - continue; - var col = new Color((int) (255 * rand.NextDouble()), (int)(255 * rand.NextDouble()), (int)(255 * rand.NextDouble()), 255); - GUI.DrawRectangle(spriteBatch,new Vector2 (hull.BoundingBox.X + drawOffset.X, -(hull.BoundingBox.Y + drawOffset.Y)), new Vector2(hull.BoundingBox.Width, hull.BoundingBox.Height),col,true ); - }*/ } private bool OnWallCollision(Fixture f1, Fixture f2, Contact contact) { - //Structure structure = f1.Body.UserData as Structure; - - //if (f2.Body.UserData as Item != null) - //{ - // if (prefab.IsPlatform || prefab.StairDirection != Direction.None) return false; - //} - if (prefab.IsPlatform) { Limb limb; diff --git a/Subsurface/Source/Map/StructurePrefab.cs b/Subsurface/Source/Map/StructurePrefab.cs index 9d9f7f123..53218ee18 100644 --- a/Subsurface/Source/Map/StructurePrefab.cs +++ b/Subsurface/Source/Map/StructurePrefab.cs @@ -52,6 +52,12 @@ namespace Barotrauma { get { return size; } } + + public Sprite BackgroundSprite + { + get; + private set; + } public static void LoadAll(List filePaths) { @@ -74,22 +80,45 @@ namespace Barotrauma StructurePrefab sp = new StructurePrefab(); sp.name = element.Name.ToString(); - Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", new Vector4(0,0,1,1)); + //Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", new Vector4(0,0,1,1)); - Rectangle sourceRect = new Rectangle( - (int)sourceVector.X, - (int)sourceVector.Y, - (int)sourceVector.Z, - (int)sourceVector.W); + //Rectangle sourceRect = new Rectangle( + // (int)sourceVector.X, + // (int)sourceVector.Y, + // (int)sourceVector.Z, + // (int)sourceVector.W); - if (element.Attribute("sprite") != null) - { - sp.sprite = new Sprite(element.Attribute("sprite").Value, sourceRect, Vector2.Zero); + //if (element.Attribute("sprite") != null) + //{ + // sp.sprite = new Sprite(element.Attribute("sprite").Value, sourceRect, Vector2.Zero); - sp.sprite.Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f); + // sp.sprite.Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f); - if (ToolBox.GetAttributeBool(element, "fliphorizontal", false)) sp.sprite.effects = SpriteEffects.FlipHorizontally; - if (ToolBox.GetAttributeBool(element, "flipvertical", false)) sp.sprite.effects = SpriteEffects.FlipVertically; + //} + + foreach (XElement subElement in element.Elements()) + { + switch (subElement.Name.ToString()) + { + case "sprite": + sp.sprite = new Sprite(subElement); + + if (ToolBox.GetAttributeBool(subElement, "fliphorizontal", false)) + sp.sprite.effects = SpriteEffects.FlipHorizontally; + if (ToolBox.GetAttributeBool(subElement, "flipvertical", false)) + sp.sprite.effects = SpriteEffects.FlipVertically; + + break; + case "backgroundsprite": + sp.BackgroundSprite = new Sprite(subElement); + + if (ToolBox.GetAttributeBool(subElement, "fliphorizontal", false)) + sp.BackgroundSprite.effects = SpriteEffects.FlipHorizontally; + if (ToolBox.GetAttributeBool(subElement, "flipvertical", false)) + sp.BackgroundSprite.effects = SpriteEffects.FlipVertically; + + break; + } } MapEntityCategory category; @@ -119,8 +148,7 @@ namespace Barotrauma sp.stairDirection = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "stairdirection", "None"), true); sp.castShadow = ToolBox.GetAttributeBool(element, "castshadow", false); - - + sp.hasBody = ToolBox.GetAttributeBool(element, "body", false); return sp; diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 52b3ee368..071302606 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -287,8 +287,7 @@ namespace Barotrauma { for (int i = 0; i < MapEntity.mapEntityList.Count; i++) { - if (MapEntity.mapEntityList[i] is Structure) continue; - if (MapEntity.mapEntityList[i].Sprite == null || MapEntity.mapEntityList[i].Sprite.Depth < 0.5f) + if (MapEntity.mapEntityList[i].DrawOverWater) MapEntity.mapEntityList[i].Draw(spriteBatch, editing, false); } } @@ -297,12 +296,11 @@ namespace Barotrauma { for (int i = 0; i < MapEntity.mapEntityList.Count; i++) { - var structure = MapEntity.mapEntityList[i] as Structure; - if (structure == null || structure.Sprite.Depth > 0.5f) continue; - - structure.Draw(spriteBatch, editing, false, damageEffect); + if (MapEntity.mapEntityList[i].DrawDamageEffect) + MapEntity.mapEntityList[i].DrawDamage(spriteBatch, damageEffect); } - damageEffect.Parameters["cutoff"].SetValue(0.5f); + damageEffect.Parameters["aCutoff"].SetValue(0.0f); + damageEffect.Parameters["cCutoff"].SetValue(0.0f); } @@ -310,7 +308,7 @@ namespace Barotrauma { for (int i = 0; i < MapEntity.mapEntityList.Count; i++) { - if (MapEntity.mapEntityList[i].Sprite == null || MapEntity.mapEntityList[i].Sprite.Depth >= 0.5f) + if (MapEntity.mapEntityList[i].DrawBelowWater) MapEntity.mapEntityList[i].Draw(spriteBatch, editing, true); } } diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 5e665cbf7..bb95df021 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -53,14 +53,11 @@ namespace Barotrauma damageStencil = TextureLoader.FromFile("Content/Map/walldamage.png"); damageEffect = content.Load("damageshader"); - // damageEffect.Parameters["cutoff"].SetValue(0.5f); damageEffect.Parameters["xStencil"].SetValue(damageStencil); - - + damageEffect.Parameters["aMultiplier"].SetValue(50.0f); + damageEffect.Parameters["cMultiplier"].SetValue(200.0f); lightBlur = new BlurEffect(blurEffect, 0.001f, 0.001f); - - } public override void Select() @@ -344,8 +341,6 @@ namespace Barotrauma null, null, damageEffect, cam.Transform); - damageEffect.Parameters["cutoff"].SetValue(-0.2f); - damageEffect.Parameters["multiplier"].SetValue(5.0f); Submarine.DrawDamageable(spriteBatch, damageEffect);