public override void ProcessKeyboard(SadConsole.Console consoleObject, SadConsole.Input.Keyboard info, out bool handled)
        {
            // Upcast this because we know we're only using it with a Console type.
            var console = (ScrollingConsole)consoleObject;

            if (info.IsKeyDown(Keys.Left))
            {
                console.ViewPort = new Rectangle(console.ViewPort.Left - 1, console.ViewPort.Top, 80, 23);
            }

            if (info.IsKeyDown(Keys.Right))
            {
                console.ViewPort = new Rectangle(console.ViewPort.Left + 1, console.ViewPort.Top, 80, 23);
            }

            if (info.IsKeyDown(Keys.Up))
            {
                console.ViewPort = new Rectangle(console.ViewPort.Left, console.ViewPort.Top - 1, 80, 23);
            }

            if (info.IsKeyDown(Keys.Down))
            {
                console.ViewPort = new Rectangle(console.ViewPort.Left, console.ViewPort.Top + 1, 80, 23);
            }


            handled = true;
        }
        public override void ProcessKeyboard(IScreenObject consoleObject, SadConsole.Input.Keyboard info, out bool handled)
        {
            // Upcast this because we know we're only using it with a Console type.
            var console = (Console)consoleObject;

            if (info.IsKeyDown(Keys.Left))
            {
                console.ViewPosition = console.ViewPosition.Translate((-1, 0));
            }

            if (info.IsKeyDown(Keys.Right))
            {
                console.ViewPosition = console.ViewPosition.Translate((1, 0));
            }

            if (info.IsKeyDown(Keys.Up))
            {
                console.ViewPosition = console.ViewPosition.Translate((0, -1));
            }

            if (info.IsKeyDown(Keys.Down))
            {
                console.ViewPosition = console.ViewPosition.Translate((0, +1));
            }

            handled = true;
        }
Esempio n. 3
0
 public override void ProcessKeyboard(SadConsole.Console console, SadConsole.Input.Keyboard info, out bool handled)
 {
     foreach (AsciiKey key in info.KeysPressed)
     {
         if (key.Character != '\0')
         {
             input += key.Character.ToString();
             console.Cursor.Print(key.Character.ToString());
         }
         if (key.Key == Keys.Back)
         {
             if (input.Length > 0)
             {
                 input = input.Remove(input.Length - 1, 1);
                 console.Cursor.LeftWrap(1).Print(" ").LeftWrap(1);
             }
         }
         if (key.Key == Keys.Enter)
         {
             ProcessInput(input);
             input = "";
         }
     }
     handled = true;
 }
Esempio n. 4
0
        public override bool ProcessKeyboard(Keyboard keyboard)
        {
            if (keyboard.IsKeyPressed(Keys.Insert))
            {
                brush.Symbol = 0;
                return(true);
            }

            if (keyboard.IsKeyPressed(Keys.Delete))
            {
                brush.Symbol = null;
                return(true);
            }

            if (brush.Symbol.HasValue)
            {
                if (keyboard.IsKeyPressed(Keys.PageUp))
                {
                    var nextSymbol = brush.Symbol.Value + 1;
                    brush.Symbol = Math.Min(Font.MaxGlyphIndex, nextSymbol);
                }

                if (keyboard.IsKeyPressed(Keys.PageDown))
                {
                    var prevSymbol = brush.Symbol.Value - 1;
                    brush.Symbol = Math.Max(0, prevSymbol);
                }
            }

            return(base.ProcessKeyboard(keyboard));
        }
Esempio n. 5
0
        /// <summary>
        /// Called by the engine to process the keyboard. If the <see cref="KeyboardHandler"/> has been set, that will be called instead of this method.
        /// </summary>
        /// <param name="info">Keyboard information.</param>
        /// <returns>True when the keyboard had data and this console did something with it.</returns>
        public virtual bool ProcessKeyboard(Input.Keyboard info)
        {
            var handlerResult = KeyboardHandler?.Invoke(this, info) ?? false;

            if (!handlerResult && this.UseKeyboard)
            {
                return(Cursor.ProcessKeyboard(info));
            }

            return(handlerResult);
        }
