1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 13:33:03 +08:00

Subscribe to changes in offset

This commit is contained in:
Dean Herbert 2022-03-01 18:29:04 +09:00
parent 071ba5c1df
commit bb8caabb8b

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using osu.Framework; using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -70,13 +71,38 @@ namespace osu.Game.Screens.Play
firstHitObjectTime = beatmap.Beatmap.HitObjects.First().StartTime; firstHitObjectTime = beatmap.Beatmap.HitObjects.First().StartTime;
} }
[BackgroundDependencyLoader] [Resolved]
private void load(OsuConfigManager config, RealmAccess realm) private RealmAccess realm { get; set; }
[Resolved]
private OsuConfigManager config { get; set; }
private IDisposable beatmapOffsetSubscription;
protected override void LoadComplete()
{ {
base.LoadComplete();
userAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset); userAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset);
userAudioOffset.BindValueChanged(offset => userGlobalOffsetClock.Offset = offset.NewValue, true); userAudioOffset.BindValueChanged(offset => userGlobalOffsetClock.Offset = offset.NewValue, true);
userBeatmapOffsetClock.Offset = realm.Run(r => r.Find<BeatmapInfo>(beatmap.BeatmapInfo.ID).UserSettings?.Offset) ?? 0; beatmapOffsetSubscription = realm.RegisterCustomSubscription(r =>
{
var userSettings = r.Find<BeatmapInfo>(beatmap.BeatmapInfo.ID).UserSettings;
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;
});
// sane default provided by ruleset. // sane default provided by ruleset.
startOffset = gameplayStartTime; startOffset = gameplayStartTime;
@ -214,6 +240,7 @@ namespace osu.Game.Screens.Play
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
beatmapOffsetSubscription?.Dispose();
removeSourceClockAdjustments(); removeSourceClockAdjustments();
} }