コード例 #1
0
ファイル: Menu.cs プロジェクト: resonancellc/OpenBVE
        //
        // PROCESS MENU COMMAND
        //
        /// <summary>Processes a user command for the current menu</summary>
        /// <param name="cmd">The command to apply to the current menu</param>
        /// <param name="timeElapsed">The time elapsed since previous frame</param>
        internal void ProcessCommand(Translations.Command cmd, double timeElapsed)
        {
            if (CurrMenu < 0)
            {
                return;
            }
            // MenuBack is managed independently from single menu data
            if (cmd == Translations.Command.MenuBack)
            {
                PopMenu();
                return;
            }

            SingleMenu menu = Menus[CurrMenu];

            if (menu.Selection == SelectionNone)                // if menu has no selection, do nothing
            {
                return;
            }
            switch (cmd)
            {
            case Translations.Command.MenuUp:                          // UP
                if (menu.Selection > 0 &&
                    !(menu.Items[menu.Selection - 1] is MenuCaption))
                {
                    menu.Selection--;
                    PositionMenu();
                }
                break;

            case Translations.Command.MenuDown:                        // DOWN
                if (menu.Selection < menu.Items.Length - 1)
                {
                    menu.Selection++;
                    PositionMenu();
                }
                break;

            //			case Translations.Command.MenuBack:	// ESC:	managed above
            //				break;
            case Translations.Command.MenuEnter:                       // ENTER
                if (menu.Items[menu.Selection] is MenuCommand)
                {
                    MenuCommand menuItem = (MenuCommand)menu.Items[menu.Selection];
                    switch (menuItem.Tag)
                    {
                    // menu management commands
                    case MenuTag.MenuBack:                                                  // BACK TO PREVIOUS MENU
                        Menu.instance.PopMenu();
                        break;

                    case MenuTag.MenuJumpToStation:                                         // TO STATIONS MENU
                        Menu.instance.PushMenu(MenuType.JumpToStation);
                        break;

                    case MenuTag.MenuExitToMainMenu:                                        // TO EXIT MENU
                        Menu.instance.PushMenu(MenuType.ExitToMainMenu);
                        break;

                    case MenuTag.MenuQuit:                                                  // TO QUIT MENU
                        Menu.instance.PushMenu(MenuType.Quit);
                        break;

                    case MenuTag.MenuControls:                                              // TO CONTROLS MENU
                        Menu.instance.PushMenu(MenuType.Controls);
                        break;

                    case MenuTag.BackToSim:                                                 // OUT OF MENU BACK TO SIMULATION
                        Reset();
                        Game.PreviousInterface = Game.InterfaceType.Menu;
                        Game.CurrentInterface  = Game.InterfaceType.Normal;
                        break;

                    // simulation commands
                    case MenuTag.JumpToStation:                                             // JUMP TO STATION
                        Reset();
                        TrainManager.JumpTrain(TrainManager.PlayerTrain, menuItem.Data);
                        TrainManager.JumpTFO();
                        break;

                    case MenuTag.ExitToMainMenu:                                            // BACK TO MAIN MENU
                        Reset();
                        Program.RestartArguments =
                            Interface.CurrentOptions.GameMode == GameMode.Arcade ? "/review" : "";
                        MainLoop.Quit = MainLoop.QuitMode.ExitToMenu;
                        break;

                    case MenuTag.Control:                                                   // CONTROL CUSTOMIZATION
                        PushMenu(MenuType.Control, ((MenuCommand)menu.Items[menu.Selection]).Data);
                        isCustomisingControl = true;
                        CustomControlIdx     = ((MenuCommand)menu.Items[menu.Selection]).Data;
                        break;

                    case MenuTag.Quit:                                                      // QUIT PROGRAMME
                        Reset();
                        MainLoop.Quit = MainLoop.QuitMode.QuitProgram;
                        break;
                    }
                }
                break;

            case Translations.Command.MiscFullscreen:
                // fullscreen
                Screen.ToggleFullscreen();
                break;

            case Translations.Command.MiscMute:
                // mute
                Program.Sounds.GlobalMute = !Program.Sounds.GlobalMute;
                Program.Sounds.Update(timeElapsed, Interface.CurrentOptions.SoundModel);
                break;
            }
        }