Esempio n. 6
0
 /// <summary>
 /// Processes the keyboard looking for the ESC key press to close the console, if required. Otherwise the base ControlsConsole will process the keyboard.
 /// </summary>
 /// <param name="info">Keyboard state.</param>
 public override bool ProcessKeyboard(Input.Keyboard info)
 {
     if (CloseOnESC && info.IsKeyReleased(Keys.Escape))
     {
         this.Hide();
         return(true);
     }
     else
     {
         return(base.ProcessKeyboard(info));
     }
 }
Esempio n. 7
0
 public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
 {
     if (info.IsKeyPressed(Keys.Escape))
     {
         Parent.IsFocused = true;
         Parent.Children.Remove(this);
     }
     else
     {
         ListControls(info);
     }
     return(true);
 }
Esempio n. 8
0
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            if (info.IsKeyDown(Keys.Left))
            {
                View = View.WithPosition(new Point(View.Position.X - 1, View.Position.Y));
            }

            if (info.IsKeyDown(Keys.Right))
            {
                View = View.WithPosition(new Point(View.Position.X + 1, View.Position.Y));
            }

            if (info.IsKeyDown(Keys.Up))
            {
                View = View.WithPosition(new Point(View.Position.X, View.Position.Y - 1));
            }

            if (info.IsKeyDown(Keys.Down))
            {
                View = View.WithPosition(new Point(View.Position.X, View.Position.Y + 1));
            }

            if (info.IsKeyReleased(Keys.Space))
            {
                NextAnsi();
                LoadAnsi();
            }

            if (info.IsKeyReleased(Keys.L))
            {
                if (writer == null || lineCounter == lines.Length)
                {
                    NextAnsi();
                    lineCounter = 0;
                    this.Clear();
                    lines  = doc.AnsiString.Split('\n');
                    writer = new SadConsole.Ansi.AnsiWriter(doc, this);
                }

                writer.AnsiReadLine(lines[lineCounter], true);

                lineCounter++;

                if (lineCounter > lines.Length)
                {
                    writer = null;
                }
            }

            return(true);
        }
Esempio n. 9
0
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            if (info.IsKeyDown(Keys.Left))
            {
                ViewPort = new Rectangle(ViewPort.Left - 1, ViewPort.Top, 80, 23);
            }

            if (info.IsKeyDown(Keys.Right))
            {
                ViewPort = new Rectangle(ViewPort.Left + 1, ViewPort.Top, 80, 23);
            }

            if (info.IsKeyDown(Keys.Up))
            {
                ViewPort = new Rectangle(ViewPort.Left, ViewPort.Top - 1, 80, 23);
            }

            if (info.IsKeyDown(Keys.Down))
            {
                ViewPort = new Rectangle(ViewPort.Left, ViewPort.Top + 1, 80, 23);
            }

            if (info.IsKeyReleased(Keys.Space))
            {
                NextAnsi();
                LoadAnsi();
            }

            if (info.IsKeyReleased(Keys.L))
            {
                if (writer == null || lineCounter == lines.Length)
                {
                    NextAnsi();
                    lineCounter = 0;
                    Clear();
                    lines  = doc.AnsiString.Split('\n');
                    writer = new SadConsole.Ansi.AnsiWriter(doc, this);
                }

                writer.AnsiReadLine(lines[lineCounter], true);

                lineCounter++;

                if (lineCounter > lines.Length)
                {
                    writer = null;
                }
            }

            return(true);
        }
Esempio n. 10
0
        /// <summary>
        /// Processes the keyboard for the console.
        /// </summary>
        /// <param name="info">Keyboard information sent by the engine.</param>
        public override bool ProcessKeyboard(Input.Keyboard info)
        {
            if (!UseGlobalKeyboardInput)
            {
                KeyboardState.Update(Global.GameTimeUpdate);
                info = KeyboardState;
            }

            var handlerResult = KeyboardHandler == null ? false : KeyboardHandler(this, info);

            if (!handlerResult && this.UseKeyboard)
            {
                bool canTab = true;

                if (FocusedControl != null)
                {
                    canTab = FocusedControl.TabStop;
                }

                if (canTab)
                {
                    if (
                        ((info.IsKeyDown(Keys.LeftShift) ||
                          info.IsKeyDown(Keys.RightShift)) ||

                         info.IsKeyReleased(Keys.LeftShift) ||
                         info.IsKeyReleased(Keys.RightShift))

                        &&
                        info.IsKeyReleased(Keys.Tab))
                    {
                        // TODO: Handle tab by changing focused control unless existing control doesn't support tab
                        TabPreviousControl();
                        return(true);
                    }
                    else if (info.IsKeyReleased(Keys.Tab))
                    {
                        // TODO: Handle tab by changing focused control unless existing control doesn't support tab
                        TabNextControl();
                        return(false);
                    }
                }

                if (FocusedControl != null && FocusedControl.IsEnabled && FocusedControl.UseKeyboard)
                {
                    return(FocusedControl.ProcessKeyboard(info));
                }
            }

            return(false);
        }
