The class representing toggling a single tile wall.
Inheritance: BaseChange
Exemple #1
0
        private bool clickBlocks(int x, int y)
        {
            if (!((x % bsize(1) >= Config.LineSize) ^ (y % bsize(1) >= Config.LineSize)))
            {
                return(true);
            }

            int  dir  = 0;
            Tile tile = null;
            int  tx   = 0;
            int  ty   = 0;

            if ((x % bsize(1) < Config.LineSize))
            {
                tx  = x / bsize(1);
                ty  = y / bsize(1);
                dir = Directions.West;
                if (tx == Width)
                {
                    dir = Directions.East;
                    tx--;
                }
                if (ty == Height)
                {
                    ty--;
                }
            }
            else
            {
                tx  = x / bsize(1);
                ty  = y / bsize(1);
                dir = Directions.North;
                if (ty == Height)
                {
                    dir = Directions.South;
                    ty--;
                }
            }
            tile = tiles[tx, ty];
            if (lastToggle == -1)
            {
                if (tile.GetBlock(dir))
                {
                    lastToggle = 0;
                }
                else
                {
                    lastToggle = 1;
                }
            }
            if (lastToggle == 1 && !tile.GetBlock(dir) || lastToggle == 0 && tile.GetBlock(dir))
            {
                ChangeToggleBlock change = new ChangeToggleBlock(tx, ty, dir);
                apply(change);
            }

            return(true);
        }
Exemple #2
0
        private bool clickBlocks(int x, int y)
        {
            if (!((x % bsize(1) >= Config.LineSize) ^ (y % bsize(1) >= Config.LineSize)))
                return true;

            int dir = 0;
            Tile tile = null;
            int tx = 0;
            int ty = 0;
            if ((x % bsize(1) < Config.LineSize))
            {
                tx = x / bsize(1);
                ty = y / bsize(1);
                dir = Directions.West;
                if (tx == Width)
                {
                    dir = Directions.East;
                    tx--;
                }
                if (ty == Height) ty--;
            }
            else
            {
                tx = x / bsize(1);
                ty = y / bsize(1);
                dir = Directions.North;
                if (ty == Height)
                {
                    dir = Directions.South;
                    ty--;
                }
            }
            tile = tiles[tx, ty];
            if (lastToggle == -1)
            {
                if (tile.GetBlock(dir)) lastToggle = 0;
                else lastToggle = 1;
            }
            if (lastToggle == 1 && !tile.GetBlock(dir) || lastToggle == 0 && tile.GetBlock(dir))
            {
                ChangeToggleBlock change = new ChangeToggleBlock(tx, ty, dir);
                apply(change);
            }

            return true;
        }
Exemple #3
0
        private void redo(bool step)
        {
            bool quit = true;

            do
            {
                changesIndex++;
                BaseChange change = changes[changesIndex];
                switch (change.Type)
                {
                case ChangeType.SetVariant:
                {
                    ChangeSetVariant ch = change as ChangeSetVariant;
                    tiles[ch.X, ch.Y].Variant = ch.To;
                    updateTile(ch.X, ch.Y);
                    break;
                }

                case ChangeType.ToggleTile:
                {
                    ChangeToggleTile ch = change as ChangeToggleTile;
                    tiles[ch.X, ch.Y].Variant = 0;
                    tiles[ch.X, ch.Y].Filled  = !tiles[ch.X, ch.Y].Filled;
                    updateTile(ch.X, ch.Y);
                    break;
                }

                case ChangeType.ToggleBlock:
                {
                    ChangeToggleBlock ch = change as ChangeToggleBlock;
                    tiles[ch.X, ch.Y].ToggleBlock(ch.Dir);
                    updateBlock(ch.X, ch.Y, ch.Dir);
                    break;
                }

                case ChangeType.InternalResize:
                {
                    ChangeInternalResize ch = change as ChangeInternalResize;
                    int size = ch.Size;

                    if (size != 0)
                    {
                        switch (ch.Dir)
                        {
                        case Directions.North:
                            redoNorthResize(ch);
                            break;

                        case Directions.East:
                            redoEastResize(ch);
                            break;

                        case Directions.South:
                            redoSouthResize(ch);
                            break;

                        case Directions.West:
                            redoWestResize(ch);
                            break;

                        default: break;
                        }
                    }

                    if (step)
                    {
                        break;
                    }
                    if (change.StopRedo)
                    {
                        quit = true;
                        FullRedraw();
                    }
                    else
                    {
                        quit = false;
                    }
                    break;
                }

                case ChangeType.Convert:
                {
                    ChangeConvert ch = change as ChangeConvert;
                    post = ch.Forward;
                    setPostMode(post);
                    FullRedraw();
                    break;
                }

                case ChangeType.ToggleWide:
                {
                    ChangeToggleWide ch = change as ChangeToggleWide;
                    int tx = ch.X;
                    int ty = ch.Y;
                    tiles[tx, ty].Wide = ch.To;
                    FullRedraw();
                    break;
                }

                case ChangeType.SetScrollblockers:
                {
                    ChangeSetScrollBlockers ch = change as ChangeSetScrollBlockers;
                    Tile tile = tiles[ch.X, ch.Y];
                    int  idx  = ch.Index;
                    if (idx == 0)
                    {
                        tile.ScrollBlocker = scrollBlockers.Count;
                        scrollBlockers.Add(new Pair <int, int>(ch.X, ch.Y));
                        updateTile(ch.X, ch.Y);
                        break;
                    }

                    for (int i = idx + 1; i < scrollBlockers.Count; i++)
                    {
                        int nx = scrollBlockers[i].First;
                        int ny = scrollBlockers[i].Second;
                        tiles[nx, ny].ScrollBlocker--;
                        updateTile(nx, ny);
                    }
                    tile.ScrollBlocker = 0;
                    updateTile(ch.X, ch.Y);
                    scrollBlockers.RemoveAt(idx);
                    break;
                }

                default: break;
                }
            } while (!quit);

            if (changesIndex + 1 == changes.Count)
            {
                setRedo(false);
            }
            setUndo(true);
        }
