예제 #1
0
		internal static void AddMessage(string Text, MessageDependency Depencency, Options.GameMode Mode, MessageColor Color, double Timeout) {
			if (Options.Current.CurrentGameMode <= Mode) {
				if (Depencency == MessageDependency.RouteLimit | Depencency == MessageDependency.SectionLimit) {
					for (int i = 0; i < Messages.Length; i++) {
						if (Messages[i].Depencency == Depencency) return;
					}
				}
				int n = Messages.Length;
				Array.Resize<Message>(ref Messages, n + 1);
				Messages[n].InternalText = Text;
				Messages[n].DisplayText = "";
				Messages[n].Depencency = Depencency;
				Messages[n].Timeout = Timeout;
				Messages[n].Color = Color;
				Messages[n].RendererPosition = new Vector2D(0.0, 0.0);
				Messages[n].RendererAlpha = 0.0;
			}
		}
예제 #2
0
	internal static void LoadOptions() {
		Current = new Options();
		CultureInfo Culture = CultureInfo.InvariantCulture;
		string File = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "options.cfg");
		if (System.IO.File.Exists(File)) {
			// load options
			string[] Lines = System.IO.File.ReadAllLines(File, new System.Text.UTF8Encoding());
			string Section = "";
			for (int i = 0; i < Lines.Length; i++) {
				Lines[i] = Lines[i].Trim();
				if (Lines[i].Length != 0 && !Lines[i].StartsWith(";", StringComparison.OrdinalIgnoreCase)) {
					if (Lines[i].StartsWith("[", StringComparison.Ordinal) & Lines[i].EndsWith("]", StringComparison.Ordinal)) {
						Section = Lines[i].Substring(1, Lines[i].Length - 2).Trim().ToLowerInvariant();
					} else {
						int j = Lines[i].IndexOf("=", StringComparison.OrdinalIgnoreCase);
						string Key, Value;
						if (j >= 0) {
							Key = Lines[i].Substring(0, j).TrimEnd().ToLowerInvariant();
							Value = Lines[i].Substring(j + 1).TrimStart();
						} else {
							Key = "";
							Value = Lines[i];
						}
						switch (Section) {
							case "language":
								switch (Key) {
									case "code":
										Current.LanguageCode = Value.Length != 0 ? Value : "en-US";
										break;
								} break;
							case "interface":
								switch (Key) {
									case "folder":
										Current.UserInterfaceFolder = Value.Length != 0 ? Value : "Default";
										break;
								} break;
							case "display":
								switch (Key) {
									case "mode":
										Current.FullscreenMode = string.Compare(Value, "fullscreen", StringComparison.OrdinalIgnoreCase) == 0;
										break;
									case "vsync":
										Current.VerticalSynchronization = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
									case "windowwidth":
										{
											int a;
											if (!int.TryParse(Value, NumberStyles.Integer, Culture, out a)) {
												a = 960;
											}
											Current.WindowWidth = a;
										} break;
									case "windowheight":
										{
											int a;
											if (!int.TryParse(Value, NumberStyles.Integer, Culture, out a)) {
												a = 600;
											}
											Current.WindowHeight = a;
										} break;
									case "fullscreenwidth":
										{
											int a;
											if (!int.TryParse(Value, NumberStyles.Integer, Culture, out a)) {
												a = 1024;
											}
											Current.FullscreenWidth = a;
										} break;
									case "fullscreenheight":
										{
											int a;
											if (!int.TryParse(Value, NumberStyles.Integer, Culture, out a)) {
												a = 768;
											}
											Current.FullscreenHeight = a;
										} break;
									case "mainmenuwidth":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											Current.MainMenuWidth = a;
										} break;
									case "mainmenuheight":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											Current.MainMenuHeight = a;
										} break;
									case "disabledisplaylists":
										Current.DisableDisplayLists = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
									case "loadinadvance":
										Current.LoadInAdvance = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
									case "notextureresize":
										Current.NoTextureResize = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
								} break;
							case "quality":
								switch (Key) {
									case "interpolation":
										switch (Value.ToLowerInvariant()) {
											case "nearestneighbor": Current.Interpolation = InterpolationMode.NearestNeighbor; break;
											case "bilinear": Current.Interpolation = InterpolationMode.Bilinear; break;
											case "nearestneighbormipmapped": Current.Interpolation = InterpolationMode.NearestNeighborMipmapped; ; break;
											case "bilinearmipmapped": Current.Interpolation = InterpolationMode.BilinearMipmapped; break;
											case "trilinearmipmapped": Current.Interpolation = InterpolationMode.TrilinearMipmapped; break;
											case "anisotropicfiltering": Current.Interpolation = InterpolationMode.AnisotropicFiltering; break;
											default: Current.Interpolation = InterpolationMode.BilinearMipmapped; break;
										} break;
									case "anisotropicfilteringlevel":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											Current.AnisotropicFilteringLevel = a;
										} break;
									case "anisotropicfilteringmaximum":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											Current.AnisotropicFilteringMaximum = a;
										} break;
									case "antialiasinglevel":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											Current.AntiAliasingLevel = a;
										} break;
									case "transparencymode":
										switch (Value.ToLowerInvariant()) {
											case "sharp": Current.TransparencyMode = Renderer.TransparencyMode.Performance; break;
											case "smooth": Current.TransparencyMode = Renderer.TransparencyMode.Quality; break;
											default: {
													int a;
													if (int.TryParse(Value, NumberStyles.Integer, Culture, out a)) {
														Current.TransparencyMode = (Renderer.TransparencyMode)a;
													} else {
														Current.TransparencyMode = Renderer.TransparencyMode.Quality;
													}
													break;
												}
										} break;
									case "viewingdistance":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											Current.ViewingDistance = a;
										} break;
									case "motionblur":
										switch (Value.ToLowerInvariant()) {
											case "low": Current.MotionBlur = MotionBlurMode.Low; break;
											case "medium": Current.MotionBlur = MotionBlurMode.Medium; break;
											case "high": Current.MotionBlur = MotionBlurMode.High; break;
											default: Current.MotionBlur = MotionBlurMode.None; break;
										} break;
								} break;
							case "objectoptimization":
								switch (Key) {
									case "basicthreshold":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											Current.ObjectOptimizationBasicThreshold = a;
										} break;
									case "fullthreshold":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											Current.ObjectOptimizationFullThreshold = a;
										} break;
								} break;
							case "simulation":
								switch (Key) {
									case "toppling":
										Current.Toppling = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
									case "collisions":
										Current.Collisions = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
									case "derailments":
										Current.Derailments = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
									case "blackbox":
										Current.BlackBox = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
									case "mode":
										switch (Value.ToLowerInvariant()) {
												case "arcade": Current.CurrentGameMode = GameMode.Arcade; break;
												case "normal": Current.CurrentGameMode = GameMode.Normal; break;
												case "expert": Current.CurrentGameMode = GameMode.Expert; break;
												default: Current.CurrentGameMode = GameMode.Normal; break;
										} break;
								} break;
							case "controls":
								switch (Key) {
									case "usejoysticks":
										Current.UseJoysticks = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
									case "joystickaxisthreshold":
										{
											double a;
											double.TryParse(Value, NumberStyles.Float, Culture, out a);
											Current.JoystickAxisThreshold = a;
										} break;
									case "keyrepeatdelay":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											if (a <= 0) a = 500;
											Current.KeyRepeatDelay = 0.001 * (double)a;
										} break;
									case "keyrepeatinterval":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											if (a <= 0) a = 100;
											Current.KeyRepeatInterval = 0.001 * (double)a;
										} break;
								} break;
							case "sound":
								switch (Key) {
									case "model":
										switch (Value.ToLowerInvariant()) {
											case "linear": Current.SoundModel = Sounds.SoundModels.Linear; break;
											default: Current.SoundModel = Sounds.SoundModels.Inverse; break;
										}
										break;
									case "range":
										switch (Value.ToLowerInvariant()) {
												case "low": Current.SoundRange = Sounds.SoundRange.Low; break;
												case "medium": Current.SoundRange = Sounds.SoundRange.Medium; break;
												case "high": Current.SoundRange = Sounds.SoundRange.High; break;
												default: Current.SoundRange = Sounds.SoundRange.Low; break;
										}
										break;
									case "number":
										{
											int a;
											int.TryParse(Value, NumberStyles.Integer, Culture, out a);
											Current.SoundNumber = a < 16 ? 16 : a;
										} break;
								} break;
							case "verbosity":
								switch (Key) {
									case "showwarningmessages":
										Current.ShowWarningMessages = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
									case "showerrormessages":
										Current.ShowErrorMessages = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
										break;
								} break;
							case "folders":
								switch (Key) {
									case "route":
										Current.RouteFolder = Value;
										break;
									case "train":
										Current.TrainFolder = Value;
										break;
								} break;
							case "proxy":
								switch (Key) {
									case "url":
										Current.ProxyUrl = Value;
										break;
									case "username":
										Current.ProxyUserName = Value;
										break;
									case "password":
										Current.ProxyPassword = Value;
										break;
								} break;
							case "recentlyusedroutes":
								{
									int n = Current.RecentlyUsedRoutes.Length;
									Array.Resize<string>(ref Current.RecentlyUsedRoutes, n + 1);
									Current.RecentlyUsedRoutes[n] = Value;
								} break;
							case "recentlyusedtrains":
								{
									int n = Current.RecentlyUsedTrains.Length;
									Array.Resize<string>(ref Current.RecentlyUsedTrains, n + 1);
									Current.RecentlyUsedTrains[n] = Value;
								} break;
							case "routeencodings":
								{
									int a = System.Text.Encoding.UTF8.CodePage;
									int.TryParse(Key, NumberStyles.Integer, Culture, out a);
									int n = Current.RouteEncodings.Length;
									Array.Resize<EncodingValue>(ref Current.RouteEncodings, n + 1);
									Current.RouteEncodings[n].Codepage = a;
									Current.RouteEncodings[n].Value = Value;
								} break;
							case "trainencodings":
								{
									int a = System.Text.Encoding.UTF8.CodePage;
									int.TryParse(Key, NumberStyles.Integer, Culture, out a);
									int n = Current.TrainEncodings.Length;
									Array.Resize<EncodingValue>(ref Current.TrainEncodings, n + 1);
									Current.TrainEncodings[n].Codepage = a;
									Current.TrainEncodings[n].Value = Value;
								} break;
						}
					}
				}
			}
		} else {
			// file not found
			string Code = CultureInfo.CurrentUICulture.Name;
			if (string.IsNullOrEmpty(Code))
				Code = "en-US";
			File = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Languages"), Code + ".cfg");
			if (System.IO.File.Exists(File)) {
				Current.LanguageCode = Code;
			} else {
				try {
					int i = Code.IndexOf("-", StringComparison.Ordinal);
					if (i > 0) {
						Code = Code.Substring(0, i);
						File = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Languages"), Code + ".cfg");
						if (System.IO.File.Exists(File)) {
							Current.LanguageCode = Code;
						}
					}
				} catch {
					Current.LanguageCode = "en-US";
				}
			}
		}
	}
