Example #1
0
        public override bool ProcessKeyboard(Keyboard info)
        {
            bool keyHandled = false;

            // Simplified way to check if any key we care about is pressed and set movement direction.
            foreach (var key in _playerMovements.Keys)
            {
                var binding = KeybindingsManager.GetKeybinding(key);
                if (info.IsKeyPressed(binding))
                {
                    var moveDirection = _playerMovements[key];
                    MoveTowards(moveDirection);
                    keyHandled = true;
                    break;
                }
            }

            //If this will grow in the future, we may want to add a Dictionary<Keybindings, EmberItem>
            // to efficiently retrieve and activate items.
            if (info.IsKeyPressed(KeybindingsManager.GetKeybinding(Keybindings.Flashlight)))
            {
                var flashLight = Game.Player.Inventory.GetItemOfType <Flashlight>();
                flashLight?.Switch();
                keyHandled = true;
            }

            if (keyHandled)
            {
                return(true);
            }
            else
            {
                return(base.ProcessKeyboard(info));
            }
        }
Example #2
0
        public void ButtonPressPlay(object sender, EventArgs args)
        {
            // Initialize user interface
            UserInterfaceManager.Initialize();

            // Remove mainmenu and transition
            Transition(UserInterfaceManager.Get <GameWindow>().Console);

            // Instantiate player in the middle of the map
            var spawnPosition = GridManager.Grid.GetCell(a => a.LightProperties.Brightness > 0.3f && a.CellProperties.Walkable);

            Game.Player = EntityManager.Create <Player>(spawnPosition.Position, GridManager.ActiveBlueprint.ObjectId);
            Game.Player.Initialize();

            // Show a tutorial dialog window.
            var dialogWindow = UserInterfaceManager.Get <DialogWindow>();

            dialogWindow.AddDialog("Game introduction", new[]
            {
                "Welcome to Emberpoint.",
                "This is a small introduction to the game.",
                "Press 'Enter' to continue."
            });
            dialogWindow.AddDialog("Flashlight introduction", new[]
            {
                "The flashlight can be used to discover new tiles.",
                "Turn on your flashlight and discover some new tiles.",
                "Press '" + KeybindingsManager.GetKeybinding(Keybindings.Flashlight) + "' to turn on your flashlight.",
                "Press 'Enter' to exit dialog."
            });
            dialogWindow.ShowNext();
        }
Example #3
0
 public void CheckForMovementKeys()
 {
     foreach (var movementKey in _playerMovements.Keys
              .Where(key => Global.KeyboardState.IsKeyPressed(KeybindingsManager.GetKeybinding(key))))
     {
         var(x, y) = _playerMovements[movementKey];
         MoveTowards(Position.Translate(x, y));
     }
 }
Example #4
0
 public void CheckForInteractionKeys()
 {
     //If this will grow in the future, we may want to add a Dictionary<Keybindings, EmberItem>
     // to efficiently retrieve and activate items.
     if (Global.KeyboardState.IsKeyPressed(KeybindingsManager.GetKeybinding(Keybindings.Flashlight)))
     {
         var flashLight = Game.Player.Inventory.GetItemOfType <Flashlight>();
         flashLight?.Switch();
     }
 }
Example #5
0
        private void DrawButtonNames()
        {
            var buttons     = Controls.OfType <Button>();
            var keybindings = KeybindingsManager.GetKeybindings()
                              .Select(a => a.Key.ToString())
                              .ToList();

            foreach (var button in buttons)
            {
                if (keybindings.Contains(button.Name))
                {
                    Print(button.Position.X + 12, button.Position.Y + 1, button.Name.ToString().Replace("_", " "), Color.White);
                }
            }
        }
Example #6
0
        public void ChangeKeybinding(Keys newKey)
        {
            if (!WaitingForAnyKeyPress)
            {
                return;
            }
            if (_buttonPressed == null)
            {
                throw new Exception("Oops?");
            }

            KeybindingsManager.EditKeybinding((Keybindings)Enum.Parse(typeof(Keybindings), _buttonPressed.Name), newKey);

            _buttonPressed.Text    = newKey.ToString();
            _buttonPressed.IsDirty = true;
            _buttonPressed         = null;
            WaitingForAnyKeyPress  = false;
            UseMouse = true;
        }
