diff --git a/Launcher2/LauncherMain.cs b/Launcher2/LauncherMain.cs index a9c615350..b58ec23ef 100644 --- a/Launcher2/LauncherMain.cs +++ b/Launcher2/LauncherMain.cs @@ -4,7 +4,6 @@ using Microsoft.Xna.Framework.Input; using Barotrauma; using System.Collections.Generic; using System.Reflection; -using System.Runtime.InteropServices; using System.Xml.Linq; using System.Linq; using System.Diagnostics; @@ -25,7 +24,7 @@ namespace Launcher2 string version = AssemblyName.GetAssemblyName("Barotrauma.exe").Version.ToString(); private const string configPath = "config.xml"; - private Barotrauma.GameSettings settings; + private GameSettings settings; private string latestVersionFileList, latestVersionFolder; @@ -38,28 +37,24 @@ namespace Launcher2 private GUIProgressBar progressBar; private GUIButton downloadButton; - GUIButton launchButton; - - //public bool FullScreenEnabled - //{ - // get { return settings.FullScreenEnabled; } - // set { settings.FullScreenEnabled = value; } - //} - + private GUIButton launchButton; + public bool AutoCheckUpdates { get { return settings.AutoCheckUpdates; } set { settings.AutoCheckUpdates = value; } } - Texture2D backgroundTexture, titleTexture; + private Texture2D backgroundTexture, titleTexture; - GraphicsDeviceManager graphics; - SpriteBatch spriteBatch; + private GraphicsDeviceManager graphics; + private SpriteBatch spriteBatch; - int graphicsWidth, graphicsHeight; + private RasterizerState scissorTestEnable; - GUIFrame guiRoot; + private int graphicsWidth, graphicsHeight; + + private GUIFrame guiRoot; public LauncherMain() : base() @@ -67,6 +62,8 @@ namespace Launcher2 graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 640; graphics.PreferredBackBufferHeight = 400; + + scissorTestEnable = new RasterizerState() { ScissorTestEnable = true }; IsMouseVisible = true; @@ -210,7 +207,7 @@ namespace Launcher2 { GraphicsDevice.Clear(Color.Black); - spriteBatch.Begin(); + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, scissorTestEnable); spriteBatch.Draw(backgroundTexture, new Rectangle(0, 0, graphicsWidth, graphicsHeight), diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 2eb25ca99..0c0d2c2fe 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -559,6 +559,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Content/Items/Artifacts/artifacts.xml b/Subsurface/Content/Items/Artifacts/artifacts.xml index 2d7145c9a..ba1631cc6 100644 --- a/Subsurface/Content/Items/Artifacts/artifacts.xml +++ b/Subsurface/Content/Items/Artifacts/artifacts.xml @@ -141,6 +141,18 @@ + + + + + + + + + + + + diff --git a/Subsurface/Content/Items/Engine/engine.xml b/Subsurface/Content/Items/Engine/engine.xml index 3d3ff81b5..41600d1c0 100644 --- a/Subsurface/Content/Items/Engine/engine.xml +++ b/Subsurface/Content/Items/Engine/engine.xml @@ -75,11 +75,12 @@ - + + @@ -105,11 +106,12 @@ - + + diff --git a/Subsurface/Content/Items/Engine/radarBlip.png b/Subsurface/Content/Items/Engine/radarBlip.png new file mode 100644 index 000000000..5c2d7c602 Binary files /dev/null and b/Subsurface/Content/Items/Engine/radarBlip.png differ diff --git a/Subsurface/Content/Items/Engine/radarOverlay.png b/Subsurface/Content/Items/Engine/radarOverlay.png index 5b50d0e4d..6f7184665 100644 Binary files a/Subsurface/Content/Items/Engine/radarOverlay.png and b/Subsurface/Content/Items/Engine/radarOverlay.png differ diff --git a/Subsurface/Content/Items/Tools/tools.xml b/Subsurface/Content/Items/Tools/tools.xml index e8ae3ced0..1b53bfdbc 100644 --- a/Subsurface/Content/Items/Tools/tools.xml +++ b/Subsurface/Content/Items/Tools/tools.xml @@ -198,12 +198,13 @@ - + + diff --git a/Subsurface/Content/Items/Weapons/railgun.xml b/Subsurface/Content/Items/Weapons/railgun.xml index 2a6ee0ab8..ec3636731 100644 --- a/Subsurface/Content/Items/Weapons/railgun.xml +++ b/Subsurface/Content/Items/Weapons/railgun.xml @@ -60,6 +60,7 @@ + diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index 47c309e6b..416133d62 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -214,7 +214,7 @@ namespace Barotrauma Limb leftLeg = GetLimb(LimbType.LeftLeg); Limb rightLeg = GetLimb(LimbType.RightLeg); - + float getUpSpeed = 0.3f; float walkCycleSpeed = movement.X * walkAnimSpeed; if (stairs != null) @@ -304,8 +304,11 @@ namespace Barotrauma torso.pullJoint.Enabled = true; head.pullJoint.Enabled = true; waist.pullJoint.Enabled = true; + + float floorPos = GetFloorY(colliderPos + new Vector2(Math.Sign(movement.X) * 0.5f, 1.0f)); + bool onSlope = floorPos > GetColliderBottom().Y + 0.05f; - if (stairs != null) + if (stairs != null || onSlope) { torso.pullJoint.WorldAnchorB = new Vector2( MathHelper.SmoothStep(torso.SimPosition.X, footMid + movement.X * 0.25f, getUpSpeed * 0.8f), @@ -351,20 +354,23 @@ namespace Barotrauma //progress the walking animation walkPos -= (walkCycleSpeed / runningModifier) * 0.8f; - MoveLimb(leftFoot, - colliderPos + new Vector2( - stepSize.X, - (stepSize.Y > 0.0f) ? stepSize.Y : -0.15f), - 15.0f, true); + for (int i = -1; i < 2; i += 2) + { + Limb foot = i == -1 ? leftFoot : rightFoot; + Limb leg = i == -1 ? leftLeg : rightLeg; - MoveLimb(rightFoot, - colliderPos + new Vector2( - -stepSize.X, - (-stepSize.Y > 0.0f) ? -stepSize.Y : -0.15f), - 15.0f, true); + Vector2 footPos = stepSize * -i; + if (stepSize.Y > 0.0f) stepSize.Y = -0.15f; - leftFoot.body.SmoothRotate(leftLeg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier); - rightFoot.body.SmoothRotate(rightLeg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier); + if (onSlope && stairs == null) + { + footPos.Y *= 2.0f; + } + footPos.Y = Math.Min(waist.SimPosition.Y - colliderPos.Y - 0.4f, footPos.Y); + + MoveLimb(foot, footPos + colliderPos, 15.0f, true); + foot.body.SmoothRotate(leg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier); + } if (runningModifier > 1.0f) { @@ -435,7 +441,11 @@ namespace Barotrauma { footPos = new Vector2(GetCenterOfMass().X + stepSize.X * i * 0.2f, colliderPos.Y - 0.1f); } - + + if (stairs == null) + { + footPos.Y = Math.Max(Math.Min(floorPos, footPos.Y + 0.5f), footPos.Y); + } var foot = i == -1 ? rightFoot : leftFoot; diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 68271e9af..23fc613b0 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -1100,7 +1100,12 @@ namespace Barotrauma { PhysicsBody refBody = refLimb == null ? Collider : refLimb.body; - Vector2 rayStart = refBody.SimPosition; + return GetFloorY(refBody.SimPosition); + } + + protected float GetFloorY(Vector2 simPosition) + { + Vector2 rayStart = simPosition; Vector2 rayEnd = rayStart - new Vector2(0.0f, TorsoPosition); var lowestLimb = FindLowestLimb(); @@ -1129,7 +1134,7 @@ namespace Barotrauma } return closestFraction; - } + } , rayStart, rayEnd); @@ -1141,7 +1146,6 @@ namespace Barotrauma { return rayStart.Y + (rayEnd.Y - rayStart.Y) * closestFraction; } - } public void SetPosition(Vector2 simPosition, bool lerp = false) diff --git a/Subsurface/Source/GUI/GUIListBox.cs b/Subsurface/Source/GUI/GUIListBox.cs index b44195a25..ed9b57158 100644 --- a/Subsurface/Source/GUI/GUIListBox.cs +++ b/Subsurface/Source/GUI/GUIListBox.cs @@ -383,7 +383,8 @@ namespace Barotrauma if (!scrollBarHidden) scrollBar.Draw(spriteBatch); - GameMain.CurrGraphicsDevice.ScissorRectangle = frame.Rect; + Rectangle prevScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle; + spriteBatch.GraphicsDevice.ScissorRectangle = frame.Rect; int lastVisible = 0; for (int i = 0; i < children.Count; i++) @@ -400,8 +401,8 @@ namespace Barotrauma lastVisible = i; child.Draw(spriteBatch); } - - GameMain.CurrGraphicsDevice.ScissorRectangle = new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight); + + spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect; } private bool IsChildVisible(GUIComponent child) diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index 121ec6650..42a37d8e9 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -276,10 +276,14 @@ namespace Barotrauma if (offset != Vector2.Zero) drawRect.Location += offset.ToPoint(); base.Draw(spriteBatch); - + if (TextGetter != null) Text = TextGetter(); - - if (overflowClipActive) GameMain.CurrGraphicsDevice.ScissorRectangle = rect; + + Rectangle prevScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle; + if (overflowClipActive) + { + spriteBatch.GraphicsDevice.ScissorRectangle = rect; + } if (!string.IsNullOrEmpty(text)) { @@ -291,7 +295,10 @@ namespace Barotrauma SpriteEffects.None, textDepth); } - if (overflowClipActive) GameMain.CurrGraphicsDevice.ScissorRectangle = new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight); + if (overflowClipActive) + { + spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect; + } DrawChildren(spriteBatch); diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index 4ed6562ce..4415a7629 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -7,30 +7,15 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Barotrauma.Networking; using Barotrauma.Particles; -using System.Collections; using System.Collections.Generic; using Microsoft.Xna.Framework.Input; -using System.Xml; namespace Barotrauma { class GameMain : Game { - public static GraphicsDeviceManager Graphics; - static int graphicsWidth, graphicsHeight; - static SpriteBatch spriteBatch; - - public static GameMain Instance; - - public static bool WindowActive - { - get { return Instance == null || Instance.IsActive; } - } - public static bool DebugDraw; - - public static GraphicsDevice CurrGraphicsDevice; - + public static FrameCounter FrameCounter; public static readonly Version Version = Assembly.GetEntryAssembly().GetName().Version; @@ -51,21 +36,17 @@ namespace Barotrauma { get { return Config.SelectedContentPackage; } } - - public static Level Level; - + public static GameSession GameSession; public static NetworkMember NetworkMember; public static ParticleManager ParticleManager; - - //public static TextureLoader TextureLoader; public static World World; public static LoadingScreen TitleScreen; - private static bool loadingScreenOpen; + private bool loadingScreenOpen; public static GameSettings Config; @@ -74,25 +55,35 @@ namespace Barotrauma private GameTime fixedTime; - //public static Random localRandom; - //public static Random random; + private static SpriteBatch spriteBatch; - //private Stopwatch renderTimer; - //public static int renderTimeElapsed; - - public Camera Cam + public static GameMain Instance { - get { return GameScreen.Cam; } + get; + private set; } + public static GraphicsDeviceManager GraphicsDeviceManager + { + get; + private set; + } + public static int GraphicsWidth { - get { return graphicsWidth; } + get; + private set; } public static int GraphicsHeight { - get { return graphicsHeight; } + get; + private set; + } + + public static bool WindowActive + { + get { return Instance == null || Instance.IsActive; } } public static GameServer Server @@ -110,23 +101,10 @@ namespace Barotrauma get; private set; } - - /// - /// Total seconds elapsed after startup - /// - public double TotalElapsedTime - { - get; - private set; - } - + public GameMain() { - Graphics = new GraphicsDeviceManager(this) - { - SynchronizeWithVerticalRetrace = false, - }; - + GraphicsDeviceManager = new GraphicsDeviceManager(this); Window.Title = "Barotrauma"; Instance = this; @@ -144,11 +122,8 @@ namespace Barotrauma Content.RootDirectory = "Content"; FrameCounter = new FrameCounter(); - - //IsMouseVisible = true; - + IsFixedTimeStep = false; - //TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55); Timing.Accumulator = 0.0f; fixedTime = new GameTime(); @@ -158,22 +133,21 @@ namespace Barotrauma FarseerPhysics.Settings.ContinuousPhysics = false; FarseerPhysics.Settings.VelocityIterations = 1; FarseerPhysics.Settings.PositionIterations = 1; - } public void ApplyGraphicsSettings() { - graphicsWidth = Config.GraphicsWidth; - graphicsHeight = Config.GraphicsHeight; - Graphics.SynchronizeWithVerticalRetrace = Config.VSyncEnabled; - - Graphics.HardwareModeSwitch = Config.WindowMode != WindowMode.BorderlessWindowed; + GraphicsWidth = Config.GraphicsWidth; + GraphicsHeight = Config.GraphicsHeight; + GraphicsDeviceManager.SynchronizeWithVerticalRetrace = Config.VSyncEnabled; - Graphics.IsFullScreen = Config.WindowMode == WindowMode.Fullscreen || Config.WindowMode == WindowMode.BorderlessWindowed; - Graphics.PreferredBackBufferWidth = graphicsWidth; - Graphics.PreferredBackBufferHeight = graphicsHeight; - - Graphics.ApplyChanges(); + GraphicsDeviceManager.HardwareModeSwitch = Config.WindowMode != WindowMode.BorderlessWindowed; + + GraphicsDeviceManager.IsFullScreen = Config.WindowMode == WindowMode.Fullscreen || Config.WindowMode == WindowMode.BorderlessWindowed; + GraphicsDeviceManager.PreferredBackBufferWidth = GraphicsWidth; + GraphicsDeviceManager.PreferredBackBufferHeight = GraphicsHeight; + + GraphicsDeviceManager.ApplyChanges(); } /// @@ -185,9 +159,7 @@ namespace Barotrauma protected override void Initialize() { base.Initialize(); - - CurrGraphicsDevice = GraphicsDevice; - + ScissorTestEnable = new RasterizerState() { ScissorTestEnable = true }; Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Character)); @@ -202,25 +174,25 @@ namespace Barotrauma /// protected override void LoadContent() { - graphicsWidth = GraphicsDevice.Viewport.Width; - graphicsHeight = GraphicsDevice.Viewport.Height; - + GraphicsWidth = GraphicsDevice.Viewport.Width; + GraphicsHeight = GraphicsDevice.Viewport.Height; + Sound.Init(); ConvertUnits.SetDisplayUnitToSimUnitRatio(Physics.DisplayToSimRation); - - spriteBatch = new SpriteBatch(GraphicsDevice); - TextureLoader.Init(GraphicsDevice); + + spriteBatch = new SpriteBatch(base.GraphicsDevice); + TextureLoader.Init(base.GraphicsDevice); loadingScreenOpen = true; - TitleScreen = new LoadingScreen(GraphicsDevice); + TitleScreen = new LoadingScreen(base.GraphicsDevice); loadingCoroutine = CoroutineManager.StartCoroutine(Load()); } public IEnumerable Load() { - GUI.GraphicsDevice = GraphicsDevice; + GUI.GraphicsDevice = base.GraphicsDevice; GUI.Init(Content); GUIComponent.Init(Window); @@ -228,9 +200,9 @@ namespace Barotrauma DebugConsole.Log(SelectedPackage == null ? "No content package selected" : "Content package \"" + SelectedPackage.Name + "\" selected"); yield return CoroutineStatus.Running; - LightManager = new Lights.LightManager(GraphicsDevice); + LightManager = new Lights.LightManager(base.GraphicsDevice); - Hull.renderer = new WaterRenderer(GraphicsDevice, Content); + Hull.renderer = new WaterRenderer(base.GraphicsDevice, Content); TitleScreen.LoadState = 1.0f; yield return CoroutineStatus.Running; @@ -275,7 +247,7 @@ namespace Barotrauma TitleScreen.LoadState = 80.0f; yield return CoroutineStatus.Running; - GameScreen = new GameScreen(Graphics.GraphicsDevice, Content); + GameScreen = new GameScreen(GraphicsDeviceManager.GraphicsDevice, Content); TitleScreen.LoadState = 90.0f; yield return CoroutineStatus.Running; @@ -289,7 +261,7 @@ namespace Barotrauma yield return CoroutineStatus.Running; - ParticleManager = new ParticleManager("Content/Particles/ParticlePrefabs.xml", Cam); + ParticleManager = new ParticleManager("Content/Particles/ParticlePrefabs.xml", GameScreen.Cam); yield return CoroutineStatus.Running; LocationType.Init(); @@ -325,8 +297,6 @@ namespace Barotrauma while (Timing.Accumulator >= Timing.Step) { - TotalElapsedTime = gameTime.TotalGameTime.TotalSeconds; - fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly; TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16); fixedTime.ElapsedGameTime = addTime; @@ -415,11 +385,11 @@ namespace Barotrauma if (loadingScreenOpen) { - TitleScreen.Draw(spriteBatch, GraphicsDevice, (float)deltaTime); + TitleScreen.Draw(spriteBatch, base.GraphicsDevice, (float)deltaTime); } else if (hasLoaded) { - Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch); + Screen.Selected.Draw(deltaTime, base.GraphicsDevice, spriteBatch); } if (!DebugDraw) return; @@ -432,7 +402,7 @@ namespace Barotrauma } static bool waitForKeyHit = true; - public static CoroutineHandle ShowLoading(IEnumerable loader, bool waitKeyHit = true) + public CoroutineHandle ShowLoading(IEnumerable loader, bool waitKeyHit = true) { waitForKeyHit = waitKeyHit; loadingScreenOpen = true; diff --git a/Subsurface/Source/GameSession/ShiftSummary.cs b/Subsurface/Source/GameSession/ShiftSummary.cs index d4227a667..232a16cc8 100644 --- a/Subsurface/Source/GameSession/ShiftSummary.cs +++ b/Subsurface/Source/GameSession/ShiftSummary.cs @@ -20,12 +20,7 @@ namespace Barotrauma selectedMission = gameSession.Mission; } - - - //public void AddCasualty(Character character, CauseOfDeath causeOfDeath) - //{ - // casualties.Add(new Casualty(character.Info, causeOfDeath, "")); - //} + public GUIFrame CreateSummaryFrame(string endMessage) { @@ -90,7 +85,6 @@ namespace Barotrauma } else { - if (character.IsUnconscious) { statusText = "Unconscious"; @@ -101,11 +95,12 @@ namespace Barotrauma statusText = "Injured"; statusColor = Color.DarkOrange; } - } - new GUITextBlock(new Rectangle(0, 0, 0, 20), statusText, - "", Alignment.BottomLeft, Alignment.TopCenter, characterFrame, true, GUI.SmallFont).Color = statusColor * 0.7f; + new GUITextBlock( + new Rectangle(0, 0, 0, 20), statusText, statusColor * 0.8f, Color.White, + Alignment.BottomLeft, Alignment.Center, + null, characterFrame, true, GUI.SmallFont); x += characterFrame.Rect.Width + 10; } @@ -120,12 +115,10 @@ namespace Barotrauma new GUITextBlock(new Rectangle(0, y, innerFrame.Rect.Width - 170, 0), (GameMain.GameSession.Mission.Completed) ? GameMain.GameSession.Mission.SuccessMessage : GameMain.GameSession.Mission.FailureMessage, "", innerFrame, true); - //y += 50; if (GameMain.GameSession.Mission.Completed && singleplayer) { new GUITextBlock(new Rectangle(0, 0, 0, 30), "Reward: " + GameMain.GameSession.Mission.Reward, "", Alignment.BottomLeft, Alignment.BottomLeft, innerFrame); - //y += 30; } } diff --git a/Subsurface/Source/GameSettings.cs b/Subsurface/Source/GameSettings.cs index df02b1033..92031d217 100644 --- a/Subsurface/Source/GameSettings.cs +++ b/Subsurface/Source/GameSettings.cs @@ -365,8 +365,8 @@ namespace Barotrauma vsyncTickBox.OnSelected = (GUITickBox box) => { VSyncEnabled = !VSyncEnabled; - GameMain.Graphics.SynchronizeWithVerticalRetrace = VSyncEnabled; - GameMain.Graphics.ApplyChanges(); + GameMain.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = VSyncEnabled; + GameMain.GraphicsDeviceManager.ApplyChanges(); UnsavedSettings = true; return true; diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index 9a8d5d52a..d8110f3a7 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -17,6 +17,8 @@ namespace Barotrauma.Items.Components private readonly Sprite pingCircle, screenOverlay; + private readonly Sprite radarBlip; + private GUITickBox isActiveTickBox; private List radarBlips; @@ -27,6 +29,8 @@ namespace Barotrauma.Items.Components private Vector2 center; private float displayRadius; private float displayScale; + + private float displayBorderSize; [HasDefaultValue(10000.0f, false)] public float Range @@ -61,6 +65,8 @@ namespace Barotrauma.Items.Components { radarBlips = new List(); + displayBorderSize = ToolBox.GetAttributeFloat(element, "displaybordersize", 0.0f); + foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) @@ -71,6 +77,9 @@ namespace Barotrauma.Items.Components case "screenoverlay": screenOverlay = new Sprite(subElement); break; + case "blip": + radarBlip = new Sprite(subElement); + break; } } @@ -149,7 +158,7 @@ namespace Barotrauma.Items.Components prevPingRadius = pingRadius; } - float passivePingRadius = (float)Math.Sin(GameMain.Instance.TotalElapsedTime*10); + float passivePingRadius = (float)Math.Sin(Timing.TotalTime * 10); if (passivePingRadius > 0.0f) { foreach (AITarget t in AITarget.List) @@ -172,19 +181,19 @@ namespace Barotrauma.Items.Components { GuiFrame.Draw(spriteBatch); - int radius = GuiFrame.Rect.Height / 2 - 30; + int radius = GuiFrame.Rect.Height / 2 - 10; DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2)); } private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect) { center = new Vector2(rect.X + rect.Width * 0.5f, rect.Center.Y); - displayRadius = rect.Width / 2.0f; + displayRadius = (rect.Width / 2.0f) * (1.0f - displayBorderSize); displayScale = displayRadius / range; if (IsActive) { - pingCircle.Draw(spriteBatch, center, Color.White * (1.0f - pingState), 0.0f, (rect.Width / pingCircle.size.X) * pingState); + pingCircle.Draw(spriteBatch, center, Color.White * (1.0f - pingState), 0.0f, (displayRadius*2 / pingCircle.size.X) * pingState); } if (item.Submarine != null && !DetectSubmarineWalls) @@ -204,14 +213,28 @@ namespace Barotrauma.Items.Components Vector2 end = (submarine.HullVertices[(i + 1) % submarine.HullVertices.Count] + offset) * simScale; end.Y = -end.Y; - GUI.DrawLine(spriteBatch, center + start, center + end, Color.Green); + GUI.DrawLine(spriteBatch, center + start, center + end, Color.LightBlue); } } } - foreach (RadarBlip radarBlip in radarBlips) + if (radarBlips.Count > 0) { - DrawBlip(spriteBatch, radarBlip, center, radarBlip.FadeTimer / 2.0f); + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive); + + foreach (RadarBlip radarBlip in radarBlips) + { + DrawBlip(spriteBatch, radarBlip, center, radarBlip.FadeTimer / 2.0f); + } + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); + } + + if (GameMain.DebugDraw) + { + GUI.DrawString(spriteBatch, rect.Location.ToVector2(), radarBlips.Count.ToString(), Color.White); } if (screenOverlay != null) @@ -402,13 +425,26 @@ namespace Barotrauma.Items.Components float alpha = pingStrength * Rand.Range(1.5f, 2.0f); for (float z = 0; z < displayRadius - pointDist * displayScale; z += zStep) { - var blip = new RadarBlip( - point + Rand.Vector(150.0f) + Vector2.Normalize(point - item.WorldPosition) * z / displayScale, - alpha * (1.0f - pointDist/range)); + Vector2 pos = point + Rand.Vector(150.0f) + Vector2.Normalize(point - item.WorldPosition) * z / displayScale; + float fadeTimer = alpha * (1.0f - pointDist / range); + + int minDist = 200; + radarBlips.RemoveAll(b => b.FadeTimer < fadeTimer && Math.Abs(pos.X - b.Position.X) < minDist && Math.Abs(pos.Y - b.Position.Y) < minDist); + + var blip = new RadarBlip(pos, fadeTimer); radarBlips.Add(blip); zStep += 0.5f; - alpha -= (z == 0) ? 0.5f : 0.1f; + + if (z == 0) + { + alpha = Math.Min(alpha - 0.5f, 1.5f); + } + else + { + alpha -= 0.1f; + } + if (alpha < 0) break; } @@ -427,7 +463,7 @@ namespace Barotrauma.Items.Components new Color(255, 255, 255) }; float scaledT = strength * (colors.Length - 1); - Color color = Color.Lerp(colors[(int)scaledT], colors[(int)scaledT], (scaledT - (int)scaledT)); + Color color = Color.Lerp(colors[(int)scaledT], colors[(int)Math.Min(scaledT+1, colors.Length-1)], (scaledT - (int)scaledT)); Vector2 pos = (blip.Position - item.WorldPosition) * displayScale; pos.Y = -pos.Y; @@ -437,21 +473,28 @@ namespace Barotrauma.Items.Components blip.FadeTimer = 0.0f; return; } - - /*pos.X = MathUtils.Round(pos.X, 4); - pos.Y = MathUtils.Round(pos.Y, 2);*/ - - + float posDist = pos.Length(); Vector2 dir = pos / posDist; float distFactor = (posDist / displayRadius); - Vector2 normal = new Vector2(dir.Y, -dir.X) * (strength + 1.0f) * distFactor * 5.0f; - - GUI.DrawLine(spriteBatch, center + pos - normal, center + pos + normal, color * (1.0f - distFactor), 0, 2); + Vector2 normal = new Vector2(dir.Y, -dir.X); - pos += Rand.Range(0.0f, 1.0f) * dir + Rand.Range(-1.0f, 1.0f) * normal; - GUI.DrawLine(spriteBatch, center + pos - normal, center + pos + normal, color * 0.2f, 0, 3); + float scale = (strength + 3.0f) * Math.Max(distFactor * 3.0f, 1.0f); + + if (radarBlip == null) + { + GUI.DrawRectangle(spriteBatch, center + pos, Vector2.One * 4, Color.Magenta, true); + return; + } + + radarBlip.Draw(spriteBatch, center + pos, color, radarBlip.Origin, MathUtils.VectorToAngle(pos), + new Vector2(scale * 0.3f, scale) * 0.04f, SpriteEffects.None, 0); + + pos += Rand.Range(0.0f, 1.0f) * dir + Rand.Range(-scale, scale) * normal; + + radarBlip.Draw(spriteBatch, center + pos, color * 0.5f, radarBlip.Origin, MathUtils.VectorToAngle(pos), + new Vector2(scale * 0.3f, scale) * 0.08f, SpriteEffects.None, 0); } private void DrawMarker(SpriteBatch spriteBatch, string label, Vector2 position, float scale, Vector2 center, float radius) @@ -473,7 +516,7 @@ namespace Barotrauma.Items.Components markerPos.X = (int)markerPos.X; markerPos.Y = (int)markerPos.Y; - GUI.DrawRectangle(spriteBatch, new Rectangle((int)markerPos.X, (int)markerPos.Y, 5, 5), Color.LightGreen * textAlpha); + GUI.DrawRectangle(spriteBatch, new Rectangle((int)markerPos.X, (int)markerPos.Y, 5, 5), Color.LightBlue); if (dir.X < 0.0f) markerPos.X -= GUI.SmallFont.MeasureString(label).X+10; @@ -484,7 +527,7 @@ namespace Barotrauma.Items.Components GUI.DrawString(spriteBatch, new Vector2(markerPos.X + 10, markerPos.Y), wrappedLabel, - Color.LightGreen * textAlpha, Color.Black * textAlpha * 0.5f, + Color.LightBlue * textAlpha, Color.Black * textAlpha * 0.5f, 2, GUI.SmallFont); } diff --git a/Subsurface/Source/Map/Levels/LevelRenderer.cs b/Subsurface/Source/Map/Levels/LevelRenderer.cs index 3c1cb824a..fb05b856d 100644 --- a/Subsurface/Source/Map/Levels/LevelRenderer.cs +++ b/Subsurface/Source/Map/Levels/LevelRenderer.cs @@ -41,7 +41,7 @@ namespace Barotrauma if (wallEdgeEffect == null) { - wallEdgeEffect = new BasicEffect(GameMain.CurrGraphicsDevice) + wallEdgeEffect = new BasicEffect(GameMain.Instance.GraphicsDevice) { DiffuseColor = new Vector3(0.8f, 0.8f, 0.8f), VertexColorEnabled = false, @@ -53,7 +53,7 @@ namespace Barotrauma if (wallCenterEffect == null) { - wallCenterEffect = new BasicEffect(GameMain.CurrGraphicsDevice) + wallCenterEffect = new BasicEffect(GameMain.Instance.GraphicsDevice) { VertexColorEnabled = false, TextureEnabled = true, @@ -90,13 +90,13 @@ namespace Barotrauma public void SetWallVertices(VertexPositionTexture[] vertices) { - wallVertices = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length,BufferUsage.WriteOnly); + wallVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length,BufferUsage.WriteOnly); wallVertices.SetData(vertices); } public void SetBodyVertices(VertexPositionTexture[] vertices) { - bodyVertices = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + bodyVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); bodyVertices.SetData(vertices); } @@ -164,7 +164,7 @@ namespace Barotrauma spriteBatch.End(); - RenderWalls(GameMain.CurrGraphicsDevice, cam); + RenderWalls(GameMain.Instance.GraphicsDevice, cam); } public void Draw(SpriteBatch spriteBatch) diff --git a/Subsurface/Source/Map/Levels/WaterRenderer.cs b/Subsurface/Source/Map/Levels/WaterRenderer.cs index e897f8b45..87e0b26a1 100644 --- a/Subsurface/Source/Map/Levels/WaterRenderer.cs +++ b/Subsurface/Source/Map/Levels/WaterRenderer.cs @@ -48,7 +48,7 @@ namespace Barotrauma if (basicEffect == null) { - basicEffect = new BasicEffect(GameMain.CurrGraphicsDevice); + basicEffect = new BasicEffect(GameMain.Instance.GraphicsDevice); basicEffect.VertexColorEnabled = false; basicEffect.TextureEnabled = true; diff --git a/Subsurface/Source/Map/Levels/WrappingWall.cs b/Subsurface/Source/Map/Levels/WrappingWall.cs index 1c200fa6a..1433c97ea 100644 --- a/Subsurface/Source/Map/Levels/WrappingWall.cs +++ b/Subsurface/Source/Map/Levels/WrappingWall.cs @@ -113,13 +113,13 @@ namespace Barotrauma public void SetWallVertices(VertexPositionTexture[] vertices) { - wallVertices = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + wallVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); wallVertices.SetData(vertices); } public void SetBodyVertices(VertexPositionColor[] vertices) { - bodyVertices = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); + bodyVertices = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly); bodyVertices.SetData(vertices); } diff --git a/Subsurface/Source/Map/Lights/ConvexHull.cs b/Subsurface/Source/Map/Lights/ConvexHull.cs index 941cc827e..ab3296206 100644 --- a/Subsurface/Source/Map/Lights/ConvexHull.cs +++ b/Subsurface/Source/Map/Lights/ConvexHull.cs @@ -151,7 +151,7 @@ namespace Barotrauma.Lights { if (enabled == value) return; enabled = value; - LastVertexChangeTime = (float)GameMain.Instance.TotalElapsedTime; + LastVertexChangeTime = (float)Timing.TotalTime; } } @@ -173,12 +173,12 @@ namespace Barotrauma.Lights { if (shadowEffect == null) { - shadowEffect = new BasicEffect(GameMain.CurrGraphicsDevice); + shadowEffect = new BasicEffect(GameMain.Instance.GraphicsDevice); shadowEffect.VertexColorEnabled = true; } if (penumbraEffect == null) { - penumbraEffect = new BasicEffect(GameMain.CurrGraphicsDevice); + penumbraEffect = new BasicEffect(GameMain.Instance.GraphicsDevice); penumbraEffect.TextureEnabled = true; //shadowEffect.VertexColorEnabled = true; penumbraEffect.LightingEnabled = false; @@ -264,7 +264,7 @@ namespace Barotrauma.Lights segments[i].End.Pos += amount; } - LastVertexChangeTime = (float)GameMain.Instance.TotalElapsedTime; + LastVertexChangeTime = (float)Timing.TotalTime; CalculateDimensions(); } @@ -273,7 +273,7 @@ namespace Barotrauma.Lights { Debug.Assert(points.Length == 4, "Only rectangular convex hulls are supported"); - LastVertexChangeTime = (float)GameMain.Instance.TotalElapsedTime; + LastVertexChangeTime = (float)Timing.TotalTime; for (int i = 0; i < 4; i++) { @@ -601,7 +601,7 @@ namespace Barotrauma.Lights } CalculateShadowVertices(lightSourcePos, los); - ShadowBuffer = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, 6 * 2, BufferUsage.None); + ShadowBuffer = new VertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColor.VertexDeclaration, 6 * 2, BufferUsage.None); ShadowBuffer.SetData(shadowVertices, 0, shadowVertices.Length); graphicsDevice.SetVertexBuffer(ShadowBuffer); diff --git a/Subsurface/Source/Map/Lights/LightManager.cs b/Subsurface/Source/Map/Lights/LightManager.cs index b1ae2f9f9..ba8212110 100644 --- a/Subsurface/Source/Map/Lights/LightManager.cs +++ b/Subsurface/Source/Map/Lights/LightManager.cs @@ -64,7 +64,7 @@ namespace Barotrauma.Lights if (lightEffect == null) { - lightEffect = new BasicEffect(GameMain.CurrGraphicsDevice); + lightEffect = new BasicEffect(GameMain.Instance.GraphicsDevice); lightEffect.VertexColorEnabled = false; lightEffect.TextureEnabled = true; diff --git a/Subsurface/Source/Map/Lights/LightSource.cs b/Subsurface/Source/Map/Lights/LightSource.cs index 0aeeada4e..ef595d15e 100644 --- a/Subsurface/Source/Map/Lights/LightSource.cs +++ b/Subsurface/Source/Map/Lights/LightSource.cs @@ -490,16 +490,16 @@ namespace Barotrauma.Lights //now we just create a buffer for 64 verts and make it larger if needed if (lightVolumeBuffer == null) { - lightVolumeBuffer = new DynamicVertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, Math.Max(64, (int)(vertexCount*1.5)), BufferUsage.None); - lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.CurrGraphicsDevice, typeof(short), Math.Max(64*3, (int)(indexCount * 1.5)), BufferUsage.None); + lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, Math.Max(64, (int)(vertexCount*1.5)), BufferUsage.None); + lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.Instance.GraphicsDevice, typeof(short), Math.Max(64*3, (int)(indexCount * 1.5)), BufferUsage.None); } else if (vertexCount > lightVolumeBuffer.VertexCount) { lightVolumeBuffer.Dispose(); lightVolumeIndexBuffer.Dispose(); - lightVolumeBuffer = new DynamicVertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, (int)(vertexCount*1.5), BufferUsage.None); - lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.CurrGraphicsDevice, typeof(short), (int)(indexCount * 1.5), BufferUsage.None); + lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, (int)(vertexCount*1.5), BufferUsage.None); + lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.Instance.GraphicsDevice, typeof(short), (int)(indexCount * 1.5), BufferUsage.None); } lightVolumeBuffer.SetData(vertices.ToArray()); @@ -549,7 +549,7 @@ namespace Barotrauma.Lights var verts = FindRaycastHits(); CalculateLightVertices(verts); - lastRecalculationTime = (float)GameMain.Instance.TotalElapsedTime; + lastRecalculationTime = (float)Timing.TotalTime; NeedsRecalculation = false; } @@ -566,10 +566,10 @@ namespace Barotrauma.Lights } lightEffect.CurrentTechnique.Passes[0].Apply(); - GameMain.CurrGraphicsDevice.SetVertexBuffer(lightVolumeBuffer); - GameMain.CurrGraphicsDevice.Indices = lightVolumeIndexBuffer; - - GameMain.CurrGraphicsDevice.DrawIndexedPrimitives + GameMain.Instance.GraphicsDevice.SetVertexBuffer(lightVolumeBuffer); + GameMain.Instance.GraphicsDevice.Indices = lightVolumeIndexBuffer; + + GameMain.Instance.GraphicsDevice.DrawIndexedPrimitives ( PrimitiveType.TriangleList, 0, 0, indexCount / 3 ); diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 3906d29c4..667310552 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -1057,7 +1057,7 @@ namespace Barotrauma.Networking } } - startGameCoroutine = GameMain.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode), false); + startGameCoroutine = GameMain.Instance.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode), false); yield return CoroutineStatus.Success; } diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index 3ca4cf2fd..194202f30 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -550,23 +550,13 @@ namespace Barotrauma deleteButton.UserData = "delete"; deleteButton.OnClicked = (btn, userdata) => { - if (subList.Selected!=null) + if (subList.Selected != null) { - Submarine sub = subList.Selected.UserData as Submarine; - try - { - File.Delete(sub.FilePath); - } - catch (Exception e) - { - DebugConsole.ThrowError("Couldn't delete file \""+sub.FilePath+"\"!", e); - } + TryDeleteSub(subList.Selected.UserData as Submarine); } deleteButton.Enabled = false; - - CreateLoadScreen(); - + return true; }; @@ -603,6 +593,29 @@ namespace Barotrauma return true; } + private void TryDeleteSub(Submarine sub) + { + if (sub == null) return; + + var msgBox = new GUIMessageBox("Delete file?", "Are you sure you want to delete \"" + sub.Name + "\"", new string[] { "OK", "Cancel" }); + msgBox.Buttons[0].OnClicked += (btn, userData) => + { + try + { + sub.Remove(); + File.Delete(sub.FilePath); + CreateLoadScreen(); + } + catch (Exception e) + { + DebugConsole.ThrowError("Couldn't delete file \"" + sub.FilePath + "\"!", e); + } + return true; + }; + msgBox.Buttons[0].OnClicked += msgBox.Close; + msgBox.Buttons[1].OnClicked += msgBox.Close; + } + private bool SelectTab(GUIButton button, object obj) { if (characterMode) ToggleCharacterMode(); diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index f94dbdeb1..26305c993 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -524,11 +524,8 @@ namespace Barotrauma { if (GameMain.GameSession.Map.SelectedConnection == null) return false; - GameMain.ShowLoading(ShiftLoading()); - - //GameMain.GameSession.StartShift(selectedLevel, false); - //GameMain.GameScreen.Select(); - + GameMain.Instance.ShowLoading(ShiftLoading()); + return true; } diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index 98210df3e..d5fe3ccd7 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -509,7 +509,7 @@ namespace Barotrauma GUI.Draw((float)deltaTime, spriteBatch, null); GUI.Font.DrawString(spriteBatch, "Barotrauma v"+GameMain.Version, new Vector2(10, GameMain.GraphicsHeight-20), Color.White); - + spriteBatch.End(); }