The class representing toggling corridor's width.
Inheritance: BaseChange
Beispiel #1
0
        private void clickToggleWidth(int x, int y)
        {
            int tx = MouseToTile(x);
            int ty = MouseToTile(y);

            Tile tile = tiles[tx, ty];

            ChangeToggleWide change = new ChangeToggleWide(tx, ty, tile.Wide, !tile.Wide);

            apply(change);
        }
Beispiel #2
0
        private void clickToggleWidth(int x, int y)
        {
            int tx = MouseToTile(x);
            int ty = MouseToTile(y);

            Tile tile = tiles[tx, ty];

            ChangeToggleWide change = new ChangeToggleWide(tx, ty, tile.Wide, !tile.Wide);
            apply(change);
        }
Beispiel #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);
        }
Beispiel #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);
        }