diff --git a/Subsurface/Content/UI/style.xml b/Subsurface/Content/UI/style.xml index 0a0b09c89..0f7a74e6e 100644 --- a/Subsurface/Content/UI/style.xml +++ b/Subsurface/Content/UI/style.xml @@ -9,8 +9,7 @@ hovercolor="0.8, 0.8, 0.8, 1.0" selectedcolor="1.0, 0.82, 0.05, 1.0" - outlinecolor="0.5, 0.57, 0.6, 1.0"> - + outlinecolor="0.5, 0.57, 0.6, 1.0"> + + + \ No newline at end of file diff --git a/Subsurface/Source/Camera.cs b/Subsurface/Source/Camera.cs index e4d4e20bf..c17ff9d94 100644 --- a/Subsurface/Source/Camera.cs +++ b/Subsurface/Source/Camera.cs @@ -174,7 +174,7 @@ namespace Barotrauma if (PlayerInput.KeyDown(Keys.S)) moveCam.Y -= moveSpeed; if (PlayerInput.KeyDown(Keys.W)) moveCam.Y += moveSpeed; - if (Submarine.Loaded!=null) + if (Submarine.Loaded!=null && Screen.Selected == GameMain.GameScreen) { moveCam += FarseerPhysics.ConvertUnits.ToDisplayUnits(Submarine.Loaded.Velocity*deltaTime); } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index fe249eae7..bad2d1bc4 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -733,7 +733,7 @@ namespace Barotrauma { Limb head = AnimController.GetLimb(LimbType.Head); - Lights.LightManager.ViewPos = DrawPosition; + //Lights.LightManager.ViewPos = WorldPosition; if (!DisableControls) { @@ -1327,10 +1327,14 @@ namespace Barotrauma message.Write(AnimController.Dir > 0.0f); } - if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return true; - - message.Write(AnimController.RefLimb.SimPosition.X); - message.Write(AnimController.RefLimb.SimPosition.Y); + message.Write(Submarine != null); + + //Vector2 position = Submarine == null ? SimPosition : SimPosition - Submarine.SimPosition; + + //if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return true; + + message.Write(SimPosition.X); + message.Write(SimPosition.Y); return true; default: @@ -1495,17 +1499,21 @@ namespace Barotrauma #endif return; } - try - { - pos.X = message.ReadFloat(); - pos.Y = message.ReadFloat(); - } - catch + bool inSub = message.ReadBoolean(); + + pos.X = message.ReadFloat(); + pos.Y = message.ReadFloat(); + + if (inSub) { - //failed to read position, Character may be further than NetConfig.CharacterIgnoreDistance - pos = SimPosition; - } + Hull newHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(pos), AnimController.CurrentHull, false); + if (newHull != null) + { + AnimController.CurrentHull = newHull; + Submarine = newHull.Submarine; + } + } if (secondaryKeyState) { @@ -1517,7 +1525,8 @@ namespace Barotrauma cursorPosition = Position + new Vector2(1000.0f, 0.0f) * dir; } - AnimController.RefLimb.body.TargetPosition = AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now + message.SenderConnection.RemoteTimeOffset) - sendingTime); + AnimController.RefLimb.body.TargetPosition = + AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now + message.SenderConnection.RemoteTimeOffset) - sendingTime); LastNetworkUpdate = sendingTime; diff --git a/Subsurface/Source/Characters/CharacterHUD.cs b/Subsurface/Source/Characters/CharacterHUD.cs index ed61c57fd..6ffbf8868 100644 --- a/Subsurface/Source/Characters/CharacterHUD.cs +++ b/Subsurface/Source/Characters/CharacterHUD.cs @@ -54,7 +54,7 @@ namespace Barotrauma if (character.ClosestCharacter != null && (character.ClosestCharacter.IsDead || character.ClosestCharacter.Stun > 0.0f)) { - Vector2 startPos = character.Position + (character.ClosestCharacter.WorldPosition - character.WorldPosition) * 0.7f; + Vector2 startPos = character.DrawPosition + (character.ClosestCharacter.DrawPosition - character.DrawPosition) * 0.7f; startPos = cam.WorldToScreen(startPos); Vector2 textPos = startPos; @@ -67,7 +67,7 @@ namespace Barotrauma else if (character.SelectedCharacter == null && character.ClosestItem != null && character.SelectedConstruction == null) { - Vector2 startPos = character.WorldPosition + (character.ClosestItem.WorldPosition - character.WorldPosition) * 0.7f; + Vector2 startPos = character.DrawPosition + (character.ClosestItem.DrawPosition - character.DrawPosition) * 0.7f; startPos = cam.WorldToScreen(startPos); Vector2 textPos = startPos; @@ -96,10 +96,10 @@ namespace Barotrauma { int width = 100, height = 20; - drowningBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 200, width, height), Color.Blue, 1.0f); + drowningBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 200, width, height), Color.Blue, GUI.Style, 1.0f, Alignment.TopLeft); new GUIImage(new Rectangle(-27, -7, 20, 20), new Rectangle(17, 0, 20, 24), statusIcons, Alignment.TopLeft, drowningBar); - healthBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 230, width, height), Color.Red, 1.0f); + healthBar = new GUIProgressBar(new Rectangle(30, GameMain.GraphicsHeight - 230, width, height), Color.Red, GUI.Style, 1.0f, Alignment.TopLeft); new GUIImage(new Rectangle(-26, -7, 20, 20), new Rectangle(0, 0, 13, 24), statusIcons, Alignment.TopLeft, healthBar); } diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 7f94e35ab..0404cb653 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -323,7 +323,7 @@ namespace Barotrauma break; case "fixhull": case "fixwalls": - foreach (Structure w in Structure.wallList) + foreach (Structure w in Structure.WallList) { for (int i = 0 ; i < w.SectionCount; i++) { diff --git a/Subsurface/Source/Events/MonsterEvent.cs b/Subsurface/Source/Events/MonsterEvent.cs index abd22b1be..5a7110191 100644 --- a/Subsurface/Source/Events/MonsterEvent.cs +++ b/Subsurface/Source/Events/MonsterEvent.cs @@ -35,7 +35,7 @@ namespace Barotrauma for (int i = 0; i < amount; i++) { - Vector2 position = (randomWayPoint == null) ? Vector2.Zero : FarseerPhysics.ConvertUnits.ToSimUnits(randomWayPoint.Position); + Vector2 position = (randomWayPoint == null) ? Vector2.Zero : randomWayPoint.Position; //!!!!!!!!!!!!!!!!!! if (spawnDeep) diff --git a/Subsurface/Source/Events/Quests/MonsterQuest.cs b/Subsurface/Source/Events/Quests/MonsterQuest.cs index d1e0ab8c6..7693d0a97 100644 --- a/Subsurface/Source/Events/Quests/MonsterQuest.cs +++ b/Subsurface/Source/Events/Quests/MonsterQuest.cs @@ -31,7 +31,7 @@ namespace Barotrauma { Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count, false)]; - monster = Character.Create(monsterFile, ConvertUnits.ToSimUnits(position)); + monster = Character.Create(monsterFile, position); } public override void Update(float deltaTime) diff --git a/Subsurface/Source/GUI/GUIProgressBar.cs b/Subsurface/Source/GUI/GUIProgressBar.cs index 53e33d6e4..a0b8dfcb1 100644 --- a/Subsurface/Source/GUI/GUIProgressBar.cs +++ b/Subsurface/Source/GUI/GUIProgressBar.cs @@ -37,12 +37,18 @@ namespace Barotrauma } public GUIProgressBar(Rectangle rect, Color color, float barSize, Alignment alignment, GUIComponent parent = null) - : base(null) + : this(rect,color,null, barSize,alignment, parent) + { + + } + + public GUIProgressBar(Rectangle rect, Color color, GUIStyle style, float barSize, Alignment alignment, GUIComponent parent = null) + : base(style) { this.rect = rect; this.color = color; isHorizontal = (rect.Width > rect.Height); - + this.alignment = alignment; margin = 5; @@ -50,19 +56,36 @@ namespace Barotrauma if (parent != null) parent.AddChild(this); - frame = new GUIFrame(new Rectangle(0,0,0,0), Color.White, null, this); + frame = new GUIFrame(new Rectangle(0, 0, 0, 0), Color.Black, null, this); this.barSize = barSize; UpdateRect(); + + if (style != null) style.Apply(this); + } + + public override void ApplyStyle(GUIComponentStyle style) + { + if (frame == null) return; + + frame.Color = style.Color; + frame.HoverColor = style.HoverColor; + frame.SelectedColor = style.SelectedColor; + + Padding = style.Padding; + + frame.OutlineColor = style.OutlineColor; + + this.style = style; } private void UpdateRect() { rect = new Rectangle( - frame.Rect.X + margin, - frame.Rect.Y + margin, - isHorizontal ? (int)((frame.Rect.Width - margin * 2) * barSize) : (frame.Rect.Width - margin * 2), - isHorizontal ? (frame.Rect.Height - margin * 2) : (int)((frame.Rect.Height - margin * 2) * barSize)); + (int)(frame.Rect.X + padding.X), + (int)(frame.Rect.Y + padding.Y), + isHorizontal ? (int)((frame.Rect.Width - padding.X - padding.Z) * barSize) : (frame.Rect.Width - margin * 2), + isHorizontal ? (int)(frame.Rect.Height - padding.Y - padding.W) : (int)((frame.Rect.Height - margin * 2) * barSize)); } public override void Draw(SpriteBatch spriteBatch) diff --git a/Subsurface/Source/GameSession/GameModes/TutorialMode.cs b/Subsurface/Source/GameSession/GameModes/TutorialMode.cs index 2c64e0bfe..0ad102f87 100644 --- a/Subsurface/Source/GameSession/GameModes/TutorialMode.cs +++ b/Subsurface/Source/GameSession/GameModes/TutorialMode.cs @@ -333,7 +333,7 @@ namespace Barotrauma infoBox = CreateInfoFrame("Uh-oh... Something enormous just appeared on the radar."); List windows = new List(); - foreach (Structure s in Structure.wallList) + foreach (Structure s in Structure.WallList) { if (s.CastShadow || !s.HasBody) continue; diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index 016de1795..d46eff019 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -353,7 +353,7 @@ namespace Barotrauma.Items.Components if (connection.Name=="toggle") { isOpen = !isOpen; - PlaySound(ActionType.OnUse, item.Position); + PlaySound(ActionType.OnUse, item.WorldPosition); } else if (connection.Name == "set_state") { diff --git a/Subsurface/Source/Items/Components/Holdable/Propulsion.cs b/Subsurface/Source/Items/Components/Holdable/Propulsion.cs index 525f9adcc..4455d4638 100644 --- a/Subsurface/Source/Items/Components/Holdable/Propulsion.cs +++ b/Subsurface/Source/Items/Components/Holdable/Propulsion.cs @@ -88,7 +88,7 @@ namespace Barotrauma.Items.Components if (!string.IsNullOrWhiteSpace(particles)) { - GameMain.ParticleManager.CreateParticle(particles, item.Position, + GameMain.ParticleManager.CreateParticle(particles, item.WorldPosition, item.body.Rotation + ((item.body.Dir > 0.0f) ? 0.0f : MathHelper.Pi), 0.0f, item.CurrentHull); } diff --git a/Subsurface/Source/Items/Components/Signal/LightComponent.cs b/Subsurface/Source/Items/Components/Signal/LightComponent.cs index 820063d4a..6ab43eafa 100644 --- a/Subsurface/Source/Items/Components/Signal/LightComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/LightComponent.cs @@ -100,8 +100,10 @@ namespace Barotrauma.Items.Components base.Update(deltaTime, cam); if (item.CurrentHull != null) { - //light.Submarine = item.CurrentHull.Submarine; + light.Submarine = item.CurrentHull.Submarine; } + + if (item.container != null) { diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 94eb23689..924437757 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -479,21 +479,21 @@ namespace Barotrauma } //returns the water block which contains the point (or null if it isn't inside any) - public static Hull FindHull(Vector2 worldPosition, Hull guess = null) + public static Hull FindHull(Vector2 position, Hull guess = null, bool useWorldCoordinates = true) { - return FindHull(worldPosition, hullList, guess); + return FindHull(position, hullList, guess, useWorldCoordinates); } - public static Hull FindHull(Vector2 worldPosition, List hulls, Hull guess = null) + public static Hull FindHull(Vector2 position, List hulls, Hull guess = null, bool useWorldCoordinates = true) { if (guess != null && hulls.Contains(guess)) { - if (Submarine.RectContains(guess.WorldRect, worldPosition)) return guess; + if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position)) return guess; } foreach (Hull hull in hulls) { - if (Submarine.RectContains(hull.WorldRect, worldPosition)) return hull; + if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position)) return hull; } return null; diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index 750bc26d6..e2142f881 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -41,7 +41,6 @@ namespace Barotrauma //List bodies; private List cells; - private VertexPositionTexture[] vertices; //private VertexBuffer vertexBuffer; private Vector2 startPosition, endPosition; @@ -314,7 +313,9 @@ namespace Barotrauma startPosition.Y = borders.Height; endPosition.Y = borders.Height; - vertices = GeneratePolygons(cells, pathCells); + renderer.BodyVertices = GeneratePolygons(cells, pathCells); + renderer.WallVertices = GenerateWallShapes(cells); + wrappingWalls = new WrappingWall[2, 2]; @@ -325,7 +326,8 @@ namespace Barotrauma wrappingWalls[side, i] = new WrappingWall(pathCells, cells, borders.Height * 0.5f, (side == 0 ? -1 : 1) * (i == 0 ? 1 : 2)); - wrappingWalls[side, i].Vertices = GeneratePolygons(wrappingWalls[side, i].Cells, new List(), false); + wrappingWalls[side, i].BodyVertices = GeneratePolygons(wrappingWalls[side, i].Cells, new List(), false); + wrappingWalls[side, i].WallVertices = GenerateWallShapes(wrappingWalls[side, i].Cells); //wrappingWalls[side, i].Cells[0].edges[1].isSolid = false; //wrappingWalls[side, i].Cells[0].edges[3].isSolid = false; @@ -622,9 +624,9 @@ namespace Barotrauma } - private VertexPositionTexture[] GeneratePolygons(List cells, List emptyCells, bool setSolid=true) + private VertexPositionColor[] GeneratePolygons(List cells, List emptyCells, bool setSolid=true) { - List verticeList = new List(); + List verticeList = new List(); //bodies = new List(); List tempVertices = new List(); @@ -657,14 +659,14 @@ namespace Barotrauma continue; } - //var triangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center); - //for (int i = 0; i < triangles.Count; i++) - //{ - // foreach (Vector2 vertex in triangles[i]) - // { - // verticeList.Add(new VertexPositionTexture(new Vector3(vertex, 0.0f), vertex/1000.0f)); - // } - //} + var triangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center); + for (int i = 0; i < triangles.Count; i++) + { + foreach (Vector2 vertex in triangles[i]) + { + verticeList.Add(new VertexPositionColor(new Vector3(vertex, 0.0f), Color.Black)); + } + } if (bodyPoints.Count < 2) continue; @@ -684,7 +686,7 @@ namespace Barotrauma bodyPoints[i] = ConvertUnits.ToSimUnits(bodyPoints[i]); } - var triangles = MathUtils.TriangulateConvexHull(bodyPoints, cell.Center); + triangles = MathUtils.TriangulateConvexHull(bodyPoints, cell.Center); Body edgeBody = new Body(GameMain.World); @@ -706,15 +708,12 @@ namespace Barotrauma bodies.Add(edgeBody); } - - verticeList = GenerateWallShapes(cells); - return verticeList.ToArray(); } - private List GenerateWallShapes(List cells) + private VertexPositionTexture[] GenerateWallShapes(List cells) { - float wallThickness = 500.0f; + float inwardThickness = 500.0f, outWardThickness = 30.0f; List verticeList = new List(); @@ -726,13 +725,13 @@ namespace Barotrauma if (edge.cell1 != null && edge.cell1.body == null) edge.cell1 = null; if (edge.cell2 != null && edge.cell2.body == null) edge.cell2 = null; - //CompareCCW compare = new CompareCCW(cell.Center); - //if (compare.Compare(edge.point1, edge.point2) == -1) - //{ - // var temp = edge.point1; - // edge.point1 = edge.point2; - // edge.point2 = temp; - //} + CompareCCW compare = new CompareCCW(cell.Center); + if (compare.Compare(edge.point1, edge.point2) == -1) + { + var temp = edge.point1; + edge.point1 = edge.point2; + edge.point2 = temp; + } } } @@ -758,7 +757,7 @@ namespace Barotrauma rightEdge = edge2; } } - + Vector2 leftNormal = Vector2.Zero, rightNormal = Vector2.Zero; if (leftEdge == null) @@ -783,6 +782,10 @@ namespace Barotrauma Vector2.Normalize(GetEdgeNormal(rightEdge) + GetEdgeNormal(edge, cell)) : Vector2.Normalize(rightEdge.Center - edge.point2); } + + + + for (int i = 0; i < 2; i++) { Vector2[] verts = new Vector2[3]; @@ -791,9 +794,9 @@ namespace Barotrauma if (i==0) { - verts[0] = edge.point1; - verts[1] = edge.point2; - verts[2] = edge.point1 + leftNormal * wallThickness; + verts[0] = edge.point1 - leftNormal * outWardThickness; + verts[1] = edge.point2 - rightNormal * outWardThickness; + verts[2] = edge.point1 + leftNormal * inwardThickness; vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), Vector2.Zero); vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX); @@ -801,9 +804,9 @@ namespace Barotrauma } else { - verts[0] = edge.point1 + leftNormal * wallThickness; - verts[1] = edge.point2; - verts[2] = edge.point2 + rightNormal * wallThickness; + verts[0] = edge.point1 + leftNormal * inwardThickness; + verts[1] = edge.point2 - rightNormal * outWardThickness; + verts[2] = edge.point2 + rightNormal * inwardThickness; vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), new Vector2(0.0f, 0.5f)); vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX); @@ -821,7 +824,7 @@ namespace Barotrauma } } - return verticeList; + return verticeList.ToArray(); } private Vector2 GetEdgeNormal(GraphEdge edge, VoronoiCell cell = null) @@ -953,16 +956,21 @@ namespace Barotrauma // } //} - public void Draw(SpriteBatch spriteBatch) + public void Update (float deltaTime) + { + renderer.Update(deltaTime); + } + + public void DrawFront(SpriteBatch spriteBatch) { if (renderer == null) return; renderer.Draw(spriteBatch); } - public void Render(GraphicsDevice graphicsDevice, Camera cam) + public void DrawBack(SpriteBatch spriteBatch, Camera cam, BackgroundSpriteManager backgroundSpriteManager = null) { if (renderer == null) return; - renderer.Render(graphicsDevice, cam, vertices); + renderer.DrawBackground(spriteBatch, cam, backgroundSpriteManager); } @@ -1094,9 +1102,7 @@ namespace Barotrauma private void Unload() { renderer = null; - - vertices = null; - + cells = null; bodies.Clear(); diff --git a/Subsurface/Source/Map/Levels/LevelRenderer.cs b/Subsurface/Source/Map/Levels/LevelRenderer.cs index 6ff978245..6ed2b1640 100644 --- a/Subsurface/Source/Map/Levels/LevelRenderer.cs +++ b/Subsurface/Source/Map/Levels/LevelRenderer.cs @@ -2,6 +2,7 @@ using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; @@ -9,20 +10,32 @@ namespace Barotrauma { class LevelRenderer { - private static BasicEffect basicEffect; + private static Sprite background, backgroundTop; + private static Texture2D dustParticles; private static Texture2D shaftTexture; - private Level level; + Vector2 dustOffset; + private Level level; + + public VertexPositionTexture[] WallVertices; + public VertexPositionColor[] BodyVertices; + public LevelRenderer(Level level) { if (shaftTexture == null) shaftTexture = TextureLoader.FromFile("Content/Map/shaft.png"); + if (background==null) + { + background = new Sprite("Content/Map/background.png", Vector2.Zero); + backgroundTop = new Sprite("Content/Map/background2.png", Vector2.Zero); + dustParticles = Sprite.LoadTexture("Content/Map/dustparticles.png"); + } + if (basicEffect == null) { - basicEffect = new BasicEffect(GameMain.CurrGraphicsDevice); basicEffect.VertexColorEnabled = false; @@ -33,6 +46,75 @@ namespace Barotrauma this.level = level; } + public void Update(float deltaTime) + { + + dustOffset -= Vector2.UnitY * 10.0f * (float)deltaTime; + } + + public void DrawBackground(SpriteBatch spriteBatch, Camera cam, BackgroundSpriteManager backgroundSpriteManager = null) + { + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap); + + Vector2 backgroundPos = cam.Position; + //if (Level.Loaded != null) backgroundPos -= Level.Loaded.Position; + backgroundPos.Y = -backgroundPos.Y; + backgroundPos /= 20.0f; + + if (backgroundPos.Y < 1024) + { + if (backgroundPos.Y > -1024) + { + background.SourceRect = new Rectangle((int)backgroundPos.X, (int)Math.Max(backgroundPos.Y, 0), 1024, 1024); + background.DrawTiled(spriteBatch, + (backgroundPos.Y < 0) ? new Vector2(0.0f, -backgroundPos.Y) : Vector2.Zero, + new Vector2(GameMain.GraphicsWidth, 1024 - backgroundPos.Y), + Vector2.Zero, Color.White); + } + + if (backgroundPos.Y < 0) + { + backgroundTop.SourceRect = new Rectangle((int)backgroundPos.X, (int)backgroundPos.Y, 1024, (int)Math.Min(-backgroundPos.Y, 1024)); + backgroundTop.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(GameMain.GraphicsWidth, Math.Min(-backgroundPos.Y, GameMain.GraphicsHeight)), + Vector2.Zero, Color.White); + } + } + + spriteBatch.End(); + + spriteBatch.Begin(SpriteSortMode.BackToFront, + BlendState.AlphaBlend, + SamplerState.LinearWrap, DepthStencilState.Default, null, null, + cam.Transform); + + if (backgroundSpriteManager!=null) backgroundSpriteManager.Draw(spriteBatch); + + spriteBatch.End(); + + spriteBatch.Begin(SpriteSortMode.BackToFront, + BlendState.AlphaBlend, + SamplerState.LinearWrap); + + backgroundPos = new Vector2(cam.WorldView.X, cam.WorldView.Y) + dustOffset; + //if (Level.Loaded != null) backgroundPos -= Level.Loaded.Position; + + Rectangle viewRect = cam.WorldView; + viewRect.Y = -viewRect.Y; + + float multiplier = 0.8f; + for (int i = 1; i < 5; i++) + { + spriteBatch.Draw(dustParticles, new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsHeight), + new Rectangle((int)((backgroundPos.X * multiplier)), (int)((-backgroundPos.Y * multiplier)), cam.WorldView.Width*2, cam.WorldView.Height*2), + Color.White * multiplier, 0.0f, Vector2.Zero, SpriteEffects.None, 1.0f - multiplier); + multiplier -= 0.1f; + } + + spriteBatch.End(); + + RenderWalls(GameMain.CurrGraphicsDevice, cam); + } + public void Draw(SpriteBatch spriteBatch) { Vector2 pos = new Vector2(0.0f, -level.StartPosition.Y);// level.EndPosition; @@ -54,36 +136,50 @@ namespace Barotrauma } - public void Render(GraphicsDevice graphicsDevice, Camera cam, VertexPositionTexture[] vertices) + public void RenderWalls(GraphicsDevice graphicsDevice, Camera cam) { - if (vertices == null) return; - if (vertices.Length <= 0) return; + if (WallVertices == null || WallVertices.Length <= 0) return; basicEffect.World = cam.ShaderTransform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; - basicEffect.CurrentTechnique.Passes[0].Apply(); - graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; - graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, (int)Math.Floor(vertices.Length / 3.0f)); + basicEffect.VertexColorEnabled = true; + basicEffect.TextureEnabled = false; + basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_VertexColor"]; + basicEffect.CurrentTechnique.Passes[0].Apply(); + graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, BodyVertices, 0, (int)Math.Floor(BodyVertices.Length / 3.0f)); for (int side = 0; side < 2; side++) { for (int i = 0; i < 2; i++) { - // basicEffect.World = Matrix.CreateTranslation( - // new Vector3(-Submarine.Loaded.Position + level.WrappingWalls[side, i].Offset, 0.0f)) * - // cam.ShaderTransform * - // Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; - - // basicEffect.CurrentTechnique.Passes[0].Apply(); - graphicsDevice.DrawUserPrimitives( - PrimitiveType.TriangleList, - level.WrappingWalls[side, i].Vertices, 0, - (int)Math.Floor(level.WrappingWalls[side, i].Vertices.Length / 3.0f)); + PrimitiveType.TriangleList, level.WrappingWalls[side, i].BodyVertices, 0, + (int)Math.Floor(level.WrappingWalls[side, i].BodyVertices.Length / 3.0f)); + + } + } + + basicEffect.VertexColorEnabled = false; + basicEffect.TextureEnabled = true; + basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_Texture"]; + basicEffect.CurrentTechnique.Passes[0].Apply(); + graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, WallVertices, 0, (int)Math.Floor(WallVertices.Length / 3.0f)); + + for (int side = 0; side < 2; side++) + { + for (int i = 0; i < 2; i++) + { + basicEffect.VertexColorEnabled = false; + basicEffect.TextureEnabled = true; + basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_Texture"]; + basicEffect.CurrentTechnique.Passes[0].Apply(); + graphicsDevice.DrawUserPrimitives( + PrimitiveType.TriangleList, level.WrappingWalls[side, i].WallVertices, 0, + (int)Math.Floor(level.WrappingWalls[side, i].WallVertices.Length / 3.0f)); } } diff --git a/Subsurface/Source/Map/Levels/WrappingWall.cs b/Subsurface/Source/Map/Levels/WrappingWall.cs index 21a5b5a2c..5a8db2df9 100644 --- a/Subsurface/Source/Map/Levels/WrappingWall.cs +++ b/Subsurface/Source/Map/Levels/WrappingWall.cs @@ -15,7 +15,9 @@ namespace Barotrauma public const float WallWidth = 20000.0f; - public VertexPositionTexture[] Vertices; + public VertexPositionTexture[] WallVertices; + + public VertexPositionColor[] BodyVertices; private Vector2 midPos; private int slot; diff --git a/Subsurface/Source/Map/Lights/ConvexHull.cs b/Subsurface/Source/Map/Lights/ConvexHull.cs index 404b97d99..fe5db85c5 100644 --- a/Subsurface/Source/Map/Lights/ConvexHull.cs +++ b/Subsurface/Source/Map/Lights/ConvexHull.cs @@ -310,10 +310,10 @@ namespace Barotrauma.Lights { Vector3 offset = Vector3.Zero; - if (parentEntity != null && parentEntity.Submarine != null) - { - offset = new Vector3(parentEntity.Submarine.DrawPosition.X, parentEntity.Submarine.DrawPosition.Y, 0.0f); - } + if (parentEntity != null && parentEntity.Submarine != null) + { + offset = new Vector3(parentEntity.Submarine.DrawPosition.X, parentEntity.Submarine.DrawPosition.Y, 0.0f); + } shadowEffect.World = Matrix.CreateTranslation(offset) * transform; diff --git a/Subsurface/Source/Map/LocationType.cs b/Subsurface/Source/Map/LocationType.cs index a75c36dc0..cbf510651 100644 --- a/Subsurface/Source/Map/LocationType.cs +++ b/Subsurface/Source/Map/LocationType.cs @@ -107,10 +107,15 @@ namespace Barotrauma return null; } - public static LocationType Random() + public static LocationType Random(string seed = "") { Debug.Assert(list.Count > 0, "LocationType.list.Count == 0, you probably need to initialize LocationTypes"); + if (!string.IsNullOrWhiteSpace(seed)) + { + Rand.SetSyncedSeed(ToolBox.StringToInt(seed)); + } + int randInt = Rand.Int(totalWeight, false); foreach (LocationType type in list) diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index c31e1168e..7f60d88e2 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -41,7 +41,7 @@ namespace Barotrauma class Structure : MapEntity, IDamageable { public static int wallSectionSize = 100; - public static List wallList = new List(); + public static List WallList = new List(); ConvexHull convexHull; @@ -169,7 +169,7 @@ namespace Barotrauma bodies.Add(newBody); - wallList.Add(this); + WallList.Add(this); int xsections = 1; int ysections = 1; @@ -273,7 +273,7 @@ namespace Barotrauma { base.Remove(); - if (wallList.Contains(this)) wallList.Remove(this); + if (WallList.Contains(this)) WallList.Remove(this); if (bodies != null) { diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index e7371907f..b8d17dce4 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -354,34 +354,7 @@ namespace Barotrauma lastPickedFraction = closestFraction; return closestBody; } - - //public static Body PickBody(Vector2 point) - //{ - // Body foundBody = null; - // AABB aabb = new AABB(point, point); - - // GameMain.World.QueryAABB(p => - // { - // foundBody = p.Body; - - // return true; - - // }, ref aabb); - - // return foundBody; - //} - - //public static bool InsideWall(Vector2 point) - //{ - // Body foundBody = PickBody(point); - // if (foundBody==null) return false; - - // Structure wall = foundBody.UserData as Structure; - // if (wall == null || wall.IsPlatform) return false; - - // return true; - //} - + //movement ---------------------------------------------------- diff --git a/Subsurface/Source/Map/SubmarineBody.cs b/Subsurface/Source/Map/SubmarineBody.cs index 79aa09b8c..7bf92e0a9 100644 --- a/Subsurface/Source/Map/SubmarineBody.cs +++ b/Subsurface/Source/Map/SubmarineBody.cs @@ -108,13 +108,17 @@ namespace Barotrauma (int)ConvertUnits.ToDisplayUnits(hullAABB.UpperBound.Y), (int)ConvertUnits.ToDisplayUnits(hullAABB.Extents.X * 2.0f), (int)ConvertUnits.ToDisplayUnits(hullAABB.Extents.Y * 2.0f)); + + //var triangulatedVertices = Triangulate.ConvexPartition(shapevertices, TriangulationAlgorithm.Bayazit); + body = BodyFactory.CreateBody(GameMain.World, this); - var triangulatedVertices = Triangulate.ConvexPartition(shapevertices, TriangulationAlgorithm.Bayazit); + foreach (Hull hull in Hull.hullList) + { + FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(hull.Rect.Width), ConvertUnits.ToSimUnits(hull.Rect.Height), 5.0f, hull.SimPosition, body, this); + } - body = BodyFactory.CreateCompoundPolygon(GameMain.World, triangulatedVertices, 5.0f); body.BodyType = BodyType.Dynamic; - body.CollisionCategories = Physics.CollisionMisc | Physics.CollisionWall; body.CollidesWith = Physics.CollisionLevel | Physics.CollisionCharacter; body.Restitution = Restitution; @@ -125,13 +129,13 @@ namespace Barotrauma body.SleepingAllowed = false; body.IgnoreGravity = true; body.OnCollision += OnCollision; - body.UserData = this; + //body.UserData = this; } private List GenerateConvexHull() { - if (!Structure.wallList.Any()) + if (!Structure.WallList.Any()) { return new List() { new Vector2(-1.0f, 1.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, -1.0f) }; } @@ -140,7 +144,7 @@ namespace Barotrauma Vector2 leftMost = Vector2.Zero; - foreach (Structure wall in Structure.wallList) + foreach (Structure wall in Structure.WallList) { for (int x = -1; x <= 1; x += 2) { @@ -175,7 +179,7 @@ namespace Barotrauma endPoint = points[i]; } } - + currPoint = endPoint; } @@ -184,9 +188,6 @@ namespace Barotrauma return hullPoints; } - - float collisionRigidness = 1.0f; - public void Update(float deltaTime) { if (Position!=Vector2.Zero) diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index adab499a0..3477a6a89 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -219,6 +219,12 @@ namespace Barotrauma public static void GenerateSubWaypoints() { + List existingWaypoints = WayPointList.FindAll(wp => wp.spawnType == SpawnType.Path); + foreach (WayPoint wayPoint in existingWaypoints) + { + wayPoint.Remove(); + } + float minDist = 200.0f; float heightFromFloor = 100.0f; diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index c55633494..4052cdabf 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -134,6 +134,8 @@ namespace Barotrauma GUIComponent.MouseOn = null; characterMode = false; + + if (Submarine.Loaded != null) cam.Position = Submarine.Loaded.Position + Submarine.HiddenSubPosition; //CreateDummyCharacter(); } diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index ed662959f..1e8195cf7 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -15,11 +15,6 @@ namespace Barotrauma readonly RenderTarget2D renderTargetWater; readonly RenderTarget2D renderTargetAir; - readonly Sprite background, backgroundTop; - readonly Texture2D dustParticles; - - Vector2 dustOffset; - public BackgroundSpriteManager BackgroundSpriteManager; public Camera Cam @@ -36,9 +31,6 @@ namespace Barotrauma renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); renderTargetAir = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); - background = new Sprite("Content/Map/background.png", Vector2.Zero); - backgroundTop = new Sprite("Content/Map/background2.png", Vector2.Zero); - dustParticles = Sprite.LoadTexture("Content/Map/dustparticles.png"); BackgroundSpriteManager = new BackgroundSpriteManager("Content/BackgroundSprites/BackgroundSpritePrefabs.xml"); } @@ -83,11 +75,12 @@ namespace Barotrauma GameMain.GameSession.Submarine.ApplyForce(targetMovement * 1000000.0f); } #endif - dustOffset -= Vector2.UnitY * 10.0f * (float)deltaTime; if (GameMain.GameSession!=null) GameMain.GameSession.Update((float)deltaTime); //EventManager.Update(gameTime); + if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime); + Character.UpdateAll(cam, (float)deltaTime); BackgroundSpriteManager.Update(cam, (float)deltaTime); @@ -101,7 +94,11 @@ namespace Barotrauma while (Physics.accumulator >= Physics.step) { cam.MoveCamera((float)Physics.step); - if (Character.Controlled != null) cam.TargetPos = Character.Controlled.WorldPosition; + if (Character.Controlled != null) + { + cam.TargetPos = Character.Controlled.WorldPosition; + Lights.LightManager.ViewPos = Character.Controlled.WorldPosition; + } if (Submarine.Loaded != null) Submarine.Loaded.SetPrevTransform(Submarine.Loaded.Position); @@ -175,6 +172,7 @@ namespace Barotrauma GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam, Character.Controlled==null ? LightManager.ViewPos : Character.Controlled.CursorWorldPosition); + //---------------------------------------------------------------------------------------- //1. draw the background, characters and the parts of the submarine that are behind them //---------------------------------------------------------------------------------------- @@ -182,63 +180,8 @@ namespace Barotrauma graphics.SetRenderTarget(renderTarget); graphics.Clear(new Color(11, 18, 26, 255)); - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap); + if (Level.Loaded != null) Level.Loaded.DrawBack(spriteBatch, cam, BackgroundSpriteManager); - Vector2 backgroundPos = cam.Position; - //if (Level.Loaded != null) backgroundPos -= Level.Loaded.Position; - backgroundPos.Y = -backgroundPos.Y; - backgroundPos /= 20.0f; - - if (backgroundPos.Y < 1024) - { - if (backgroundPos.Y > -1024) - { - background.SourceRect = new Rectangle((int)backgroundPos.X, (int)Math.Max(backgroundPos.Y, 0), 1024, 1024); - background.DrawTiled(spriteBatch, - (backgroundPos.Y < 0) ? new Vector2(0.0f, -backgroundPos.Y) : Vector2.Zero, - new Vector2(GameMain.GraphicsWidth, 1024 - backgroundPos.Y), - Vector2.Zero, Color.White); - } - - if (backgroundPos.Y < 0) - { - backgroundTop.SourceRect = new Rectangle((int)backgroundPos.X, (int)backgroundPos.Y, 1024, (int)Math.Min(-backgroundPos.Y, 1024)); - backgroundTop.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(GameMain.GraphicsWidth, Math.Min(-backgroundPos.Y, GameMain.GraphicsHeight)), - Vector2.Zero, Color.White); - } - } - - spriteBatch.End(); - - spriteBatch.Begin(SpriteSortMode.BackToFront, - BlendState.AlphaBlend, - SamplerState.LinearWrap, DepthStencilState.Default, null, null, - cam.Transform); - - BackgroundSpriteManager.Draw(spriteBatch); - - backgroundPos = new Vector2(cam.WorldView.X, cam.WorldView.Y) + dustOffset; - //if (Level.Loaded != null) backgroundPos -= Level.Loaded.Position; - - Rectangle viewRect = cam.WorldView; - viewRect.Y = -viewRect.Y; - - float multiplier = 0.8f; - for (int i = 1; i < 4; i++) - { - spriteBatch.Draw(dustParticles, viewRect, - new Rectangle((int)((backgroundPos.X * multiplier)), (int)((-backgroundPos.Y * multiplier)), cam.WorldView.Width, cam.WorldView.Height), - Color.White * multiplier, 0.0f, Vector2.Zero, SpriteEffects.None, 1.0f-multiplier); - multiplier -= 0.15f; - } - - spriteBatch.End(); - - if (GameMain.GameSession != null && GameMain.GameSession.Level != null) - { - GameMain.GameSession.Level.Render(graphics, cam); - //GameMain.GameSession.Level.SetObserverPosition(cam.WorldViewCenter); - } spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, @@ -344,7 +287,7 @@ namespace Barotrauma Submarine.DrawFront(spriteBatch); - if (Level.Loaded!=null) Level.Loaded.Draw(spriteBatch); + if (Level.Loaded!=null) Level.Loaded.DrawFront(spriteBatch); spriteBatch.End(); diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index aed41e4ae..5393f7f3d 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -368,8 +368,7 @@ namespace Barotrauma Sprite backGround = GameMain.GameSession.Map.CurrentLocation.Type.Background; spriteBatch.Draw(backGround.Texture, Vector2.Zero, null, Color.White, 0.0f, Vector2.Zero, Math.Max((float)GameMain.GraphicsWidth / backGround.SourceRect.Width, (float)GameMain.GraphicsHeight / backGround.SourceRect.Height), SpriteEffects.None, 0.0f); - - + topPanel.Draw(spriteBatch); bottomPanel[selectedRightPanel].Draw(spriteBatch); diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index 065732e91..6d8ca83df 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -36,6 +36,8 @@ namespace Barotrauma public bool IsServer; public string ServerName, ServerMessage; + private Sprite backgroundSprite; + private GUITextBox serverMessage; public GUIListBox SubList @@ -98,6 +100,9 @@ namespace Barotrauma } private set { + if (levelSeed == value) return; + backgroundSprite = LocationType.Random(LevelSeed).Background; + levelSeed = value; seedBox.Text = levelSeed; } @@ -266,6 +271,7 @@ namespace Barotrauma serverMessage.Wrap = true; serverMessage.TextGetter = GetServerMessage; serverMessage.OnTextChanged = UpdateServerMessage; + } public override void Deselect() @@ -284,7 +290,7 @@ namespace Barotrauma textBox.Select(); Character.Controlled = null; - GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; + //GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; subList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowSubVoting; playerList.Enabled = GameMain.Server != null; @@ -597,19 +603,19 @@ namespace Barotrauma { base.Update(deltaTime); - Vector2 pos = new Vector2( - Submarine.Borders.X + Submarine.Borders.Width / 2, - Submarine.Borders.Y - Submarine.Borders.Height / 2); + //Vector2 pos = new Vector2( + // Submarine.Borders.X + Submarine.Borders.Width / 2, + // Submarine.Borders.Y - Submarine.Borders.Height / 2); - camAngle += (float)deltaTime / 10.0f; - Vector2 offset = (new Vector2( - (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f), - (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f))); + //camAngle += (float)deltaTime / 10.0f; + //Vector2 offset = (new Vector2( + // (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f), + // (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f))); - pos += offset * 0.8f; + //pos += offset * 0.8f; - GameMain.GameScreen.Cam.TargetPos = pos; - GameMain.GameScreen.Cam.MoveCamera((float)deltaTime); + //GameMain.GameScreen.Cam.TargetPos = pos; + //GameMain.GameScreen.Cam.MoveCamera((float)deltaTime); menu.Update((float)deltaTime); @@ -632,12 +638,17 @@ namespace Barotrauma public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { - graphics.Clear(Color.CornflowerBlue); - - GameMain.GameScreen.DrawMap(graphics, spriteBatch); - + graphics.Clear(Color.Black); + spriteBatch.Begin(); + if (backgroundSprite!=null) + { + spriteBatch.Draw(backgroundSprite.Texture, Vector2.Zero, null, Color.White, 0.0f, Vector2.Zero, + Math.Max((float)GameMain.GraphicsWidth / backgroundSprite.SourceRect.Width, (float)GameMain.GraphicsHeight / backgroundSprite.SourceRect.Height), + SpriteEffects.None, 0.0f); + } + menu.Draw(spriteBatch); if (jobInfoFrame != null) jobInfoFrame.Draw(spriteBatch); diff --git a/Subsurface/Source/Screens/ServerListScreen.cs b/Subsurface/Source/Screens/ServerListScreen.cs index 16b7b5543..e3acdaddc 100644 --- a/Subsurface/Source/Screens/ServerListScreen.cs +++ b/Subsurface/Source/Screens/ServerListScreen.cs @@ -81,7 +81,6 @@ namespace Barotrauma GUIButton button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, GUI.Style, menu); button.OnClicked = GameMain.MainMenuScreen.SelectTab; - button.CanBeSelected = false; button.SelectedColor = button.Color; refreshDisableTimer = DateTime.Now; diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index b1453c56c..6e06c07fa 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