From 00bbd1d60761dd9999fbff268dbcd65ec13f8a4e Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 3 May 2017 20:58:48 +0300 Subject: [PATCH] Sonar tweaking --- Subsurface/Barotrauma.csproj | 3 + Subsurface/Content/Items/Engine/engine.xml | 2 + Subsurface/Content/Items/Engine/radarBlip.png | Bin 0 -> 1912 bytes Subsurface/Content/Items/Tools/tools.xml | 1 + .../Source/Items/Components/Machines/Radar.cs | 70 +++++++++++++----- 5 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 Subsurface/Content/Items/Engine/radarBlip.png diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 7789088ff..da1beacb0 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -554,6 +554,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Content/Items/Engine/engine.xml b/Subsurface/Content/Items/Engine/engine.xml index 3d3ff81b5..00f9ef996 100644 --- a/Subsurface/Content/Items/Engine/engine.xml +++ b/Subsurface/Content/Items/Engine/engine.xml @@ -80,6 +80,7 @@ + @@ -110,6 +111,7 @@ + diff --git a/Subsurface/Content/Items/Engine/radarBlip.png b/Subsurface/Content/Items/Engine/radarBlip.png new file mode 100644 index 0000000000000000000000000000000000000000..5c2d7c6020d6356a96b2b16359dbd3d730e9df5c GIT binary patch literal 1912 zcmV-;2Z#8HP)(_`g8%^e{{R4h=l}px2mk>USO5SzmjD14Z`WEM zkN^M%{z*hZRCwC7TiKGMFc9N#_WwV3GMKPW%?hDD%lmHv+x?YH| zFCNen9yE2LJhdZs7Sh)V0wh6bUT@&$DiTU$58YJR*RdAupT~87`0{GhMyj5h6;Q##jBZ=_* z0h7RvkZ+Qc9t4k0P^rr!0EuN1qyl*M5xgQmkx(&%i~x=R=ItZtdkXNPL#xidfj0u| z$Y!7j@XWv?pd$awxvH>=<1_)4=y-O|;5`y5zMw(?dVf=Zx=tmmGI&$M#RpWuGXY8g zo+*qHz%y@g|7lLKEX%oGxG2C&bUerRgoLLAcyV7vlqi`}YG^9WWd(SSFeAat!An{q z0@(IBWR`;F9~A%&k`vQ`0MqOd4#E;MWK&X;E})~GE%_^0XX|l2r%%50ey+7;Bt z&jeI4gYB0|QBi`4@XP=KDF^5!JtK=Il)vYTq!WzDPzxU~La++(dL98d`&i`2oE;C& z9lRW(c@-aA#3(YnDB%&I`~U-E2dGSiSBqZKqzWgBgr>^cks4ItBXf{8aBYC#ct#O? zRx4n@XyegjUKEhk_EouC`H3iTLKS2LSdGtH)1#U2Oym8jd*{)3_a;(9<|DW^sLX^N zA)A1exxN3HbIa`9E69XCz&jr?5oIPw2HPRpwxy@&?LVK-#iL_*jOq=l9IsZ8O>KU7 zU&shiq$p)@B)|yZg}N$O@4mgw+otyXMnHR?;TvUAlmZw$rooYnDWq#K-s^0Mb~+Hf2shpsNIq$ofc}Fo6o%sis=78?F8ZP@Uf|VId$XF52)`&tuE&9O!gQC zRZEPj>Z%gAy046c7Tt8EzMl2+sGME(2B~HUub`O`6yac!TQ*bKh=3~K?Cm)Z;QC#K zmH2*@%d#OpHgwaU4?{o!JO1=jhzLfKrUs0t{Yt zf{c*jedbg^CSfiqR|*i(lGZZ3XgS<_pSEqAwr#tS;VDCvzB4mwUUj8%j>SeUW2qzs zm%AAO`@Ww9;9&4fL^MfCF)fobUl@xH2s|rYAICAZ)@}qu6(LlCf#)L=5h+6w;MLan zLTaYBZF3hVULm7e6SUt^DnJrEGpRV!(+Mhj<}X)jY*Fdj*7GA(VKV~*`~CgxnuKzk z-Ut;CeX-K?z@hH^At+{4_XU(0cq+jAWHV7JxcC6;xMbVRnYS_lp7) zNPHhv!X|K84Dp5p_Ti28<#65pfAj}|Cpj40z zQ@|}1R=K$4@0qPS=J2*{a~mW_ z6rh@&yd0n9UIiaMG{q!jU6?rYwvbY(v + diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index 399407f68..97475e616 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -16,6 +16,8 @@ namespace Barotrauma.Items.Components private readonly Sprite pingCircle, screenOverlay; + private readonly Sprite radarBlip; + private GUITickBox isActiveTickBox; private List radarBlips; @@ -70,6 +72,9 @@ namespace Barotrauma.Items.Components case "screenoverlay": screenOverlay = new Sprite(subElement); break; + case "blip": + radarBlip = new Sprite(subElement); + break; } } @@ -162,9 +167,15 @@ namespace Barotrauma.Items.Components public override void DrawHUD(SpriteBatch spriteBatch, Character character) { GuiFrame.Draw(spriteBatch); - + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive); + int radius = GuiFrame.Rect.Height / 2 - 30; DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2)); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); } private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect) @@ -205,6 +216,11 @@ namespace Barotrauma.Items.Components DrawBlip(spriteBatch, radarBlip, center, radarBlip.FadeTimer / 2.0f); } + if (GameMain.DebugDraw) + { + GUI.DrawString(spriteBatch, rect.Location.ToVector2(), radarBlips.Count.ToString(), Color.White); + } + if (screenOverlay != null) { screenOverlay.Draw(spriteBatch, center, 0.0f, rect.Width / screenOverlay.size.X); @@ -393,13 +409,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; } @@ -418,7 +447,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; @@ -428,21 +457,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) @@ -483,7 +519,7 @@ namespace Barotrauma.Items.Components { if (pingCircle!=null) pingCircle.Remove(); if (screenOverlay != null) screenOverlay.Remove(); - + if (radarBlip != null) radarBlip.Remove(); } public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)