Esempio n. 11
0
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            foreach (var component in ComponentsKeyboard.ToArray())
            {
                component.ProcessKeyboard(this, info, out bool isHandled);

                if (isHandled)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 12
0
        public bool HandleMove(SadConsole.Input.Keyboard info)
        {
            foreach (Keys key in MovementDirectionMapping.Keys)
            {
                if (info.IsKeyPressed(key))
                {
                    Direction moveDirection = MovementDirectionMapping[key];
                    Point     coorToMove    = new Point(moveDirection.DeltaX, moveDirection.DeltaY);

                    bool sucess = CommandManager.MoveActorBy((Actor)GameLoop.World.CurrentMap.ControlledEntitiy, coorToMove);
                    return(sucess);
                }
            }

            return(false);
        }
Esempio n. 13
0
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            if (info.IsKeyReleased(Keys.Space))
            {
                showMouse = !showMouse;
            }
            if (info.IsKeyReleased(Keys.Enter))
            {
                UsePrintProcessor = !UsePrintProcessor;
            }
            if (info.IsKeyReleased(Keys.C))
            {
                DoClear = !DoClear;
            }


            return(true);
        }
Esempio n. 14
0
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            if (info.IsKeyReleased(Keys.C))
            {
                backIndex++;

                if (backIndex == backgroundcycle.Length)
                {
                    backIndex = 0;
                }

                var theme = Theme;
                theme.FillStyle.Background = backgroundcycle[backIndex];
                Theme = theme;
            }


            return(base.ProcessKeyboard(info));
        }
Esempio n. 15
0
 public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
 {
     if (info.IsKeyPressed(Keys.Escape))
     {
         if (targetSelector != null)
         {
             targetSelector = null;
             //UpdateItemSelector();
         }
         else
         {
             Close();
         }
         return(true);
     }
     else
     {
         return(((Console)targetSelector ?? itemSelector).ProcessKeyboard(info));
     }
 }
Esempio n. 16
0
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            if (info.IsKeyReleased(Keys.C))
            {
                backIndex++;

                if (backIndex == backgroundcycle.Length)
                {
                    backIndex = 0;
                }

                var theme = Theme.Clone();
                theme.Colors.ControlBack = backgroundcycle[backIndex];
                theme.Colors.RebuildAppearances();
                Theme = theme;
            }


            return(base.ProcessKeyboard(info));
        }
Esempio n. 17
0
        /// <summary>
        /// Focuses the previous or next selection button depending on if the UP or DOWN arrow keys were pressed.
        /// </summary>
        /// <param name="info">The keyboard state.</param>
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            if (info.IsKeyReleased(Keys.Up))
            {
                SelectPrevious();
                PreviousSelection.IsFocused = true;
                return(true);
            }
            else if (info.IsKeyReleased(Keys.Down))
            {
                SelectNext();
                NextSelection.IsFocused = true;
                return(true);
            }
            else if (info.IsKeyReleased(Keys.Enter))
            {
                InvokeClick();
            }

            return(base.ProcessKeyboard(info));
        }
Esempio n. 18
0
        public override bool ProcessKeyboard(SadInput.Keyboard info)
        {
            // TODO use some StateMachine instead.

            if (info.IsKeyDown(Keys.Right))
            {
                Animation = Animations["WalkRight"];
            }
            else if (info.IsKeyDown(Keys.Left))
            {
                Animation = Animations["WalkLeft"];
            }
            else
            {
                Animation = Animations["Idle"];
            }

            Animation.Start();

            return(base.ProcessKeyboard(info));
        }
Esempio n. 19
0
 public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
 {
     return(false);
 }
