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