Exemple #1
0
 public void AddShape(Shape newShape)
 {
     _undoStack.Do(@do => {
         if (@do)
         {
             AddShapeCore(newShape, true);
         }
         else
         {
             RemoveShapesCore(Range.Single(newShape), @do);
         }
     }, true);
 }
Exemple #2
0
    private void TryMovement(Direction dir)
    {
        var blocks = FindGroundedBlocks(dir).OrderBy(t => t.position.y);

        foreach (var block in blocks)
        {
            SetMovement(dir, block);

            if (TestMovement())
            {
                undoes.Do();
                Moving = true;
                break;
            }
        }
    }
Exemple #3
0
 public override void OnKeyDown(KeyEventArgs e)
 {
     if (e.Modifiers == 0 && e.KeyCode == Keys.Back && Text.Length > 0)
     {
         char last = Text[Text.Length - 1];
         UndoStack.Do(@do => {
             if (@do)
             {
                 this.Text = this.Text.Left(this.Text.Length - 1);
             }
             else
             {
                 this.Text += last;
             }
         }, true);
     }
 }
Exemple #4
0
        public override void OnKeyPress(KeyPressEventArgs e)
        {
            e.Handled = true;
            char ch = e.KeyChar;

            if (ch >= ' ')
            {
                UndoStack.Do(@do => {
                    if (@do)
                    {
                        TextTopLeft.Text += ch;
                    }
                    else
                    {
                        TextTopLeft.Text = TextTopLeft.Text.Left(TextTopLeft.Text.Length - 1);
                    }
                }, true);
            }
        }
Exemple #5
0
        public override void OnKeyPress(KeyPressEventArgs e)
        {
            e.Handled = true;
            char ch = e.KeyChar;

            if (ch >= 32 || ch == '\r')
            {
                if (ch == '\r')
                {
                    ch = '\n';
                }
                UndoStack.Do(@do => {
                    if (@do)
                    {
                        this.Text += ch;
                    }
                    else
                    {
                        this.Text = this.Text.Left(this.Text.Length - 1);
                    }
                }, true);
            }
        }
Exemple #6
0
    //------------------------------------------------------------------
    //Undo related methods. Called mainly by UI/Keyboard input. Most modelling
    //operations will call SaveUndoState() to add an Undo step after that
    //operation.

    public static void SaveUndoState()
    {
        undoStack.Do(new MeshObjectSerializable(selMesh));
    }
        private void SetupDropKeyInput()
        {
            BrokerToScene(ConsoleKey.W, () => { UndoStack.Do(new DropWallAction()
                {
                    Context = this
                }); });
            BrokerToScene(ConsoleKey.C, () => { UndoStack.Do(new DropAutoCeilingAction()
                {
                    Context = this
                }); });
            BrokerToScene(ConsoleKey.T, () => { UndoStack.Do(new DropTurretAction()
                {
                    Context = this
                }); });

            BrokerToScene(ConsoleKey.M, () => { UndoStack.Do(new DropMainCharacterAction()
                {
                    Context = this
                }); });

            BrokerToScene(ConsoleKey.Z, () => { UndoStack.Do(new DropZombieAction()
                {
                    Context = this
                }); });
            PushAppHandler(ConsoleKey.A, () => { UndoStack.Do(new DropAmmoAction()
                {
                    Context = this
                }); });
            PushAppHandler(ConsoleKey.P, () => { UndoStack.Do(new DropPortalAction()
                {
                    Context = this
                }); });
            BrokerToScene(ConsoleKey.D, () =>
            {
                if (PositionDoorAction.IsReadyForDrop(this) == false)
                {
                    UndoStack.Do(new PositionDoorAction(false)
                    {
                        Context = this
                    });
                }
                else
                {
                    UndoStack.Do(new DropDoorAction()
                    {
                        Context = this
                    });
                }
            });

            BrokerToScene(ConsoleKey.D, () =>
            {
                if (PositionDoorAction.IsReadyForDrop(this) == false)
                {
                    UndoStack.Do(new PositionDoorAction(true)
                    {
                        Context = this
                    });
                }
                else
                {
                    UndoStack.Do(new DropDoorAction()
                    {
                        Context = this
                    });
                }
            }, ConsoleModifiers.Shift);


            BrokerToScene(ConsoleKey.Delete, () => { UndoStack.Do(new DeleteAction()
                {
                    Context = this
                }); });

            BrokerToScene(ConsoleKey.U, () => { UndoStack.Undo(); });
            BrokerToScene(ConsoleKey.R, () => { UndoStack.Redo(); });

            PushAppHandler(ConsoleKey.T, () =>
            {
                Dialog.PickFromEnum <ConsoleColor>("Choose a background color".ToConsoleString())
                .Then((val) =>
                {
                    if (val.HasValue == false)
                    {
                        return;
                    }

                    this.WallPen = new ConsoleCharacter(this.WallPen.Value, this.WallPen.ForegroundColor, val.Value);
                }).Then((val) =>
                {
                    Dialog.ShowTextInput("Pick a character".ToConsoleString(), (result) =>
                    {
                        this.WallPen = new ConsoleCharacter(result.Length == 0 ? ' ' : result[0].Value, WallPen.ForegroundColor, WallPen.BackgroundColor);

                        Dialog.ShowTextInput("Pick HP".ToConsoleString(), (hpResult) =>
                        {
                            float hpVal;
                            if (float.TryParse(hpResult.ToString(), out hpVal) == false)
                            {
                                hpVal = 10;
                            }
                            this.WallPenHP = hpVal;
                        });
                    });
                });
            });
        }