mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:57:36 +08:00
Move api request outside the scores container
This commit is contained in:
parent
ebff35de66
commit
5d81445454
@ -50,120 +50,123 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var scores = new List<ScoreInfo>
|
var allScores = new APILegacyScores
|
||||||
{
|
{
|
||||||
new ScoreInfo
|
Scores = new List<APILegacyScoreInfo>
|
||||||
{
|
{
|
||||||
User = new User
|
new APILegacyScoreInfo
|
||||||
{
|
{
|
||||||
Id = 6602580,
|
User = new User
|
||||||
Username = @"waaiiru",
|
|
||||||
Country = new Country
|
|
||||||
{
|
{
|
||||||
FullName = @"Spain",
|
Id = 6602580,
|
||||||
FlagName = @"ES",
|
Username = @"waaiiru",
|
||||||
|
Country = new Country
|
||||||
|
{
|
||||||
|
FullName = @"Spain",
|
||||||
|
FlagName = @"ES",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
Mods = new Mod[]
|
||||||
Mods = new Mod[]
|
|
||||||
{
|
|
||||||
new OsuModDoubleTime(),
|
|
||||||
new OsuModHidden(),
|
|
||||||
new OsuModFlashlight(),
|
|
||||||
new OsuModHardRock(),
|
|
||||||
},
|
|
||||||
Rank = ScoreRank.XH,
|
|
||||||
PP = 200,
|
|
||||||
MaxCombo = 1234,
|
|
||||||
TotalScore = 1234567890,
|
|
||||||
Accuracy = 1,
|
|
||||||
},
|
|
||||||
new ScoreInfo
|
|
||||||
{
|
|
||||||
User = new User
|
|
||||||
{
|
|
||||||
Id = 4608074,
|
|
||||||
Username = @"Skycries",
|
|
||||||
Country = new Country
|
|
||||||
{
|
{
|
||||||
FullName = @"Brazil",
|
new OsuModDoubleTime(),
|
||||||
FlagName = @"BR",
|
new OsuModHidden(),
|
||||||
|
new OsuModFlashlight(),
|
||||||
|
new OsuModHardRock(),
|
||||||
},
|
},
|
||||||
|
Rank = ScoreRank.XH,
|
||||||
|
PP = 200,
|
||||||
|
MaxCombo = 1234,
|
||||||
|
TotalScore = 1234567890,
|
||||||
|
Accuracy = 1,
|
||||||
},
|
},
|
||||||
Mods = new Mod[]
|
new APILegacyScoreInfo
|
||||||
{
|
{
|
||||||
new OsuModDoubleTime(),
|
User = new User
|
||||||
new OsuModHidden(),
|
|
||||||
new OsuModFlashlight(),
|
|
||||||
},
|
|
||||||
Rank = ScoreRank.S,
|
|
||||||
PP = 190,
|
|
||||||
MaxCombo = 1234,
|
|
||||||
TotalScore = 1234789,
|
|
||||||
Accuracy = 0.9997,
|
|
||||||
},
|
|
||||||
new ScoreInfo
|
|
||||||
{
|
|
||||||
User = new User
|
|
||||||
{
|
|
||||||
Id = 1014222,
|
|
||||||
Username = @"eLy",
|
|
||||||
Country = new Country
|
|
||||||
{
|
{
|
||||||
FullName = @"Japan",
|
Id = 4608074,
|
||||||
FlagName = @"JP",
|
Username = @"Skycries",
|
||||||
|
Country = new Country
|
||||||
|
{
|
||||||
|
FullName = @"Brazil",
|
||||||
|
FlagName = @"BR",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
Mods = new Mod[]
|
||||||
Mods = new Mod[]
|
|
||||||
{
|
|
||||||
new OsuModDoubleTime(),
|
|
||||||
new OsuModHidden(),
|
|
||||||
},
|
|
||||||
Rank = ScoreRank.B,
|
|
||||||
PP = 180,
|
|
||||||
MaxCombo = 1234,
|
|
||||||
TotalScore = 12345678,
|
|
||||||
Accuracy = 0.9854,
|
|
||||||
},
|
|
||||||
new ScoreInfo
|
|
||||||
{
|
|
||||||
User = new User
|
|
||||||
{
|
|
||||||
Id = 1541390,
|
|
||||||
Username = @"Toukai",
|
|
||||||
Country = new Country
|
|
||||||
{
|
{
|
||||||
FullName = @"Canada",
|
new OsuModDoubleTime(),
|
||||||
FlagName = @"CA",
|
new OsuModHidden(),
|
||||||
|
new OsuModFlashlight(),
|
||||||
},
|
},
|
||||||
|
Rank = ScoreRank.S,
|
||||||
|
PP = 190,
|
||||||
|
MaxCombo = 1234,
|
||||||
|
TotalScore = 1234789,
|
||||||
|
Accuracy = 0.9997,
|
||||||
},
|
},
|
||||||
Mods = new Mod[]
|
new APILegacyScoreInfo
|
||||||
{
|
{
|
||||||
new OsuModDoubleTime(),
|
User = new User
|
||||||
},
|
|
||||||
Rank = ScoreRank.C,
|
|
||||||
PP = 170,
|
|
||||||
MaxCombo = 1234,
|
|
||||||
TotalScore = 1234567,
|
|
||||||
Accuracy = 0.8765,
|
|
||||||
},
|
|
||||||
new ScoreInfo
|
|
||||||
{
|
|
||||||
User = new User
|
|
||||||
{
|
|
||||||
Id = 7151382,
|
|
||||||
Username = @"Mayuri Hana",
|
|
||||||
Country = new Country
|
|
||||||
{
|
{
|
||||||
FullName = @"Thailand",
|
Id = 1014222,
|
||||||
FlagName = @"TH",
|
Username = @"eLy",
|
||||||
|
Country = new Country
|
||||||
|
{
|
||||||
|
FullName = @"Japan",
|
||||||
|
FlagName = @"JP",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
Mods = new Mod[]
|
||||||
|
{
|
||||||
|
new OsuModDoubleTime(),
|
||||||
|
new OsuModHidden(),
|
||||||
|
},
|
||||||
|
Rank = ScoreRank.B,
|
||||||
|
PP = 180,
|
||||||
|
MaxCombo = 1234,
|
||||||
|
TotalScore = 12345678,
|
||||||
|
Accuracy = 0.9854,
|
||||||
},
|
},
|
||||||
Rank = ScoreRank.D,
|
new APILegacyScoreInfo
|
||||||
PP = 160,
|
{
|
||||||
MaxCombo = 1234,
|
User = new User
|
||||||
TotalScore = 123456,
|
{
|
||||||
Accuracy = 0.6543,
|
Id = 1541390,
|
||||||
},
|
Username = @"Toukai",
|
||||||
|
Country = new Country
|
||||||
|
{
|
||||||
|
FullName = @"Canada",
|
||||||
|
FlagName = @"CA",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Mods = new Mod[]
|
||||||
|
{
|
||||||
|
new OsuModDoubleTime(),
|
||||||
|
},
|
||||||
|
Rank = ScoreRank.C,
|
||||||
|
PP = 170,
|
||||||
|
MaxCombo = 1234,
|
||||||
|
TotalScore = 1234567,
|
||||||
|
Accuracy = 0.8765,
|
||||||
|
},
|
||||||
|
new APILegacyScoreInfo
|
||||||
|
{
|
||||||
|
User = new User
|
||||||
|
{
|
||||||
|
Id = 7151382,
|
||||||
|
Username = @"Mayuri Hana",
|
||||||
|
Country = new Country
|
||||||
|
{
|
||||||
|
FullName = @"Thailand",
|
||||||
|
FlagName = @"TH",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Rank = ScoreRank.D,
|
||||||
|
PP = 160,
|
||||||
|
MaxCombo = 1234,
|
||||||
|
TotalScore = 123456,
|
||||||
|
Accuracy = 0.6543,
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var myBestScore = new APILegacyUserTopScoreInfo
|
var myBestScore = new APILegacyUserTopScoreInfo
|
||||||
@ -189,7 +192,39 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
Position = 1337,
|
Position = 1337,
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var s in scores)
|
var oneScore = new APILegacyScores
|
||||||
|
{
|
||||||
|
Scores = new List<APILegacyScoreInfo>
|
||||||
|
{
|
||||||
|
new APILegacyScoreInfo
|
||||||
|
{
|
||||||
|
User = new User
|
||||||
|
{
|
||||||
|
Id = 6602580,
|
||||||
|
Username = @"waaiiru",
|
||||||
|
Country = new Country
|
||||||
|
{
|
||||||
|
FullName = @"Spain",
|
||||||
|
FlagName = @"ES",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Mods = new Mod[]
|
||||||
|
{
|
||||||
|
new OsuModDoubleTime(),
|
||||||
|
new OsuModHidden(),
|
||||||
|
new OsuModFlashlight(),
|
||||||
|
new OsuModHardRock(),
|
||||||
|
},
|
||||||
|
Rank = ScoreRank.XH,
|
||||||
|
PP = 200,
|
||||||
|
MaxCombo = 1234,
|
||||||
|
TotalScore = 1234567890,
|
||||||
|
Accuracy = 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var s in allScores.Scores)
|
||||||
{
|
{
|
||||||
s.Statistics.Add(HitResult.Great, RNG.Next(2000));
|
s.Statistics.Add(HitResult.Great, RNG.Next(2000));
|
||||||
s.Statistics.Add(HitResult.Good, RNG.Next(2000));
|
s.Statistics.Add(HitResult.Good, RNG.Next(2000));
|
||||||
@ -199,16 +234,16 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
AddStep("Load all scores", () =>
|
AddStep("Load all scores", () =>
|
||||||
{
|
{
|
||||||
scoresContainer.Scores = scores;
|
allScores.UserScore = null;
|
||||||
scoresContainer.UserScore = myBestScore;
|
scoresContainer.Scores = allScores;
|
||||||
});
|
});
|
||||||
AddStep("Load null scores", () =>
|
AddStep("Load null scores", () => scoresContainer.Scores = null);
|
||||||
|
AddStep("Load only one score", () => scoresContainer.Scores = oneScore);
|
||||||
|
AddStep("Load scores with my best", () =>
|
||||||
{
|
{
|
||||||
scoresContainer.Scores = null;
|
allScores.UserScore = myBestScore;
|
||||||
scoresContainer.UserScore = null;
|
scoresContainer.Scores = allScores;
|
||||||
});
|
});
|
||||||
AddStep("Load only one score", () => scoresContainer.Scores = new[] { scores.First() });
|
|
||||||
AddStep("Add my best score", () => scoresContainer.UserScore = myBestScore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
@ -5,15 +5,11 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Online.API.Requests;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Game.Scoring;
|
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapSet.Scores
|
namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||||
@ -29,9 +25,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
private readonly FillFlowContainer topScoresContainer;
|
private readonly FillFlowContainer topScoresContainer;
|
||||||
private readonly LoadingAnimation loadingAnimation;
|
private readonly LoadingAnimation loadingAnimation;
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private IAPIProvider api { get; set; }
|
|
||||||
|
|
||||||
public ScoresContainer()
|
public ScoresContainer()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
@ -72,7 +65,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
loadingAnimation = new LoadingAnimation
|
loadingAnimation = new LoadingAnimation
|
||||||
{
|
{
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
Margin = new MarginPadding(20)
|
Margin = new MarginPadding(20),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -84,87 +77,46 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
updateDisplay();
|
updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool loading
|
public bool Loading
|
||||||
{
|
{
|
||||||
set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration);
|
set
|
||||||
|
{
|
||||||
|
loadingAnimation.FadeTo(value ? 1 : 0, fade_duration);
|
||||||
|
|
||||||
|
if (value)
|
||||||
|
Scores = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private GetScoresRequest getScoresRequest;
|
private APILegacyScores scores;
|
||||||
private IReadOnlyList<ScoreInfo> scores;
|
|
||||||
|
|
||||||
public IReadOnlyList<ScoreInfo> Scores
|
public APILegacyScores Scores
|
||||||
{
|
{
|
||||||
get => scores;
|
get => scores;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
getScoresRequest?.Cancel();
|
|
||||||
scores = value;
|
scores = value;
|
||||||
|
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private APILegacyUserTopScoreInfo userScore;
|
|
||||||
|
|
||||||
public APILegacyUserTopScoreInfo UserScore
|
|
||||||
{
|
|
||||||
get => userScore;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
getScoresRequest?.Cancel();
|
|
||||||
userScore = value;
|
|
||||||
|
|
||||||
updateDisplay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private BeatmapInfo beatmap;
|
|
||||||
|
|
||||||
public BeatmapInfo Beatmap
|
|
||||||
{
|
|
||||||
get => beatmap;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
beatmap = value;
|
|
||||||
|
|
||||||
Scores = null;
|
|
||||||
|
|
||||||
if (beatmap?.OnlineBeatmapID.HasValue != true)
|
|
||||||
return;
|
|
||||||
|
|
||||||
loading = true;
|
|
||||||
|
|
||||||
getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
|
|
||||||
getScoresRequest.Success += r => Schedule(() =>
|
|
||||||
{
|
|
||||||
scores = r.Scores;
|
|
||||||
userScore = r.UserScore;
|
|
||||||
updateDisplay();
|
|
||||||
});
|
|
||||||
api.Queue(getScoresRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDisplay()
|
private void updateDisplay()
|
||||||
{
|
{
|
||||||
loading = false;
|
|
||||||
topScoresContainer.Clear();
|
topScoresContainer.Clear();
|
||||||
|
|
||||||
scoreTable.Scores = scores?.Count > 1 ? scores : new List<ScoreInfo>();
|
scoreTable.Scores = scores?.Scores.Count > 1 ? scores.Scores : new List<APILegacyScoreInfo>();
|
||||||
scoreTable.FadeTo(scores?.Count > 1 ? 1 : 0);
|
scoreTable.FadeTo(scores?.Scores.Count > 1 ? 1 : 0);
|
||||||
|
|
||||||
if (scores?.Any() == true)
|
if (scores?.Scores.Any() == true)
|
||||||
{
|
{
|
||||||
topScoresContainer.Add(new DrawableTopScore(scores.FirstOrDefault()));
|
topScoresContainer.Add(new DrawableTopScore(scores.Scores.FirstOrDefault()));
|
||||||
|
|
||||||
|
var userScore = scores.UserScore;
|
||||||
|
|
||||||
if (userScore != null && userScore.Position != 1)
|
if (userScore != null && userScore.Position != 1)
|
||||||
topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position));
|
topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
|
||||||
{
|
|
||||||
getScoresRequest?.Cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ using osu.Framework.Input.Events;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Overlays.BeatmapSet;
|
using osu.Game.Overlays.BeatmapSet;
|
||||||
using osu.Game.Overlays.BeatmapSet.Scores;
|
using osu.Game.Overlays.BeatmapSet.Scores;
|
||||||
@ -30,9 +31,14 @@ namespace osu.Game.Overlays
|
|||||||
protected readonly Header Header;
|
protected readonly Header Header;
|
||||||
|
|
||||||
private RulesetStore rulesets;
|
private RulesetStore rulesets;
|
||||||
|
private ScoresContainer scores;
|
||||||
|
private GetScoresRequest getScoresRequest;
|
||||||
|
|
||||||
private readonly Bindable<BeatmapSetInfo> beatmapSet = new Bindable<BeatmapSetInfo>();
|
private readonly Bindable<BeatmapSetInfo> beatmapSet = new Bindable<BeatmapSetInfo>();
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
// receive input outside our bounds so we can trigger a close event on ourselves.
|
// receive input outside our bounds so we can trigger a close event on ourselves.
|
||||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||||
|
|
||||||
@ -40,7 +46,6 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
OsuScrollContainer scroll;
|
OsuScrollContainer scroll;
|
||||||
Info info;
|
Info info;
|
||||||
ScoresContainer scores;
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -74,12 +79,33 @@ namespace osu.Game.Overlays
|
|||||||
Header.Picker.Beatmap.ValueChanged += b =>
|
Header.Picker.Beatmap.ValueChanged += b =>
|
||||||
{
|
{
|
||||||
info.Beatmap = b.NewValue;
|
info.Beatmap = b.NewValue;
|
||||||
scores.Beatmap = b.NewValue;
|
getScores(b.NewValue);
|
||||||
|
|
||||||
scroll.ScrollToStart();
|
scroll.ScrollToStart();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getScores(BeatmapInfo b)
|
||||||
|
{
|
||||||
|
getScoresRequest?.Cancel();
|
||||||
|
|
||||||
|
if (b?.OnlineBeatmapID.HasValue != true)
|
||||||
|
{
|
||||||
|
scores.Scores = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scores.Loading = true;
|
||||||
|
|
||||||
|
getScoresRequest = new GetScoresRequest(b, b.Ruleset);
|
||||||
|
getScoresRequest.Success += r => Schedule(() =>
|
||||||
|
{
|
||||||
|
scores.Scores = r;
|
||||||
|
scores.Loading = false;
|
||||||
|
});
|
||||||
|
api.Queue(getScoresRequest);
|
||||||
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(RulesetStore rulesets)
|
private void load(RulesetStore rulesets)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user