mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 06:52:55 +08:00
Avoid triggering SeasonalBackgroundChanged
unless actually required
This commit is contained in:
parent
1e159eb328
commit
32c77ddf71
@ -38,19 +38,21 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
private void load(OsuConfigManager config, SessionStatics sessionStatics)
|
||||
{
|
||||
seasonalBackgroundMode = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode);
|
||||
seasonalBackgroundMode.BindValueChanged(_ => SeasonalBackgroundChanged?.Invoke());
|
||||
seasonalBackgroundMode.BindValueChanged(_ => triggerSeasonalBackgroundChanged());
|
||||
|
||||
seasonalBackgrounds = sessionStatics.GetBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds);
|
||||
seasonalBackgrounds.BindValueChanged(response =>
|
||||
{
|
||||
if (response.NewValue?.Backgrounds?.Count > 0)
|
||||
SeasonalBackgroundChanged?.Invoke();
|
||||
});
|
||||
seasonalBackgrounds.BindValueChanged(_ => triggerSeasonalBackgroundChanged());
|
||||
|
||||
apiState.BindTo(api.State);
|
||||
apiState.BindValueChanged(fetchSeasonalBackgrounds, true);
|
||||
}
|
||||
|
||||
private void triggerSeasonalBackgroundChanged()
|
||||
{
|
||||
if (shouldShowSeasonal)
|
||||
SeasonalBackgroundChanged?.Invoke();
|
||||
}
|
||||
|
||||
private void fetchSeasonalBackgrounds(ValueChangedEvent<APIState> stateChanged)
|
||||
{
|
||||
if (seasonalBackgrounds.Value != null || stateChanged.NewValue != APIState.Online)
|
||||
@ -68,15 +70,10 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
|
||||
public SeasonalBackground LoadNextBackground()
|
||||
{
|
||||
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Never
|
||||
|| (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && !isInSeason))
|
||||
{
|
||||
if (!shouldShowSeasonal)
|
||||
return null;
|
||||
}
|
||||
|
||||
var backgrounds = seasonalBackgrounds.Value?.Backgrounds;
|
||||
if (backgrounds == null || !backgrounds.Any())
|
||||
return null;
|
||||
var backgrounds = seasonalBackgrounds.Value.Backgrounds;
|
||||
|
||||
current = (current + 1) % backgrounds.Count;
|
||||
string url = backgrounds[current].Url;
|
||||
@ -84,6 +81,20 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
return new SeasonalBackground(url);
|
||||
}
|
||||
|
||||
private bool shouldShowSeasonal
|
||||
{
|
||||
get
|
||||
{
|
||||
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Never)
|
||||
return false;
|
||||
|
||||
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && !isInSeason)
|
||||
return false;
|
||||
|
||||
return seasonalBackgrounds.Value?.Backgrounds?.Any() == true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool isInSeason => seasonalBackgrounds.Value != null && DateTimeOffset.Now < seasonalBackgrounds.Value.EndDate;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user