Esempio n. 20
0
    public void ListControls(SadConsole.Input.Keyboard info)
    {
        if (info.IsKeyPressed(Keys.Up))
        {
            if (CanScrollUp)
            {
                startIndex--;
            }
        }
        else if (info.IsKeyPressed(Keys.Down))
        {
            if (CanScrollDown)
            {
                startIndex++;
            }
        }
        else if (info.IsKeyPressed(Keys.Left))
        {
            if (CanPageUp)
            {
                startIndex -= 26;
            }
            else
            {
                startIndex = 0;
            }
        }
        else if (info.IsKeyPressed(Keys.Right))
        {
            if (CanPageDown)
            {
                startIndex += 26;
            }
            else
            {
                startIndex = Math.Max(0, Choices.Count - 26);
            }
        }
        else
        {
            //If this key represents an item, then we select it
            foreach (var k in info.KeysPressed)
            {
                var key = k.Key;
                if (Keys.A <= key && key <= Keys.Z)
                {
                    //A represents the first displayed item (i.e. the one at startIndex). Z represents the last displayed item (startIndex + 25)
                    int index = (key - Keys.A) + startIndex;
                    if (index < Choices.Count)
                    {
                        //Select the item
                        ListChoice <T> selected = Choices.ToList()[index];
                        if (select.Invoke(selected.Value))
                        {
                            Choices.Remove(selected);

                            //If we're at the bottom of the menu and we're removing an item here, move the list view up so that we don't have empty slots
                            if (Choices.Count > 25 && !CanPageDown)
                            {
                                startIndex = Choices.Count - 26;
                            }
                        }
                    }
                    break;
                }
            }
        }
    }
Esempio n. 21
0
 public virtual bool ProcessKeyboard(Input.Keyboard state)
 {
     return(false);
 }
