public void MouseMoveSurface(MouseInfo info, ITextSurface surface)
{
Brush.Position = info.ConsoleLocation;
Brush.IsVisible = true;
if (info.LeftClicked)
{
Cell cellToMatch = new Cell();
Cell currentFillCell = new Cell();
surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y).Copy(cellToMatch);
cellToMatch.Effect = surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y).Effect;
currentFillCell.GlyphIndex = CharacterPickPanel.SharedInstance.SettingCharacter;
currentFillCell.Foreground = CharacterPickPanel.SharedInstance.SettingForeground;
currentFillCell.Background = CharacterPickPanel.SharedInstance.SettingBackground;
currentFillCell.SpriteEffect = CharacterPickPanel.SharedInstance.SettingMirrorEffect;
Func<Cell, bool> isTargetCell = (c) =>
{
bool effect = c.Effect == null && cellToMatch.Effect == null;
if (c.Effect != null && cellToMatch.Effect != null)
effect = c.Effect == cellToMatch.Effect;
if (c.GlyphIndex == 0 && cellToMatch.GlyphIndex == 0)
return c.Background == cellToMatch.Background;
return c.Foreground == cellToMatch.Foreground &&
c.Background == cellToMatch.Background &&
c.GlyphIndex == cellToMatch.GlyphIndex &&
c.SpriteEffect == cellToMatch.SpriteEffect &&
effect;
};
Action<Cell> fillCell = (c) =>
{
currentFillCell.Copy(c);
//console.TextSurface.SetEffect(c, _currentFillCell.Effect);
};
System.Collections.Generic.List<Cell> cells = new System.Collections.Generic.List<Cell>(surface.Cells);
Func<Cell, SadConsole.Algorithms.NodeConnections<Cell>> getConnectedCells = (c) =>
{
Algorithms.NodeConnections<Cell> connections = new Algorithms.NodeConnections<Cell>();
Point position = TextSurface.GetPointFromIndex(cells.IndexOf(c), surface.Width);
connections.West = surface.IsValidCell(position.X - 1, position.Y) ? surface.GetCell(position.X - 1, position.Y) : null;
connections.East = surface.IsValidCell(position.X + 1, position.Y) ? surface.GetCell(position.X + 1, position.Y) : null;
connections.North = surface.IsValidCell(position.X, position.Y - 1) ? surface.GetCell(position.X, position.Y - 1) : null;
connections.South = surface.IsValidCell(position.X, position.Y + 1) ? surface.GetCell(position.X, position.Y + 1) : null;
return connections;
};
if (!isTargetCell(currentFillCell))
SadConsole.Algorithms.FloodFill<Cell>(surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y), isTargetCell, fillCell, getConnectedCells);
}
if (info.RightButtonDown)
{
var cell = surface.GetCell(info.ConsoleLocation.X, info.ConsoleLocation.Y);
CharacterPickPanel.SharedInstance.SettingCharacter = cell.GlyphIndex;
CharacterPickPanel.SharedInstance.SettingForeground = cell.Foreground;
CharacterPickPanel.SharedInstance.SettingBackground = cell.Background;
CharacterPickPanel.SharedInstance.SettingMirrorEffect = cell.SpriteEffect;
}
}