Add user skin setting storage

This commit is contained in:
Dean Herbert
2018-02-22 16:29:05 +09:00
parent 659cf629b6
commit 402d71a8d9
5 changed files with 24 additions and 7 deletions

View File

@ -14,6 +14,8 @@ namespace osu.Game.Configuration
{ {
// UI/selection defaults // UI/selection defaults
Set(OsuSetting.Ruleset, 0, 0, int.MaxValue); Set(OsuSetting.Ruleset, 0, 0, int.MaxValue);
Set(OsuSetting.Skin, 0, 0, int.MaxValue);
Set(OsuSetting.BeatmapDetailTab, BeatmapDetailTab.Details); Set(OsuSetting.BeatmapDetailTab, BeatmapDetailTab.Details);
Set(OsuSetting.ShowConvertedBeatmaps, true); Set(OsuSetting.ShowConvertedBeatmaps, true);
@ -122,6 +124,7 @@ namespace osu.Game.Configuration
ChatDisplayHeight, ChatDisplayHeight,
Version, Version,
ShowConvertedBeatmaps, ShowConvertedBeatmaps,
SpeedChangeVisualisation SpeedChangeVisualisation,
Skin
} }
} }

View File

@ -48,7 +48,7 @@ namespace osu.Game.Database
protected readonly IDatabaseContextFactory ContextFactory; protected readonly IDatabaseContextFactory ContextFactory;
protected readonly MutableDatabaseBackedStore<TModel> ModelStore; public readonly MutableDatabaseBackedStore<TModel> ModelStore;
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
private ArchiveImportIPCChannel ipc; private ArchiveImportIPCChannel ipc;

View File

@ -30,6 +30,7 @@ using osu.Game.Rulesets;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Skinning;
using OpenTK.Graphics; using OpenTK.Graphics;
namespace osu.Game namespace osu.Game
@ -79,6 +80,8 @@ namespace osu.Game
private Bindable<int> configRuleset; private Bindable<int> configRuleset;
public Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>(); public Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
private Bindable<int> configSkin;
private readonly string[] args; private readonly string[] args;
private SettingsOverlay settings; private SettingsOverlay settings;
@ -122,10 +125,18 @@ namespace osu.Game
dependencies.CacheAs(this); dependencies.CacheAs(this);
// bind config int to database RulesetInfo
configRuleset = LocalConfig.GetBindable<int>(OsuSetting.Ruleset); configRuleset = LocalConfig.GetBindable<int>(OsuSetting.Ruleset);
Ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First(); Ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First();
Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0; Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0;
// bind config int to database SkinInfo
configSkin = LocalConfig.GetBindable<int>(OsuSetting.Skin);
SkinManager.CurrentSkinInfo.ValueChanged += s => configSkin.Value = s.ID;
configSkin.ValueChanged += id => SkinManager.CurrentSkinInfo.Value = SkinManager.ModelStore.ConsumableItems.FirstOrDefault(s => s.ID == id) ?? SkinInfo.Default;
configSkin.TriggerChange();
LocalConfig.BindWith(OsuSetting.VolumeInactive, inactiveVolumeAdjust); LocalConfig.BindWith(OsuSetting.VolumeInactive, inactiveVolumeAdjust);
} }

View File

@ -15,7 +15,7 @@ namespace osu.Game.Overlays.Settings.Sections
{ {
public class SkinSection : SettingsSection public class SkinSection : SettingsSection
{ {
private SettingsDropdown<SkinInfo> skinDropdown; private SettingsDropdown<int> skinDropdown;
public override string Header => "Skin"; public override string Header => "Skin";
@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Settings.Sections
FlowContent.Spacing = new Vector2(0, 5); FlowContent.Spacing = new Vector2(0, 5);
Children = new Drawable[] Children = new Drawable[]
{ {
skinDropdown = new SettingsDropdown<SkinInfo>(), skinDropdown = new SettingsDropdown<int>(),
new SettingsSlider<double, SizeSlider> new SettingsSlider<double, SizeSlider>
{ {
LabelText = "Menu cursor size", LabelText = "Menu cursor size",
@ -47,13 +47,13 @@ namespace osu.Game.Overlays.Settings.Sections
}, },
}; };
void reloadSkins() => skinDropdown.Items = skins.GetAllUsableSkins().Select(s => new KeyValuePair<string, SkinInfo>(s.Name, s)); void reloadSkins() => skinDropdown.Items = skins.GetAllUsableSkins().Select(s => new KeyValuePair<string, int>(s.Name, s.ID));
skins.ItemAdded += _ => reloadSkins(); skins.ItemAdded += _ => reloadSkins();
skins.ItemRemoved += _ => reloadSkins(); skins.ItemRemoved += _ => reloadSkins();
reloadSkins(); reloadSkins();
skinDropdown.Bindable = skins.CurrentSkinInfo; skinDropdown.Bindable = config.GetBindable<int>(OsuSetting.Skin);
} }
private class SizeSlider : OsuSliderBar<double> private class SizeSlider : OsuSliderBar<double>

View File

@ -1,13 +1,14 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using osu.Game.Database; using osu.Game.Database;
namespace osu.Game.Skinning namespace osu.Game.Skinning
{ {
public class SkinInfo : IHasFiles<SkinFileInfo>, IHasPrimaryKey, ISoftDelete public class SkinInfo : IHasFiles<SkinFileInfo>, IEquatable<SkinInfo>, IHasPrimaryKey, ISoftDelete
{ {
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; } public int ID { get; set; }
@ -21,5 +22,7 @@ namespace osu.Game.Skinning
public bool DeletePending { get; set; } public bool DeletePending { get; set; }
public static SkinInfo Default { get; } = new SkinInfo { Name = "osu!lazer", Creator = "team osu!" }; public static SkinInfo Default { get; } = new SkinInfo { Name = "osu!lazer", Creator = "team osu!" };
public bool Equals(SkinInfo other) => other != null && ID == other.ID;
} }
} }