/******************** * PUBLIC METHODS *********************/ // // PROCESS COMMAND // /// <summary>Processes commands.</summary> /// <returns><c>true</c>, if command was processed, <c>false</c> otherwise.</returns> /// <param name="command">The Translations.Command command to process.</param> internal bool ProcessCommand(Translations.Command command) { if (command != Translations.Command.RouteInformation) // only accept RouteInformation command { return(false); } // cycle through available state setState((state)((int)(currentState + 1) % (int)state.numOf)); return(true); }
/// <summary>Changes the wiper speed</summary> internal void ChangeSpeed(Translations.Command Command) { Program.Sounds.PlayCarSound(SwitchSound, 1.0, 1.0, Windscreen.Car, false); switch (Command) { case Translations.Command.WiperSpeedUp: if (CurrentSpeed < WiperSpeed.Fast) { CurrentSpeed++; } break; case Translations.Command.WiperSpeedDown: if (CurrentSpeed > WiperSpeed.Off) { CurrentSpeed--; } break; } }
/// <summary>Changes the wiper speed</summary> public void ChangeSpeed(Translations.Command Command) { SwitchSound.Play(Windscreen.Car, false); switch (Command) { case Translations.Command.WiperSpeedUp: if (CurrentSpeed < WiperSpeed.Fast) { CurrentSpeed++; } break; case Translations.Command.WiperSpeedDown: if (CurrentSpeed > WiperSpeed.Off) { CurrentSpeed--; } break; } }
// // 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; } }
private static void ParsePanelAnimatedNode(XElement Element, string FileName, string TrainPath, TrainManager.Train Train, int Car, TrainManager.CarSection CarSection, int GroupIndex) { System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; int currentSectionElement = 0; int numberOfSectionElements = Element.Elements().Count(); double invfac = numberOfSectionElements == 0 ? Loading.TrainProgressCurrentWeight : Loading.TrainProgressCurrentWeight / (double)numberOfSectionElements; foreach (XElement SectionElement in Element.Elements()) { Loading.TrainProgress = Loading.TrainProgressCurrentSum + invfac * (double)currentSectionElement; if ((currentSectionElement & 4) == 0) { System.Threading.Thread.Sleep(1); if (Loading.Cancel) { return; } } string Section = SectionElement.Name.LocalName; switch (SectionElement.Name.LocalName.ToLowerInvariant()) { case "group": if (GroupIndex == 0) { int n = 0; foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "number": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out n)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; } } if (n + 1 >= CarSection.Groups.Length) { Array.Resize(ref CarSection.Groups, n + 2); CarSection.Groups[n + 1] = new TrainManager.ElementsGroup { Elements = new ObjectManager.AnimatedObject[] { }, Overlay = true }; } ParsePanelAnimatedNode(SectionElement, FileName, TrainPath, Train, Car, CarSection, n + 1); } break; case "touch": if (GroupIndex > 0) { Vector3 Position = Vector3.Zero; Vector3 Size = Vector3.Zero; int JumpScreen = GroupIndex - 1; int SoundIndex = -1; Translations.Command Command = Translations.Command.None; int CommandOption = 0; foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "position": { string[] s = Value.Split(','); if (s.Length == 3) { if (s[0].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[0], out Position.X)) { Interface.AddMessage(MessageType.Error, false, "X is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } if (s[1].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[1], out Position.Y)) { Interface.AddMessage(MessageType.Error, false, "Y is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } if (s[2].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[2], out Position.Z)) { Interface.AddMessage(MessageType.Error, false, "Z is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } else { Interface.AddMessage(MessageType.Error, false, "Three arguments are expected in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } break; case "size": { string[] s = Value.Split(','); if (s.Length == 3) { if (s[0].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[0], out Size.X)) { Interface.AddMessage(MessageType.Error, false, "X is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } if (s[1].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[1], out Size.Y)) { Interface.AddMessage(MessageType.Error, false, "Y is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } if (s[2].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[2], out Size.Z)) { Interface.AddMessage(MessageType.Error, false, "Z is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } else { Interface.AddMessage(MessageType.Error, false, "Three arguments are expected in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } break; case "jumpscreen": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out JumpScreen)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "soundindex": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out SoundIndex)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "command": { int i; for (i = 0; i < Translations.CommandInfos.Length; i++) { if (string.Compare(Value, Translations.CommandInfos[i].Name, StringComparison.OrdinalIgnoreCase) == 0) { break; } } if (i == Translations.CommandInfos.Length || Translations.CommandInfos[i].Type != Translations.CommandType.Digital) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } else { Command = Translations.CommandInfos[i].Command; } } break; case "commandoption": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out CommandOption)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; } } CreateTouchElement(CarSection.Groups[GroupIndex], Position, Size, JumpScreen, SoundIndex, Command, CommandOption); } break; case "include": { foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "filename": { string File = OpenBveApi.Path.CombineFile(TrainPath, Value); if (System.IO.File.Exists(File)) { System.Text.Encoding e = TextEncoding.GetSystemEncodingFromFile(File); ObjectManager.AnimatedObjectCollection a = AnimatedObjectParser.ReadObject(File, e); if (a != null) { for (int i = 0; i < a.Objects.Length; i++) { a.Objects[i].ObjectIndex = ObjectManager.CreateDynamicObject(); } CarSection.Groups[GroupIndex].Elements = a.Objects; } else { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } } break; } } } break; } } }
private static void CreateTouchElement(TrainManager.ElementsGroup Group, Vector3 Position, Vector3 Size, int ScreenIndex, int SoundIndex, Translations.Command Command, int CommandOption) { Vertex t0 = new Vertex(Size.X, Size.Y, -Size.Z); Vertex t1 = new Vertex(Size.X, -Size.Y, -Size.Z); Vertex t2 = new Vertex(-Size.X, -Size.Y, -Size.Z); Vertex t3 = new Vertex(-Size.X, Size.Y, -Size.Z); Vertex t4 = new Vertex(Size.X, Size.Y, Size.Z); Vertex t5 = new Vertex(Size.X, -Size.Y, Size.Z); Vertex t6 = new Vertex(-Size.X, -Size.Y, Size.Z); Vertex t7 = new Vertex(-Size.X, Size.Y, Size.Z); ObjectManager.StaticObject Object = new ObjectManager.StaticObject(); Object.Mesh.Vertices = new VertexTemplate[] { t0, t1, t2, t3, t4, t5, t6, t7 }; Object.Mesh.Faces = new MeshFace[] { new MeshFace(new int[] { 0, 1, 2, 3 }), new MeshFace(new int[] { 0, 4, 5, 1 }), new MeshFace(new int[] { 0, 3, 7, 4 }), new MeshFace(new int[] { 6, 5, 4, 7 }), new MeshFace(new int[] { 6, 7, 3, 2 }), new MeshFace(new int[] { 6, 2, 1, 5 }) }; Object.Mesh.Materials = new MeshMaterial[1]; Object.Mesh.Materials[0].Flags = 0; Object.Mesh.Materials[0].Color = Color32.White; Object.Mesh.Materials[0].TransparentColor = Color24.Blue; Object.Mesh.Materials[0].DaytimeTexture = null; Object.Mesh.Materials[0].NighttimeTexture = null; Object.Dynamic = true; if (Group.TouchElements == null) { Group.TouchElements = new TrainManager.TouchElement[0]; } int n = Group.TouchElements.Length; Array.Resize(ref Group.TouchElements, n + 1); Group.TouchElements[n] = new TrainManager.TouchElement { Element = new ObjectManager.AnimatedObject(), JumpScreenIndex = ScreenIndex, SoundIndex = SoundIndex, Command = Command, CommandOption = CommandOption }; Group.TouchElements[n].Element.States = new ObjectManager.AnimatedObjectState[1]; Group.TouchElements[n].Element.States[0].Position = Position; Group.TouchElements[n].Element.States[0].Object = Object; Group.TouchElements[n].Element.CurrentState = 0; Group.TouchElements[n].Element.ObjectIndex = ObjectManager.CreateDynamicObject(); ObjectManager.Objects[Group.TouchElements[n].Element.ObjectIndex] = Object.Clone(); int m = Interface.CurrentControls.Length; Array.Resize(ref Interface.CurrentControls, m + 1); Interface.CurrentControls[m].Command = Command; Interface.CurrentControls[m].Method = Interface.ControlMethod.Touch; Interface.CurrentControls[m].Option = CommandOption; }