ping on map feature complete
This commit is contained in:
parent
17cce56866
commit
bce97de302
19 changed files with 1002 additions and 233 deletions
|
@ -6,6 +6,7 @@ using Microsoft.Xna.Framework.Content;
|
|||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MonoGame.Extended;
|
||||
using MonoGame.Extended.VectorDraw;
|
||||
using Myra;
|
||||
using Myra.Graphics2D.Brushes;
|
||||
using Myra.Graphics2D.TextureAtlases;
|
||||
|
@ -24,6 +25,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AsyncAwaitBestPractices;
|
||||
|
||||
namespace Sledgemapper
|
||||
{
|
||||
|
@ -177,6 +179,7 @@ namespace Sledgemapper
|
|||
_lblOverlayName.Visible = false;
|
||||
}
|
||||
|
||||
private SpriteSheet _rippleSpriteSheet;
|
||||
Label _lblOverlayName;
|
||||
|
||||
private void OnTileButtonTouchEntered(object sender, EventArgs e)
|
||||
|
@ -221,7 +224,10 @@ namespace Sledgemapper
|
|||
_wallsContent = Content.LoadContentFolder<Texture2D>("walls");
|
||||
|
||||
_spriteSheet = new SpriteSheet();
|
||||
_spriteSheet.LoadContent(Content);
|
||||
_spriteSheet.LoadContent(Content, "spriteIndex", "sprites");
|
||||
_rippleSpriteSheet = new SpriteSheet();
|
||||
_rippleSpriteSheet.LoadContent(Content, "handcursorsIndex", "handcursors");
|
||||
|
||||
_lblOverlayName = new Label();
|
||||
_lblOverlayName.Background = new SolidBrush(Color.SlateGray);
|
||||
_lblOverlayName.Padding = new Myra.Graphics2D.Thickness(4);
|
||||
|
@ -375,6 +381,7 @@ namespace Sledgemapper
|
|||
window.ShowModal(_desktop);
|
||||
noteWindow.NoteText.SetKeyboardFocus();
|
||||
}
|
||||
private bool _showRipple = false;
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
|
@ -619,6 +626,17 @@ namespace Sledgemapper
|
|||
}
|
||||
}
|
||||
|
||||
if (oldState.IsKeyDown(Keys.LeftShift) && newState.IsKeyUp(Keys.LeftShift))
|
||||
{
|
||||
_communicationManager.Ping(_state.HoveredTile).SafeFireAndForget();
|
||||
|
||||
_sessionData.Pings.TryAdd(Guid.NewGuid(),new Ping{
|
||||
X=_state.HoveredTile.X,
|
||||
Y=_state.HoveredTile.Y,
|
||||
Player=new Player{Color=Color.Purple.ToHexString()}
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var key in newState.GetPressedKeys())
|
||||
{
|
||||
switch (key)
|
||||
|
@ -688,7 +706,7 @@ namespace Sledgemapper
|
|||
|
||||
_spriteBatch.Begin(
|
||||
transformMatrix: Matrix.CreateTranslation(_viewportCenter),
|
||||
sortMode: SpriteSortMode.Texture);
|
||||
sortMode: SpriteSortMode.Texture, samplerState: SamplerState.PointClamp);
|
||||
|
||||
DrawTiles();
|
||||
|
||||
|
@ -711,8 +729,10 @@ namespace Sledgemapper
|
|||
DrawLinePreview();
|
||||
|
||||
DrawRoomPreview();
|
||||
|
||||
_spriteBatch.End();
|
||||
DrawRipple(gameTime);
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -724,6 +744,83 @@ namespace Sledgemapper
|
|||
}
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
private int _rippleFrameIndex = 0;
|
||||
|
||||
|
||||
private void DrawRipple(GameTime gameTime)
|
||||
{
|
||||
_spriteBatch.Begin(
|
||||
blendState: BlendState.NonPremultiplied,
|
||||
transformMatrix: Matrix.CreateTranslation(_viewportCenter));
|
||||
|
||||
var durationMs = 2000;
|
||||
var baseRadius = _state.TileSize / 4f;
|
||||
var baseOuterRadius = (float)_state.TileSize;
|
||||
var iterations = 3f;
|
||||
var guids = _sessionData.Pings.Keys.ToArray();
|
||||
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var pingFound = _sessionData.Pings.TryGetValue(guid, out var ping);
|
||||
if (!pingFound)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ping.StartTime == 0)
|
||||
{
|
||||
ping.StartTime = gameTime.TotalGameTime.TotalMilliseconds;
|
||||
}
|
||||
|
||||
var x = ping.X * _state.TileSize + _state.TileSize / 2f;
|
||||
var y = ping.Y * _state.TileSize + _state.TileSize / 2f;
|
||||
|
||||
if (IsOffscreen(new Tile { X = ping.X, Y = ping.Y }))
|
||||
{
|
||||
DrawPingPointer(ping, gameTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
_spriteBatch.DrawCircle(
|
||||
center: new Vector2(x, y),
|
||||
radius: baseRadius,
|
||||
sides: 20,
|
||||
color: ping.Player.Color.ToColor(),
|
||||
thickness: baseRadius);
|
||||
|
||||
for (var i = 0; i < iterations; i++)
|
||||
{
|
||||
var cycleTime = (((float)gameTime.TotalGameTime.TotalMilliseconds + (float)i * durationMs / iterations) % durationMs) / durationMs;
|
||||
var easing = Easings.Interpolate(cycleTime, Easings.Functions.SineEaseInOut);
|
||||
_spriteBatch.DrawCircle(
|
||||
center: new Vector2(x, y),
|
||||
radius: baseRadius + baseOuterRadius * easing,
|
||||
sides: 20,
|
||||
color: new Color(ping.Player.Color.ToColor(), (1 - easing)),
|
||||
thickness: 2 + 5 * (1 - easing));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var pingFound = _sessionData.Pings.TryGetValue(guid, out var ping);
|
||||
if (!pingFound)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((gameTime.TotalGameTime.TotalMilliseconds - ping.StartTime) > 20000 )
|
||||
{
|
||||
_sessionData.Pings.TryRemove(guid, out var _);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_spriteBatch.End();
|
||||
}
|
||||
|
||||
private void DrawRoomPreview()
|
||||
{
|
||||
|
@ -1440,6 +1537,106 @@ namespace Sledgemapper
|
|||
}
|
||||
}
|
||||
|
||||
private void DrawPingPointer(Ping ping, GameTime gameTime)
|
||||
{
|
||||
var durationMs = 2000f;
|
||||
var baseRadius = _state.TileSize / 4f;
|
||||
var baseOuterRadius = (float)_state.TileSize;
|
||||
var iterations = 3f;
|
||||
|
||||
|
||||
var center = new Point((Window.ClientBounds.Width + 200) / 2 - (int)_viewportCenter.X, Window.ClientBounds.Height / 2 - (int)_viewportCenter.Y);
|
||||
|
||||
var cx = center.X / _state.TileSize;
|
||||
var cy = center.Y / _state.TileSize;
|
||||
|
||||
var p1 = new Vector2(cx * _state.TileSize, cy * _state.TileSize);
|
||||
var p2 = new Vector2(ping.X * _state.TileSize, ping.Y * _state.TileSize);
|
||||
|
||||
var p3 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, 0 - _viewportCenter.Y);
|
||||
var p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
||||
var ua1 = ((p4.X - p3.X) * (p1.Y - p3.Y) - (p4.Y - p3.Y) * (p1.X - p3.X)) / ((p4.Y - p3.Y) * (p2.X - p1.X) - (p4.X - p3.X) * (p2.Y - p1.Y));
|
||||
|
||||
p3 = new Vector2(200 - _viewportCenter.X, 0 - _viewportCenter.Y);
|
||||
p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, 0 - _viewportCenter.Y);
|
||||
var ua2 = ((p4.X - p3.X) * (p1.Y - p3.Y) - (p4.Y - p3.Y) * (p1.X - p3.X)) / ((p4.Y - p3.Y) * (p2.X - p1.X) - (p4.X - p3.X) * (p2.Y - p1.Y));
|
||||
|
||||
p3 = new Vector2(200 - _viewportCenter.X, 0 - _viewportCenter.Y);
|
||||
p4 = new Vector2(200 - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
||||
var ua3 = ((p4.X - p3.X) * (p1.Y - p3.Y) - (p4.Y - p3.Y) * (p1.X - p3.X)) / ((p4.Y - p3.Y) * (p2.X - p1.X) - (p4.X - p3.X) * (p2.Y - p1.Y));
|
||||
|
||||
p3 = new Vector2(200 - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
||||
p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
||||
var ua4 = ((p4.X - p3.X) * (p1.Y - p3.Y) - (p4.Y - p3.Y) * (p1.X - p3.X)) / ((p4.Y - p3.Y) * (p2.X - p1.X) - (p4.X - p3.X) * (p2.Y - p1.Y));
|
||||
|
||||
var uas = new List<float> { ua1, ua2, ua3, ua4 };
|
||||
if (uas.Any(u => u > 0 && u < 1))
|
||||
{
|
||||
var ua = uas.Where(u => u > 0 && u < 1).Min();
|
||||
var i = uas.IndexOf(ua);
|
||||
var x = (p1.X + ua * (p2.X - p1.X));
|
||||
var y = (p1.Y + ua * (p2.Y - p1.Y));
|
||||
Vector2[] vertexes = new Vector2[0];
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x - 20, y + 10), new Vector2(x - 20, y - 10), new Vector2(x, y) };
|
||||
break;
|
||||
case 1:
|
||||
y += 20;
|
||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x - 10, y + 20), new Vector2(x + 10, y + 20), new Vector2(x, y) };
|
||||
break;
|
||||
case 2:
|
||||
x += 0;
|
||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x + 20, y + 10), new Vector2(x + 20, y - 10), new Vector2(x, y) };
|
||||
break;
|
||||
case 3:
|
||||
y -= 20;
|
||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x - 10, y - 20), new Vector2(x + 10, y - 20), new Vector2(x, y) };
|
||||
break;
|
||||
}
|
||||
|
||||
_spriteBatch.DrawPolygon(Vector2.Zero, vertexes, ping.Player.Color.ToColor(), 4);
|
||||
|
||||
|
||||
for (var j = 0; j < iterations; j++)
|
||||
{
|
||||
var cycleTime = (((float)gameTime.TotalGameTime.TotalMilliseconds + (float)j * durationMs / iterations) % durationMs) / durationMs;
|
||||
var easing = Easings.Interpolate(cycleTime, Easings.Functions.SineEaseInOut);
|
||||
var v2 = new Vector2[vertexes.Length];
|
||||
|
||||
|
||||
var tCenter = new Vector2((vertexes[0].X + vertexes[1].X + vertexes[2].X) / 3f, (vertexes[0].Y + vertexes[1].Y + vertexes[2].Y) / 3f);
|
||||
|
||||
// var v1s = ((v2[0].X-tCenter.X)*(2 * (1 - easing)))+tCenter.X
|
||||
|
||||
for (int i1 = 0; i1 < v2.Length; i1++)
|
||||
{
|
||||
|
||||
var svx = ((vertexes[i1].X - tCenter.X) * (1 + (2 * easing))) + tCenter.X;
|
||||
var svy = ((vertexes[i1].Y - tCenter.Y) * (1 + (2 * easing))) + tCenter.Y;
|
||||
v2[i1] = new Vector2(svx, svy);
|
||||
}
|
||||
|
||||
_spriteBatch.DrawPolygon(
|
||||
offset: Vector2.Zero,
|
||||
points: v2,
|
||||
color:new Color(ping.Player.Color.ToColor(), 1f-easing),
|
||||
thickness: 2+2*(1-easing));
|
||||
|
||||
// _spriteBatch.DrawCircle(
|
||||
// center: new Vector2(x, y),
|
||||
// radius: baseRadius + baseOuterRadius * easing,
|
||||
// sides: 20,
|
||||
// color: new Color(ping.Player.Color.ToColor(), (1 - easing)),
|
||||
// thickness: 2 + 5 * (1 - easing));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPlayerPointer(Player player)
|
||||
{
|
||||
var center = new Point((Window.ClientBounds.Width + 200) / 2 - (int)_viewportCenter.X, Window.ClientBounds.Height / 2 - (int)_viewportCenter.Y);
|
||||
|
@ -2328,10 +2525,10 @@ namespace Sledgemapper
|
|||
internal Texture2D Texture;
|
||||
internal Dictionary<String, Rectangle> index;
|
||||
|
||||
public void LoadContent(ContentManager content)
|
||||
public void LoadContent(ContentManager content, string spriteIndex, string texture)
|
||||
{
|
||||
index = content.Load<Dictionary<String, Rectangle>>("spriteIndex");
|
||||
Texture = content.Load<Texture2D>("sprites");
|
||||
index = content.Load<Dictionary<String, Rectangle>>(spriteIndex);
|
||||
Texture = content.Load<Texture2D>(texture);
|
||||
}
|
||||
|
||||
internal Rectangle? SourceRectangle(string spriteName)
|
||||
|
@ -2349,4 +2546,6 @@ namespace Sledgemapper
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue