Information on an in-game control
예제 #1
0
        protected override void OnLoad(EventArgs e)
        {
            Program.FileSystem.AppendToLogFile("Game window initialised successfully.");
            Renderer.DetermineMaxAFLevel();
            //Initialise the loader thread queues
            jobs  = new Queue <ThreadStart>(10);
            locks = new Queue <object>(10);
            LibRender.Renderer.Initialize();
            HUD.LoadHUD();
            LoadingScreen.InitLoading(Program.FileSystem.GetDataFolder("In-game"), typeof(Renderer).Assembly.GetName().Version.ToString());
            Renderer.UpdateViewport(ViewPortChangeMode.NoChange);
            LibRender.MotionBlur.Initialize(Interface.CurrentOptions.MotionBlur);
            Loading.LoadAsynchronously(MainLoop.currentResult.RouteFile, MainLoop.currentResult.RouteEncoding, MainLoop.currentResult.TrainFolder, MainLoop.currentResult.TrainEncoding);
            LoadingScreenLoop();
            //Add event handler hooks for keyboard and mouse buttons
            //Do this after the renderer has init and the loop has started to prevent timing issues
            KeyDown    += MainLoop.keyDownEvent;
            KeyUp      += MainLoop.keyUpEvent;
            MouseDown  += MainLoop.mouseDownEvent;
            MouseUp    += MainLoop.mouseUpEvent;
            MouseMove  += MainLoop.mouseMoveEvent;
            MouseWheel += MainLoop.mouseWheelEvent;

            for (int i = 0; i < InputDevicePlugin.AvailablePluginInfos.Count; i++)
            {
                if (InputDevicePlugin.AvailablePluginInfos[i].Status == InputDevicePlugin.PluginInfo.PluginStatus.Enable)
                {
                    int AddControlsLength           = InputDevicePlugin.AvailablePlugins[i].Controls.Length;
                    Interface.Control[] AddControls = new Interface.Control[AddControlsLength];
                    for (int j = 0; j < AddControlsLength; j++)
                    {
                        AddControls[j].Command = InputDevicePlugin.AvailablePlugins[i].Controls[j].Command;
                        AddControls[j].Method  = Interface.ControlMethod.InputDevicePlugin;
                        AddControls[j].Option  = InputDevicePlugin.AvailablePlugins[i].Controls[j].Option;
                    }
                    Interface.CurrentControls = Interface.CurrentControls.Concat(AddControls).ToArray();
                    foreach (var Train in TrainManager.Trains)
                    {
                        if (Train.State != TrainState.Bogus)
                        {
                            if (Train == TrainManager.PlayerTrain)
                            {
                                InputDevicePlugin.AvailablePlugins[i].SetMaxNotch(Train.Handles.Power.MaximumDriverNotch, Train.Handles.Brake.MaximumDriverNotch);
                            }
                        }
                    }
                    InputDevicePlugin.AvailablePlugins[i].KeyDown += MainLoop.InputDevicePluginKeyDown;
                    InputDevicePlugin.AvailablePlugins[i].KeyUp   += MainLoop.InputDevicePluginKeyUp;
                }
            }
        }
예제 #2
0
 // control down
 private void buttonControlDown_Click(object sender, EventArgs e)
 {
     if (listviewControls.SelectedIndices.Count == 1)
     {
         int j = listviewControls.SelectedIndices[0];
         if (j < Interface.CurrentControls.Length - 1)
         {
             Interface.Control c = Interface.CurrentControls[j];
             Interface.CurrentControls[j]     = Interface.CurrentControls[j + 1];
             Interface.CurrentControls[j + 1] = c;
             ListViewItem v = listviewControls.Items[j];
             listviewControls.Items.RemoveAt(j);
             listviewControls.Items.Insert(j + 1, v);
         }
     }
 }
예제 #3
0
            public int TopItem;                     // the top displayed menu item


            /********************
             *      MENU C'TOR
             *********************/
            public SingleMenu(MenuType menuType, int data = 0)
            {
                int  i, menuItem;
                int  jump = 0;
                Size size;

                Align     = TextAlignment.TopMiddle;
                Height    = Width = 0;
                Selection = 0;                                      // defaults to first menu item
                switch (menuType)
                {
                case MenuType.Top:                                  // top level menu
                    for (i = 0; i < CurrentRoute.Stations.Length; i++)
                    {
                        if (CurrentRoute.Stations[i].PlayerStops() & CurrentRoute.Stations[i].Stops.Length > 0)
                        {
                            jump = 1;
                            break;
                        }
                    }
                    Items    = new MenuEntry[4 + jump];
                    Items[0] = new MenuCommand(Translations.GetInterfaceString("menu_resume"), MenuTag.BackToSim, 0);
                    if (jump > 0)
                    {
                        Items[1] = new MenuCommand(Translations.GetInterfaceString("menu_jump"), MenuTag.MenuJumpToStation, 0);
                    }
                    if (!Interface.CurrentOptions.KioskMode)
                    {
                        //Don't allow quitting or customisation of the controls in kiosk mode
                        Items[1 + jump] = new MenuCommand(Translations.GetInterfaceString("menu_exit"), MenuTag.MenuExitToMainMenu, 0);
                        Items[2 + jump] = new MenuCommand(Translations.GetInterfaceString("menu_customize_controls"), MenuTag.MenuControls, 0);
                        Items[3 + jump] = new MenuCommand(Translations.GetInterfaceString("menu_quit"), MenuTag.MenuQuit, 0);
                    }
                    else
                    {
                        Array.Resize(ref Items, Items.Length - 3);
                    }
                    break;

                case MenuType.JumpToStation:                            // list of stations to jump to
                    // count the number of available stations
                    menuItem = 0;
                    for (i = 0; i < CurrentRoute.Stations.Length; i++)
                    {
                        if (CurrentRoute.Stations[i].PlayerStops() & CurrentRoute.Stations[i].Stops.Length > 0)
                        {
                            menuItem++;
                        }
                    }
                    // list available stations, selecting the next station as predefined choice
                    jump     = 0;                                                   // no jump found yet
                    Items    = new MenuEntry[menuItem + 1];
                    Items[0] = new MenuCommand(Translations.GetInterfaceString("menu_back"), MenuTag.MenuBack, 0);
                    menuItem = 1;
                    for (i = 0; i < CurrentRoute.Stations.Length; i++)
                    {
                        if (CurrentRoute.Stations[i].PlayerStops() & CurrentRoute.Stations[i].Stops.Length > 0)
                        {
                            Items[menuItem] = new MenuCommand(CurrentRoute.Stations[i].Name, MenuTag.JumpToStation, i);
                            // if no preferred jump-to-station found yet and this station is
                            // after the last station the user stopped at, select this item
                            if (jump == 0 && i > TrainManager.PlayerTrain.LastStation)
                            {
                                jump      = i;
                                Selection = menuItem;
                            }
                            menuItem++;
                        }
                    }
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.ExitToMainMenu:
                    Items     = new MenuEntry[3];
                    Items[0]  = new MenuCaption(Translations.GetInterfaceString("menu_exit_question"));
                    Items[1]  = new MenuCommand(Translations.GetInterfaceString("menu_exit_no"), MenuTag.MenuBack, 0);
                    Items[2]  = new MenuCommand(Translations.GetInterfaceString("menu_exit_yes"), MenuTag.ExitToMainMenu, 0);
                    Selection = 1;
                    break;

                case MenuType.Quit:                                 // ask for quit confirmation
                    Items     = new MenuEntry[3];
                    Items[0]  = new MenuCaption(Translations.GetInterfaceString("menu_quit_question"));
                    Items[1]  = new MenuCommand(Translations.GetInterfaceString("menu_quit_no"), MenuTag.MenuBack, 0);
                    Items[2]  = new MenuCommand(Translations.GetInterfaceString("menu_quit_yes"), MenuTag.Quit, 0);
                    Selection = 1;
                    break;

                case MenuType.Controls:
                    //Refresh the joystick list
                    Program.Joysticks.RefreshJoysticks();
                    Items    = new MenuEntry[Interface.CurrentControls.Length + 1];
                    Items[0] = new MenuCommand(Translations.GetInterfaceString("menu_back"), MenuTag.MenuBack, 0);
                    for (i = 0; i < Interface.CurrentControls.Length; i++)
                    {
                        Items[i + 1] = new MenuCommand(Interface.CurrentControls[i].Command.ToString(), MenuTag.Control, i);
                    }
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.Control:
                    //Refresh the joystick list
                    Program.Joysticks.RefreshJoysticks();
                    Selection = SelectionNone;
                    Items     = new MenuEntry[4];
                    // get code name and description
                    Interface.Control loadedControl = Interface.CurrentControls[data];
                    for (int h = 0; h < Translations.CommandInfos.Length; h++)
                    {
                        if (Translations.CommandInfos[h].Command == loadedControl.Command)
                        {
                            Items[0] = new MenuCommand(loadedControl.Command.ToString() + " - " +
                                                       Translations.CommandInfos[h].Description, MenuTag.None, 0);
                            break;
                        }
                    }
                    // get assignment
                    String str = "";
                    switch (loadedControl.Method)
                    {
                    case Interface.ControlMethod.Keyboard:
                        string keyName = loadedControl.Key.ToString();
                        for (int k = 0; k < Translations.TranslatedKeys.Length; k++)
                        {
                            if (Translations.TranslatedKeys[k].Key == loadedControl.Key)
                            {
                                keyName = Translations.TranslatedKeys[k].Description;
                                break;
                            }
                        }
                        if (loadedControl.Modifier != Interface.KeyboardModifier.None)
                        {
                            str = Translations.GetInterfaceString("menu_keyboard") + " [" + loadedControl.Modifier + "-" + keyName + "]";
                        }
                        else
                        {
                            str = Translations.GetInterfaceString("menu_keyboard") + " [" + keyName + "]";
                        }
                        break;

                    case Interface.ControlMethod.Joystick:
                        str = Translations.GetInterfaceString("menu_joystick") + " " + loadedControl.Device + " [" + loadedControl.Component + " " + loadedControl.Element + "]";
                        switch (loadedControl.Component)
                        {
                        case Interface.JoystickComponent.FullAxis:
                        case Interface.JoystickComponent.Axis:
                            str += " " + (loadedControl.Direction == 1 ? Translations.GetInterfaceString("menu_joystickdirection_positive") : Translations.GetInterfaceString("menu_joystickdirection_negative"));
                            break;

                        //						case Interface.JoystickComponent.Button:	// NOTHING TO DO FOR THIS CASE!
                        //							str = str;
                        //							break;
                        case Interface.JoystickComponent.Hat:
                            str += " " + (OpenTK.Input.HatPosition)loadedControl.Direction;
                            break;

                        case Interface.JoystickComponent.Invalid:
                            str = Translations.GetInterfaceString("menu_joystick_notavailable");
                            break;
                        }
                        break;

                    case Interface.ControlMethod.RailDriver:
                        str = "RailDriver [" + loadedControl.Component + " " + loadedControl.Element + "]";
                        switch (loadedControl.Component)
                        {
                        case Interface.JoystickComponent.FullAxis:
                        case Interface.JoystickComponent.Axis:
                            str += " " + (loadedControl.Direction == 1 ? Translations.GetInterfaceString("menu_joystickdirection_positive") : Translations.GetInterfaceString("menu_joystickdirection_negative"));
                            break;

                        case Interface.JoystickComponent.Invalid:
                            str = Translations.GetInterfaceString("menu_joystick_notavailable");
                            break;
                        }
                        break;

                    case Interface.ControlMethod.Invalid:
                        str = Translations.GetInterfaceString("menu_joystick_notavailable");
                        break;
                    }
                    Items[1] = new MenuCommand(Translations.GetInterfaceString("menu_assignment_current") + " " + str, MenuTag.None, 0);
                    Items[2] = new MenuCommand(" ", MenuTag.None, 0);
                    Items[3] = new MenuCommand(Translations.GetInterfaceString("menu_assign"), MenuTag.None, 0);
                    break;
                }

                // compute menu extent
                for (i = 0; i < Items.Length; i++)
                {
                    if (Items[i] == null)
                    {
                        continue;
                    }
                    size = Game.Menu.MenuFont.MeasureString(Items[i].Text);
                    if (size.Width > Width)
                    {
                        Width = size.Width;
                    }
                    if (!(Items[i] is MenuCaption) && size.Width > ItemWidth)
                    {
                        ItemWidth = size.Width;
                    }
                }
                Height  = Items.Length * Game.Menu.LineHeight;
                TopItem = 0;
            }