예제 #3
0
파일: Options.cs 프로젝트: sladen/openbve2
 // --- static functions ---
 internal static Options LoadFromFile(string file)
 {
     Options options = new Options();
     CultureInfo culture = CultureInfo.InvariantCulture;
     string[] lines = OpenBveApi.Text.GetLinesFromFile(file, Encoding.UTF8);
     for (int i = 0; i < lines.Length; i++) {
         int semicolon = lines[i].IndexOf(';');
         if (semicolon >= 0) {
             lines[i] = lines[i].Substring(0, semicolon).Trim();
         } else {
             lines[i] = lines[i].Trim();
         }
         if (lines[i].Length != 0) {
             int equals = lines[i].IndexOf('=');
             if (equals >= 0) {
                 string key = lines[i].Substring(0, equals).TrimEnd();
                 string value = lines[i].Substring(equals + 1).TrimStart();
                 switch (key.ToLowerInvariant()) {
                     case "width":
                         options.Width = int.Parse(value, culture);
                         break;
                     case "height":
                         options.Height = int.Parse(value, culture);
                         break;
                     case "fullscreen":
                         options.Fullscreen = value.Equals("true", StringComparison.OrdinalIgnoreCase);
                         break;
                     case "vsync":
                         options.VSync = value.Equals("true", StringComparison.OrdinalIgnoreCase);
                         break;
                     case "viewingdistance":
                         options.ViewingDistance = double.Parse(value, culture);
                         break;
                     case "redsize":
                         options.RedSize = int.Parse(value, culture);
                         break;
                     case "greensize":
                         options.GreenSize = int.Parse(value, culture);
                         break;
                     case "bluesize":
                         options.BlueSize = int.Parse(value, culture);
                         break;
                     case "alphasize":
                         options.AlphaSize = int.Parse(value, culture);
                         break;
                     case "depthsize":
                         options.DepthSize = int.Parse(value, culture);
                         break;
                     case "interpolationmode":
                         options.InterpolationMode = (TextureInterpolationMode)int.Parse(value, culture);
                         break;
                     case "objectoptimization":
                         options.ObjectOptimization = int.Parse(value, culture);
                         break;
                     case "blockclipping":
                         options.BlockClipping = value.Equals("true", StringComparison.OrdinalIgnoreCase);
                         break;
                     case "facesperdisplaylist":
                         options.FacesPerDisplayList = int.Parse(value, culture);
                         break;
                     case "sortinterval":
                         options.SortInterval = double.Parse(value, culture);
                         break;
                     case "gridsize":
                         options.GridSize = double.Parse(value, culture);
                         break;
                     case "showgrid":
                         options.ShowGrid = value.Equals("true", StringComparison.OrdinalIgnoreCase);
                         break;
                     case "contenttype":
                         options.ContentType = value;
                         break;
                     case "contentfile":
                         options.ContentFile = value;
                         break;
                     case "contentcount":
                         options.ContentCount = int.Parse(value, culture);
                         break;
                 }
             }
         }
     }
     return options;
 }