mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 21:02:55 +08:00
Update existing usages to use SubscribeToPropertyChanged
This commit is contained in:
parent
35f532fefa
commit
cecc746f9e
@ -86,26 +86,10 @@ namespace osu.Game.Screens.Play
|
||||
userAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset);
|
||||
userAudioOffset.BindValueChanged(offset => userGlobalOffsetClock.Offset = offset.NewValue, true);
|
||||
|
||||
beatmapOffsetSubscription = realm.RegisterCustomSubscription(r =>
|
||||
{
|
||||
var userSettings = r.Find<BeatmapInfo>(beatmap.BeatmapInfo.ID)?.UserSettings;
|
||||
|
||||
if (userSettings == null) // only the case for tests.
|
||||
return null;
|
||||
|
||||
void onUserSettingsOnPropertyChanged(object sender, PropertyChangedEventArgs args)
|
||||
{
|
||||
if (args.PropertyName == nameof(BeatmapUserSettings.Offset))
|
||||
updateOffset();
|
||||
}
|
||||
|
||||
updateOffset();
|
||||
userSettings.PropertyChanged += onUserSettingsOnPropertyChanged;
|
||||
|
||||
return new InvokeOnDisposal(() => userSettings.PropertyChanged -= onUserSettingsOnPropertyChanged);
|
||||
|
||||
void updateOffset() => userBeatmapOffsetClock.Offset = userSettings.Offset;
|
||||
});
|
||||
beatmapOffsetSubscription = realm.SubscribeToPropertyChanged(
|
||||
r => r.Find<BeatmapInfo>(beatmap.BeatmapInfo.ID)?.UserSettings,
|
||||
settings => settings.Offset,
|
||||
val => userBeatmapOffsetClock.Offset = val);
|
||||
|
||||
// sane default provided by ruleset.
|
||||
startOffset = gameplayStartTime;
|
||||
|
@ -2,13 +2,13 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
@ -94,24 +94,13 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
|
||||
ReferenceScore.BindValueChanged(scoreChanged, true);
|
||||
|
||||
beatmapOffsetSubscription = realm.RegisterCustomSubscription(r =>
|
||||
{
|
||||
var userSettings = r.Find<BeatmapInfo>(beatmap.Value.BeatmapInfo.ID)?.UserSettings;
|
||||
|
||||
if (userSettings == null) // only the case for tests.
|
||||
return null;
|
||||
|
||||
Current.Value = userSettings.Offset;
|
||||
userSettings.PropertyChanged += onUserSettingsOnPropertyChanged;
|
||||
|
||||
return new InvokeOnDisposal(() => userSettings.PropertyChanged -= onUserSettingsOnPropertyChanged);
|
||||
|
||||
void onUserSettingsOnPropertyChanged(object sender, PropertyChangedEventArgs args)
|
||||
beatmapOffsetSubscription = realm.SubscribeToPropertyChanged(
|
||||
realm => realm.Find<BeatmapInfo>(beatmap.Value.BeatmapInfo.ID)?.UserSettings,
|
||||
settings => settings.Offset,
|
||||
val =>
|
||||
{
|
||||
if (args.PropertyName == nameof(BeatmapUserSettings.Offset))
|
||||
Current.Value = userSettings.Offset;
|
||||
}
|
||||
});
|
||||
Current.Value = val;
|
||||
});
|
||||
|
||||
Current.BindValueChanged(currentChanged);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user