From b0a597322fe9db2ab8194a3b6ed45493b17609dd Mon Sep 17 00:00:00 2001 From: stoj Date: Sat, 9 Sep 2023 12:51:54 +0800 Subject: [PATCH] feeder: automatically select simulator unknown (in addition to VPX) when no simulator was previously selected --- ClrVpin/Feeder/FeederResultsViewModel.cs | 8 +++++--- ClrVpin/Shared/FeatureType/FeatureOptions.cs | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ClrVpin/Feeder/FeederResultsViewModel.cs b/ClrVpin/Feeder/FeederResultsViewModel.cs index 1969ace..58d6a5d 100644 --- a/ClrVpin/Feeder/FeederResultsViewModel.cs +++ b/ClrVpin/Feeder/FeederResultsViewModel.cs @@ -369,7 +369,9 @@ private void UpdateFilterOptionsBasedOnSelectedFileTypes() // - enable simulator options and also default first option VPX if none are already selected var isTableEnabled = Settings.SelectedOnlineFileTypeOptions.Contains(OnlineFileTypeEnum.Tables.GetDescription()); - FeatureOptions.UpdateFeatureOptions(isTableEnabled, GameFiltersViewModel.SimulatorOptionsFilterView.ToList(), (int)SimulatorOptionEnum.VirtualPinballX); + FeatureOptions.EnableDisableFeatureOptions(isTableEnabled, GameFiltersViewModel.SimulatorOptionsFilterView.ToList()); + if (isTableEnabled) + FeatureOptions.SelectDefaultFeatureTypes(GameFiltersViewModel.SimulatorOptionsFilterView.ToList(), (int)SimulatorOptionEnum.VirtualPinballX, (int)SimulatorOptionEnum.Unknown); // backglass file - enable features UpdateMiscFeatureState(new[] { OnlineFileTypeEnum.Backglasses }, MiscFeatureOptionEnum.FullDmd); @@ -381,7 +383,7 @@ private void UpdateFilterOptionsBasedOnSelectedFileTypes() // - automatically standard simulator options and also default first option VPX if none are already selected var isTableOrBackglassEnabled = Settings.SelectedOnlineFileTypeOptions.ContainsAny(tableAndBackglassFileType.Select(x => x.GetDescription())); if (isTableOrBackglassEnabled) - FeatureOptions.SelectDefaultFeatureType(GameFiltersViewModel.MiscFeaturesOptionsView.ToList(), (int)MiscFeatureOptionEnum.Standard); + FeatureOptions.SelectDefaultFeatureTypes(GameFiltersViewModel.MiscFeaturesOptionsView.ToList(), (int)MiscFeatureOptionEnum.Standard, (int)MiscFeatureOptionEnum.Standard); UpdateOnlineGameFileDetails(); } @@ -393,7 +395,7 @@ private void UpdateMiscFeatureState(IEnumerable onlineFileTy var miscFeatureOptionItems = GameFiltersViewModel.MiscFeaturesOptionsView.Where(option => miscFeatureOptions.Contains(option.Id)); // update each of the relevant feature options - FeatureOptions.UpdateFeatureOptions(isFileTypeEnabled, miscFeatureOptionItems.ToList()); + FeatureOptions.EnableDisableFeatureOptions(isFileTypeEnabled, miscFeatureOptionItems.ToList()); } private void UpdateOnlineGameFileDetails() diff --git a/ClrVpin/Shared/FeatureType/FeatureOptions.cs b/ClrVpin/Shared/FeatureType/FeatureOptions.cs index 646c2e6..48dbbae 100644 --- a/ClrVpin/Shared/FeatureType/FeatureOptions.cs +++ b/ClrVpin/Shared/FeatureType/FeatureOptions.cs @@ -107,7 +107,7 @@ public static ListCollectionView CreateFeatureOptionsMultiSelection } // update multiple feature options - public static void UpdateFeatureOptions(bool isEnabled, List featureTypes, int? defaultFeatureTypeEnum = null) + public static void EnableDisableFeatureOptions(bool isEnabled, List featureTypes) { // enable/disable the features featureTypes.ForEach(featureType => @@ -117,17 +117,19 @@ public static void UpdateFeatureOptions(bool isEnabled, List featur else DisableFeatureType(featureType); }); - - if (defaultFeatureTypeEnum != null) - SelectDefaultFeatureType(featureTypes, defaultFeatureTypeEnum.Value); } - public static void SelectDefaultFeatureType(List featureTypes, int defaultFeatureTypeEnum) + public static void SelectDefaultFeatureTypes(List featureTypes, params int[] defaultFeatureTypeEnums) { - // if the feature is enabled AND no options are active, then select the default feature type - var featureType = featureTypes.First(feature => feature.Id == defaultFeatureTypeEnum); - if (featureType.IsSupported && !featureTypes.Any(option => option.IsActive)) - SelectFeatureType(featureType, true); + // do nothing if a feature type is already selected/active + if (featureTypes.Any(option => option.IsActive)) + return; + + // select all of the specified default feature types + var defaultFeatureTypes = featureTypes.Where(feature => defaultFeatureTypeEnums.Contains(feature.Id)); + defaultFeatureTypes + .Where(defaultFeatureType => defaultFeatureType.IsSupported) + .ForEach(defaultFeatureType => SelectFeatureType(defaultFeatureType, true)); } public static void DisableFeatureType(FeatureType featureType, string message = null)