Esempio n. 22
0
    public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
    {
        int delta = 1;    //Distance moved by camera

        if (info.IsKeyDown(Keys.RightControl))
        {
            delta *= 8;
        }

        /*
         * if (info.IsKeyDown(Keys.RightControl)) {
         *  examineMenu.ListControls(info);
         * } else
         */
        if (info.IsKeyPressed(Keys.Up))
        {
            if (info.IsKeyDown(Keys.RightShift))
            {
                world.camera += new XYZ(0, 0, delta);
            }
            else
            {
                world.camera += new XYZ(0, delta);
            }
            UpdateExamine();
        }
        else if (info.IsKeyPressed(Keys.Down))
        {
            if (info.IsKeyDown(Keys.RightShift))
            {
                world.camera += new XYZ(0, 0, -delta);
            }
            else
            {
                world.camera += new XYZ(0, -delta);
            }
            UpdateExamine();
        }
        else if (info.IsKeyPressed(Keys.Left))
        {
            world.camera += new XYZ(-delta, 0);
            UpdateExamine();
        }
        else if (info.IsKeyPressed(Keys.Right))
        {
            world.camera += new XYZ(delta, 0);
            UpdateExamine();
        }
        else if (info.IsKeyPressed(Keys.Escape))
        {
            world.camera = world.player.Position;

            Parent.IsFocused = true;
            Parent.Children.Remove(this);
        }
        else if (info.IsKeyPressed(Keys.Enter))
        {
            selectAt(world.camera);
        }
        else
        {
            examineMenu.ListControls(info);
        }
        return(true);
    }
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            // Forward the keyboard data to the entity to handle the movement code.
            // We could detect if the users hit ESC and popup a menu or something.
            // By not setting the entity as the active object, twe let this
            // "game level" (the console we're hosting the entity on) determine if
            // the keyboard data should be sent to the entity.

            // Process logic for moving the entity.
            bool  keyHit      = false;
            Point oldPosition = player.Position;
            Point newPosition = (0, 0);

            // Toggles entity random movements
            if (info.IsKeyPressed(Keys.Q))
            {
                moveEntities = !moveEntities;
            }

            // Process UP/DOWN movements
            if (info.IsKeyPressed(Keys.Up))
            {
                newPosition = player.Position + (0, -1);
                keyHit      = true;
            }
            else if (info.IsKeyPressed(Keys.Down))
            {
                newPosition = player.Position + (0, 1);
                keyHit      = true;
            }

            // Process LEFT/RIGHT movements
            if (info.IsKeyPressed(Keys.Left))
            {
                newPosition = player.Position + (-1, 0);
                keyHit      = true;
            }
            else if (info.IsKeyPressed(Keys.Right))
            {
                newPosition = player.Position + (1, 0);
                keyHit      = true;
            }

            // If a movement key was pressed
            if (keyHit)
            {
                // Check if the new position is valid
                if (Surface.Area.Contains(player.Position))
                {
                    // Entity moved. Let's draw a trail of where they moved from.
                    Surface.SetGlyph(player.Position.X, player.Position.Y, 250);
                    player.Position = newPosition;

                    return(true);
                }
            }

            // You could have multiple entities in the game for example, and change
            // which entity gets keyboard commands.
            return(false);
        }
        public override void ProcessKeyboard(SadConsole.Console consoleObject, SadConsole.Input.Keyboard info, out bool handled)
        {
            // Upcast this because we know we're only using it with a Console type.
            var console = (ScrollingConsole)consoleObject;

            // Check each key pressed.
            foreach (var key in info.KeysPressed)
            {
                // If the character associated with the key pressed is a printable character, print it
                if (key.Character != '\0')
                {
                    console.Cursor.Print(key.Character.ToString());
                }

                // Special character - BACKSPACE
                else if (key.Key == Keys.Back)
                {
                    // Get the prompt that the console has.
                    string prompt = ((CustomConsoles.DOSConsole)console).Prompt;

                    // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much.
                    if (console.TimesShiftedUp != 0)
                    {
                        CursorLastY           -= console.TimesShiftedUp;
                        console.TimesShiftedUp = 0;
                    }

                    // Do not let them backspace into the prompt
                    if (console.Cursor.Position.Y != CursorLastY || console.Cursor.Position.X > prompt.Length)
                    {
                        console.Cursor.LeftWrap(1).Print(" ").LeftWrap(1);
                    }
                }

                // Special character - ENTER
                else if (key.Key == Keys.Enter)
                {
                    // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much.
                    if (console.TimesShiftedUp != 0)
                    {
                        CursorLastY           -= console.TimesShiftedUp;
                        console.TimesShiftedUp = 0;
                    }

                    // Get the prompt to exclude it in determining the total length of the string the user has typed.
                    string prompt        = ((CustomConsoles.DOSConsole)console).Prompt;
                    int    startingIndex = console.GetIndexFromPoint(new Point(prompt.Length, CursorLastY));
                    string data          = ((ScrollingConsole)console).GetString(startingIndex, console.GetIndexFromPoint(console.Cursor.Position) - startingIndex);

                    // Move the cursor to the next line before we send the string data to the processor
                    console.Cursor.CarriageReturn().LineFeed();

                    // Send the string data
                    EnterPressedAction(data);

                    // After they have processed the string, we will create a new line and display the prompt.
                    console.Cursor.CarriageReturn().LineFeed();
                    console.Cursor.DisableWordBreak = true;
                    console.Cursor.Print(((CustomConsoles.DOSConsole)console).Prompt);
                    console.Cursor.DisableWordBreak = false;
                    CursorLastY = console.Cursor.Position.Y;

                    // Preparing the next lines could have scrolled the console, reset the counter
                    console.TimesShiftedUp = 0;
                }
            }

            handled = true;
        }
        public bool HandleKeyboard(IConsole console, SadConsole.Input.Keyboard info)
        {
            var realConsole = (SadConsole.Console)console;

            // Check each key pressed.
            foreach (var key in info.KeysPressed)
            {
                // If the character associated with the key pressed is a printable character, print it
                if (key.Character != '\0')
                {
                    int    startingIndex = realConsole.GetIndexFromPoint(Room.MapWidth + 2, Room.MapHeight + 4);
                    String data          = realConsole.GetString(startingIndex, realConsole.GetIndexFromPoint(console.Cursor.Position) - startingIndex);
                    if (data.Length < 14)
                    {
                        console.Cursor.Print(key.Character.ToString().ToUpper());
                    }
                }

                // Special character - BACKSPACE
                else if (key.Key == Keys.Back)
                {
                    // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much.
                    if (realConsole.TimesShiftedUp != 0)
                    {
                        realConsole.TimesShiftedUp = 0;
                    }

                    // Do not let them backspace into the prompt
                    if (console.Cursor.Position.Y != Room.MapHeight + 4 || console.Cursor.Position.X > Room.MapWidth + 2)
                    {
                        console.Cursor.LeftWrap(1).Print(" ").LeftWrap(1);
                    }
                }

                // Special character - ENTER
                else if (key.Key == Keys.Enter)
                {
                    // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much.
                    if (realConsole.TimesShiftedUp != 0)
                    {
                        CursorLastY -= realConsole.TimesShiftedUp;
                        realConsole.TimesShiftedUp = 0;
                    }

                    // Get the prompt to exclude it in determining the total length of the string the user has typed.
                    int    startingIndex = realConsole.GetIndexFromPoint(Room.MapWidth + 2, Room.MapHeight + 4);
                    String data          = realConsole.GetString(startingIndex, realConsole.GetIndexFromPoint(console.Cursor.Position) - startingIndex);

                    // Move the cursor to the next line before we send the string data to the processor

                    // Send the string data
                    EnterPressedAction(data);

                    // After they have processed the string, we will create a new line and display the prompt.
                    CursorLastY = console.Cursor.Position.Y;

                    // Preparing the next lines could have scrolled the console, reset the counter
                    realConsole.TimesShiftedUp = 0;
                }
            }

            return(true);
        }