Exemple #4
0
        /// <summary>
        /// Handler for action undoing.
        /// </summary>
        public void Undo()
        {
            bool quit = true;

            do
            {
                BaseChange change = changes[changesIndex];
                switch (change.Type)
                {
                case ChangeType.SetVariant:
                {
                    ChangeSetVariant ch = change as ChangeSetVariant;
                    tiles[ch.X, ch.Y].Variant = ch.From;
                    updateTile(ch.X, ch.Y);
                    break;
                }

                case ChangeType.ToggleTile:
                {
                    ChangeToggleTile ch = change as ChangeToggleTile;
                    tiles[ch.X, ch.Y].Variant = ch.PreviousVariant;
                    tiles[ch.X, ch.Y].Filled  = !tiles[ch.X, ch.Y].Filled;
                    updateTile(ch.X, ch.Y);
                    break;
                }

                case ChangeType.ToggleBlock:
                {
                    ChangeToggleBlock ch = change as ChangeToggleBlock;
                    tiles[ch.X, ch.Y].ToggleBlock(ch.Dir);
                    updateBlock(ch.X, ch.Y, ch.Dir);
                    break;
                }

                case ChangeType.InternalResize:
                {
                    ChangeInternalResize ch = change as ChangeInternalResize;
                    int size = ch.Size;

                    if (size != 0)
                    {
                        switch (ch.Dir)
                        {
                        case Directions.North:
                            undoNorthResize(ch);
                            break;

                        case Directions.East:
                            undoEastResize(ch);
                            break;

                        case Directions.South:
                            undoSouthResize(ch);
                            break;

                        case Directions.West:
                            undoWestResize(ch);
                            break;

                        default: break;
                        }
                    }

                    if (change.StopUndo)
                    {
                        FullRedraw();
                        quit = true;
                    }
                    else
                    {
                        quit = false;
                    }
                    break;
                }

                case ChangeType.ToggleWide:
                {
                    ChangeToggleWide ch = change as ChangeToggleWide;
                    int tx = ch.X;
                    int ty = ch.Y;
                    tiles[tx, ty].Wide = ch.From;
                    FullRedraw();
                    break;
                }

                case ChangeType.Convert:
                {
                    ChangeConvert ch = change as ChangeConvert;
                    post = !ch.Forward;
                    setPostMode(post);
                    FullRedraw();
                    break;
                }

                case ChangeType.SetScrollblockers:
                {
                    ChangeSetScrollBlockers ch = change as ChangeSetScrollBlockers;
                    int  idx  = ch.Index;
                    Tile tile = tiles[ch.X, ch.Y];
                    if (idx == 0)         // was new
                    {
                        tile.ScrollBlocker = 0;
                        scrollBlockers.RemoveAt(scrollBlockers.Count - 1);
                        updateTile(ch.X, ch.Y);
                        break;
                    }

                    // was deleted at idx position
                    tile.ScrollBlocker = idx;
                    scrollBlockers.Insert(idx, new Pair <int, int>(ch.X, ch.Y));
                    for (int i = idx + 1; i < scrollBlockers.Count; i++)
                    {
                        int nx = scrollBlockers[i].First;
                        int ny = scrollBlockers[i].Second;
                        tiles[nx, ny].ScrollBlocker++;
                        updateTile(nx, ny);
                    }
                    updateTile(ch.X, ch.Y);
                    break;
                }

                default: break;
                }
                changesIndex--;
            } while (!quit);

            if (changesIndex == 0)
            {
                setUndo(false);
            }
            setRedo(true);
        }