Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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));
        }
Exemplo 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));
     }
 }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
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();
        }
    }
Exemplo n.º 10
0
        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.Appearance.Decorators(0, 2, new[] { new CellDecorator(Color.Green, 67, Mirror.None) });
                keyHit = true;
            }
            if (info.IsKeyPressed(Keys.Q))
            {
                //player.Animation.Surface.ClearDecorators(0, 1);
                keyHit = true;
            }

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

            if (info.IsKeyReleased(Keys.Left))
            {
                player.Position = new Point(player.Position.X - 1, player.Position.Y);
                keyHit          = true;
            }
            else if (info.IsKeyReleased(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);
        }