Fix two mostly unrelated nyma settings issues

Mednafen has extra aliases of enum values that we don't need here and were confusing the system.  Now, NGP no longer has three different "English" options for language.
Internal Mednafen code expects MDFN_GetSettingB ("bool") to work with enum values, so long as those enums are 0 and 1, but we weren't handling that.

Fixes #2385
This commit is contained in:
nattthebear 2020-09-10 08:05:11 -04:00 committed by adelikat
parent 76c97e49e7
commit d619a3c7c3
9 changed files with 12 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
@ -170,12 +171,16 @@ namespace BizHawk.Emulation.Cores.Waterbox
private class MyTypeConverter : TypeConverter
{
public SettingT Setting { get; set; }
// Mednafen includes extra fallback aliases of enums that are nameless, just one way value aliases.
// They confuse our code and are not needed here.
private IEnumerable<EnumValueT> ValidSettingEnums => Setting.SettingEnums
.Where(e => e.Name != null);
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string);
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => destinationType == typeof(string);
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return Setting.SettingEnums
return ValidSettingEnums
.SingleOrDefault(d => d.Name == (string)value)
?.Value
?? Setting.DefaultValue;
@ -183,16 +188,16 @@ namespace BizHawk.Emulation.Cores.Waterbox
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
return Setting.SettingEnums
return ValidSettingEnums
.SingleOrDefault(d => d.Value == (string)value)
?.Name
?? Setting.SettingEnums
?? ValidSettingEnums
.Single(d => d.Value == Setting.DefaultValue)
.Name;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) => new StandardValuesCollection(
Setting.SettingEnums.Select(e => e.Value).ToList()
ValidSettingEnums.Select(e => e.Value).ToList()
);
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true;

View File

@ -289,7 +289,8 @@ namespace BizHawk.Emulation.Cores.Waterbox
{
s.AllOverrides[kvp.Key] = kvp.Value;
}
foreach (var setting in GetSettingsData().Concat(ExtraSettings))
var originalSettings = GetSettingsData();
foreach (var setting in originalSettings.Concat(ExtraSettings))
{
s.AllSettingsByKey.Add(setting.SettingsKey, setting);
s.AllSettings.Add(setting);

View File

@ -176,9 +176,7 @@ namespace Mednafen
}
bool MDFN_GetSettingB(const char *name)
{
char tmp[SETTING_VALUE_MAX_LENGTH];
FrontendSettingQuery(name, tmp);
return strtol(tmp, nullptr, 10) != 0;
return (bool)MDFN_GetSettingUI(name);
}
std::string MDFN_GetSettingS(const char *name)
{