Ballz.Logic.LogicControl.MenuLogic C# (CSharp) Method

MenuLogic() private method

private MenuLogic ( InputMessage msg ) : void
msg Ballz.Messages.InputMessage
return void
        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;
                    }
                }
            }
        }