1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-20 18:23:21 +08:00

Merge pull request #2 from ppy/master

Sync fork
This commit is contained in:
Oskar Solecki 2019-07-11 15:10:22 +02:00 committed by GitHub
commit af45abb7eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 314 additions and 202 deletions

View File

@ -70,7 +70,7 @@ namespace osu.Game.Tests.Visual.Online
}); });
channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel); channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel);
channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.NewValue.ToString(); channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.NewValue;
AddStep("Add random private channel", addRandomPrivateChannel); AddStep("Add random private channel", addRandomPrivateChannel);
AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2); AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2);

View File

@ -3,19 +3,18 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
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.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Game.Graphics; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.BeatmapSet.Scores; using osu.Game.Overlays.BeatmapSet.Scores;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Users; using osu.Game.Users;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -30,11 +29,9 @@ namespace osu.Game.Tests.Visual.Online
typeof(ScoreTableRowBackground), typeof(ScoreTableRowBackground),
}; };
private readonly Box background;
public TestSceneScoresContainer() public TestSceneScoresContainer()
{ {
ScoresContainer scoresContainer; TestScoresContainer scoresContainer;
Child = new Container Child = new Container
{ {
@ -44,14 +41,20 @@ namespace osu.Game.Tests.Visual.Online
Width = 0.8f, Width = 0.8f,
Children = new Drawable[] Children = new Drawable[]
{ {
background = new Box { RelativeSizeAxes = Axes.Both }, new Box
scoresContainer = new ScoresContainer(), {
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
scoresContainer = new TestScoresContainer(),
} }
}; };
var scores = new List<ScoreInfo> var allScores = new APILegacyScores
{ {
new ScoreInfo Scores = new List<APILegacyScoreInfo>
{
new APILegacyScoreInfo
{ {
User = new User User = new User
{ {
@ -76,7 +79,7 @@ namespace osu.Game.Tests.Visual.Online
TotalScore = 1234567890, TotalScore = 1234567890,
Accuracy = 1, Accuracy = 1,
}, },
new ScoreInfo new APILegacyScoreInfo
{ {
User = new User User = new User
{ {
@ -100,7 +103,7 @@ namespace osu.Game.Tests.Visual.Online
TotalScore = 1234789, TotalScore = 1234789,
Accuracy = 0.9997, Accuracy = 0.9997,
}, },
new ScoreInfo new APILegacyScoreInfo
{ {
User = new User User = new User
{ {
@ -123,7 +126,7 @@ namespace osu.Game.Tests.Visual.Online
TotalScore = 12345678, TotalScore = 12345678,
Accuracy = 0.9854, Accuracy = 0.9854,
}, },
new ScoreInfo new APILegacyScoreInfo
{ {
User = new User User = new User
{ {
@ -145,7 +148,7 @@ namespace osu.Game.Tests.Visual.Online
TotalScore = 1234567, TotalScore = 1234567,
Accuracy = 0.8765, Accuracy = 0.8765,
}, },
new ScoreInfo new APILegacyScoreInfo
{ {
User = new User User = new User
{ {
@ -163,9 +166,65 @@ namespace osu.Game.Tests.Visual.Online
TotalScore = 123456, TotalScore = 123456,
Accuracy = 0.6543, Accuracy = 0.6543,
}, },
}
}; };
foreach (var s in scores) var myBestScore = new APILegacyUserTopScoreInfo
{
Score = 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,
},
Position = 1337,
};
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));
@ -173,15 +232,26 @@ namespace osu.Game.Tests.Visual.Online
s.Statistics.Add(HitResult.Miss, RNG.Next(2000)); s.Statistics.Add(HitResult.Miss, RNG.Next(2000));
} }
AddStep("Load all scores", () => scoresContainer.Scores = scores); AddStep("Load all scores", () =>
{
allScores.UserScore = null;
scoresContainer.Scores = allScores;
});
AddStep("Load null scores", () => scoresContainer.Scores = null); AddStep("Load null scores", () => scoresContainer.Scores = null);
AddStep("Load only one score", () => scoresContainer.Scores = new[] { scores.First() }); AddStep("Load only one score", () => scoresContainer.Scores = oneScore);
AddStep("Load scores with my best", () =>
{
allScores.UserScore = myBestScore;
scoresContainer.Scores = allScores;
});
} }
[BackgroundDependencyLoader] private class TestScoresContainer : ScoresContainer
private void load(OsuColour colours)
{ {
background.Colour = colours.Gray2; public new APILegacyScores Scores
{
set => base.Scores = value;
}
} }
} }
} }

View File

@ -14,8 +14,6 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
public class TestSceneBackButton : OsuTestScene public class TestSceneBackButton : OsuTestScene
{ {
private readonly BackButton button;
public override IReadOnlyList<Type> RequiredTypes => new[] public override IReadOnlyList<Type> RequiredTypes => new[]
{ {
typeof(TwoLayerButton) typeof(TwoLayerButton)
@ -23,6 +21,8 @@ namespace osu.Game.Tests.Visual.UserInterface
public TestSceneBackButton() public TestSceneBackButton()
{ {
BackButton button;
Child = new Container Child = new Container
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
@ -40,11 +40,12 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Action = () => button.Hide(),
} }
} }
}; };
button.Action = () => button.Hide();
AddStep("show button", () => button.Show()); AddStep("show button", () => button.Show());
AddStep("hide button", () => button.Hide()); AddStep("hide button", () => button.Hide());
} }

View File

@ -48,7 +48,7 @@ namespace osu.Game.Tests.Visual.UserInterface
}, },
}; };
breadcrumbs.Current.ValueChanged += screen => titleText.Text = $"Changed to {screen.NewValue.ToString()}"; breadcrumbs.Current.ValueChanged += screen => titleText.Text = $"Changed to {screen.NewValue}";
breadcrumbs.Current.TriggerChange(); breadcrumbs.Current.TriggerChange();
waitForCurrent(); waitForCurrent();

View File

@ -42,6 +42,14 @@ namespace osu.Game.Online.API.Requests
score.Beatmap = beatmap; score.Beatmap = beatmap;
score.Ruleset = ruleset; score.Ruleset = ruleset;
} }
var userScore = r.UserScore;
if (userScore != null)
{
userScore.Score.Beatmap = beatmap;
userScore.Score.Ruleset = ruleset;
}
} }
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores{createQueryParameters()}"; protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores{createQueryParameters()}";

View File

@ -72,7 +72,7 @@ namespace osu.Game.Online.API.Requests.Responses
StarDifficulty = starDifficulty, StarDifficulty = starDifficulty,
OnlineBeatmapID = OnlineBeatmapID, OnlineBeatmapID = OnlineBeatmapID,
Version = version, Version = version,
Length = TimeSpan.FromSeconds(length).Milliseconds, Length = TimeSpan.FromSeconds(length).TotalMilliseconds,
Status = Status, Status = Status,
BeatmapSet = set, BeatmapSet = set,
Metrics = metrics, Metrics = metrics,

View File

@ -10,5 +10,17 @@ namespace osu.Game.Online.API.Requests.Responses
{ {
[JsonProperty(@"scores")] [JsonProperty(@"scores")]
public List<APILegacyScoreInfo> Scores; public List<APILegacyScoreInfo> Scores;
[JsonProperty(@"userScore")]
public APILegacyUserTopScoreInfo UserScore;
}
public class APILegacyUserTopScoreInfo
{
[JsonProperty(@"position")]
public int Position;
[JsonProperty(@"score")]
public APILegacyScoreInfo Score;
} }
} }

View File

@ -203,8 +203,13 @@ namespace osu.Game.Online.Leaderboards
public void APIStateChanged(IAPIProvider api, APIState state) public void APIStateChanged(IAPIProvider api, APIState state)
{ {
if (state == APIState.Online) switch (state)
{
case APIState.Online:
case APIState.Offline:
UpdateScores(); UpdateScores();
break;
}
} }
protected void UpdateScores() protected void UpdateScores()

View File

