Ejemplo n.º 1
0
 public virtual void HandleInput(Messages.InputMessage input)
 {
     if (input.Pressed && input.Kind == ButtonKey)
     {
         CloseButton.OnClick?.Invoke(CloseButton);
     }
 }
Ejemplo n.º 2
0
 private void MenuLogic(InputMessage msg)
 {
     Composite top = activeMenu.Peek();
     if(msg.Kind == InputMessage.MessageType.RawInput ||  msg.Kind == InputMessage.MessageType.RawBack || msg.Pressed.Value)
     {
     switch (msg.Kind)
     {
         case InputMessage.MessageType.ControlsAction:
             top.SelectedItem?.Activate();
             break;
         case InputMessage.MessageType.ControlsBack:
             if (activeMenu.Count == 1) // exit if we are in main menuToPrepare
                 Ballz.The().Exit();     //TODO: this is rather ugly find a nice way to terminate the programm like sending a termination message
             else
             {
                     if (rawInput)
                         rawInput = false;
                     else
                     {
                         if (top.SelectedItem != null)
                             top.SelectedItem.DeActivate();
                         else
                             top.DeActivate();
                     }
             }
             RaiseMessageEvent(new MenuMessage(activeMenu.Peek()));
             break;
         case InputMessage.MessageType.ControlsUp:
             if (top.SelectedItem != null)
             {
                 top.SelectPrevious();
                 RaiseMessageEvent(new MenuMessage(top));
             }
             break;
         case InputMessage.MessageType.ControlsDown:
             if (top.SelectedItem != null)
             {
                 top.SelectNext();
                 RaiseMessageEvent(new MenuMessage(top));
             }
             break;
             case InputMessage.MessageType.ControlsLeft:
                 (top.SelectedItem as IChooseable)?.selectPrevious();
             break;
         case InputMessage.MessageType.ControlsRight:
                 (top.SelectedItem as IChooseable)?.selectNext();
             break;
         case InputMessage.MessageType.RawInput:
             if (msg.Key != null)
                 (top.SelectedItem as IRawInputConsumer)?.HandleRawKey(msg.Key.Value);
             break;
         case InputMessage.MessageType.RawBack:
             (top.SelectedItem as IRawInputConsumer)?.HandleBackspace();
             break;
         default:
             //throw new ArgumentOutOfRangeException();
             break;
     }
     }
 }
Ejemplo n.º 3
0
 private void GameLogic(InputMessage msg)
 {
     if (msg.Pressed.Value)
     {
         switch (msg.Kind)
         {
             case InputMessage.MessageType.ControlsBack:
                 state = GameState.MenuState;
                 RaiseMessageEvent(new LogicMessage(LogicMessage.MessageType.GameMessage));
             //todo: implement LogicMessage and use it here
                 break;
             case InputMessage.MessageType.ControlsUp:
                 break;
             case InputMessage.MessageType.ControlsDown:
                 break;
             case InputMessage.MessageType.ControlsLeft:
                 break;
             case InputMessage.MessageType.ControlsRight:
                 break;
             case InputMessage.MessageType.ControlsAction:
                 break;
             case InputMessage.MessageType.RawInput:
                 break;
             default:
             //throw new ArgumentOutOfRangeException();
                 break;
         }
     }
 }
Ejemplo n.º 4
0
 public void InjectInputMessage(InputMessage message, Player player)
 {
     OnInput(message.Kind, message.Pressed, message.Key, player);
 }
Ejemplo n.º 5
0
        private void OnInput(InputMessage.MessageType inputType, bool pressed = false, char key = char.MinValue, Player player = null)
        {
            var inputMessage = new InputMessage(inputType, pressed, key, player);

            if (Ballz.The().MessageOverlay != null)
                Ballz.The().MessageOverlay.HandleInput(inputMessage);
            else
                Input?.Invoke(this, inputMessage); //todo: use object pooling and specify message better
        }
Ejemplo n.º 6
0
        private void processInput(InputMessage message)
        {
            if (message.Pressed.HasValue)
            {
                KeyPressed[message.Kind] = message.Pressed.Value;

                if (message.Pressed.Value)
                    controlInput = message.Kind;
            }
        }
Ejemplo n.º 7
0
        private void ProcessInput(InputMessage.MessageType? messageType)
        {
            if (messageType == null)
                return;

            switch (messageType)
            {
                case InputMessage.MessageType.ControlsCameraModeToggle:
                    {
                        var cam = Game.Camera;
                        var time = Game.Match.GameTime;
                        cam.SetZoom(1f, true, time);
                    }
                    break;
                case InputMessage.MessageType.ControlsCameraZoomIn:
                    {
                        var cam = Game.Camera;
                        var time = Game.Match.GameTime;
                        cam.SetZoom(cam.Zoom * 1.2f, true, time);
                    }
                    break;
                case InputMessage.MessageType.ControlsCameraZoomOut:   
                    {
                        var cam = Game.Camera;
                        var time = Game.Match.GameTime;
                        cam.SetZoom(cam.Zoom * (1 / 1.2f), true, time);
                    }
                    break;
                case InputMessage.MessageType.ControlsJump:
                    TryJump();
                    break;
                case InputMessage.MessageType.ControlsNextWeapon:
                    if (CanSwitchWeapons)
                    {
                        SelectedWeaponIndex = (SelectedWeaponIndex + 1) % AvailableWeapons.Count;
                        Weapon = AvailableWeapons[SelectedWeaponIndex];
                        Ball.HoldingWeapon = AvailableWeapons[SelectedWeaponIndex].Icon;
                        Ball.IsCharging = false;
                        Ball.ShootCharge = 0f;
                    }
                    break;
                case InputMessage.MessageType.ControlsPreviousWeapon:
                    if (CanSwitchWeapons)
                    {
                        SelectedWeaponIndex = SelectedWeaponIndex - 1;
                        if (SelectedWeaponIndex < 0)
                            SelectedWeaponIndex += AvailableWeapons.Count;
                        Weapon = AvailableWeapons[SelectedWeaponIndex];
                        Ball.HoldingWeapon = AvailableWeapons[SelectedWeaponIndex].Icon;
                        Ball.IsCharging = false;
                        Ball.ShootCharge = 0f;
                    }
                    break;
                default:
                    break;
            }
        }
Ejemplo n.º 8
0
        public override void HandleInput(InputMessage input)
        {
            if (Game.Match.IsRemoteControlled)
                return;

            if(input.Pressed && input.Kind == InputMessage.MessageType.ControlsAction)
            {
                FireShot();
            }

            base.HandleInput(input);
        }
Ejemplo n.º 9
0
 private void OnInput(InputMessage.MessageType inputMessage, bool? pressed = null, char? key = null, Player player = null)
 {
     Input?.Invoke(this, new InputMessage(inputMessage, pressed, key, player)); //todo: use object pooling and specify message better
 }
Ejemplo n.º 10
0
        private void MenuLogic(InputMessage msg)
        {
            Composite top = activeMenu.Peek();
            //KeyPress Events
            if (msg.Kind == InputMessage.MessageType.RawInput || msg.Kind == InputMessage.MessageType.RawBack || msg.Pressed)
            {
                ButtonDelay.Stop();
                ButtonDelay.Start();
                ButtonRepeat.Elapsed -= repeatHandler;
                repeatHandler = (s, e) => this.MenuLogic(msg);
                ButtonRepeat.Elapsed += repeatHandler;

                switch (msg.Kind)
                {
                    case InputMessage.MessageType.ControlsAction:
                        top.SelectedItem?.Activate();
                        Ballz.The().Services.GetService<SoundControl>().PlaySound(SoundControl.AcceptSound);
                        break;
                    case InputMessage.MessageType.ControlsBack:
                        Ballz.The().Services.GetService<SoundControl>().PlaySound(SoundControl.DeclineSound);
                        if (activeMenu.Count == 1) // exit if we are in main menuToPrepare
                            Ballz.The().Exit();     //TODO: this is rather ugly find a nice way to terminate the programm like sending a termination message
                        else
                        {
                            if (rawInput)
                                rawInput = false;
                            else
                            {
                                MenuGoBack();
                            }
                        }

                        RaiseMessageEvent(new MenuMessage(activeMenu.Peek()));
                        break;
                    case InputMessage.MessageType.ControlsUp:
                        if (top.SelectedItem != null)
                        {
                            Ballz.The().Services.GetService<SoundControl>().PlaySound(SoundControl.SelectSound);
                            top.SelectPrevious();
                            RaiseMessageEvent(new MenuMessage(top));
                        }

                        break;
                    case InputMessage.MessageType.ControlsDown:
                        if (top.SelectedItem != null)
                        {
                            Ballz.The().Services.GetService<SoundControl>().PlaySound(SoundControl.SelectSound);
                            top.SelectNext();
                            RaiseMessageEvent(new MenuMessage(top));
                        }

                        break;
                    case InputMessage.MessageType.ControlsLeft:
                        (top.SelectedItem as IChooseable)?.SelectPrevious();
                        break;
                    case InputMessage.MessageType.ControlsRight:
                        (top.SelectedItem as IChooseable)?.SelectNext();
                        break;
                    case InputMessage.MessageType.RawInput:
                            (top.SelectedItem as IRawInputConsumer)?.HandleRawKey(msg.Key);
                        break;
                    case InputMessage.MessageType.RawBack:
                        (top.SelectedItem as IRawInputConsumer)?.HandleBackspace();
                        break;
                    default:
                        //throw new ArgumentOutOfRangeException();
                        break;
                }
            }
            else
            {
                //Key release events
                if (!msg.Pressed)
                {
                    ButtonRepeat.Stop();
                    ButtonDelay.Stop();
                    switch(msg.Kind)
                    {
                        case InputMessage.MessageType.ControlsLeft:
                            break;
                        case InputMessage.MessageType.ControlsRight:
                            break;
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public virtual void HandleInput(InputMessage input)
 {
 }