Merge pull request 'Multiple players visible in cell' (#40) from multiPlayerPerCell into develop
Reviewed-on: michele/Map#40
This commit is contained in:
commit
17cce56866
2 changed files with 182 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace Sledgemapper.Shared.Entities
|
namespace Sledgemapper.Shared.Entities
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,64 @@ namespace Sledgemapper.Shared.Entities
|
||||||
|
|
||||||
public class Tile : BaseMapEntity
|
public class Tile : BaseMapEntity
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public bool Equals(Tile other)
|
||||||
|
{
|
||||||
|
if (other == null) return false;
|
||||||
|
return (X == other.X && Y == other.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Tile a, Tile b)
|
||||||
|
{
|
||||||
|
// If both are null, or both are same instance, return true.
|
||||||
|
if (System.Object.ReferenceEquals(a, b))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If one is null, but not both, return false.
|
||||||
|
if (((object)a == null) || ((object)b == null))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return true if the fields match:
|
||||||
|
return a.X == b.X && a.Y == b.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Tile a, Tile b)
|
||||||
|
{
|
||||||
|
return !(a == b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// See the full list of guidelines at
|
||||||
|
// http://go.microsoft.com/fwlink/?LinkID=85237
|
||||||
|
// and also the guidance for operator== at
|
||||||
|
// http://go.microsoft.com/fwlink/?LinkId=85238
|
||||||
|
//
|
||||||
|
|
||||||
|
if (obj == null || GetType() != obj.GetType())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Equals(obj as Tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// override object.GetHashCode
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int hash = 13;
|
||||||
|
hash = (hash * 7) + X + Y;
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Line : BaseMapEntity
|
public class Line : BaseMapEntity
|
||||||
|
|
|
@ -1304,22 +1304,130 @@ namespace Sledgemapper
|
||||||
|
|
||||||
private void DrawPlayers()
|
private void DrawPlayers()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _sessionData.Players.Count; i++)
|
var ffont = _fonts.FirstOrDefault(m => int.Parse(m.Key.Replace("font", "")) > _state.TileSize).Value ?? _fonts.Last().Value;
|
||||||
|
var fscale = _state.TileSize / ((float)ffont.LineSpacing * 3f);
|
||||||
|
|
||||||
|
var playerCells = _sessionData.Players.Select(m => m.Position).Distinct().ToList();
|
||||||
|
|
||||||
|
foreach (var cell in playerCells)
|
||||||
{
|
{
|
||||||
Player player = _sessionData.Players[i];
|
var playersInCell = _sessionData.Players.Where(m => m.Position == cell).ToList();
|
||||||
var color = player.Color.ToColor();
|
var i = 0;
|
||||||
_spriteBatch.DrawRectangle(new Rectangle(player.Position.X * _state.TileSize - 4, player.Position.Y * _state.TileSize - 4, _state.TileSize + 7, _state.TileSize + 7), color, 2);
|
foreach (var player in playersInCell)
|
||||||
var ffont = _fonts.FirstOrDefault(m => int.Parse(m.Key.Replace("font", "")) > _state.TileSize).Value ?? _fonts.Last().Value;
|
{
|
||||||
var fscale = _state.TileSize / ((float)ffont.LineSpacing * 2);
|
var color = player.Color.ToColor();
|
||||||
_spriteBatch.DrawString(ffont,
|
|
||||||
player.Initials,
|
var rectangle = new Rectangle();
|
||||||
new Vector2(player.Position.X * _state.TileSize + 2, player.Position.Y * _state.TileSize + _state.TileSize - 2 - ffont.LineSpacing * fscale),
|
var stringPosition = new Vector2();
|
||||||
color,
|
var measure = ffont.MeasureString(player.Initials);
|
||||||
0,
|
var maxSize = Math.Max(measure.X, measure.Y);
|
||||||
Vector2.Zero,
|
|
||||||
fscale,
|
if (playersInCell.Count == 1)
|
||||||
SpriteEffects.None,
|
{
|
||||||
0);
|
fscale = (_state.TileSize - 2) / maxSize;
|
||||||
|
rectangle = new Rectangle(
|
||||||
|
player.Position.X * _state.TileSize,
|
||||||
|
player.Position.Y * _state.TileSize,
|
||||||
|
_state.TileSize - 1,
|
||||||
|
_state.TileSize - 1);
|
||||||
|
stringPosition = new Vector2(
|
||||||
|
player.Position.X * _state.TileSize,
|
||||||
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
|
}
|
||||||
|
else if (playersInCell.Count == 2)
|
||||||
|
{
|
||||||
|
fscale = (_state.TileSize / 2 - 2) / maxSize;
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
rectangle = new Rectangle(
|
||||||
|
player.Position.X * _state.TileSize,
|
||||||
|
player.Position.Y * _state.TileSize,
|
||||||
|
_state.TileSize / 2 - 1,
|
||||||
|
_state.TileSize - 1);
|
||||||
|
stringPosition = new Vector2(
|
||||||
|
player.Position.X * _state.TileSize,
|
||||||
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rectangle = new Rectangle(
|
||||||
|
player.Position.X * _state.TileSize + _state.TileSize / 2,
|
||||||
|
player.Position.Y * _state.TileSize,
|
||||||
|
_state.TileSize / 2 - 1,
|
||||||
|
_state.TileSize - 1);
|
||||||
|
stringPosition = new Vector2(
|
||||||
|
player.Position.X * _state.TileSize + _state.TileSize / 2,
|
||||||
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else if (playersInCell.Count >= 3)
|
||||||
|
{
|
||||||
|
fscale = (_state.TileSize / 2 - 2) / maxSize;
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
rectangle = new Rectangle(
|
||||||
|
player.Position.X * _state.TileSize,
|
||||||
|
player.Position.Y * _state.TileSize,
|
||||||
|
_state.TileSize / 2 - 1,
|
||||||
|
_state.TileSize / 2 - 1);
|
||||||
|
stringPosition = new Vector2(
|
||||||
|
player.Position.X * _state.TileSize,
|
||||||
|
player.Position.Y * _state.TileSize + _state.TileSize / 2 - measure.Y * fscale);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
rectangle = new Rectangle(
|
||||||
|
player.Position.X * _state.TileSize + _state.TileSize / 2,
|
||||||
|
player.Position.Y * _state.TileSize,
|
||||||
|
_state.TileSize / 2 - 1,
|
||||||
|
_state.TileSize / 2 - 1);
|
||||||
|
stringPosition = new Vector2(
|
||||||
|
player.Position.X * _state.TileSize + _state.TileSize / 2,
|
||||||
|
player.Position.Y * _state.TileSize + _state.TileSize / 2 - measure.Y * fscale);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
rectangle = new Rectangle(
|
||||||
|
player.Position.X * _state.TileSize,
|
||||||
|
player.Position.Y * _state.TileSize + _state.TileSize / 2,
|
||||||
|
_state.TileSize / 2 - 1,
|
||||||
|
_state.TileSize / 2 - 1);
|
||||||
|
stringPosition = new Vector2(
|
||||||
|
player.Position.X * _state.TileSize,
|
||||||
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
default:
|
||||||
|
rectangle = new Rectangle(
|
||||||
|
player.Position.X * _state.TileSize + _state.TileSize / 2,
|
||||||
|
player.Position.Y * _state.TileSize + _state.TileSize / 2,
|
||||||
|
_state.TileSize / 2 - 1,
|
||||||
|
_state.TileSize / 2 - 1);
|
||||||
|
stringPosition = new Vector2(
|
||||||
|
player.Position.X * _state.TileSize + _state.TileSize / 2,
|
||||||
|
player.Position.Y * _state.TileSize + _state.TileSize - measure.Y * fscale);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
_spriteBatch.DrawRectangle(rectangle, color, 2);
|
||||||
|
_spriteBatch.DrawString(ffont,
|
||||||
|
player.Initials,
|
||||||
|
stringPosition,
|
||||||
|
color,
|
||||||
|
0,
|
||||||
|
Vector2.Zero,
|
||||||
|
fscale,
|
||||||
|
SpriteEffects.None,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var player in _sessionData.Players)
|
foreach (var player in _sessionData.Players)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue