internal static void CreateMenu(bool QuitOnly) { if (QuitOnly) { // quit menu only CurrentMenu = new MenuEntry[3]; CurrentMenu[0] = new MenuCaption(Interface.GetInterfaceString("menu_quit_question")); CurrentMenu[1] = new MenuCommand(Interface.GetInterfaceString("menu_quit_no"), MenuTag.Back, 0); CurrentMenu[2] = new MenuCommand(Interface.GetInterfaceString("menu_quit_yes"), MenuTag.Quit, 0); CurrentMenuSelection = new int[] { 1 }; CurrentMenuOffsets = new double[] { double.NegativeInfinity }; CurrentMenu[1].Highlight = 1.0; } else { // full menu int n = 0; for (int i = 0; i < Stations.Length; i++) { if (PlayerStopsAtStation(i) & Stations[i].Stops.Length > 0) { n++; } } MenuEntry[] a = new MenuCommand[n]; n = 0; for (int i = 0; i < Stations.Length; i++) { if (PlayerStopsAtStation(i) & Stations[i].Stops.Length > 0) { a[n] = new MenuCommand(Stations[i].Name, MenuTag.JumpToStation, i); n++; } } if (n != 0) { CurrentMenu = new MenuEntry[4]; CurrentMenu[0] = new MenuCommand(Interface.GetInterfaceString("menu_resume"), MenuTag.Back, 0); CurrentMenu[1] = new MenuSubmenu(Interface.GetInterfaceString("menu_jump"), a); CurrentMenu[2] = new MenuSubmenu(Interface.GetInterfaceString("menu_exit"), new MenuEntry[] { new MenuCaption(Interface.GetInterfaceString("menu_exit_question")), new MenuCommand(Interface.GetInterfaceString("menu_exit_no"), MenuTag.Back, 0), new MenuCommand(Interface.GetInterfaceString("menu_exit_yes"), MenuTag.ExitToMainMenu, 0) }); CurrentMenu[3] = new MenuSubmenu(Interface.GetInterfaceString("menu_quit"), new MenuEntry[] { new MenuCaption(Interface.GetInterfaceString("menu_quit_question")), new MenuCommand(Interface.GetInterfaceString("menu_quit_no"), MenuTag.Back, 0), new MenuCommand(Interface.GetInterfaceString("menu_quit_yes"), MenuTag.Quit, 0) }); } else { CurrentMenu = new MenuEntry[3]; CurrentMenu[0] = new MenuCommand(Interface.GetInterfaceString("menu_resume"), MenuTag.Back, 0); CurrentMenu[1] = new MenuSubmenu(Interface.GetInterfaceString("menu_exit"), new MenuEntry[] { new MenuCaption(Interface.GetInterfaceString("menu_exit_question")), new MenuCommand(Interface.GetInterfaceString("menu_exit_no"), MenuTag.Back, 0), new MenuCommand(Interface.GetInterfaceString("menu_exit_yes"), MenuTag.ExitToMainMenu, 0) }); CurrentMenu[2] = new MenuSubmenu(Interface.GetInterfaceString("menu_quit"), new MenuEntry[] { new MenuCaption(Interface.GetInterfaceString("menu_quit_question")), new MenuCommand(Interface.GetInterfaceString("menu_quit_no"), MenuTag.Back, 0), new MenuCommand(Interface.GetInterfaceString("menu_quit_yes"), MenuTag.Quit, 0) }); } CurrentMenuSelection = new int[] { 0 }; CurrentMenuOffsets = new double[] { double.NegativeInfinity }; CurrentMenu[0].Highlight = 1.0; } }
/******************** MENU C'TOR *********************/ public SingleMenu(MenuType menuType, int data = 0) { int i, menuItem; int jump = 0; Size size; Align = Renderer.TextAlignment.TopMiddle; Height = Width = 0; Selection = 0; // defaults to first menu item switch (menuType) { case MenuType.Top: // top level menu for (i = 0; i < Game.Stations.Length; i++) if (Game.PlayerStopsAtStation(i) & Game.Stations[i].Stops.Length > 0) { jump = 1; break; } Items = new MenuEntry[4 + jump]; Items[0] = new MenuCommand(Interface.GetInterfaceString("menu_resume"), MenuTag.BackToSim, 0); if (jump > 0) Items[1] = new MenuCommand(Interface.GetInterfaceString("menu_jump"), MenuTag.MenuJumpToStation, 0); Items[1+jump] = new MenuCommand(Interface.GetInterfaceString("menu_exit"), MenuTag.MenuExitToMainMenu, 0); Items[2+jump] = new MenuCommand(Interface.GetInterfaceString("menu_customize_controls"), MenuTag.MenuControls, 0); Items[3+jump] = new MenuCommand(Interface.GetInterfaceString("menu_quit"), MenuTag.MenuQuit, 0); break; case MenuType.JumpToStation: // list of stations to jump to // count the number of available stations menuItem = 0; for (i = 0; i < Game.Stations.Length; i++) if (Game.PlayerStopsAtStation (i) & Game.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 (Interface.GetInterfaceString ("menu_back"), MenuTag.MenuBack, 0); menuItem = 1; for (i = 0; i < Game.Stations.Length; i++) if (Game.PlayerStopsAtStation(i) & Game.Stations[i].Stops.Length > 0) { Items[menuItem] = new MenuCommand(Game.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 = Renderer.TextAlignment.TopLeft; break; case MenuType.ExitToMainMenu: Items = new MenuEntry[3]; Items[0] = new MenuCaption (Interface.GetInterfaceString ("menu_exit_question")); Items[1] = new MenuCommand (Interface.GetInterfaceString ("menu_exit_no"), MenuTag.MenuBack, 0); Items[2] = new MenuCommand (Interface.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(Interface.GetInterfaceString("menu_quit_question")); Items[1] = new MenuCommand(Interface.GetInterfaceString("menu_quit_no"), MenuTag.MenuBack, 0); Items[2] = new MenuCommand(Interface.GetInterfaceString("menu_quit_yes"), MenuTag.Quit, 0); Selection = 1; break; case MenuType.Controls: //Refresh the joystick list Joysticks.RefreshJoysticks(); Items = new MenuEntry[Interface.CurrentControls.Length + 1]; Items[0] = new MenuCommand (Interface.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 = Renderer.TextAlignment.TopLeft; break; case MenuType.Control: //Refresh the joystick list Joysticks.RefreshJoysticks(); Selection = SelectionNone; Items = new MenuEntry[4]; // get code name and description Interface.Control loadedControl = Interface.CurrentControls[data]; for (int h = 0; h < Interface.CommandInfos.Length; h++) { if (Interface.CommandInfos[h].Command == loadedControl.Command) { Items[0] = new MenuCommand(loadedControl.Command.ToString() + " - " + Interface.CommandInfos[h].Description, MenuTag.None, 0); break; } } // get assignment String str = ""; switch (loadedControl.Method) { case Interface.ControlMethod.Keyboard: if (loadedControl.Modifier != Interface.KeyboardModifier.None) str = Interface.GetInterfaceString("menu_keyboard") + " [" + loadedControl.Modifier + "-" + loadedControl.Key + "]"; else str = Interface.GetInterfaceString("menu_keyboard") + " [" + loadedControl.Key + "]"; break; case Interface.ControlMethod.Joystick: str = Interface.GetInterfaceString("menu_joystick") + " " + loadedControl.Device + " [" + loadedControl.Component + " " + loadedControl.Element + "]"; switch (loadedControl.Component) { case Interface.JoystickComponent.FullAxis: case Interface.JoystickComponent.Axis: str += " " + (loadedControl.Direction == 1 ? Interface.GetInterfaceString("menu_joystickdirection_positive") : Interface.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 = Interface.GetInterfaceString("menu_joystick_notavailable"); break; } break; case Interface.ControlMethod.Invalid: str = Interface.GetInterfaceString("menu_joystick_notavailable"); break; } Items[1] = new MenuCommand(Interface.GetInterfaceString("menu_assignment_current") + " " + str, MenuTag.None, 0); Items[2] = new MenuCommand(" ", MenuTag.None, 0); Items[3] = new MenuCommand(Interface.GetInterfaceString("menu_assign"), MenuTag.None, 0); break; } // compute menu extent for (i = 0; i < Items.Length; i++) { size = Renderer.MeasureString(Game.Menu.MenuFont, 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; }