Merge pull request 'ping on map feature complete' (#41) from pingOnMap into develop
Reviewed-on: michele/Map#41
This commit is contained in:
commit
7b552a0c61
20 changed files with 1025 additions and 366 deletions
13
Sledgemapper.Api/Commands/PingCommand.cs
Normal file
13
Sledgemapper.Api/Commands/PingCommand.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// using Sledgemapper.Shared.Entities;
|
||||||
|
|
||||||
|
// namespace Sledgemapper.Api.Commands
|
||||||
|
// {
|
||||||
|
// public class PingCommand : BaseCommand<bool>
|
||||||
|
// {
|
||||||
|
// public Ping Location { get; private set; }
|
||||||
|
// public PingCommand(string sessionName, Ping location, int userId) : base(sessionName, userId)
|
||||||
|
// {
|
||||||
|
// Location = location;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
|
@ -2,6 +2,7 @@ using MediatR;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Sledgemapper.Api.Commands;
|
using Sledgemapper.Api.Commands;
|
||||||
|
using Sledgemapper.Api.Notifications;
|
||||||
using Sledgemapper.Shared.Entities;
|
using Sledgemapper.Shared.Entities;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -30,6 +31,12 @@ namespace Sledgemapper.Api.Controllers
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [HttpPost("ping")]
|
||||||
|
// public async Task Post(string sessionName, [FromBody] Ping pingLocation)
|
||||||
|
// {
|
||||||
|
// await _mediator.Send(new PingCommand(sessionName, pingLocation, UserId));
|
||||||
|
// }
|
||||||
|
|
||||||
[HttpPost("snapshot")]
|
[HttpPost("snapshot")]
|
||||||
public async Task Post(string sessionName, [FromBody] Session session)
|
public async Task Post(string sessionName, [FromBody] Session session)
|
||||||
{
|
{
|
||||||
|
@ -60,13 +67,13 @@ namespace Sledgemapper.Api.Controllers
|
||||||
await _mediator.Send(new NewNoteCommand(sessionName, note, UserId));
|
await _mediator.Send(new NewNoteCommand(sessionName, note, UserId));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("room")]
|
[HttpPost("room")]
|
||||||
public async Task Post(string sessionName, [FromBody] Room room)
|
public async Task Post(string sessionName, [FromBody] Room room)
|
||||||
{
|
{
|
||||||
await _mediator.Send(new NewRoomCommand(sessionName, room, UserId));
|
await _mediator.Send(new NewRoomCommand(sessionName, room, UserId));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("line")]
|
[HttpPost("line")]
|
||||||
public async Task Post(string sessionName, [FromBody] Line line)
|
public async Task Post(string sessionName, [FromBody] Line line)
|
||||||
{
|
{
|
||||||
await _mediator.Send(new NewLineCommand(sessionName, line, UserId));
|
await _mediator.Send(new NewLineCommand(sessionName, line, UserId));
|
||||||
|
|
|
@ -35,7 +35,5 @@ namespace Sledgemapper.Api.Commands
|
||||||
await _mediator.Publish(new NewTileNotification(session, notification.Tile, notification.UserId));
|
await _mediator.Publish(new NewTileNotification(session, notification.Tile, notification.UserId));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
Sledgemapper.Api/Handlers/PingCommandHandler.cs
Normal file
28
Sledgemapper.Api/Handlers/PingCommandHandler.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// using MediatR;
|
||||||
|
// using Sledgemapper.Api.Data;
|
||||||
|
// using System.Threading;
|
||||||
|
// using System.Threading.Tasks;
|
||||||
|
// using Sledgemapper.Api.Notifications;
|
||||||
|
// using System.Linq;
|
||||||
|
|
||||||
|
// namespace Sledgemapper.Api.Commands
|
||||||
|
// {
|
||||||
|
// public class PingCommandHandler : IRequestHandler<PingCommand, bool>
|
||||||
|
// {
|
||||||
|
// private readonly MyDbContext _dbcontext;
|
||||||
|
// private readonly IMediator _mediator;
|
||||||
|
|
||||||
|
// public PingCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
|
||||||
|
|
||||||
|
// public async Task<bool> Handle(PingCommand notification, CancellationToken cancellationToken)
|
||||||
|
// {
|
||||||
|
// var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
|
||||||
|
|
||||||
|
|
||||||
|
// await _mediator.Publish(new PingNotification(session, notification.Location, notification.UserId));
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
23
Sledgemapper.Api/Handlers/SendPingMessage.cs
Normal file
23
Sledgemapper.Api/Handlers/SendPingMessage.cs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// using MediatR;
|
||||||
|
// using Microsoft.AspNetCore.SignalR;
|
||||||
|
// using Sledgemapper.Api.Notifications;
|
||||||
|
// using Sledgemapper.Clients;
|
||||||
|
// using System.Threading;
|
||||||
|
// using System.Threading.Tasks;
|
||||||
|
// using Sledgemapper.Api.Hubs;
|
||||||
|
|
||||||
|
// namespace Sledgemapper.Api.Handlers
|
||||||
|
// {
|
||||||
|
// public class SendPingMessage : INotificationHandler<PingNotification>
|
||||||
|
// {
|
||||||
|
// private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;
|
||||||
|
|
||||||
|
// public SendPingMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;
|
||||||
|
|
||||||
|
// public async Task Handle(PingNotification notification, CancellationToken cancellationToken)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// await _hub.Clients.Groups(notification.Session.SessionName).Ping(notification.Location, notification.UserId);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
|
@ -51,7 +51,7 @@ namespace Sledgemapper.Api.Hubs
|
||||||
await Clients.Group(sessionName).NewRoom(room);
|
await Clients.Group(sessionName).NewRoom(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task NewLine(string sessionName, Line line)
|
public async Task NewLine(string sessionName, Line line)
|
||||||
{
|
{
|
||||||
await Clients.Group(sessionName).NewLine(line);
|
await Clients.Group(sessionName).NewLine(line);
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,15 @@ namespace Sledgemapper.Api.Hubs
|
||||||
await Clients.Group(sessionName).DeleteOverlay(tile);
|
await Clients.Group(sessionName).DeleteOverlay(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task Ping(string sessionName, Tile location)
|
||||||
|
{
|
||||||
|
var userId = int.Parse(Context.User.Identity.Name);
|
||||||
|
var user = _datacontext.Users.First(u => u.Id == userId);
|
||||||
|
|
||||||
|
var player = new Player { UserId = userId, Initials = user.Initials, Position = new Tile { X = 0, Y = 0 }, Color = UserColors[userId] };
|
||||||
|
await Clients.Group(sessionName).Ping(new Ping{X=location.X, Y=location.Y, Player=player});
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Sledgemapper.Shared.Entities.Session> JoinSession(string sessionName)
|
public async Task<Sledgemapper.Shared.Entities.Session> JoinSession(string sessionName)
|
||||||
{
|
{
|
||||||
var session = _dbContext.Sessions.FirstOrDefault(s => s.SessionName == sessionName);
|
var session = _dbContext.Sessions.FirstOrDefault(s => s.SessionName == sessionName);
|
||||||
|
|
14
Sledgemapper.Api/Notifications/PingNotification.cs
Normal file
14
Sledgemapper.Api/Notifications/PingNotification.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// using Sledgemapper.Shared.Entities;
|
||||||
|
|
||||||
|
// namespace Sledgemapper.Api.Notifications
|
||||||
|
// {
|
||||||
|
// public class PingNotification : BaseNotification
|
||||||
|
// {
|
||||||
|
// public Ping Location { get; private set; }
|
||||||
|
|
||||||
|
// public PingNotification(Models.Session session, Ping location, int userId) : base(session, userId)
|
||||||
|
// {
|
||||||
|
// Location = location;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
|
@ -20,5 +20,6 @@ namespace Sledgemapper.Clients
|
||||||
Task UpdateMap(Session player);
|
Task UpdateMap(Session player);
|
||||||
Task RefreshPlayers();
|
Task RefreshPlayers();
|
||||||
Task NewLine(Line line);
|
Task NewLine(Line line);
|
||||||
|
Task Ping(Ping ping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
450
Sledgemapper.Shared/Easings.cs
Normal file
450
Sledgemapper.Shared/Easings.cs
Normal file
|
@ -0,0 +1,450 @@
|
||||||
|
|
||||||
|
using System;
|
||||||
|
#if UNITY
|
||||||
|
using UnityEngine;
|
||||||
|
using Math = UnityEngine.Mathf;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static public class Easings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constant Pi.
|
||||||
|
/// </summary>
|
||||||
|
private const float PI = (float)(float)Math.PI;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constant Pi / 2.
|
||||||
|
/// </summary>
|
||||||
|
private const float HALFPI =(float) (float)Math.PI / 2.0f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Easing Functions enumeration
|
||||||
|
/// </summary>
|
||||||
|
public enum Functions
|
||||||
|
{
|
||||||
|
Linear,
|
||||||
|
QuadraticEaseIn,
|
||||||
|
QuadraticEaseOut,
|
||||||
|
QuadraticEaseInOut,
|
||||||
|
CubicEaseIn,
|
||||||
|
CubicEaseOut,
|
||||||
|
CubicEaseInOut,
|
||||||
|
QuarticEaseIn,
|
||||||
|
QuarticEaseOut,
|
||||||
|
QuarticEaseInOut,
|
||||||
|
QuinticEaseIn,
|
||||||
|
QuinticEaseOut,
|
||||||
|
QuinticEaseInOut,
|
||||||
|
SineEaseIn,
|
||||||
|
SineEaseOut,
|
||||||
|
SineEaseInOut,
|
||||||
|
CircularEaseIn,
|
||||||
|
CircularEaseOut,
|
||||||
|
CircularEaseInOut,
|
||||||
|
ExponentialEaseIn,
|
||||||
|
ExponentialEaseOut,
|
||||||
|
ExponentialEaseInOut,
|
||||||
|
ElasticEaseIn,
|
||||||
|
ElasticEaseOut,
|
||||||
|
ElasticEaseInOut,
|
||||||
|
BackEaseIn,
|
||||||
|
BackEaseOut,
|
||||||
|
BackEaseInOut,
|
||||||
|
BounceEaseIn,
|
||||||
|
BounceEaseOut,
|
||||||
|
BounceEaseInOut
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interpolate using the specified function.
|
||||||
|
/// </summary>
|
||||||
|
static public float Interpolate(float p, Functions function)
|
||||||
|
{
|
||||||
|
switch(function)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case Functions.Linear: return Linear(p);
|
||||||
|
case Functions.QuadraticEaseOut: return QuadraticEaseOut(p);
|
||||||
|
case Functions.QuadraticEaseIn: return QuadraticEaseIn(p);
|
||||||
|
case Functions.QuadraticEaseInOut: return QuadraticEaseInOut(p);
|
||||||
|
case Functions.CubicEaseIn: return CubicEaseIn(p);
|
||||||
|
case Functions.CubicEaseOut: return CubicEaseOut(p);
|
||||||
|
case Functions.CubicEaseInOut: return CubicEaseInOut(p);
|
||||||
|
case Functions.QuarticEaseIn: return QuarticEaseIn(p);
|
||||||
|
case Functions.QuarticEaseOut: return QuarticEaseOut(p);
|
||||||
|
case Functions.QuarticEaseInOut: return QuarticEaseInOut(p);
|
||||||
|
case Functions.QuinticEaseIn: return QuinticEaseIn(p);
|
||||||
|
case Functions.QuinticEaseOut: return QuinticEaseOut(p);
|
||||||
|
case Functions.QuinticEaseInOut: return QuinticEaseInOut(p);
|
||||||
|
case Functions.SineEaseIn: return SineEaseIn(p);
|
||||||
|
case Functions.SineEaseOut: return SineEaseOut(p);
|
||||||
|
case Functions.SineEaseInOut: return SineEaseInOut(p);
|
||||||
|
case Functions.CircularEaseIn: return CircularEaseIn(p);
|
||||||
|
case Functions.CircularEaseOut: return CircularEaseOut(p);
|
||||||
|
case Functions.CircularEaseInOut: return CircularEaseInOut(p);
|
||||||
|
case Functions.ExponentialEaseIn: return ExponentialEaseIn(p);
|
||||||
|
case Functions.ExponentialEaseOut: return ExponentialEaseOut(p);
|
||||||
|
case Functions.ExponentialEaseInOut: return ExponentialEaseInOut(p);
|
||||||
|
case Functions.ElasticEaseIn: return ElasticEaseIn(p);
|
||||||
|
case Functions.ElasticEaseOut: return ElasticEaseOut(p);
|
||||||
|
case Functions.ElasticEaseInOut: return ElasticEaseInOut(p);
|
||||||
|
case Functions.BackEaseIn: return BackEaseIn(p);
|
||||||
|
case Functions.BackEaseOut: return BackEaseOut(p);
|
||||||
|
case Functions.BackEaseInOut: return BackEaseInOut(p);
|
||||||
|
case Functions.BounceEaseIn: return BounceEaseIn(p);
|
||||||
|
case Functions.BounceEaseOut: return BounceEaseOut(p);
|
||||||
|
case Functions.BounceEaseInOut: return BounceEaseInOut(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the line y = x
|
||||||
|
/// </summary>
|
||||||
|
static public float Linear(float p)
|
||||||
|
{
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the parabola y = x^2
|
||||||
|
/// </summary>
|
||||||
|
static public float QuadraticEaseIn(float p)
|
||||||
|
{
|
||||||
|
return p * p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the parabola y = -x^2 + 2x
|
||||||
|
/// </summary>
|
||||||
|
static public float QuadraticEaseOut(float p)
|
||||||
|
{
|
||||||
|
return -(p * (p - 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the piecewise quadratic
|
||||||
|
/// y = (1/2)((2x)^2) ; [0, 0.5)
|
||||||
|
/// y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1]
|
||||||
|
/// </summary>
|
||||||
|
static public float QuadraticEaseInOut(float p)
|
||||||
|
{
|
||||||
|
if(p < 0.5f)
|
||||||
|
{
|
||||||
|
return 2 * p * p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (-2 * p * p) + (4 * p) - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the cubic y = x^3
|
||||||
|
/// </summary>
|
||||||
|
static public float CubicEaseIn(float p)
|
||||||
|
{
|
||||||
|
return p * p * p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the cubic y = (x - 1)^3 + 1
|
||||||
|
/// </summary>
|
||||||
|
static public float CubicEaseOut(float p)
|
||||||
|
{
|
||||||
|
float f = (p - 1);
|
||||||
|
return f * f * f + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the piecewise cubic
|
||||||
|
/// y = (1/2)((2x)^3) ; [0, 0.5)
|
||||||
|
/// y = (1/2)((2x-2)^3 + 2) ; [0.5, 1]
|
||||||
|
/// </summary>
|
||||||
|
static public float CubicEaseInOut(float p)
|
||||||
|
{
|
||||||
|
if(p < 0.5f)
|
||||||
|
{
|
||||||
|
return 4 * p * p * p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float f = ((2 * p) - 2);
|
||||||
|
return 0.5f * f * f * f + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the quartic x^4
|
||||||
|
/// </summary>
|
||||||
|
static public float QuarticEaseIn(float p)
|
||||||
|
{
|
||||||
|
return p * p * p * p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the quartic y = 1 - (x - 1)^4
|
||||||
|
/// </summary>
|
||||||
|
static public float QuarticEaseOut(float p)
|
||||||
|
{
|
||||||
|
float f = (p - 1);
|
||||||
|
return f * f * f * (1 - p) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
// Modeled after the piecewise quartic
|
||||||
|
// y = (1/2)((2x)^4) ; [0, 0.5)
|
||||||
|
// y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1]
|
||||||
|
/// </summary>
|
||||||
|
static public float QuarticEaseInOut(float p)
|
||||||
|
{
|
||||||
|
if(p < 0.5f)
|
||||||
|
{
|
||||||
|
return 8 * p * p * p * p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float f = (p - 1);
|
||||||
|
return -8 * f * f * f * f + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the quintic y = x^5
|
||||||
|
/// </summary>
|
||||||
|
static public float QuinticEaseIn(float p)
|
||||||
|
{
|
||||||
|
return p * p * p * p * p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the quintic y = (x - 1)^5 + 1
|
||||||
|
/// </summary>
|
||||||
|
static public float QuinticEaseOut(float p)
|
||||||
|
{
|
||||||
|
float f = (p - 1);
|
||||||
|
return f * f * f * f * f + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the piecewise quintic
|
||||||
|
/// y = (1/2)((2x)^5) ; [0, 0.5)
|
||||||
|
/// y = (1/2)((2x-2)^5 + 2) ; [0.5, 1]
|
||||||
|
/// </summary>
|
||||||
|
static public float QuinticEaseInOut(float p)
|
||||||
|
{
|
||||||
|
if(p < 0.5f)
|
||||||
|
{
|
||||||
|
return 16 * p * p * p * p * p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float f = ((2 * p) - 2);
|
||||||
|
return 0.5f * f * f * f * f * f + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after quarter-cycle of sine wave
|
||||||
|
/// </summary>
|
||||||
|
static public float SineEaseIn(float p)
|
||||||
|
{
|
||||||
|
return (float)(float)Math.Sin((p - 1) * HALFPI) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after quarter-cycle of sine wave (different phase)
|
||||||
|
/// </summary>
|
||||||
|
static public float SineEaseOut(float p)
|
||||||
|
{
|
||||||
|
return (float)(float)Math.Sin(p * HALFPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after half sine wave
|
||||||
|
/// </summary>
|
||||||
|
static public float SineEaseInOut(float p)
|
||||||
|
{
|
||||||
|
return 0.5f * (1 - (float)(float)Math.Cos(p * PI));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after shifted quadrant IV of unit circle
|
||||||
|
/// </summary>
|
||||||
|
static public float CircularEaseIn(float p)
|
||||||
|
{
|
||||||
|
return 1 - (float)Math.Sqrt(1 - (p * p));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after shifted quadrant II of unit circle
|
||||||
|
/// </summary>
|
||||||
|
static public float CircularEaseOut(float p)
|
||||||
|
{
|
||||||
|
return (float)Math.Sqrt((2 - p) * p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the piecewise circular function
|
||||||
|
/// y = (1/2)(1 - (float)Math.Sqrt(1 - 4x^2)) ; [0, 0.5)
|
||||||
|
/// y = (1/2)((float)Math.Sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1]
|
||||||
|
/// </summary>
|
||||||
|
static public float CircularEaseInOut(float p)
|
||||||
|
{
|
||||||
|
if(p < 0.5f)
|
||||||
|
{
|
||||||
|
return 0.5f * (1 - (float)Math.Sqrt(1 - 4 * (p * p)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0.5f * ((float)Math.Sqrt(-((2 * p) - 3) * ((2 * p) - 1)) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the exponential function y = 2^(10(x - 1))
|
||||||
|
/// </summary>
|
||||||
|
static public float ExponentialEaseIn(float p)
|
||||||
|
{
|
||||||
|
return (p == 0.0f) ? p : (float)Math.Pow(2, 10 * (p - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the exponential function y = -2^(-10x) + 1
|
||||||
|
/// </summary>
|
||||||
|
static public float ExponentialEaseOut(float p)
|
||||||
|
{
|
||||||
|
return (p == 1.0f) ? p : 1 - (float)Math.Pow(2, -10 * p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the piecewise exponential
|
||||||
|
/// y = (1/2)2^(10(2x - 1)) ; [0,0.5)
|
||||||
|
/// y = -(1/2)*2^(-10(2x - 1))) + 1 ; [0.5,1]
|
||||||
|
/// </summary>
|
||||||
|
static public float ExponentialEaseInOut(float p)
|
||||||
|
{
|
||||||
|
if(p == 0.0 || p == 1.0) return p;
|
||||||
|
|
||||||
|
if(p < 0.5f)
|
||||||
|
{
|
||||||
|
return 0.5f * (float)Math.Pow(2, (20 * p) - 10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -0.5f * (float)Math.Pow(2, (-20 * p) + 10) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the damped sine wave y = sin(13pi/2*x)*(float)Math.Pow(2, 10 * (x - 1))
|
||||||
|
/// </summary>
|
||||||
|
static public float ElasticEaseIn(float p)
|
||||||
|
{
|
||||||
|
return (float)Math.Sin(13 * HALFPI * p) * (float)Math.Pow(2, 10 * (p - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the damped sine wave y = sin(-13pi/2*(x + 1))*(float)Math.Pow(2, -10x) + 1
|
||||||
|
/// </summary>
|
||||||
|
static public float ElasticEaseOut(float p)
|
||||||
|
{
|
||||||
|
return (float)Math.Sin(-13 * HALFPI * (p + 1)) * (float)Math.Pow(2, -10 * p) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the piecewise exponentially-damped sine wave:
|
||||||
|
/// y = (1/2)*sin(13pi/2*(2*x))*(float)Math.Pow(2, 10 * ((2*x) - 1)) ; [0,0.5)
|
||||||
|
/// y = (1/2)*(sin(-13pi/2*((2x-1)+1))*(float)Math.Pow(2,-10(2*x-1)) + 2) ; [0.5, 1]
|
||||||
|
/// </summary>
|
||||||
|
static public float ElasticEaseInOut(float p)
|
||||||
|
{
|
||||||
|
if(p < 0.5f)
|
||||||
|
{
|
||||||
|
return 0.5f * (float)Math.Sin(13 * HALFPI * (2 * p)) * (float)Math.Pow(2, 10 * ((2 * p) - 1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0.5f * ((float)Math.Sin(-13 * HALFPI * ((2 * p - 1) + 1)) * (float)Math.Pow(2, -10 * (2 * p - 1)) + 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the overshooting cubic y = x^3-x*sin(x*pi)
|
||||||
|
/// </summary>
|
||||||
|
static public float BackEaseIn(float p)
|
||||||
|
{
|
||||||
|
return p * p * p - p * (float)Math.Sin(p * PI);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after overshooting cubic y = 1-((1-x)^3-(1-x)*sin((1-x)*pi))
|
||||||
|
/// </summary>
|
||||||
|
static public float BackEaseOut(float p)
|
||||||
|
{
|
||||||
|
float f = (1 - p);
|
||||||
|
return 1 - (f * f * f - f * (float)Math.Sin(f * PI));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Modeled after the piecewise overshooting cubic function:
|
||||||
|
/// y = (1/2)*((2x)^3-(2x)*sin(2*x*pi)) ; [0, 0.5)
|
||||||
|
/// y = (1/2)*(1-((1-x)^3-(1-x)*sin((1-x)*pi))+1) ; [0.5, 1]
|
||||||
|
/// </summary>
|
||||||
|
static public float BackEaseInOut(float p)
|
||||||
|
{
|
||||||
|
if(p < 0.5f)
|
||||||
|
{
|
||||||
|
float f = 2 * p;
|
||||||
|
return 0.5f * (f * f * f - f * (float)Math.Sin(f * PI));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float f = (1 - (2*p - 1));
|
||||||
|
return 0.5f * (1 - (f * f * f - f * (float)Math.Sin(f * PI))) + 0.5f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// </summary>
|
||||||
|
static public float BounceEaseIn(float p)
|
||||||
|
{
|
||||||
|
return 1 - BounceEaseOut(1 - p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// </summary>
|
||||||
|
static public float BounceEaseOut(float p)
|
||||||
|
{
|
||||||
|
if(p < 4/11.0f)
|
||||||
|
{
|
||||||
|
return (121 * p * p)/16.0f;
|
||||||
|
}
|
||||||
|
else if(p < 8/11.0f)
|
||||||
|
{
|
||||||
|
return (363/40.0f * p * p) - (99/10.0f * p) + 17/5.0f;
|
||||||
|
}
|
||||||
|
else if(p < 9/10.0f)
|
||||||
|
{
|
||||||
|
return (4356/361.0f * p * p) - (35442/1805.0f * p) + 16061/1805.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (54/5.0f * p * p) - (513/25.0f * p) + 268/25.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// </summary>
|
||||||
|
static public float BounceEaseInOut(float p)
|
||||||
|
{
|
||||||
|
if(p < 0.5f)
|
||||||
|
{
|
||||||
|
return 0.5f * BounceEaseIn(p*2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0.5f * BounceEaseOut(p * 2 - 1) + 0.5f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,10 +27,11 @@ namespace Sledgemapper.Shared.Entities
|
||||||
Overlays = new ConcurrentDictionary<string, Overlay>();
|
Overlays = new ConcurrentDictionary<string, Overlay>();
|
||||||
Walls = new ConcurrentDictionary<string, Wall>();
|
Walls = new ConcurrentDictionary<string, Wall>();
|
||||||
Notes = new ConcurrentDictionary<string, Note>();
|
Notes = new ConcurrentDictionary<string, Note>();
|
||||||
Lines=new ConcurrentDictionary<string, Line>();
|
Lines = new ConcurrentDictionary<string, Line>();
|
||||||
Rooms=new ConcurrentDictionary<string, Room>();
|
Rooms = new ConcurrentDictionary<string, Room>();
|
||||||
Players = new List<Player>();
|
Players = new List<Player>();
|
||||||
Colors = new List<string>();
|
Colors = new List<string>();
|
||||||
|
Pings = new ConcurrentDictionary<Guid, Ping>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcurrentDictionary<string, Tile> Map { get; set; }
|
public ConcurrentDictionary<string, Tile> Map { get; set; }
|
||||||
|
@ -39,189 +40,190 @@ namespace Sledgemapper.Shared.Entities
|
||||||
public ConcurrentDictionary<string, Note> Notes { get; set; }
|
public ConcurrentDictionary<string, Note> Notes { get; set; }
|
||||||
public bool IsValid { get; set; }
|
public bool IsValid { get; set; }
|
||||||
public List<Player> Players { get; set; }
|
public List<Player> Players { get; set; }
|
||||||
public List<string> Colors { get; set; }
|
public ConcurrentDictionary<Guid, Ping> Pings { get; set; }
|
||||||
public string SessionName { get; set; }
|
public List<string> Colors { get; set; }
|
||||||
public int SessionId { get; set; }
|
public string SessionName { get; set; }
|
||||||
public ConcurrentDictionary<string, Line> Lines { get; set; }
|
public int SessionId { get; set; }
|
||||||
public ConcurrentDictionary<string, Room> Rooms { get; set; }
|
public ConcurrentDictionary<string, Line> Lines { get; set; }
|
||||||
|
public ConcurrentDictionary<string, Room> Rooms { get; set; }
|
||||||
|
|
||||||
public void NewTile(Tile selectedTile, string tileId)
|
public void NewTile(Tile selectedTile, string tileId)
|
||||||
|
{
|
||||||
|
if (selectedTile is null || string.IsNullOrWhiteSpace(tileId))
|
||||||
{
|
{
|
||||||
if (selectedTile is null || string.IsNullOrWhiteSpace(tileId))
|
return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var tileExist = Map.TryGetValue(selectedTile.ToString(), out var tile);
|
|
||||||
var newTile = new Tile { X = selectedTile.X, Y = selectedTile.Y, ID = tileId };
|
|
||||||
if (tileExist)
|
|
||||||
{
|
|
||||||
Map.TryRemove(tile.ToString(), out var _);
|
|
||||||
if (tile.ID == tileId)
|
|
||||||
{
|
|
||||||
newTile.Rotation = (tile.Rotation + 1) % 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Map.TryAdd(newTile.ToString(), newTile);
|
|
||||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newTile));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewOverlay(Overlay selectedOverlay, string overlayId)
|
var tileExist = Map.TryGetValue(selectedTile.ToString(), out var tile);
|
||||||
|
var newTile = new Tile { X = selectedTile.X, Y = selectedTile.Y, ID = tileId };
|
||||||
|
if (tileExist)
|
||||||
{
|
{
|
||||||
if (selectedOverlay is null || string.IsNullOrWhiteSpace(overlayId))
|
Map.TryRemove(tile.ToString(), out var _);
|
||||||
|
if (tile.ID == tileId)
|
||||||
{
|
{
|
||||||
return;
|
newTile.Rotation = (tile.Rotation + 1) % 4;
|
||||||
}
|
|
||||||
var overlayExist = Overlays.TryGetValue(selectedOverlay.ToString(), out var overlay);
|
|
||||||
var newOverlay = new Overlay { X = selectedOverlay.X, Y = selectedOverlay.Y, ID = overlayId, Intersection = selectedOverlay.Intersection };
|
|
||||||
if (overlayExist)
|
|
||||||
{
|
|
||||||
Overlays.TryRemove(overlay.ToString(), out var _);
|
|
||||||
if (overlay.ID == overlayId)
|
|
||||||
{
|
|
||||||
newOverlay.Rotation = (overlay.Rotation + 1) % 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Overlays.TryAdd(newOverlay.ToString(), newOverlay);
|
|
||||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newOverlay));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void NewWall(Wall selectedWall, string wallId)
|
|
||||||
{
|
|
||||||
if (selectedWall is null || string.IsNullOrWhiteSpace(wallId))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var tileExist = Walls.TryGetValue(selectedWall.ToString(), out var wall);
|
|
||||||
var newWall = new Wall { X = selectedWall.X, Y = selectedWall.Y, ID = wallId, Rotation = selectedWall.Rotation };
|
|
||||||
if (tileExist)
|
|
||||||
{
|
|
||||||
Walls.TryRemove(wall.ToString(), out var _);
|
|
||||||
}
|
|
||||||
|
|
||||||
Walls.TryAdd(newWall.ToString(), newWall);
|
|
||||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newWall));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void NewNote(Note selectedNote)
|
|
||||||
{
|
|
||||||
if (selectedNote is null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var noteExists = Notes.TryGetValue(selectedNote.ToString(), out var note);
|
|
||||||
var newNote = new Note { X = selectedNote.X, Y = selectedNote.Y, Text=selectedNote.Text };
|
|
||||||
if (noteExists)
|
|
||||||
{
|
|
||||||
Walls.TryRemove(note.ToString(), out var _);
|
|
||||||
}
|
|
||||||
|
|
||||||
Notes.TryAdd(newNote.ToString(), newNote);
|
|
||||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newNote));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteWall(Wall wall)
|
|
||||||
{
|
|
||||||
if (wall is null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var removed = Walls.TryRemove(wall.ToString(), out var _);
|
|
||||||
if (removed)
|
|
||||||
{
|
|
||||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(wall));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteNote(Note note)
|
Map.TryAdd(newTile.ToString(), newTile);
|
||||||
|
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newTile));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NewOverlay(Overlay selectedOverlay, string overlayId)
|
||||||
|
{
|
||||||
|
if (selectedOverlay is null || string.IsNullOrWhiteSpace(overlayId))
|
||||||
{
|
{
|
||||||
if (note is null)
|
return;
|
||||||
|
}
|
||||||
|
var overlayExist = Overlays.TryGetValue(selectedOverlay.ToString(), out var overlay);
|
||||||
|
var newOverlay = new Overlay { X = selectedOverlay.X, Y = selectedOverlay.Y, ID = overlayId, Intersection = selectedOverlay.Intersection };
|
||||||
|
if (overlayExist)
|
||||||
|
{
|
||||||
|
Overlays.TryRemove(overlay.ToString(), out var _);
|
||||||
|
if (overlay.ID == overlayId)
|
||||||
{
|
{
|
||||||
return;
|
newOverlay.Rotation = (overlay.Rotation + 1) % 4;
|
||||||
}
|
|
||||||
var removed = Notes.TryRemove(note.ToString(), out var _);
|
|
||||||
if (removed)
|
|
||||||
{
|
|
||||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(note));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteOverlay(Overlay overlay)
|
Overlays.TryAdd(newOverlay.ToString(), newOverlay);
|
||||||
|
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newOverlay));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NewWall(Wall selectedWall, string wallId)
|
||||||
|
{
|
||||||
|
if (selectedWall is null || string.IsNullOrWhiteSpace(wallId))
|
||||||
{
|
{
|
||||||
if (overlay is null)
|
return;
|
||||||
{
|
}
|
||||||
return;
|
var tileExist = Walls.TryGetValue(selectedWall.ToString(), out var wall);
|
||||||
}
|
var newWall = new Wall { X = selectedWall.X, Y = selectedWall.Y, ID = wallId, Rotation = selectedWall.Rotation };
|
||||||
var removed = Overlays.TryRemove(overlay.ToString(), out var _);
|
if (tileExist)
|
||||||
if (removed)
|
{
|
||||||
{
|
Walls.TryRemove(wall.ToString(), out var _);
|
||||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(overlay));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteTile(Tile tile)
|
Walls.TryAdd(newWall.ToString(), newWall);
|
||||||
|
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newWall));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NewNote(Note selectedNote)
|
||||||
|
{
|
||||||
|
if (selectedNote is null)
|
||||||
{
|
{
|
||||||
if (tile is null)
|
return;
|
||||||
{
|
}
|
||||||
return;
|
var noteExists = Notes.TryGetValue(selectedNote.ToString(), out var note);
|
||||||
}
|
var newNote = new Note { X = selectedNote.X, Y = selectedNote.Y, Text = selectedNote.Text };
|
||||||
var removed = Map.TryRemove(tile.ToString(), out var _);
|
if (noteExists)
|
||||||
if (removed)
|
{
|
||||||
{
|
Walls.TryRemove(note.ToString(), out var _);
|
||||||
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(tile));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnRaiseMapEntityAddedEvent(MapEntityAddedEventArgs e)
|
Notes.TryAdd(newNote.ToString(), newNote);
|
||||||
|
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newNote));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteWall(Wall wall)
|
||||||
|
{
|
||||||
|
if (wall is null)
|
||||||
{
|
{
|
||||||
MapEntityAdded?.Invoke(this, e);
|
return;
|
||||||
}
|
}
|
||||||
|
var removed = Walls.TryRemove(wall.ToString(), out var _);
|
||||||
protected virtual void OnRaiseMapEntityDeletedEvent(MapEntityDeletedEventArgs e)
|
if (removed)
|
||||||
{
|
{
|
||||||
MapEntityDeleted?.Invoke(this, e);
|
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(wall));
|
||||||
}
|
|
||||||
|
|
||||||
public void NewLine(Line line)
|
|
||||||
{
|
|
||||||
if (line is null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var lineExist = Lines.TryGetValue(line.ToString(), out var tile);
|
|
||||||
var newLine = new Line { Start=line.Start, End=line.End, Width=line.Width};
|
|
||||||
if (lineExist)
|
|
||||||
{
|
|
||||||
Lines.TryRemove(line.ToString(), out var _);
|
|
||||||
}
|
|
||||||
|
|
||||||
Lines.TryAdd(newLine.ToString(), newLine);
|
|
||||||
|
|
||||||
//TODO fix this
|
|
||||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void NewRoom(Room line)
|
|
||||||
{
|
|
||||||
if (line is null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var lineExist = Rooms.TryGetValue(line.ToString(), out var tile);
|
|
||||||
var newLine = new Room { Start=line.Start, End=line.End, Delete=line.Delete};
|
|
||||||
if (lineExist)
|
|
||||||
{
|
|
||||||
Rooms.TryRemove(line.ToString(), out var _);
|
|
||||||
}
|
|
||||||
|
|
||||||
Rooms.TryAdd(newLine.ToString(), newLine);
|
|
||||||
|
|
||||||
//TODO fix this
|
|
||||||
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DeleteNote(Note note)
|
||||||
|
{
|
||||||
|
if (note is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var removed = Notes.TryRemove(note.ToString(), out var _);
|
||||||
|
if (removed)
|
||||||
|
{
|
||||||
|
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(note));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteOverlay(Overlay overlay)
|
||||||
|
{
|
||||||
|
if (overlay is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var removed = Overlays.TryRemove(overlay.ToString(), out var _);
|
||||||
|
if (removed)
|
||||||
|
{
|
||||||
|
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(overlay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteTile(Tile tile)
|
||||||
|
{
|
||||||
|
if (tile is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var removed = Map.TryRemove(tile.ToString(), out var _);
|
||||||
|
if (removed)
|
||||||
|
{
|
||||||
|
OnRaiseMapEntityDeletedEvent(new MapEntityDeletedEventArgs(tile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnRaiseMapEntityAddedEvent(MapEntityAddedEventArgs e)
|
||||||
|
{
|
||||||
|
MapEntityAdded?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnRaiseMapEntityDeletedEvent(MapEntityDeletedEventArgs e)
|
||||||
|
{
|
||||||
|
MapEntityDeleted?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NewLine(Line line)
|
||||||
|
{
|
||||||
|
if (line is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lineExist = Lines.TryGetValue(line.ToString(), out var tile);
|
||||||
|
var newLine = new Line { Start = line.Start, End = line.End, Width = line.Width };
|
||||||
|
if (lineExist)
|
||||||
|
{
|
||||||
|
Lines.TryRemove(line.ToString(), out var _);
|
||||||
|
}
|
||||||
|
|
||||||
|
Lines.TryAdd(newLine.ToString(), newLine);
|
||||||
|
|
||||||
|
//TODO fix this
|
||||||
|
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NewRoom(Room line)
|
||||||
|
{
|
||||||
|
if (line is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lineExist = Rooms.TryGetValue(line.ToString(), out var tile);
|
||||||
|
var newLine = new Room { Start = line.Start, End = line.End, Delete = line.Delete };
|
||||||
|
if (lineExist)
|
||||||
|
{
|
||||||
|
Rooms.TryRemove(line.ToString(), out var _);
|
||||||
|
}
|
||||||
|
|
||||||
|
Rooms.TryAdd(newLine.ToString(), newLine);
|
||||||
|
|
||||||
|
//TODO fix this
|
||||||
|
OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,13 @@ namespace Sledgemapper.Shared.Entities
|
||||||
public double Timestamp { get; set; }
|
public double Timestamp { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Ping : BaseMapEntity
|
||||||
|
{
|
||||||
|
public Player Player { get; set; }
|
||||||
|
public int Iterations {get;set;}
|
||||||
|
public double StartTime {get;set;}
|
||||||
|
}
|
||||||
|
|
||||||
public class Tile : BaseMapEntity
|
public class Tile : BaseMapEntity
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,11 @@ namespace Sledgemapper
|
||||||
p.Position = player.Position;
|
p.Position = player.Position;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Connection.On<Ping>("Ping", (ping) =>
|
||||||
|
{
|
||||||
|
SessionData.Pings.TryAdd(Guid.NewGuid(), ping);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<string> GetToken()
|
private Task<string> GetToken()
|
||||||
|
@ -233,6 +238,14 @@ namespace Sledgemapper
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal async Task Ping(Tile location)
|
||||||
|
{
|
||||||
|
if (Connection!=null && Connection.State == HubConnectionState.Connected)
|
||||||
|
{
|
||||||
|
await Connection.InvokeAsync("Ping",SessionData.SessionName, location);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AuthenticatedHttpClientHandler : HttpClientHandler
|
class AuthenticatedHttpClientHandler : HttpClientHandler
|
||||||
|
|
|
@ -93,6 +93,23 @@
|
||||||
/processorParam:TextureFormat=Compressed
|
/processorParam:TextureFormat=Compressed
|
||||||
/build:fonts/font99.spritefont
|
/build:fonts/font99.spritefont
|
||||||
|
|
||||||
|
#begin handcursors
|
||||||
|
/importer:TextureImporter
|
||||||
|
/processor:TextureProcessor
|
||||||
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
|
/processorParam:ColorKeyEnabled=True
|
||||||
|
/processorParam:GenerateMipmaps=False
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
|
/processorParam:MakeSquare=False
|
||||||
|
/processorParam:TextureFormat=Color
|
||||||
|
/build:handcursors
|
||||||
|
|
||||||
|
#begin handcursorsIndex
|
||||||
|
/importer:XmlImporter
|
||||||
|
/processor:
|
||||||
|
/build:handcursorsIndex
|
||||||
|
|
||||||
#begin icon_delete.png
|
#begin icon_delete.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
|
@ -141,6 +158,23 @@
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:location.png
|
/build:location.png
|
||||||
|
|
||||||
|
#begin rippleSpriteIndex
|
||||||
|
/importer:XmlImporter
|
||||||
|
/processor:PassThroughProcessor
|
||||||
|
/build:rippleSpriteIndex
|
||||||
|
|
||||||
|
#begin rippleSpriteMap
|
||||||
|
/importer:TextureImporter
|
||||||
|
/processor:TextureProcessor
|
||||||
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
|
/processorParam:ColorKeyEnabled=True
|
||||||
|
/processorParam:GenerateMipmaps=False
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
|
/processorParam:MakeSquare=False
|
||||||
|
/processorParam:TextureFormat=Color
|
||||||
|
/build:rippleSpriteMap
|
||||||
|
|
||||||
#begin shaders/OutlineShader.fx
|
#begin shaders/OutlineShader.fx
|
||||||
/importer:EffectImporter
|
/importer:EffectImporter
|
||||||
/processor:EffectProcessor
|
/processor:EffectProcessor
|
||||||
|
@ -380,30 +414,6 @@
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:walls/wall01.png
|
/build:walls/wall01.png
|
||||||
|
|
||||||
#begin walls/wall01.png
|
|
||||||
/importer:TextureImporter
|
|
||||||
/processor:TextureProcessor
|
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
|
||||||
/processorParam:ColorKeyEnabled=True
|
|
||||||
/processorParam:GenerateMipmaps=False
|
|
||||||
/processorParam:PremultiplyAlpha=True
|
|
||||||
/processorParam:ResizeToPowerOfTwo=False
|
|
||||||
/processorParam:MakeSquare=False
|
|
||||||
/processorParam:TextureFormat=Color
|
|
||||||
/build:walls/wall01.png
|
|
||||||
|
|
||||||
#begin walls/wall02.png
|
|
||||||
/importer:TextureImporter
|
|
||||||
/processor:TextureProcessor
|
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
|
||||||
/processorParam:ColorKeyEnabled=True
|
|
||||||
/processorParam:GenerateMipmaps=False
|
|
||||||
/processorParam:PremultiplyAlpha=True
|
|
||||||
/processorParam:ResizeToPowerOfTwo=False
|
|
||||||
/processorParam:MakeSquare=False
|
|
||||||
/processorParam:TextureFormat=Color
|
|
||||||
/build:walls/wall02.png
|
|
||||||
|
|
||||||
#begin walls/wall02.png
|
#begin walls/wall02.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
|
@ -428,18 +438,6 @@
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:walls/wall03.png
|
/build:walls/wall03.png
|
||||||
|
|
||||||
#begin walls/wall03.png
|
|
||||||
/importer:TextureImporter
|
|
||||||
/processor:TextureProcessor
|
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
|
||||||
/processorParam:ColorKeyEnabled=True
|
|
||||||
/processorParam:GenerateMipmaps=False
|
|
||||||
/processorParam:PremultiplyAlpha=True
|
|
||||||
/processorParam:ResizeToPowerOfTwo=False
|
|
||||||
/processorParam:MakeSquare=False
|
|
||||||
/processorParam:TextureFormat=Color
|
|
||||||
/build:walls/wall03.png
|
|
||||||
|
|
||||||
#begin walls/wall04.png
|
#begin walls/wall04.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
|
@ -452,30 +450,6 @@
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:walls/wall04.png
|
/build:walls/wall04.png
|
||||||
|
|
||||||
#begin walls/wall04.png
|
|
||||||
/importer:TextureImporter
|
|
||||||
/processor:TextureProcessor
|
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
|
||||||
/processorParam:ColorKeyEnabled=True
|
|
||||||
/processorParam:GenerateMipmaps=False
|
|
||||||
/processorParam:PremultiplyAlpha=True
|
|
||||||
/processorParam:ResizeToPowerOfTwo=False
|
|
||||||
/processorParam:MakeSquare=False
|
|
||||||
/processorParam:TextureFormat=Color
|
|
||||||
/build:walls/wall04.png
|
|
||||||
|
|
||||||
#begin walls/wall05.png
|
|
||||||
/importer:TextureImporter
|
|
||||||
/processor:TextureProcessor
|
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
|
||||||
/processorParam:ColorKeyEnabled=True
|
|
||||||
/processorParam:GenerateMipmaps=False
|
|
||||||
/processorParam:PremultiplyAlpha=True
|
|
||||||
/processorParam:ResizeToPowerOfTwo=False
|
|
||||||
/processorParam:MakeSquare=False
|
|
||||||
/processorParam:TextureFormat=Color
|
|
||||||
/build:walls/wall05.png
|
|
||||||
|
|
||||||
#begin walls/wall05.png
|
#begin walls/wall05.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
|
|
BIN
Sledgemapper/Content/handcursors
Normal file
BIN
Sledgemapper/Content/handcursors
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
BIN
Sledgemapper/Content/handcursors.png
Normal file
BIN
Sledgemapper/Content/handcursors.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 349 B |
7
Sledgemapper/Content/handcursorsIndex
Normal file
7
Sledgemapper/Content/handcursorsIndex
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<XnaContent>
|
||||||
|
<Asset Type="System.Collections.Generic.Dictionary[System.String, Microsoft.Xna.Framework.Rectangle]">
|
||||||
|
<Item><Key>handcursor_00</Key><Value>0 0 60 60</Value></Item>
|
||||||
|
<Item><Key>handcursor_01</Key><Value>61 0 60 60</Value></Item>
|
||||||
|
</Asset>
|
||||||
|
</XnaContent>
|
24
Sledgemapper/Content/rippleSpriteIndex
Normal file
24
Sledgemapper/Content/rippleSpriteIndex
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<XnaContent>
|
||||||
|
<Asset Type="System.Collections.Generic.Dictionary[System.String, Microsoft.Xna.Framework.Rectangle]">
|
||||||
|
<Item><Key>ripple_00</Key><Value>0 0 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_01</Key><Value>129 0 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_02</Key><Value>258 0 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_03</Key><Value>0 129 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_04</Key><Value>129 129 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_05</Key><Value>0 258 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_06</Key><Value>129 258 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_07</Key><Value>258 129 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_08</Key><Value>258 258 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_09</Key><Value>387 0 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_10</Key><Value>387 129 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_11</Key><Value>516 0 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_12</Key><Value>387 258 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_13</Key><Value>516 129 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_14</Key><Value>645 0 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_15</Key><Value>774 0 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_16</Key><Value>645 129 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_17</Key><Value>516 258 128 128</Value></Item>
|
||||||
|
<Item><Key>ripple_18</Key><Value>645 258 128 128</Value></Item>
|
||||||
|
</Asset>
|
||||||
|
</XnaContent>
|
BIN
Sledgemapper/Content/rippleSpriteMap
Normal file
BIN
Sledgemapper/Content/rippleSpriteMap
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
|
@ -12,6 +12,7 @@ namespace Sledgemapper
|
||||||
public Color NoteColor { get; set; }
|
public Color NoteColor { get; set; }
|
||||||
public string MachineName { get; set; }
|
public string MachineName { get; set; }
|
||||||
public int TileDeleteDivider { get; set; }
|
public int TileDeleteDivider { get; set; }
|
||||||
|
public int PingDuration {get;set;}
|
||||||
|
|
||||||
public Settings()
|
public Settings()
|
||||||
{
|
{
|
||||||
|
@ -19,7 +20,8 @@ namespace Sledgemapper
|
||||||
GridColor = Color.Black;
|
GridColor = Color.Black;
|
||||||
NoteColor = Color.DarkRed;
|
NoteColor = Color.DarkRed;
|
||||||
OverlayTintColor = new Color(24, 118, 157);
|
OverlayTintColor = new Color(24, 118, 157);
|
||||||
TileDeleteDivider=14;
|
TileDeleteDivider = 14;
|
||||||
|
PingDuration = 4000;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MachineName = Environment.MachineName;
|
MachineName = Environment.MachineName;
|
||||||
|
|
|
@ -6,6 +6,7 @@ using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using MonoGame.Extended;
|
using MonoGame.Extended;
|
||||||
|
using MonoGame.Extended.VectorDraw;
|
||||||
using Myra;
|
using Myra;
|
||||||
using Myra.Graphics2D.Brushes;
|
using Myra.Graphics2D.Brushes;
|
||||||
using Myra.Graphics2D.TextureAtlases;
|
using Myra.Graphics2D.TextureAtlases;
|
||||||
|
@ -24,6 +25,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AsyncAwaitBestPractices;
|
||||||
|
|
||||||
namespace Sledgemapper
|
namespace Sledgemapper
|
||||||
{
|
{
|
||||||
|
@ -152,7 +154,6 @@ namespace Sledgemapper
|
||||||
{
|
{
|
||||||
var indexX = 0;
|
var indexX = 0;
|
||||||
var indexY = 0;
|
var indexY = 0;
|
||||||
//foreach (var item in spriteSheet.index)
|
|
||||||
grid.Widgets.Clear();
|
grid.Widgets.Clear();
|
||||||
_mainWidget.ScrOverlay.ResetScroll();
|
_mainWidget.ScrOverlay.ResetScroll();
|
||||||
foreach (var item in spriteSheet.index.Where(t => String.IsNullOrWhiteSpace(e) || t.Key.ToLower().Contains(e.ToLower())))
|
foreach (var item in spriteSheet.index.Where(t => String.IsNullOrWhiteSpace(e) || t.Key.ToLower().Contains(e.ToLower())))
|
||||||
|
@ -177,6 +178,7 @@ namespace Sledgemapper
|
||||||
_lblOverlayName.Visible = false;
|
_lblOverlayName.Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SpriteSheet _rippleSpriteSheet;
|
||||||
Label _lblOverlayName;
|
Label _lblOverlayName;
|
||||||
|
|
||||||
private void OnTileButtonTouchEntered(object sender, EventArgs e)
|
private void OnTileButtonTouchEntered(object sender, EventArgs e)
|
||||||
|
@ -187,7 +189,6 @@ namespace Sledgemapper
|
||||||
_lblOverlayName.Visible = true;
|
_lblOverlayName.Visible = true;
|
||||||
_lblOverlayName.Text = ((ImageButton)sender).Id;
|
_lblOverlayName.Text = ((ImageButton)sender).Id;
|
||||||
_desktop.ShowContextMenu(_lblOverlayName, mouseState);
|
_desktop.ShowContextMenu(_lblOverlayName, mouseState);
|
||||||
// _lblOverlayName.true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadContent()
|
protected override void LoadContent()
|
||||||
|
@ -221,7 +222,10 @@ namespace Sledgemapper
|
||||||
_wallsContent = Content.LoadContentFolder<Texture2D>("walls");
|
_wallsContent = Content.LoadContentFolder<Texture2D>("walls");
|
||||||
|
|
||||||
_spriteSheet = new SpriteSheet();
|
_spriteSheet = new SpriteSheet();
|
||||||
_spriteSheet.LoadContent(Content);
|
_spriteSheet.LoadContent(Content, "spriteIndex", "sprites");
|
||||||
|
_rippleSpriteSheet = new SpriteSheet();
|
||||||
|
_rippleSpriteSheet.LoadContent(Content, "handcursorsIndex", "handcursors");
|
||||||
|
|
||||||
_lblOverlayName = new Label();
|
_lblOverlayName = new Label();
|
||||||
_lblOverlayName.Background = new SolidBrush(Color.SlateGray);
|
_lblOverlayName.Background = new SolidBrush(Color.SlateGray);
|
||||||
_lblOverlayName.Padding = new Myra.Graphics2D.Thickness(4);
|
_lblOverlayName.Padding = new Myra.Graphics2D.Thickness(4);
|
||||||
|
@ -249,20 +253,7 @@ namespace Sledgemapper
|
||||||
|
|
||||||
private void OnTxtOverlaySearchChange(object sender, ValueChangedEventArgs<string> e)
|
private void OnTxtOverlaySearchChange(object sender, ValueChangedEventArgs<string> e)
|
||||||
{
|
{
|
||||||
// var filteredWidget = _mainWidget.GridOverlays.Widgets.Where(m => m.Id.ToLower().Contains(e.NewValue.ToLower())).ToArray();
|
|
||||||
// foreach (var w in _mainWidget.GridOverlays.Widgets)
|
|
||||||
// {
|
|
||||||
// w.
|
|
||||||
// w.Visible = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// foreach (var w in filteredWidget)
|
|
||||||
// {
|
|
||||||
// w.Visible = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
AddItemToToolGrid(_mainWidget.GridOverlays, OnOverlayButtonClicked, _spriteSheet, e.NewValue);
|
AddItemToToolGrid(_mainWidget.GridOverlays, OnOverlayButtonClicked, _spriteSheet, e.NewValue);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBtnToolbarDeleteClicked(object sender, EventArgs e)
|
private void OnBtnToolbarDeleteClicked(object sender, EventArgs e)
|
||||||
|
@ -449,6 +440,8 @@ namespace Sledgemapper
|
||||||
var newNoteButton = new TextButton { Text = "New Note", Width = 80, Height = 20, Padding = new Myra.Graphics2D.Thickness(2), HorizontalAlignment = HorizontalAlignment.Left };
|
var newNoteButton = new TextButton { Text = "New Note", Width = 80, Height = 20, Padding = new Myra.Graphics2D.Thickness(2), HorizontalAlignment = HorizontalAlignment.Left };
|
||||||
newNoteButton.Click += OnContextMenuNewNoteClick;
|
newNoteButton.Click += OnContextMenuNewNoteClick;
|
||||||
popup.AddChild(newNoteButton);
|
popup.AddChild(newNoteButton);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -463,6 +456,11 @@ namespace Sledgemapper
|
||||||
popup.AddChild(deleteNoteButton);
|
popup.AddChild(deleteNoteButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pingButton = new TextButton { Text = "Ping", Width = 80, Height = 20, Padding = new Myra.Graphics2D.Thickness(2), HorizontalAlignment = HorizontalAlignment.Left };
|
||||||
|
var location = new Tile { X = _state.HoveredTile.X, Y = _state.HoveredTile.Y };
|
||||||
|
pingButton.Click += (s, e) => OnContextMenuPingClick(s, e, location);
|
||||||
|
popup.AddChild(pingButton);
|
||||||
|
|
||||||
_desktop.ShowContextMenu(popup, mouseState.Position);
|
_desktop.ShowContextMenu(popup, mouseState.Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,6 +617,11 @@ namespace Sledgemapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldState.IsKeyDown(Keys.P) && newState.IsKeyUp(Keys.P))
|
||||||
|
{
|
||||||
|
_communicationManager.Ping(_state.HoveredTile).SafeFireAndForget();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var key in newState.GetPressedKeys())
|
foreach (var key in newState.GetPressedKeys())
|
||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
|
@ -670,10 +673,17 @@ namespace Sledgemapper
|
||||||
var center = new Point((Window.ClientBounds.Width + 200) / 2 - _state.TileSize / 2, Window.ClientBounds.Height / 2 - _state.TileSize / 2);
|
var center = new Point((Window.ClientBounds.Width + 200) / 2 - _state.TileSize / 2, Window.ClientBounds.Height / 2 - _state.TileSize / 2);
|
||||||
var dx = center.X - x * _state.TileSize - _viewportCenter.X;
|
var dx = center.X - x * _state.TileSize - _viewportCenter.X;
|
||||||
var dy = center.Y - y * _state.TileSize - _viewportCenter.Y;
|
var dy = center.Y - y * _state.TileSize - _viewportCenter.Y;
|
||||||
|
|
||||||
_viewportCenter.X += dx;
|
_viewportCenter.X += dx;
|
||||||
_viewportCenter.Y += dy;
|
_viewportCenter.Y += dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnContextMenuPingClick(object sender, EventArgs e, Tile location)
|
||||||
|
{
|
||||||
|
_desktop.HideContextMenu();
|
||||||
|
_communicationManager.Ping(location).SafeFireAndForget();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Draw(GameTime gameTime)
|
protected override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
if (_spriteBatch is null)
|
if (_spriteBatch is null)
|
||||||
|
@ -688,7 +698,7 @@ namespace Sledgemapper
|
||||||
|
|
||||||
_spriteBatch.Begin(
|
_spriteBatch.Begin(
|
||||||
transformMatrix: Matrix.CreateTranslation(_viewportCenter),
|
transformMatrix: Matrix.CreateTranslation(_viewportCenter),
|
||||||
sortMode: SpriteSortMode.Texture);
|
sortMode: SpriteSortMode.Texture, samplerState: SamplerState.PointClamp);
|
||||||
|
|
||||||
DrawTiles();
|
DrawTiles();
|
||||||
|
|
||||||
|
@ -714,6 +724,8 @@ namespace Sledgemapper
|
||||||
|
|
||||||
_spriteBatch.End();
|
_spriteBatch.End();
|
||||||
|
|
||||||
|
DrawRipple(gameTime);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_desktop?.Render();
|
_desktop?.Render();
|
||||||
|
@ -725,6 +737,81 @@ namespace Sledgemapper
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) > _settings.PingDuration)
|
||||||
|
{
|
||||||
|
_sessionData.Pings.TryRemove(guid, out var _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_spriteBatch.End();
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawRoomPreview()
|
private void DrawRoomPreview()
|
||||||
{
|
{
|
||||||
if ((_state.InsertMode == InsertMode.NewRoom || _state.InsertMode == InsertMode.NewDelete) && _state.SelectedSnapPoint != null)
|
if ((_state.InsertMode == InsertMode.NewRoom || _state.InsertMode == InsertMode.NewDelete) && _state.SelectedSnapPoint != null)
|
||||||
|
@ -992,88 +1079,16 @@ namespace Sledgemapper
|
||||||
var isoffscreen = IsOffscreen(_state.SelectedTile);
|
var isoffscreen = IsOffscreen(_state.SelectedTile);
|
||||||
if (isoffscreen)
|
if (isoffscreen)
|
||||||
{
|
{
|
||||||
var center = new Point((Window.ClientBounds.Width + 200) / 2 - (int)_viewportCenter.X, Window.ClientBounds.Height / 2 - (int)_viewportCenter.Y);
|
var validPointer = GetPointerVector(new Point(_state.SelectedTile.X, _state.SelectedTile.Y), out var points);
|
||||||
|
if (validPointer)
|
||||||
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(_state.SelectedTile.X * _state.TileSize, _state.SelectedTile.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 float[] { ua1, ua2, ua3, ua4 };
|
|
||||||
if (uas.Any(u => u > 0 && u < 1))
|
|
||||||
{
|
{
|
||||||
var ua = uas.Where(u => u > 0 && u < 1).Min();
|
_spriteBatch.DrawPolygon(Vector2.Zero, points, Color.Red, 2);
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (var j = 0; j < 4; j++)
|
|
||||||
{
|
|
||||||
if (uas[j] == ua)
|
|
||||||
{
|
|
||||||
i = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var x = (p1.X + ua * (p2.X - p1.X));
|
|
||||||
var y = (p1.Y + ua * (p2.Y - p1.Y));
|
|
||||||
|
|
||||||
|
|
||||||
var v = _vector2Pool.Rent(4);
|
|
||||||
switch (i)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
v[0] = new Vector2(x, y);
|
|
||||||
v[1] = new Vector2(x - 20, y + 10);
|
|
||||||
v[2] = new Vector2(x - 20, y - 10);
|
|
||||||
v[3] = new Vector2(x, y);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
v[0] = new Vector2(x, y);
|
|
||||||
v[1] = new Vector2(x - 10, y + 20);
|
|
||||||
v[2] = new Vector2(x + 10, y + 20);
|
|
||||||
v[3] = new Vector2(x, y);
|
|
||||||
y += 20;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
x += 0;
|
|
||||||
v[0] = new Vector2(x, y);
|
|
||||||
v[1] = new Vector2(x + 20, y + 10);
|
|
||||||
v[2] = new Vector2(x + 20, y - 10);
|
|
||||||
v[3] = new Vector2(x, y);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
y -= 20;
|
|
||||||
v[0] = new Vector2(x, y);
|
|
||||||
v[1] = new Vector2(x - 10, y - 20);
|
|
||||||
v[2] = new Vector2(x + 10, y - 20);
|
|
||||||
v[3] = new Vector2(x, y);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_spriteBatch.DrawPolygon(Vector2.Zero, v, Color.Red, 2);
|
|
||||||
_vector2Pool.Return(v);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_spriteBatch.DrawRectangle(new Rectangle((_state.SelectedTile.X * _state.TileSize) - 2, (_state.SelectedTile.Y * _state.TileSize) - 2, _state.TileSize + 3, _state.TileSize + 3), Color.Red, 2);
|
_spriteBatch.DrawRectangle(new Rectangle((_state.SelectedTile.X * _state.TileSize) - 2, (_state.SelectedTile.Y * _state.TileSize) - 2, _state.TileSize + 3, _state.TileSize + 3), Color.Red, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1309,11 +1324,12 @@ namespace Sledgemapper
|
||||||
|
|
||||||
var playerCells = _sessionData.Players.Select(m => m.Position).Distinct().ToList();
|
var playerCells = _sessionData.Players.Select(m => m.Position).Distinct().ToList();
|
||||||
|
|
||||||
foreach (var cell in playerCells)
|
foreach (var cell in playerCells.Where(c => !IsOffscreen(c)))
|
||||||
{
|
{
|
||||||
var playersInCell = _sessionData.Players.Where(m => m.Position == cell).ToList();
|
var playersInCell = _sessionData.Players.Where(m => m.Position == cell).ToList();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
foreach (var player in playersInCell)
|
foreach (var player in playersInCell)
|
||||||
|
|
||||||
{
|
{
|
||||||
var color = player.Color.ToColor();
|
var color = player.Color.ToColor();
|
||||||
|
|
||||||
|
@ -1331,7 +1347,7 @@ namespace Sledgemapper
|
||||||
_state.TileSize - 1,
|
_state.TileSize - 1,
|
||||||
_state.TileSize - 1);
|
_state.TileSize - 1);
|
||||||
stringPosition = new Vector2(
|
stringPosition = new Vector2(
|
||||||
player.Position.X * _state.TileSize,
|
player.Position.X * _state.TileSize + 1,
|
||||||
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
}
|
}
|
||||||
else if (playersInCell.Count == 2)
|
else if (playersInCell.Count == 2)
|
||||||
|
@ -1346,7 +1362,7 @@ namespace Sledgemapper
|
||||||
_state.TileSize / 2 - 1,
|
_state.TileSize / 2 - 1,
|
||||||
_state.TileSize - 1);
|
_state.TileSize - 1);
|
||||||
stringPosition = new Vector2(
|
stringPosition = new Vector2(
|
||||||
player.Position.X * _state.TileSize,
|
player.Position.X * _state.TileSize + 1,
|
||||||
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1357,7 +1373,7 @@ namespace Sledgemapper
|
||||||
_state.TileSize / 2 - 1,
|
_state.TileSize / 2 - 1,
|
||||||
_state.TileSize - 1);
|
_state.TileSize - 1);
|
||||||
stringPosition = new Vector2(
|
stringPosition = new Vector2(
|
||||||
player.Position.X * _state.TileSize + _state.TileSize / 2,
|
player.Position.X * _state.TileSize + _state.TileSize / 2 + 1,
|
||||||
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
@ -1374,7 +1390,7 @@ namespace Sledgemapper
|
||||||
_state.TileSize / 2 - 1,
|
_state.TileSize / 2 - 1,
|
||||||
_state.TileSize / 2 - 1);
|
_state.TileSize / 2 - 1);
|
||||||
stringPosition = new Vector2(
|
stringPosition = new Vector2(
|
||||||
player.Position.X * _state.TileSize,
|
player.Position.X * _state.TileSize + 1,
|
||||||
player.Position.Y * _state.TileSize + _state.TileSize / 2 - measure.Y * fscale);
|
player.Position.Y * _state.TileSize + _state.TileSize / 2 - measure.Y * fscale);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1385,7 +1401,7 @@ namespace Sledgemapper
|
||||||
_state.TileSize / 2 - 1,
|
_state.TileSize / 2 - 1,
|
||||||
_state.TileSize / 2 - 1);
|
_state.TileSize / 2 - 1);
|
||||||
stringPosition = new Vector2(
|
stringPosition = new Vector2(
|
||||||
player.Position.X * _state.TileSize + _state.TileSize / 2,
|
player.Position.X * _state.TileSize + _state.TileSize / 2 + 1,
|
||||||
player.Position.Y * _state.TileSize + _state.TileSize / 2 - measure.Y * fscale);
|
player.Position.Y * _state.TileSize + _state.TileSize / 2 - measure.Y * fscale);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1396,7 +1412,7 @@ namespace Sledgemapper
|
||||||
_state.TileSize / 2 - 1,
|
_state.TileSize / 2 - 1,
|
||||||
_state.TileSize / 2 - 1);
|
_state.TileSize / 2 - 1);
|
||||||
stringPosition = new Vector2(
|
stringPosition = new Vector2(
|
||||||
player.Position.X * _state.TileSize,
|
player.Position.X * _state.TileSize + 1,
|
||||||
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1408,7 +1424,7 @@ namespace Sledgemapper
|
||||||
_state.TileSize / 2 - 1,
|
_state.TileSize / 2 - 1,
|
||||||
_state.TileSize / 2 - 1);
|
_state.TileSize / 2 - 1);
|
||||||
stringPosition = new Vector2(
|
stringPosition = new Vector2(
|
||||||
player.Position.X * _state.TileSize + _state.TileSize / 2,
|
player.Position.X * _state.TileSize + _state.TileSize / 2 + 1,
|
||||||
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1440,30 +1456,88 @@ namespace Sledgemapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawPlayerPointer(Player player)
|
private void DrawPingPointer(Ping ping, GameTime gameTime)
|
||||||
{
|
{
|
||||||
var center = new Point((Window.ClientBounds.Width + 200) / 2 - (int)_viewportCenter.X, Window.ClientBounds.Height / 2 - (int)_viewportCenter.Y);
|
var durationMs = 2000f;
|
||||||
|
var baseRadius = _state.TileSize / 4f;
|
||||||
|
var baseOuterRadius = (float)_state.TileSize;
|
||||||
|
var iterations = 3f;
|
||||||
|
var validPointer = GetPointerVector(new Point(ping.X, ping.Y), out var points);
|
||||||
|
|
||||||
var cx = center.X / _state.TileSize;
|
if (validPointer)
|
||||||
var cy = center.Y / _state.TileSize;
|
{
|
||||||
|
_spriteBatch.DrawPolygon(Vector2.Zero, points, ping.Player.Color.ToColor(), 4);
|
||||||
|
|
||||||
var p1 = new Vector2(cx * _state.TileSize, cy * _state.TileSize);
|
|
||||||
var p2 = new Vector2(player.Position.X * _state.TileSize, player.Position.Y * _state.TileSize);
|
|
||||||
|
|
||||||
var p3 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, 0 - _viewportCenter.Y);
|
for (var j = 0; j < iterations; j++)
|
||||||
var p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
{
|
||||||
|
var cycleTime = (((float)gameTime.TotalGameTime.TotalMilliseconds + (float)j * durationMs / iterations) % durationMs) / durationMs;
|
||||||
|
var easing = Easings.Interpolate(cycleTime, Easings.Functions.SineEaseInOut);
|
||||||
|
var v2 = new Vector2[points.Length];
|
||||||
|
|
||||||
|
|
||||||
|
var tCenter = new Vector2((points[0].X + points[1].X + points[2].X) / 3f, (points[0].Y + points[1].Y + points[2].Y) / 3f);
|
||||||
|
|
||||||
|
|
||||||
|
for (int i1 = 0; i1 < v2.Length; i1++)
|
||||||
|
{
|
||||||
|
|
||||||
|
var svx = ((points[i1].X - tCenter.X) * (1 + (2 * easing))) + tCenter.X;
|
||||||
|
var svy = ((points[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));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool GetPointerVector(Point target, out Vector2[] points)
|
||||||
|
{
|
||||||
|
var offset = _state.TileSize / 2;
|
||||||
|
var leftBound = 200 + offset;
|
||||||
|
var topBound = 75 + offset;
|
||||||
|
var bottomBound = 25 + offset;
|
||||||
|
var rightBound = offset;
|
||||||
|
points = new Vector2[0];
|
||||||
|
var center = new Point((Window.ClientBounds.Width + leftBound) / 2 - (int)_viewportCenter.X, Window.ClientBounds.Height / 2 - (int)_viewportCenter.Y);
|
||||||
|
|
||||||
|
// center
|
||||||
|
var p1 = new Vector2(center.X, center.Y);
|
||||||
|
|
||||||
|
// point
|
||||||
|
var p2 = new Vector2(
|
||||||
|
target.X * _state.TileSize + offset,
|
||||||
|
target.Y * _state.TileSize + offset);
|
||||||
|
|
||||||
|
// top right
|
||||||
|
var p3 = new Vector2(
|
||||||
|
Window.ClientBounds.Width - _viewportCenter.X - rightBound,
|
||||||
|
topBound - _viewportCenter.Y);
|
||||||
|
|
||||||
|
//bottom right
|
||||||
|
var p4 = new Vector2(
|
||||||
|
Window.ClientBounds.Width - _viewportCenter.X - rightBound,
|
||||||
|
Window.ClientBounds.Height - _viewportCenter.Y - bottomBound);
|
||||||
|
|
||||||
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));
|
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);
|
p3 = new Vector2(leftBound - _viewportCenter.X, topBound - _viewportCenter.Y);
|
||||||
p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, 0 - _viewportCenter.Y);
|
p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, topBound - _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));
|
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);
|
p3 = new Vector2(leftBound - _viewportCenter.X, topBound - _viewportCenter.Y);
|
||||||
p4 = new Vector2(200 - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
p4 = new Vector2(leftBound - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y - bottomBound);
|
||||||
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));
|
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);
|
p3 = new Vector2(leftBound - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y - bottomBound);
|
||||||
p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y);
|
p4 = new Vector2(Window.ClientBounds.Width - _viewportCenter.X, Window.ClientBounds.Height - _viewportCenter.Y - bottomBound);
|
||||||
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 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 };
|
var uas = new List<float> { ua1, ua2, ua3, ua4 };
|
||||||
|
@ -1473,26 +1547,37 @@ namespace Sledgemapper
|
||||||
var i = uas.IndexOf(ua);
|
var i = uas.IndexOf(ua);
|
||||||
var x = (p1.X + ua * (p2.X - p1.X));
|
var x = (p1.X + ua * (p2.X - p1.X));
|
||||||
var y = (p1.Y + ua * (p2.Y - p1.Y));
|
var y = (p1.Y + ua * (p2.Y - p1.Y));
|
||||||
Vector2[] vertexes = new Vector2[0];
|
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case 0:
|
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) };
|
x += offset;
|
||||||
|
points = new Vector2[] { new Vector2(x, y), new Vector2(x - 20, y - 10), new Vector2(x - 20, y + 10), new Vector2(x, y) };
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
y += 20;
|
y -= offset;
|
||||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x - 10, y + 20), new Vector2(x + 10, y + 20), new Vector2(x, y) };
|
points = new Vector2[] { new Vector2(x, y), new Vector2(x - 10, y + 20), new Vector2(x + 10, y + 20), new Vector2(x, y) };
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
x += 0;
|
x -= offset;
|
||||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x + 20, y + 10), new Vector2(x + 20, y - 10), new Vector2(x, y) };
|
points = new Vector2[] { new Vector2(x, y), new Vector2(x + 20, y + 10), new Vector2(x + 20, y - 10), new Vector2(x, y) };
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
y -= 20;
|
y += offset;
|
||||||
vertexes = new Vector2[] { new Vector2(x, y), new Vector2(x - 10, y - 20), new Vector2(x + 10, y - 20), new Vector2(x, y) };
|
points = new Vector2[] { new Vector2(x, y), new Vector2(x + 10, y - 20), new Vector2(x - 10, y - 20), new Vector2(x, y) };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_spriteBatch.DrawPolygon(Vector2.Zero, vertexes, player.Color.ToColor(), 2);
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawPlayerPointer(Player player)
|
||||||
|
{
|
||||||
|
var validPointer = GetPointerVector(new Point(player.Position.X, player.Position.Y), out var points);
|
||||||
|
if (validPointer)
|
||||||
|
{
|
||||||
|
_spriteBatch.DrawPolygon(Vector2.Zero, points, player.Color.ToColor(), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1500,20 +1585,18 @@ namespace Sledgemapper
|
||||||
|
|
||||||
private bool IsOffscreen(Tile position)
|
private bool IsOffscreen(Tile position)
|
||||||
{
|
{
|
||||||
var visibleTilesX = GraphicsDevice.Viewport.Width / _state.TileSize + 1;
|
var boxTL = new Point(200 - _state.TileSize / 2, 75 - _state.TileSize / 2);
|
||||||
var visibleTilesY = GraphicsDevice.Viewport.Height / _state.TileSize + 1;
|
var boxBR = new Point(GraphicsDevice.Viewport.Width + _state.TileSize / 2, GraphicsDevice.Viewport.Height - 25 + _state.TileSize / 2);
|
||||||
|
|
||||||
var screenPositionTopLeft = new Point(200 - _state.TileSize + 0 * _state.TileSize - (int)_viewportCenter.X, 0 * _state.TileSize + _state.TileSize - (int)_viewportCenter.Y);
|
var tileTL = new Point(position.X * _state.TileSize + (int)_viewportCenter.X, position.Y * _state.TileSize + (int)_viewportCenter.Y);
|
||||||
var screenPositionBottomRight = new Point(visibleTilesX * _state.TileSize - (int)_viewportCenter.X, visibleTilesY * _state.TileSize - 20 - (int)_viewportCenter.Y);
|
var tileBR = new Point(position.X * _state.TileSize + (int)_viewportCenter.X + _state.TileSize, position.Y * _state.TileSize + (int)_viewportCenter.Y + _state.TileSize);
|
||||||
var tileTopLeft = new Point(screenPositionTopLeft.X / _state.TileSize, screenPositionTopLeft.Y / _state.TileSize);
|
|
||||||
var tileBottomRight = new Point(screenPositionBottomRight.X / _state.TileSize, screenPositionBottomRight.Y / _state.TileSize);
|
|
||||||
|
|
||||||
if (position.X < tileTopLeft.X || position.Y < tileTopLeft.Y || position.X > tileBottomRight.X || position.Y > tileBottomRight.Y)
|
if (tileTL.X <= boxTL.X || tileTL.Y <= boxTL.Y || tileBR.X >= boxBR.X || tileBR.Y >= boxBR.Y)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _borderWidth => (_state.TileSize / 6) % 2 == 0 ? (_state.TileSize / 6) : (_state.TileSize / 6) + 1;
|
private int _borderWidth => (_state.TileSize / 6) % 2 == 0 ? (_state.TileSize / 6) : (_state.TileSize / 6) + 1;
|
||||||
|
@ -2107,6 +2190,8 @@ namespace Sledgemapper
|
||||||
noteWindow.NoteText.SetKeyboardFocus();
|
noteWindow.NoteText.SetKeyboardFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void OnContextMenuDeleteNoteClick(object sender, EventArgs e)
|
private void OnContextMenuDeleteNoteClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_desktop.HideContextMenu();
|
_desktop.HideContextMenu();
|
||||||
|
@ -2328,10 +2413,10 @@ namespace Sledgemapper
|
||||||
internal Texture2D Texture;
|
internal Texture2D Texture;
|
||||||
internal Dictionary<String, Rectangle> index;
|
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");
|
index = content.Load<Dictionary<String, Rectangle>>(spriteIndex);
|
||||||
Texture = content.Load<Texture2D>("sprites");
|
Texture = content.Load<Texture2D>(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Rectangle? SourceRectangle(string spriteName)
|
internal Rectangle? SourceRectangle(string spriteName)
|
||||||
|
@ -2349,4 +2434,6 @@ namespace Sledgemapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue