コード例 #1
0
ファイル: FillTool.cs プロジェクト: Thraka/SadConsoleEditor
        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;
            }
        }
コード例 #2
0
ファイル: FillTool.cs プロジェクト: Thraka/SadConsoleEditor
        public void ProcessMouse(MouseConsoleState info, ISurface surface, bool isInBounds)
        {
            if (info.Mouse.LeftClicked && info.IsOnConsole)
            {
                Cell cellToMatch     = new Cell();
                Cell currentFillCell = new Cell();

                info.Cell.CopyAppearanceTo(cellToMatch);

                currentFillCell.Glyph      = CharacterPickPanel.SharedInstance.SettingCharacter;
                currentFillCell.Foreground = CharacterPickPanel.SharedInstance.SettingForeground;
                currentFillCell.Background = CharacterPickPanel.SharedInstance.SettingBackground;
                currentFillCell.Mirror     = CharacterPickPanel.SharedInstance.SettingMirrorEffect;

                Func <Cell, bool> isTargetCell = (c) =>
                {
                    if (c.Glyph == 0 && cellToMatch.Glyph == 0)
                    {
                        return(c.Background == cellToMatch.Background);
                    }

                    return(c.Foreground == cellToMatch.Foreground &&
                           c.Background == cellToMatch.Background &&
                           c.Glyph == cellToMatch.Glyph &&
                           c.Mirror == cellToMatch.Mirror);
                };

                Action <Cell> fillCell = (c) =>
                {
                    currentFillCell.CopyAppearanceTo(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 = BasicSurface.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>(info.Cell, isTargetCell, fillCell, getConnectedCells);
                }

                info.Console.TextSurface.IsDirty = true;
            }

            if (info.Mouse.RightButtonDown && info.IsOnConsole)
            {
                var cell = info.Cell;

                CharacterPickPanel.SharedInstance.SettingCharacter    = cell.Glyph;
                CharacterPickPanel.SharedInstance.SettingForeground   = cell.Foreground;
                CharacterPickPanel.SharedInstance.SettingBackground   = cell.Background;
                CharacterPickPanel.SharedInstance.SettingMirrorEffect = cell.Mirror;
            }
        }