예제 #1
0
        private static IList <ComboBoxItem <T> > FromEnum <T>(ICatalog catalog) where T : Enum
        {
            string context = EnumExtension.EnumDescription <T>();

            return((from data in EnumExtension.GetValues <T>()
                    select new ComboBoxItem <T>(data,
                                                string.IsNullOrEmpty(context) ? catalog.GetString(data.GetDescription()) : catalog.GetParticularString(context, data.GetDescription()))).ToList());
        }
예제 #2
0
        private static IList <ComboBoxItem <int> > FromEnumValue <E>(ICatalog catalog) where E : Enum
        {
            string context = EnumExtension.EnumDescription <E>();

            return((from data in EnumExtension.GetValues <E>()
                    select new ComboBoxItem <int>(
                        Convert.ToInt32(data, System.Globalization.CultureInfo.InvariantCulture),
                        string.IsNullOrEmpty(context) ? catalog.GetString(data.GetDescription()) : catalog.GetParticularString(context, data.GetDescription()))).ToList());
        }
예제 #3
0
        public OptionsForm(UserSettings settings, UpdateManager updateManager, ICatalog catalog, ICatalog commonCatalog, bool initialContentSetup)
        {
            InitializeComponent();
            Localizer.Localize(this, catalog);

            this.settings      = settings ?? throw new ArgumentNullException(nameof(settings));
            this.updateManager = updateManager ?? throw new ArgumentNullException(nameof(updateManager));
            this.catalog       = catalog ?? throw new ArgumentNullException(nameof(catalog));
            this.commonCatalog = commonCatalog ?? throw new ArgumentNullException(nameof(catalog));

            // Collect all the available language codes by searching for
            // localisation files, but always include English (base language).
            List <string> languageCodes = new List <string> {
                "en"
            };

            if (Directory.Exists(RuntimeInfo.LocalesFolder))
            {
                foreach (string path in Directory.EnumerateDirectories(RuntimeInfo.LocalesFolder))
                {
                    if (Directory.EnumerateFiles(path, "*.mo").Any())
                    {
                        try
                        {
                            string languageCode = Path.GetFileName(path);
                            CultureInfo.GetCultureInfo(languageCode);
                            languageCodes.Add(languageCode);
                        }
                        catch (CultureNotFoundException) { }
                    }
                }
            }
            // Turn the list of codes in to a list of code + name pairs for
            // displaying in the dropdown list.
            languageCodes.Add(string.Empty);
            languageCodes.Sort();
            comboLanguage.DataSourceFromList(languageCodes, (language) => string.IsNullOrEmpty(language) ? "System" : CultureInfo.GetCultureInfo(language).NativeName);
            comboLanguage.SelectedValue = this.settings.Language;
            if (comboLanguage.SelectedValue == null)
            {
                comboLanguage.SelectedIndex = 0;
            }

            comboBoxOtherUnits.DataSourceFromEnum <MeasurementUnit>(commonCatalog);
            comboPressureUnit.DataSourceFromEnum <PressureUnit>(commonCatalog);

            AdhesionLevelValue.Font = new Font(Font, FontStyle.Bold);

            // Fix up the TrackBars on TabPanels to match the current theme.
            if (!Application.RenderWithVisualStyles)
            {
                trackAdhesionFactor.BackColor       = BackColor;
                trackAdhesionFactorChange.BackColor = BackColor;
                trackDayAmbientLight.BackColor      = BackColor;
                trackLODBias.BackColor = BackColor;
            }

            // General tab
            checkAlerter.Checked               = this.settings.Alerter;
            checkAlerterExternal.Enabled       = this.settings.Alerter;
            checkAlerterExternal.Checked       = this.settings.Alerter && !this.settings.AlerterDisableExternal;
            checkSpeedControl.Checked          = this.settings.SpeedControl;
            checkConfirmations.Checked         = !this.settings.SuppressConfirmations;
            checkViewDispatcher.Checked        = this.settings.ViewDispatcher;
            checkRetainers.Checked             = this.settings.RetainersOnAllCars;
            checkGraduatedRelease.Checked      = this.settings.GraduatedRelease;
            numericBrakePipeChargingRate.Value = this.settings.BrakePipeChargingRate;
            comboLanguage.Text = this.settings.Language;
            comboPressureUnit.SelectedValue  = this.settings.PressureUnit;
            comboBoxOtherUnits.SelectedValue = settings.MeasurementUnit;
            checkDisableTCSScripts.Checked   = this.settings.DisableTCSScripts;
            checkEnableWebServer.Checked     = this.settings.WebServer;
            numericWebServerPort.Value       = this.settings.WebServerPort;

            // Audio tab
            numericSoundVolumePercent.Value           = this.settings.SoundVolumePercent;
            numericSoundDetailLevel.Value             = this.settings.SoundDetailLevel;
            numericExternalSoundPassThruPercent.Value = this.settings.ExternalSoundPassThruPercent;

            // Video tab
            checkDynamicShadows.Checked       = this.settings.DynamicShadows;
            checkShadowAllShapes.Checked      = this.settings.ShadowAllShapes;
            checkFastFullScreenAltTab.Checked = this.settings.FastFullScreenAltTab;
            checkWindowGlass.Checked          = this.settings.WindowGlass;
            checkModelInstancing.Checked      = this.settings.ModelInstancing;
            checkWire.Checked           = this.settings.Wire;
            checkVerticalSync.Checked   = this.settings.VerticalSync;
            trackbarMultiSampling.Value = (int)Math.Log(this.settings.MultisamplingCount, 2);
            TrackbarMultiSampling_Scroll(this, null);
            numericCab2DStretch.Value     = this.settings.Cab2DStretch;
            numericViewingDistance.Value  = this.settings.ViewingDistance;
            checkDistantMountains.Checked = this.settings.DistantMountains;
            labelDistantMountainsViewingDistance.Enabled   = checkDistantMountains.Checked;
            numericDistantMountainsViewingDistance.Enabled = checkDistantMountains.Checked;
            numericDistantMountainsViewingDistance.Value   = this.settings.DistantMountainsViewingDistance / 1000;
            numericViewingFOV.Value         = this.settings.ViewingFOV;
            numericWorldObjectDensity.Value = this.settings.WorldObjectDensity;
            comboWindowSize.Text            = this.settings.WindowSize;
            trackDayAmbientLight.Value      = this.settings.DayAmbientLight;
            TrackDayAmbientLight_ValueChanged(null, null);
            checkDoubleWire.Checked = this.settings.DoubleWire;
            checkBoxFullScreenNativeResolution.Checked = this.settings.NativeFullscreenResolution;
            radioButtonFullScreen.Checked = this.settings.FullScreen;
            radioButtonWindow.Checked     = !radioButtonFullScreen.Checked;

            // Simulation tab
            checkUseAdvancedAdhesion.Checked               = this.settings.UseAdvancedAdhesion;
            labelAdhesionMovingAverageFilterSize.Enabled   = checkUseAdvancedAdhesion.Checked;
            numericAdhesionMovingAverageFilterSize.Enabled = checkUseAdvancedAdhesion.Checked;
            numericAdhesionMovingAverageFilterSize.Value   = this.settings.AdhesionMovingAverageFilterSize;
            checkBreakCouplers.Checked                = this.settings.BreakCouplers;
            checkCurveResistanceDependent.Checked     = this.settings.CurveResistanceDependent;
            checkCurveSpeedDependent.Checked          = this.settings.CurveSpeedDependent;
            checkTunnelResistanceDependent.Checked    = this.settings.TunnelResistanceDependent;
            checkWindResistanceDependent.Checked      = this.settings.WindResistanceDependent;
            checkOverrideNonElectrifiedRoutes.Checked = this.settings.OverrideNonElectrifiedRoutes;
            checkHotStart.Checked                = this.settings.HotStart;
            checkSimpleControlPhysics.Checked    = this.settings.SimpleControlPhysics;
            checkForcedRedAtStationStops.Checked = !this.settings.NoForcedRedAtStationStops;
            checkDoorsAITrains.Checked           = this.settings.OpenDoorsInAITrains;

            //// Keyboard tab
            //InitializeKeyboardSettings();

            ////RailDriver tab
            //InitializeRailDriverSettings());

            // DataLogger tab
            comboDataLoggerSeparator.DataSourceFromEnum <SeparatorChar>(commonCatalog);
            comboDataLoggerSeparator.SelectedValue = settings.DataLoggerSeparator;

            comboDataLogSpeedUnits.DataSourceFromEnum <SpeedUnit>(commonCatalog);
            comboDataLogSpeedUnits.SelectedValue = settings.DataLogSpeedUnits;

            checkDataLogger.Checked                   = this.settings.DataLogger;
            checkDataLogPerformance.Checked           = this.settings.DataLogPerformance;
            checkDataLogPhysics.Checked               = this.settings.DataLogPhysics;
            checkDataLogMisc.Checked                  = this.settings.DataLogMisc;
            checkDataLogSteamPerformance.Checked      = this.settings.DataLogSteamPerformance;
            checkVerboseConfigurationMessages.Checked = this.settings.VerboseConfigurationMessages;

            // Evaluation tab
            checkDataLogTrainSpeed.Checked     = this.settings.EvaluationTrainSpeed;
            labelDataLogTSInterval.Enabled     = checkDataLogTrainSpeed.Checked;
            numericDataLogTSInterval.Enabled   = checkDataLogTrainSpeed.Checked;
            checkListDataLogTSContents.Enabled = checkDataLogTrainSpeed.Checked;
            numericDataLogTSInterval.Value     = this.settings.EvaluationInterval;

            string context = EnumExtension.EnumDescription <EvaluationLogContents>();

            checkListDataLogTSContents.Items.AddRange(EnumExtension.GetValues <EvaluationLogContents>().
                                                      Where(content => content != EvaluationLogContents.None).
                                                      Select(content => commonCatalog.GetParticularString(context, content.GetDescription())).ToArray());

            for (int i = 0; i < checkListDataLogTSContents.Items.Count; i++)
            {
                checkListDataLogTSContents.SetItemChecked(i, settings.EvaluationContent.HasFlag((EvaluationLogContents)(1 << i)));
            }
            checkDataLogStationStops.Checked = this.settings.EvaluationStationStops;

            // Content tab
            bindingSourceContent.DataSource = (from folder in this.settings.FolderSettings.Folders
                                               orderby folder.Key
                                               select new ContentFolder()
            {
                Name = folder.Key, Path = folder.Value
            }).ToList();
            if (initialContentSetup)
            {
                tabOptions.SelectedTab      = tabPageContent;
                buttonContentBrowse.Enabled = false; // Initial state because browsing a null path leads to an exception
                bindingSourceContent.Add(new ContentFolder()
                {
                    Name = "Train Simulator", Path = FolderStructure.MstsFolder
                });
            }

            // Updater tab
            trackBarUpdaterFrequency.Value = this.settings.UpdateCheckFrequency;
            TrackBarUpdaterFrequency_Scroll(this, null);

            buttonUpdatesRefresh.Font   = new Font("Wingdings 3", 14);
            buttonUpdatesRefresh.Text   = char.ConvertFromUtf32(81);
            buttonUpdatesRefresh.Width  = 23;
            buttonUpdatesRefresh.Height = 23;

            comboBoxUpdateChannels.DataSourceFromList(updateManager.GetChannels().OrderByDescending((s) => s), (channel) => catalog.GetString(channel));
            comboBoxUpdateChannels.SelectedIndex = comboBoxUpdateChannels.FindStringExact(this.settings.UpdateChannel);

            // Experimental tab
            numericUseSuperElevation.Value        = this.settings.UseSuperElevation;
            numericSuperElevationMinLen.Value     = this.settings.SuperElevationMinLen;
            numericSuperElevationGauge.Value      = this.settings.SuperElevationGauge;
            checkPerformanceTuner.Checked         = this.settings.PerformanceTuner;
            labelPerformanceTunerTarget.Enabled   = checkPerformanceTuner.Checked;
            numericPerformanceTunerTarget.Enabled = checkPerformanceTuner.Checked;
            numericPerformanceTunerTarget.Value   = this.settings.PerformanceTunerTarget;
            trackLODBias.Value = this.settings.LODBias;
            TrackLODBias_ValueChanged(null, null);
            checkConditionalLoadOfNightTextures.Checked = this.settings.ConditionalLoadOfDayOrNightTextures;
            checkSignalLightGlow.Checked         = this.settings.SignalLightGlow;
            checkCircularSpeedGauge.Checked      = this.settings.CircularSpeedGauge;
            checkLODViewingExtention.Checked     = this.settings.LODViewingExtention;
            checkPreferDDSTexture.Checked        = this.settings.PreferDDSTexture;
            checkUseLocationPassingPaths.Checked = this.settings.UseLocationPassingPaths;
            checkUseMSTSEnv.Checked            = this.settings.UseMSTSEnv;
            trackAdhesionFactor.Value          = this.settings.AdhesionFactor;
            checkAdhesionPropToWeather.Checked = this.settings.AdhesionProportionalToWeather;
            trackAdhesionFactorChange.Value    = this.settings.AdhesionFactorChange;
            TrackAdhesionFactor_ValueChanged(null, null);
            checkShapeWarnings.Checked   = !this.settings.SuppressShapeWarnings;
            precipitationBoxHeight.Value = this.settings.PrecipitationBoxHeight;
            precipitationBoxWidth.Value  = this.settings.PrecipitationBoxWidth;
            precipitationBoxLength.Value = this.settings.PrecipitationBoxLength;
            checkCorrectQuestionableBrakingParams.Checked = this.settings.CorrectQuestionableBrakingParams;
            numericActRandomizationLevel.Value            = this.settings.ActRandomizationLevel;
            numericActWeatherRandomizationLevel.Value     = this.settings.ActWeatherRandomizationLevel;
        }