@ -23,10 +23,8 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
private Color4 backgroundHoveredColour; private Color4 backgroundHoveredColour;
private readonly Box background; private readonly Box background;
private readonly TopScoreUserSection userSection;
private readonly TopScoreStatisticsSection statisticsSection;
public DrawableTopScore() public DrawableTopScore(ScoreInfo score, int position = 1)
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -61,16 +59,19 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
new Drawable[] new Drawable[]
{ {
userSection = new TopScoreUserSection new TopScoreUserSection
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Score = score,
ScorePosition = position,
}, },
null, null,
statisticsSection = new TopScoreStatisticsSection new TopScoreStatisticsSection
{ {
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
Score = score,
} }
}, },
}, },
@ -91,18 +92,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
background.Colour = backgroundIdleColour; background.Colour = backgroundIdleColour;
} }
/// <summary>
/// Sets the score to be displayed.
/// </summary>
public ScoreInfo Score
{
set
{
userSection.Score = value;
statisticsSection.Score = value;
}
}
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
background.FadeColour(backgroundHoveredColour, fade_duration, Easing.OutQuint); background.FadeColour(backgroundHoveredColour, fade_duration, Easing.OutQuint);

View File

@ -59,7 +59,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Content = null; Content = null;
backgroundFlow.Clear(); backgroundFlow.Clear();
if (value == null || !value.Any()) if (value?.Any() != true)
return; return;
for (int i = 0; i < value.Count; i++) for (int i = 0; i < value.Count; i++)

View File

@ -5,15 +5,14 @@ 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 osuTK;
using System.Linq;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Beatmaps;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osuTK;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Scoring;
namespace osu.Game.Overlays.BeatmapSet.Scores namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
@ -24,18 +23,65 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
private readonly Box background; private readonly Box background;
private readonly ScoreTable scoreTable; private readonly ScoreTable scoreTable;
private readonly FillFlowContainer topScoresContainer;
private readonly DrawableTopScore topScore;
private readonly LoadingAnimation loadingAnimation; private readonly LoadingAnimation loadingAnimation;
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
private GetScoresRequest getScoresRequest;
private BeatmapInfo beatmap;
public BeatmapInfo Beatmap
{
get => beatmap;
set
{
if (beatmap == value)
return;
beatmap = value;
getScores(beatmap);
}
}
protected APILegacyScores Scores
{
set
{
Schedule(() =>
{
loading = false;
topScoresContainer.Clear();
if (value?.Scores.Any() != true)
{
scoreTable.Scores = null;
scoreTable.Hide();
return;
}
scoreTable.Scores = value.Scores;
scoreTable.Show();
var topScore = value.Scores.First();
var userScore = value.UserScore;
topScoresContainer.Add(new DrawableTopScore(topScore));
if (userScore != null && userScore.Score.OnlineScoreID != topScore.OnlineScoreID)
topScoresContainer.Add(new DrawableTopScore(userScore.Score, userScore.Position));
});
}
}
public ScoresContainer() public ScoresContainer()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
background = new Box background = new Box
@ -54,7 +100,13 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Margin = new MarginPadding { Vertical = spacing }, Margin = new MarginPadding { Vertical = spacing },
Children = new Drawable[] Children = new Drawable[]
{ {
topScore = new DrawableTopScore(), topScoresContainer = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
},
scoreTable = new ScoreTable scoreTable = new ScoreTable
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
@ -65,7 +117,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),
}, },
}; };
} }
@ -74,7 +126,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
background.Colour = colours.Gray2; background.Colour = colours.Gray2;
updateDisplay();
} }
private bool loading private bool loading
@ -82,62 +133,23 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration); set => loadingAnimation.FadeTo(value ? 1 : 0, fade_duration);
} }
private GetScoresRequest getScoresRequest; private void getScores(BeatmapInfo beatmap)
private IReadOnlyList<ScoreInfo> scores;
public IReadOnlyList<ScoreInfo> Scores
{
get => scores;
set
{ {
getScoresRequest?.Cancel(); getScoresRequest?.Cancel();
scores = value; getScoresRequest = null;
updateDisplay();
}
}
private BeatmapInfo beatmap;
public BeatmapInfo Beatmap
{
get => beatmap;
set
{
beatmap = value;
Scores = null; Scores = null;
if (beatmap?.OnlineBeatmapID.HasValue != true) if (beatmap?.OnlineBeatmapID.HasValue != true)
return;
loading = true;
getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
getScoresRequest.Success += r => Schedule(() => Scores = r.Scores);
api.Queue(getScoresRequest);
}
}
private void updateDisplay()
{ {
loading = false; loading = false;
return;
scoreTable.Scores = scores?.Count > 1 ? scores : new List<ScoreInfo>();
scoreTable.FadeTo(scores?.Count > 1 ? 1 : 0);
if (scores?.Any() == true)
{
topScore.Score = scores.FirstOrDefault();
topScore.Show();
}
else
topScore.Hide();
} }
protected override void Dispose(bool isDisposing) getScoresRequest = new GetScoresRequest(beatmap, beatmap.Ruleset);
{ getScoresRequest.Success += scores => Scores = scores;
getScoresRequest?.Cancel(); api.Queue(getScoresRequest);
loading = true;
} }
} }
} }