Esempio n. 26
0
        /// <summary>
        /// Called by the engine to process the keyboard. If the <see cref="KeyboardHandler"/> has been set, that will be called instead of this method.
        /// </summary>
        /// <param name="info">Keyboard information.</param>
        /// <returns>True when the keyboard had data and this console did something with it.</returns>
        public virtual bool ProcessKeyboard(Input.Keyboard info)
        {
            var handlerResult = KeyboardHandler == null ? false : KeyboardHandler(this, info);

            if (!handlerResult && this.UseKeyboard)
            {
                bool didSomething = false;
                foreach (var key in info.KeysPressed)
                {
                    if (key.Character == '\0')
                    {
                        switch (key.Key)
                        {
                        case Keys.Space:
                            this.virtualCursor.Print(key.Character.ToString());
                            didSomething = true;
                            break;

                        case Keys.Enter:
                            this.virtualCursor.CarriageReturn().LineFeed();
                            didSomething = true;
                            break;

                        case Keys.Pause:
                        case Keys.Escape:
                        case Keys.F1:
                        case Keys.F2:
                        case Keys.F3:
                        case Keys.F4:
                        case Keys.F5:
                        case Keys.F6:
                        case Keys.F7:
                        case Keys.F8:
                        case Keys.F9:
                        case Keys.F10:
                        case Keys.F11:
                        case Keys.F12:
                        case Keys.LeftShift:
                        case Keys.RightShift:
                        case Keys.LeftAlt:
                        case Keys.RightAlt:
                        case Keys.LeftControl:
                        case Keys.RightControl:
                        case Keys.LeftWindows:
                        case Keys.RightWindows:
                        case Keys.F13:
                        case Keys.F14:
                        case Keys.F15:
                        case Keys.F16:
                        case Keys.F17:
                        case Keys.F18:
                        case Keys.F19:
                        case Keys.F20:
                        case Keys.F21:
                        case Keys.F22:
                        case Keys.F23:
                        case Keys.F24:
                            //this._virtualCursor.Print(key.Character.ToString());
                            break;

                        case Keys.Up:
                            this.virtualCursor.Up(1);
                            didSomething = true;
                            break;

                        case Keys.Left:
                            this.virtualCursor.Left(1);
                            didSomething = true;
                            break;

                        case Keys.Right:
                            this.virtualCursor.Right(1);
                            didSomething = true;
                            break;

                        case Keys.Down:
                            this.virtualCursor.Down(1);
                            didSomething = true;
                            break;

                        case Keys.None:
                            break;

                        case Keys.Back:
                            this.virtualCursor.Left(1).Print(" ").Left(1);
                            didSomething = true;
                            break;

                        default:
                            this.virtualCursor.Print(key.Character.ToString());
                            didSomething = true;
                            break;
                        }
                    }
                    else
                    {
                        this.virtualCursor.Print(key.Character.ToString());
                        didSomething = true;
                    }
                }

                return(didSomething);
            }

            return(handlerResult);
        }