Example #7
0
        private void CreateKeybindingButtons()
        {
            var bindings = KeybindingsManager.GetKeybindings();

            var       row          = 12;
            const int maxPerColumn = 8;
            const int maxColumns   = 2;
            var       total        = 0;
            var       columns      = 0;

            foreach (var(key, value) in bindings)
            {
                if (total == maxPerColumn)
                {
                    columns++;
                    total = 0;
                    row   = 12;

                    if (columns == maxColumns)
                    {
                        // Show paging when the need arises?
                        throw new Exception("Exceeded max keybindings limit (16)");
                    }
                }

                var pos    = columns == 0 ? new Point(25, row) : new Point(65, row);
                var button = new Button(10, 3)
                {
                    Name        = key.ToString(),
                    Text        = value.ToString(),
                    Position    = pos,
                    UseMouse    = true,
                    UseKeyboard = false,
                };

                // Add key re-arrange method
                button.Click += TriggerKeybindingChangeCheck;
                Add(button);
                row += 3;
                total++;
            }
        }
Example #8
0
        public override bool ProcessKeyboard(Keyboard info)
        {
            var baseValue = base.ProcessKeyboard(info);

            if (_textInput.DisableKeyboard && info.IsKeyPressed(KeybindingsManager.GetKeybinding(Keybindings.DeveloperConsole)))
            {
                if (IsVisible)
                {
                    Hide();
                }
                else
                {
                    Show();
                }
                return(true);
            }

            // Check for enter key press
            for (int i = 0; i < info.KeysPressed.Count; i++)
            {
                if (info.KeysPressed[i].Key == Microsoft.Xna.Framework.Input.Keys.Enter && _textInputInUse)
                {
                    if (!ParseCommand(_textInput.Text, out string output) && !string.IsNullOrWhiteSpace(output))
                    {
                        WriteText(output, Color.Red);
                    }
                    else
                    {
                        WriteText(output, Color.Green);
                    }

                    // Empty textfield but make sure we can keep typing
                    _textInput.Text            = string.Empty;
                    _textInput.DisableKeyboard = false;
                    return(true);
                }
            }

            return(baseValue);
        }
        public static MainMenuWindow Show()
        {
            var mainMenu = UserInterfaceManager.Get<MainMenuWindow>();
            if (mainMenu == null)
            {
                // Intialize default keybindings
                KeybindingsManager.InitializeDefaultKeybindings();

                mainMenu = new MainMenuWindow(Constants.GameWindowWidth, Constants.GameWindowHeight);
                mainMenu.InitializeButtons();
                UserInterfaceManager.Add(mainMenu);
            }
            else
            {
                mainMenu.IsVisible = true;
                mainMenu.IsFocused = true;
                mainMenu.IsCursorDisabled = false;
            }
            Global.CurrentScreen = mainMenu;
            Game.Reset();
            return mainMenu;
        }
Example #10
0
        public override bool ProcessKeyboard(Keyboard info)
        {
            bool keyHandled = false;

            // Simplified way to check if any key we care about is pressed and set movement direction.
            foreach (var key in _playerMovements.Keys)
            {
                var binding = KeybindingsManager.GetKeybinding(key);
                if (info.IsKeyPressed(binding))
                {
                    var moveDirection = _playerMovements[key];
                    _interaction.PrintMessage(Constants.EmptyMessage);
                    MoveTowards(moveDirection);
                    InteractionStatus = CheckInteraction(_interaction);
                    keyHandled        = true;
                    break;
                }
            }

            // Handle cell interactions
            if (info.IsKeyPressed(KeybindingsManager.GetKeybinding(Keybindings.Interact)) &&
                InteractionStatus && GetInteractedCell(out Point position))
            {
                interactionManager.HandleInteraction(position);
                keyHandled = true;
            }

            //If this will grow in the future, we may want to add a Dictionary<Keybindings, EmberItem>
            // to efficiently retrieve and activate items.
            if (info.IsKeyPressed(KeybindingsManager.GetKeybinding(Keybindings.Flashlight)))
            {
                var flashLight = Game.Player.Inventory.GetItemOfType <Flashlight>();
                flashLight?.Switch();
                keyHandled = true;
            }

            // Handle dialog window
            if (info.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Enter))
            {
                var devConsole = UserInterfaceManager.Get <DeveloperWindow>();
                if (!devConsole.IsVisible)
                {
                    var dialogWindow = UserInterfaceManager.Get <DialogWindow>();
                    if (dialogWindow.IsVisible)
                    {
                        dialogWindow.ShowNext();
                        keyHandled = true;
                    }
                }
            }

            // Handle dev console showing
            if (info.IsKeyPressed(KeybindingsManager.GetKeybinding(Keybindings.DeveloperConsole)))
            {
                var devConsole = UserInterfaceManager.Get <DeveloperWindow>();
                if (devConsole.IsVisible)
                {
                    devConsole.Hide();
                }
                else
                {
                    devConsole.Show();
                }
                keyHandled = true;
            }

            if (keyHandled)
            {
                return(true);
            }
            else
            {
                return(base.ProcessKeyboard(info));
            }
        }