tiles and lines

This commit is contained in:
Michele Scandura 2020-12-21 16:29:59 +00:00
parent 9085f4d5cb
commit b21a7c7ef2
4 changed files with 160 additions and 14 deletions

View file

@ -27,6 +27,7 @@ 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>();
Players = new List<Player>(); Players = new List<Player>();
Colors = new List<string>(); Colors = new List<string>();
} }
@ -40,6 +41,7 @@ namespace Sledgemapper.Shared.Entities
public List<string> Colors { get; set; } public List<string> Colors { get; set; }
public string SessionName { get; set; } public string SessionName { get; set; }
public int SessionId { get; set; } public int SessionId { get; set; }
public ConcurrentDictionary<string, Line> Lines { get; private set; }
public void NewTile(Tile selectedTile, string tileId) public void NewTile(Tile selectedTile, string tileId)
{ {
@ -179,5 +181,25 @@ namespace Sledgemapper.Shared.Entities
{ {
MapEntityDeleted?.Invoke(this, 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 { X = line.X, Y = line.Y,EndX=line.EndX, EndY=line.EndY };
if (lineExist)
{
Lines.TryRemove(line.ToString(), out var _);
}
Lines.TryAdd(newLine.ToString(), newLine);
//TODO fix this
//OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newTile));
}
} }
} }

View file

@ -1,21 +1,30 @@
namespace Sledgemapper.Shared.Entities namespace Sledgemapper.Shared.Entities
{ {
public abstract class BaseMapEntity public abstract class BaseMapEntity
{ {
public int X { get; set; } public int X { get; set; }
public int Y { get; set; } public int Y { get; set; }
public string ID { get; set; } public string ID { get; set; }
public int Rotation { get; set; } public int Rotation { get; set; }
public override string ToString() public override string ToString()
{ {
return $"{X}_{Y}"; return $"{X}_{Y}";
} }
public double Timestamp {get;set;} public double Timestamp { get; set; }
} }
public class Tile :BaseMapEntity public class Tile : BaseMapEntity
{ {
} }
public class Line : BaseMapEntity
{
public int EndX { get; set; }
public int EndY { get; set; }
public override string ToString()
{
return $"{X}_{Y}_{EndX}_{EndY}";
}
}
} }

View file

