mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 19:43:22 +08:00
Create placeholder classes instead of changing Children.
- Add MessagePlaceholder - Use MessagePlacholder for when API is offline/user isn't a supporter - Remove unnecessary placeholderFlow field - Hook into API state changes
This commit is contained in:
parent
6d471da459
commit
23f4799840
@ -34,7 +34,6 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
|
|
||||||
private readonly ScrollContainer scrollContainer;
|
private readonly ScrollContainer scrollContainer;
|
||||||
private readonly Container placeholderContainer;
|
private readonly Container placeholderContainer;
|
||||||
private readonly FillFlowContainer placeholderFlow;
|
|
||||||
|
|
||||||
private FillFlowContainer<LeaderboardScore> scrollFlow;
|
private FillFlowContainer<LeaderboardScore> scrollFlow;
|
||||||
|
|
||||||
@ -63,22 +62,7 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
|
|
||||||
if (!scores.Any())
|
if (!scores.Any())
|
||||||
{
|
{
|
||||||
placeholderFlow.Children = new Drawable[]
|
replacePlaceholder(new MessagePlaceholder(@"No records yet!"));
|
||||||
{
|
|
||||||
new SpriteIcon
|
|
||||||
{
|
|
||||||
Icon = FontAwesome.fa_exclamation_circle,
|
|
||||||
Size = new Vector2(26),
|
|
||||||
Margin = new MarginPadding { Right = 10 },
|
|
||||||
},
|
|
||||||
new OsuSpriteText
|
|
||||||
{
|
|
||||||
Text = @"No records yet!",
|
|
||||||
TextSize = 22,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
placeholderContainer.FadeIn(fade_duration);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,17 +119,9 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
placeholderContainer = new Container
|
placeholderContainer = new Container
|
||||||
{
|
{
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
RelativeSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Anchor = Anchor.Centre,
|
||||||
{
|
Origin = Anchor.Centre,
|
||||||
placeholderFlow = new FillFlowContainer
|
|
||||||
{
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -181,6 +157,9 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
|
|
||||||
if (osuGame != null)
|
if (osuGame != null)
|
||||||
osuGame.Ruleset.ValueChanged += handleRulesetChange;
|
osuGame.Ruleset.ValueChanged += handleRulesetChange;
|
||||||
|
|
||||||
|
if (api != null)
|
||||||
|
api.OnStateChange += handleApiStateChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
@ -195,6 +174,23 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
|
|
||||||
private void handleRulesetChange(RulesetInfo ruleset) => UpdateScores();
|
private void handleRulesetChange(RulesetInfo ruleset) => UpdateScores();
|
||||||
|
|
||||||
|
private void handleApiStateChange(APIState oldState, APIState newState)
|
||||||
|
{
|
||||||
|
if (Scope == LeaderboardScope.Local)
|
||||||
|
// No need to respond to API state change while current scope is local
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (newState == APIState.Offline)
|
||||||
|
{
|
||||||
|
Scores = null;
|
||||||
|
replacePlaceholder(new MessagePlaceholder(@"Please login to view online leaderboards!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newState == APIState.Online)
|
||||||
|
UpdateScores();
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void UpdateScores()
|
protected virtual void UpdateScores()
|
||||||
{
|
{
|
||||||
if (!IsLoaded) return;
|
if (!IsLoaded) return;
|
||||||
@ -215,6 +211,20 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!api.IsLoggedIn)
|
||||||
|
{
|
||||||
|
loading.Hide();
|
||||||
|
replacePlaceholder(new MessagePlaceholder(@"Please login to view online leaderboards!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Scope != LeaderboardScope.Global && !api.LocalUser.Value.IsSupporter)
|
||||||
|
{
|
||||||
|
loading.Hide();
|
||||||
|
replacePlaceholder(new MessagePlaceholder(@"Please invest in a supporter tag to view this leaderboard!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
getScoresRequest = new GetScoresRequest(Beatmap, osuGame?.Ruleset.Value ?? Beatmap.Ruleset, Scope);
|
getScoresRequest = new GetScoresRequest(Beatmap, osuGame?.Ruleset.Value ?? Beatmap.Ruleset, Scope);
|
||||||
getScoresRequest.Success += r =>
|
getScoresRequest.Success += r =>
|
||||||
{
|
{
|
||||||
@ -230,24 +240,21 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
if (e is OperationCanceledException) return;
|
if (e is OperationCanceledException) return;
|
||||||
|
|
||||||
Scores = null;
|
Scores = null;
|
||||||
placeholderFlow.Children = new Drawable[]
|
replacePlaceholder(new RetrievalFailurePlaceholder
|
||||||
{
|
{
|
||||||
new RetryButton
|
OnRetry = UpdateScores,
|
||||||
{
|
});
|
||||||
Action = UpdateScores,
|
|
||||||
Margin = new MarginPadding { Right = 10 },
|
|
||||||
},
|
|
||||||
new OsuSpriteText
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopLeft,
|
|
||||||
Text = @"Couldn't retrieve scores!",
|
|
||||||
TextSize = 22,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
placeholderContainer.FadeIn(fade_duration);
|
|
||||||
Logger.Error(e, @"Couldn't fetch beatmap scores!");
|
Logger.Error(e, @"Couldn't fetch beatmap scores!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void replacePlaceholder(Drawable placeholder)
|
||||||
|
{
|
||||||
|
placeholderContainer.FadeOutFromOne(fade_duration, Easing.OutQuint);
|
||||||
|
placeholderContainer.Clear(true);
|
||||||
|
placeholderContainer.Child = placeholder;
|
||||||
|
placeholderContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
@ -277,6 +284,54 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MessagePlaceholder : FillFlowContainer
|
||||||
|
{
|
||||||
|
public MessagePlaceholder(string message)
|
||||||
|
{
|
||||||
|
Direction = FillDirection.Horizontal;
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new SpriteIcon
|
||||||
|
{
|
||||||
|
Icon = FontAwesome.fa_exclamation_circle,
|
||||||
|
Size = new Vector2(26),
|
||||||
|
Margin = new MarginPadding { Right = 10 },
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Text = message,
|
||||||
|
TextSize = 22,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RetrievalFailurePlaceholder : FillFlowContainer
|
||||||
|
{
|
||||||
|
public Action OnRetry;
|
||||||
|
|
||||||
|
public RetrievalFailurePlaceholder()
|
||||||
|
{
|
||||||
|
Direction = FillDirection.Horizontal;
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new RetryButton
|
||||||
|
{
|
||||||
|
Action = () => OnRetry?.Invoke(),
|
||||||
|
Margin = new MarginPadding { Right = 10 },
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopLeft,
|
||||||
|
Text = @"Couldn't retrieve scores!",
|
||||||
|
TextSize = 22,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class RetryButton : BeatSyncedContainer
|
private class RetryButton : BeatSyncedContainer
|
||||||
{
|
{
|
||||||
private readonly SpriteIcon icon;
|
private readonly SpriteIcon icon;
|
||||||
|
Loading…
Reference in New Issue
Block a user