コード例 #1
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));
        }
コード例 #2
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);
 }
コード例 #3
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);
        }
コード例 #4
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));
     }
 }
コード例 #5
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();
        }
    }
コード例 #6
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.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);
        }
コード例 #7
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;
            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);
        }
コード例 #8
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);
    }
コード例 #9
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;
                }
            }
        }
    }