Esempio n. 27
0
 public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
 {
     return(base.ProcessKeyboard(info));
 }
        public override bool ProcessKeyboard(SadConsole.Input.Keyboard info)
        {
            // Forward the keyboard data to the entity to handle the movement code.
            // We could detect if the users hit ESC and popup a menu or something.
            // By not setting the entity as the active object, twe let this
            // "game level" (the console we're hosting the entity on) determine if
            // the keyboard data should be sent to the entity.

            // Process logic for moving the entity.
            bool  keyHit      = false;
            Point oldPosition = player.Position;

            if (info.IsKeyPressed(Keys.W))
            {
                //player.Animation.Surface.AddDecorator(0, 2, new[] { new CellDecorator(Color.Green, 67, Mirror.None) });
                keyHit = true;
            }
            if (info.IsKeyPressed(Keys.Q))
            {
                moveEntities = !moveEntities;
                keyHit       = true;
            }

            if (info.IsKeyPressed(Keys.Up))
            {
                player.Position = new Point(player.Position.X, player.Position.Y - 1);
                keyHit          = true;
            }
            else if (info.IsKeyPressed(Keys.Down))
            {
                player.Position = new Point(player.Position.X, player.Position.Y + 1);
                keyHit          = true;
            }

            if (info.IsKeyPressed(Keys.Left))
            {
                player.Position = new Point(player.Position.X - 1, player.Position.Y);
                keyHit          = true;
            }
            else if (info.IsKeyPressed(Keys.Right))
            {
                player.Position = new Point(player.Position.X + 1, player.Position.Y);
                keyHit          = true;
            }


            if (keyHit)
            {
                // Check if the new position is valid
                if (Surface.Area.Contains(player.Position))
                {
                    // Entity moved. Let's draw a trail of where they moved from.
                    Surface.SetGlyph(playerPreviousPosition.X, playerPreviousPosition.Y, 250);
                    playerPreviousPosition = player.Position;

                    return(true);
                }
                else  // New position was not in the area of the console, move back
                {
                    player.Position = oldPosition;
                }
            }

            // You could have multiple entities in the game for example, and change
            // which entity gets keyboard commands.
            return(false);
        }
Esempio n. 29
0
    public override void ProcessKeyboard(SadConsole.Console console, Keyboard info, out bool handled)
    {
        handled = true;
        bool shift = info.IsKeyDown(Keys.LeftShift) || info.IsKeyDown(Keys.RightShift);         // could move this to line 36 if (info.IsKeyPressed(Keys.X)){ if this is an issue

        if (Program.world != null)
        {
            // movement keys can use else ifs since they are contradictory
            if (info.IsKeyPressed(Keys.Left))
            {
                Program.world.MoveCursor(-1, 0);
            }
            else if (info.IsKeyPressed(Keys.Right))
            {
                Program.world.MoveCursor(1, 0);
            }
            if (info.IsKeyPressed(Keys.Up))
            {
                Program.world.MoveCursor(0, -1);
            }
            else if (info.IsKeyPressed(Keys.Down))
            {
                Program.world.MoveCursor(0, 1);
            }
            // when released, update the map
            if (info.IsKeyReleased(Keys.Left) ||
                info.IsKeyReleased(Keys.Right) ||
                info.IsKeyReleased(Keys.Up) ||
                info.IsKeyReleased(Keys.Down)
                )
            {
                new Task(() => { Program.world.RedrawTooltip(); }).Start();
            }
            // ditto for zoom keys
            if (info.IsKeyPressed(Keys.OemPlus))
            {
                Program.world.Zoom(1);
            }
            else if (info.IsKeyPressed(Keys.OemMinus))
            {
                Program.world.Zoom(-1);
            }
            // other keys can be pressed simultaneously
            if (info.IsKeyPressed(Keys.E))
            {
                Program.world.selection.Embark();
                Program.Log("Embarked! (Not yet implemented...)");
            }
            if (info.IsKeyPressed(Keys.R))             // debug
            {
                Program.Log(People.NamingSystem.systems
                            [Program.rng.Next(0, People.NamingSystem.systems.Count)]
                            .RandomFromGender(MochaRandom.Bool()));
            }
            if (info.IsKeyPressed(Keys.S))             // save map
            {
                new Task(() => { Export.Celestia.ExportBitmap(); }).Start();
            }
            if (info.IsKeyPressed(Keys.X))
            {
                Mapping.CycleChar(shift ? -1 : 1);
                Program.world.Print();
            }
            if (info.IsKeyPressed(Keys.Z))
            {
                Mapping.CycleColor(shift ? -1 : 1);
                Program.world.Print();
            }
        }
        if (info.IsKeyPressed(Keys.Escape))
        {
            Program.Exit();
        }
    }
Esempio n. 30
0
 public virtual bool ProcessKeyboard(Keyboard info)
 {
     return(false);
 }