@ -329,6 +329,25 @@ namespace Sledgemapper
} }
} }
if (newState.IsKeyDown(Keys.LeftControl) && newState.IsKeyDown(Keys.LeftShift)
&& mouseState.LeftButton == ButtonState.Released
&& mouseState.LeftButton != oldMouseState.LeftButton)
{
if (_state.LineStart is null)
{
_state.LineStart = new Tile{X=_state.HoveredTile.X, Y=_state.HoveredTile.Y};
}
else
{
var line = new Line{X = _state.LineStart.X, Y = _state.LineStart.Y, EndX=_state.HoveredTile.X, EndY=_state.HoveredTile.Y};
_state.LineStart=null;
_sessionData.NewLine(line);
}
}
if (newState.IsKeyDown(Keys.LeftControl) && mouseState.ScrollWheelValue != oldMouseState.ScrollWheelValue) if (newState.IsKeyDown(Keys.LeftControl) && mouseState.ScrollWheelValue != oldMouseState.ScrollWheelValue)
{ {
// var center = new Point(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); // var center = new Point(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
@ -441,7 +460,7 @@ namespace Sledgemapper
_spriteBatch.Begin(transformMatrix: Matrix.CreateTranslation(_viewportCenter)); _spriteBatch.Begin(transformMatrix: Matrix.CreateTranslation(_viewportCenter));
DrawTiles(); DrawTiles();
DrawLines();
DrawWalls(); DrawWalls();
DrawOverlays(); DrawOverlays();
DrawNotes(); DrawNotes();
@ -766,15 +785,109 @@ namespace Sledgemapper
private void DrawTiles() private void DrawTiles()
{ {
// foreach (var tile in _sessionData.Map.Values)
// {
// var content = Content.Load<Texture2D>($"tiles/{tile.ID}");
// var posX = tile.X * _state.TileSize + _state.TileSize / 2f;
// var posY = tile.Y * _state.TileSize + _state.TileSize / 2f;
// _spriteBatch.Draw(content, new Vector2(posX, posY),
// null, Color.White, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize) / content.Width, SpriteEffects.None, 0);
// }
// border pass
foreach (var tile in _sessionData.Map.Values) foreach (var tile in _sessionData.Map.Values)
{ {
var content = Content.Load<Texture2D>($"tiles/{tile.ID}"); var content = Content.Load<Texture2D>($"tiles/{tile.ID}");
var posX = tile.X * _state.TileSize + _state.TileSize / 2f; var posX = tile.X * _state.TileSize ;
var posY = tile.Y * _state.TileSize + _state.TileSize / 2f; var posY = tile.Y * _state.TileSize ;
_spriteBatch.Draw(content, new Vector2(posX, posY), var whiteRectangle = new Texture2D(GraphicsDevice, 1, 1);
null, Color.White, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize) / content.Width, SpriteEffects.None, 0); whiteRectangle.SetData(new[] { _settings.OverlayTintColor });
_spriteBatch.Draw(whiteRectangle, new Rectangle((int)posX-4, (int)posY-4, _state.TileSize+8, _state.TileSize+8),null,Color.White,0,Vector2.Zero,SpriteEffects.None, 1);
// _spriteBatch.DrawRectangle(new Rectangle((int)posX-4, (int)posY-4, _state.TileSize+8, _state.TileSize+8), _settings.OverlayTintColor,1);
// _spriteBatch.Draw(content, new Vector2(posX, posY),
// null, Color.White, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize) / content.Width, SpriteEffects.None, 0);
}
//inner pass
foreach (var tile in _sessionData.Map.Values)
{
var content = Content.Load<Texture2D>($"tiles/{tile.ID}");
var posX = tile.X * _state.TileSize ;
var posY = tile.Y * _state.TileSize ;
var whiteRectangle = new Texture2D(GraphicsDevice, 1, 1);
whiteRectangle.SetData(new[] { Color.White });
_spriteBatch.Draw(whiteRectangle, new Rectangle((int)posX, (int)posY, _state.TileSize, _state.TileSize),null,Color.White,0,Vector2.Zero,SpriteEffects.None, 1);
// _spriteBatch.DrawRectangle(new Rectangle((int)posX, (int)posY, _state.TileSize, _state.TileSize), _settings.BackgroundColor,1);
// _spriteBatch.Draw(content, new Vector2(posX, posY),
// null, Color.White, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize) / content.Width, SpriteEffects.None, 0);
}
}
private void DrawLines()
{
// border pass
foreach (var tile in _sessionData.Lines.Values)
{
// var content = Content.Load<Texture2D>($"tiles/{tile.ID}");
var posX = tile.X * _state.TileSize ;
var posY = tile.Y * _state.TileSize ;
var endposX = tile.EndX * _state.TileSize ;
var endposY = tile.EndY * _state.TileSize ;
var whiteRectangle = new Texture2D(GraphicsDevice, 1, 1);
whiteRectangle.SetData(new[] { _settings.OverlayTintColor });
_spriteBatch.DrawLine(posX, posY, endposX, endposY,_settings.OverlayTintColor,_state.TileSize+4);
// _spriteBatch.Draw(whiteRectangle, new Rectangle((int)posX-4, (int)posY-4, _state.TileSize+8, _state.TileSize+8),null,Color.White,0,Vector2.Zero,SpriteEffects.None, 1);
// _spriteBatch.DrawRectangle(new Rectangle((int)posX-4, (int)posY-4, _state.TileSize+8, _state.TileSize+8), _settings.OverlayTintColor,1);
// _spriteBatch.Draw(content, new Vector2(posX, posY),
// null, Color.White, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize) / content.Width, SpriteEffects.None, 0);
}
//inner pass
foreach (var tile in _sessionData.Lines.Values)
{
// var content = Content.Load<Texture2D>($"tiles/{tile.ID}");
var posX = tile.X * _state.TileSize ;
var posY = tile.Y * _state.TileSize ;
var endposX = tile.EndX * _state.TileSize ;
var endposY = tile.EndY * _state.TileSize ;
var whiteRectangle = new Texture2D(GraphicsDevice, 1, 1);
whiteRectangle.SetData(new[] { _settings.OverlayTintColor });
_spriteBatch.DrawLine(posX, posY, endposX, endposY,Color.White,_state.TileSize);
// _spriteBatch.Draw(whiteRectangle, new Rectangle((int)posX-4, (int)posY-4, _state.TileSize+8, _state.TileSize+8),null,Color.White,0,Vector2.Zero,SpriteEffects.None, 1);
// _spriteBatch.DrawRectangle(new Rectangle((int)posX-4, (int)posY-4, _state.TileSize+8, _state.TileSize+8), _settings.OverlayTintColor,1);
// _spriteBatch.Draw(content, new Vector2(posX, posY),
// null, Color.White, MathHelper.ToRadians(90 * tile.Rotation), new Vector2(content.Width / 2, content.Height / 2), ((float)_state.TileSize) / content.Width, SpriteEffects.None, 0);
} }
} }

View file

@ -15,6 +15,8 @@ namespace Sledgemapper
public string CurrentTileId { get; set; } public string CurrentTileId { get; set; }
public string CurrentWallId { get; set; } public string CurrentWallId { get; set; }
public string CurrentOverlayId { get; set; } public string CurrentOverlayId { get; set; }
public Tile LineStart { get; internal set; }
public InsertMode InsertMode; public InsertMode InsertMode;
public State() public State()