Create Guid constants for system skins (and store skin choice to configuration as guid)

This commit is contained in:
Dean Herbert 2021-11-23 16:04:55 +09:00
parent e283379f0e
commit 3db5646fa8
4 changed files with 29 additions and 29 deletions

View File

@ -27,7 +27,7 @@ protected override void InitialiseDefaults()
{
// UI/selection defaults
SetDefault(OsuSetting.Ruleset, string.Empty);
SetDefault(OsuSetting.Skin, 0, -1, int.MaxValue);
SetDefault(OsuSetting.Skin, string.Empty);
SetDefault(OsuSetting.BeatmapDetailTab, PlayBeatmapDetailArea.TabType.Details);
SetDefault(OsuSetting.BeatmapDetailModsFilter, false);
@ -210,9 +210,12 @@ public override TrackedSettings CreateTrackedSettings()
value: scalingMode.GetLocalisableDescription()
)
),
new TrackedSetting<int>(OsuSetting.Skin, skin =>
new TrackedSetting<string>(OsuSetting.Skin, skin =>
{
string skinName = LookupSkinName(skin) ?? string.Empty;
string skinName = string.Empty;
if (Guid.TryParse(skin, out var id))
skinName = LookupSkinName(id) ?? string.Empty;
return new SettingDescription(
rawValue: skinName,
@ -233,7 +236,7 @@ public override TrackedSettings CreateTrackedSettings()
};
}
public Func<int, string> LookupSkinName { private get; set; }
public Func<Guid, string> LookupSkinName { private get; set; }
public Func<GlobalAction, LocalisableString> LookupKeyBindings { get; set; }
}

View File

@ -161,7 +161,7 @@ public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>, ILocalUser
private Bindable<float> uiScale;
private Bindable<int> configSkin;
private Bindable<string> configSkin;
private readonly string[] args;
@ -243,27 +243,23 @@ private void load()
Ruleset.ValueChanged += r => configRuleset.Value = r.NewValue.ShortName;
// bind config int to database SkinInfo
configSkin = LocalConfig.GetBindable<int>(OsuSetting.Skin);
SkinManager.CurrentSkinInfo.ValueChanged += skin => configSkin.Value = skin.NewValue.ID;
configSkin = LocalConfig.GetBindable<string>(OsuSetting.Skin);
SkinManager.CurrentSkinInfo.ValueChanged += skin => configSkin.Value = skin.NewValue.ID.ToString();
configSkin.ValueChanged += skinId =>
{
var skinInfo = SkinManager.Query(s => s.ID == skinId.NewValue);
// TODO: migrate the user skin selection to the new ID format.
SkinInfo skinInfo = null;
if (Guid.TryParse(skinId.NewValue, out var guid))
skinInfo = SkinManager.Query(s => s.ID == guid);
if (skinInfo == null)
{
switch (skinId.NewValue)
{
case -1:
skinInfo = DefaultLegacySkin.Info;
break;
default:
skinInfo = SkinInfo.Default;
break;
}
if (guid == SkinInfo.CLASSIC_SKIN)
skinInfo = DefaultLegacySkin.Info;
}
SkinManager.CurrentSkinInfo.Value = skinInfo;
SkinManager.CurrentSkinInfo.Value = skinInfo ?? SkinInfo.Default;
};
configSkin.TriggerChange();

View File

@ -33,7 +33,7 @@ public class SkinSection : SettingsSection
};
private readonly Bindable<SkinInfo> dropdownBindable = new Bindable<SkinInfo> { Default = SkinInfo.Default };
private readonly Bindable<int> configBindable = new Bindable<int>();
private readonly Bindable<string> configBindable = new Bindable<string>();
private static readonly SkinInfo random_skin_info = new SkinInfo
{
@ -47,7 +47,7 @@ private int firstNonDefaultSkinIndex
{
get
{
int index = skinItems.FindIndex(s => s.ID > 0);
int index = skinItems.FindIndex(s => s.ID == SkinInfo.CLASSIC_SKIN);
if (index < 0)
index = skinItems.Count;
@ -84,33 +84,33 @@ private void load(OsuConfigManager config, [CanBeNull] SkinEditorOverlay skinEdi
updateItems();
// Todo: This should not be necessary when OsuConfigManager is databased
if (skinDropdown.Items.All(s => s.ID != configBindable.Value))
configBindable.Value = 0;
if (!Guid.TryParse(configBindable.Value, out var configId) || skinDropdown.Items.All(s => s.ID != configId))
configBindable.Value = string.Empty;
configBindable.BindValueChanged(id => Scheduler.AddOnce(updateSelectedSkinFromConfig), true);
dropdownBindable.BindValueChanged(skin =>
{
if (skin.NewValue == random_skin_info)
if (skin.NewValue.Equals(random_skin_info))
{
skins.SelectRandomSkin();
return;
}
configBindable.Value = skin.NewValue.ID;
configBindable.Value = skin.NewValue.ID.ToString();
});
}
private void updateSelectedSkinFromConfig()
{
int id = configBindable.Value;
if (!Guid.TryParse(configBindable.Value, out var configId)) return;
var skin = skinDropdown.Items.FirstOrDefault(s => s.ID == id);
var skin = skinDropdown.Items.FirstOrDefault(s => s.ID == configId);
if (skin == null)
{
// there may be a thread race condition where an item is selected that hasn't yet been added to the dropdown.
// to avoid adding complexity, let's just ensure the item is added so we can perform the selection.
skin = skins.Query(s => s.ID == id);
skin = skins.Query(s => s.ID == configId);
addItem(skin);
}
@ -181,7 +181,7 @@ private void load()
Action = export;
currentSkin = skins.CurrentSkin.GetBoundCopy();
currentSkin.BindValueChanged(skin => Enabled.Value = skin.NewValue.SkinInfo.ID > 0, true);
currentSkin.BindValueChanged(skin => Enabled.Value = skin.NewValue.SkinInfo.IsManaged, true);
}
private void export()

View File

@ -50,6 +50,7 @@ public virtual Skin CreateInstance(IStorageResourceProvider resources)
public static SkinInfo Default { get; } = new SkinInfo
{
ID = DEFAULT_SKIN,
Name = "osu! (triangles)",
Creator = "team osu!",
InstantiationInfo = typeof(DefaultSkin).GetInvariantInstantiationInfo()