mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 02:32:59 +08:00
Allow song select to refresh the global WorkingBeatmap
after an external update
This commit is contained in:
parent
6999933d33
commit
66a01d1ed2
@ -453,6 +453,12 @@ namespace osu.Game.Beatmaps
|
|||||||
void IWorkingBeatmapCache.Invalidate(BeatmapSetInfo beatmapSetInfo) => workingBeatmapCache.Invalidate(beatmapSetInfo);
|
void IWorkingBeatmapCache.Invalidate(BeatmapSetInfo beatmapSetInfo) => workingBeatmapCache.Invalidate(beatmapSetInfo);
|
||||||
void IWorkingBeatmapCache.Invalidate(BeatmapInfo beatmapInfo) => workingBeatmapCache.Invalidate(beatmapInfo);
|
void IWorkingBeatmapCache.Invalidate(BeatmapInfo beatmapInfo) => workingBeatmapCache.Invalidate(beatmapInfo);
|
||||||
|
|
||||||
|
public event Action<WorkingBeatmap>? OnInvalidated
|
||||||
|
{
|
||||||
|
add => workingBeatmapCache.OnInvalidated += value;
|
||||||
|
remove => workingBeatmapCache.OnInvalidated -= value;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool IsAvailableLocally(BeatmapSetInfo model) => Realm.Run(realm => realm.All<BeatmapSetInfo>().Any(s => s.OnlineID == model.OnlineID));
|
public override bool IsAvailableLocally(BeatmapSetInfo model) => Realm.Run(realm => realm.All<BeatmapSetInfo>().Any(s => s.OnlineID == model.OnlineID));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
namespace osu.Game.Beatmaps
|
||||||
{
|
{
|
||||||
public interface IWorkingBeatmapCache
|
public interface IWorkingBeatmapCache
|
||||||
@ -25,5 +27,7 @@ namespace osu.Game.Beatmaps
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmapInfo">The beatmap info to invalidate any cached entries for.</param>
|
/// <param name="beatmapInfo">The beatmap info to invalidate any cached entries for.</param>
|
||||||
void Invalidate(BeatmapInfo beatmapInfo);
|
void Invalidate(BeatmapInfo beatmapInfo);
|
||||||
|
|
||||||
|
event Action<WorkingBeatmap> OnInvalidated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,13 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
Logger.Log($"Invalidating working beatmap cache for {info}");
|
Logger.Log($"Invalidating working beatmap cache for {info}");
|
||||||
workingCache.Remove(working);
|
workingCache.Remove(working);
|
||||||
|
OnInvalidated?.Invoke(working);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public event Action<WorkingBeatmap> OnInvalidated;
|
||||||
|
|
||||||
public virtual WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo)
|
public virtual WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
if (beatmapInfo?.BeatmapSet == null)
|
if (beatmapInfo?.BeatmapSet == null)
|
||||||
|
@ -296,8 +296,24 @@ namespace osu.Game.Screens.Select
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
modSelectOverlayRegistration = OverlayManager?.RegisterBlockingOverlay(ModSelect);
|
modSelectOverlayRegistration = OverlayManager?.RegisterBlockingOverlay(ModSelect);
|
||||||
|
|
||||||
|
beatmaps.OnInvalidated += workingBeatmapInvalidated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void workingBeatmapInvalidated(WorkingBeatmap working) => Scheduler.AddOnce(w =>
|
||||||
|
{
|
||||||
|
// The global beatmap may have already been updated (ie. by the editor).
|
||||||
|
// Only perform the actual switch if we still need to.
|
||||||
|
if (w == Beatmap.Value)
|
||||||
|
{
|
||||||
|
// Not sure if this refresh is required.
|
||||||
|
var beatmapInfo = beatmaps.QueryBeatmap(b => b.ID == w.BeatmapInfo.ID);
|
||||||
|
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateComponentFromBeatmap(Beatmap.Value);
|
||||||
|
}, working);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the buttons to be displayed in the footer.
|
/// Creates the buttons to be displayed in the footer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -700,6 +716,8 @@ namespace osu.Game.Screens.Select
|
|||||||
music.TrackChanged -= ensureTrackLooping;
|
music.TrackChanged -= ensureTrackLooping;
|
||||||
|
|
||||||
modSelectOverlayRegistration?.Dispose();
|
modSelectOverlayRegistration?.Dispose();
|
||||||
|
|
||||||
|
beatmaps.OnInvalidated -= workingBeatmapInvalidated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user