View File

@ -38,13 +38,20 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0), Spacing = new Vector2(10, 0),
Children = new Drawable[] Children = new Drawable[]
{
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{ {
rankText = new OsuSpriteText rankText = new OsuSpriteText
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Text = "#1", Font = OsuFont.GetFont(size: 24, weight: FontWeight.Bold, italics: true)
Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true)
}, },
rank = new UpdateableRank(ScoreRank.D) rank = new UpdateableRank(ScoreRank.D)
{ {
@ -53,6 +60,8 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Size = new Vector2(40), Size = new Vector2(40),
FillMode = FillMode.Fit, FillMode = FillMode.Fit,
}, },
}
},
avatar = new UpdateableAvatar(hideImmediately: true) avatar = new UpdateableAvatar(hideImmediately: true)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
@ -109,6 +118,11 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
rankText.Colour = colours.Yellow; rankText.Colour = colours.Yellow;
} }
public int ScorePosition
{
set => rankText.Text = $"#{value}";
}
/// <summary> /// <summary>
/// Sets the score to be displayed. /// Sets the score to be displayed.
/// </summary> /// </summary>

View File

@ -21,12 +21,9 @@ namespace osu.Game.Overlays
{ {
public class BeatmapSetOverlay : FullscreenOverlay public class BeatmapSetOverlay : FullscreenOverlay
{ {
private const int fade_duration = 300;
public const float X_PADDING = 40; public const float X_PADDING = 40;
public const float TOP_PADDING = 25; public const float TOP_PADDING = 25;
public const float RIGHT_WIDTH = 275; public const float RIGHT_WIDTH = 275;
protected readonly Header Header; protected readonly Header Header;
private RulesetStore rulesets; private RulesetStore rulesets;
@ -40,7 +37,7 @@ namespace osu.Game.Overlays
{ {
OsuScrollContainer scroll; OsuScrollContainer scroll;
Info info; Info info;
ScoresContainer scores; ScoresContainer scoreContainer;
Children = new Drawable[] Children = new Drawable[]
{ {
@ -62,7 +59,7 @@ namespace osu.Game.Overlays
{ {
Header = new Header(), Header = new Header(),
info = new Info(), info = new Info(),
scores = new ScoresContainer(), scoreContainer = new ScoresContainer(),
}, },
}, },
}, },
@ -74,7 +71,7 @@ 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; scoreContainer.Beatmap = b.NewValue;
scroll.ScrollToStart(); scroll.ScrollToStart();
}; };
@ -101,6 +98,7 @@ namespace osu.Game.Overlays
public void FetchAndShowBeatmap(int beatmapId) public void FetchAndShowBeatmap(int beatmapId)
{ {
beatmapSet.Value = null; beatmapSet.Value = null;
var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId); var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);
req.Success += res => req.Success += res =>
{ {
@ -108,15 +106,18 @@ namespace osu.Game.Overlays
Header.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId); Header.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId);
}; };
API.Queue(req); API.Queue(req);
Show(); Show();
} }
public void FetchAndShowBeatmapSet(int beatmapSetId) public void FetchAndShowBeatmapSet(int beatmapSetId)
{ {
beatmapSet.Value = null; beatmapSet.Value = null;
var req = new GetBeatmapSetRequest(beatmapSetId); var req = new GetBeatmapSetRequest(beatmapSetId);
req.Success += res => beatmapSet.Value = res.ToBeatmapSet(rulesets); req.Success += res => beatmapSet.Value = res.ToBeatmapSet(rulesets);
API.Queue(req); API.Queue(req);
Show(); Show();
} }