mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 21:13:01 +08:00
Merge pull request #14219 from peppy/multiplayer-team-vs-results
Show team versus team scores and winner at the results screen
This commit is contained in:
commit
0642a337df
@ -0,0 +1,51 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerResults : ScreenTestScene
|
||||
{
|
||||
[Test]
|
||||
public void TestDisplayResults()
|
||||
{
|
||||
MultiplayerResultsScreen screen = null;
|
||||
|
||||
AddStep("show results screen", () =>
|
||||
{
|
||||
var rulesetInfo = new OsuRuleset().RulesetInfo;
|
||||
var beatmapInfo = CreateBeatmap(rulesetInfo).BeatmapInfo;
|
||||
|
||||
var score = new ScoreInfo
|
||||
{
|
||||
Rank = ScoreRank.B,
|
||||
TotalScore = 987654,
|
||||
Accuracy = 0.8,
|
||||
MaxCombo = 500,
|
||||
Combo = 250,
|
||||
Beatmap = beatmapInfo,
|
||||
User = new User { Username = "Test user" },
|
||||
Date = DateTimeOffset.Now,
|
||||
OnlineScoreID = 12345,
|
||||
Ruleset = rulesetInfo,
|
||||
};
|
||||
|
||||
PlaylistItem playlistItem = new PlaylistItem
|
||||
{
|
||||
BeatmapID = beatmapInfo.ID,
|
||||
};
|
||||
|
||||
Stack.Push(screen = new MultiplayerResultsScreen(score, 1, playlistItem));
|
||||
});
|
||||
|
||||
AddUntilStep("wait for loaded", () => screen.IsLoaded);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerTeamResults : ScreenTestScene
|
||||
{
|
||||
[TestCase(7483253, 1048576)]
|
||||
[TestCase(1048576, 7483253)]
|
||||
[TestCase(1048576, 1048576)]
|
||||
public void TestDisplayTeamResults(int team1Score, int team2Score)
|
||||
{
|
||||
MultiplayerResultsScreen screen = null;
|
||||
|
||||
AddStep("show results screen", () =>
|
||||
{
|
||||
var rulesetInfo = new OsuRuleset().RulesetInfo;
|
||||
var beatmapInfo = CreateBeatmap(rulesetInfo).BeatmapInfo;
|
||||
|
||||
var score = new ScoreInfo
|
||||
{
|
||||
Rank = ScoreRank.B,
|
||||
TotalScore = 987654,
|
||||
Accuracy = 0.8,
|
||||
MaxCombo = 500,
|
||||
Combo = 250,
|
||||
Beatmap = beatmapInfo,
|
||||
User = new User { Username = "Test user" },
|
||||
Date = DateTimeOffset.Now,
|
||||
OnlineScoreID = 12345,
|
||||
Ruleset = rulesetInfo,
|
||||
};
|
||||
|
||||
PlaylistItem playlistItem = new PlaylistItem
|
||||
{
|
||||
BeatmapID = beatmapInfo.ID,
|
||||
};
|
||||
|
||||
SortedDictionary<int, BindableInt> teamScores = new SortedDictionary<int, BindableInt>
|
||||
{
|
||||
{ 0, new BindableInt(team1Score) },
|
||||
{ 1, new BindableInt(team2Score) }
|
||||
};
|
||||
|
||||
Stack.Push(screen = new MultiplayerTeamResultsScreen(score, 1, playlistItem, teamScores));
|
||||
});
|
||||
|
||||
AddUntilStep("wait for loaded", () => screen.IsLoaded);
|
||||
}
|
||||
}
|
||||
}
|
24
osu.Game/Localisation/MultiplayerTeamResultsScreenStrings.cs
Normal file
24
osu.Game/Localisation/MultiplayerTeamResultsScreenStrings.cs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Localisation;
|
||||
|
||||
namespace osu.Game.Localisation
|
||||
{
|
||||
public static class MultiplayerTeamResultsScreenStrings
|
||||
{
|
||||
private const string prefix = @"osu.Game.Resources.Localisation.MultiplayerTeamResultsScreen";
|
||||
|
||||
/// <summary>
|
||||
/// "Team {0} wins!"
|
||||
/// </summary>
|
||||
public static LocalisableString TeamWins(string winner) => new TranslatableString(getKey(@"team_wins"), @"Team {0} wins!", winner);
|
||||
|
||||
/// <summary>
|
||||
/// "The teams are tied!"
|
||||
/// </summary>
|
||||
public static LocalisableString TheTeamsAreTied => new TranslatableString(getKey(@"the_teams_are_tied"), @"The teams are tied!");
|
||||
|
||||
private static string getKey(string key) => $@"{prefix}:{key}";
|
||||
}
|
||||
}
|
@ -181,7 +181,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
protected override ResultsScreen CreateResults(ScoreInfo score)
|
||||
{
|
||||
Debug.Assert(RoomId.Value != null);
|
||||
return new MultiplayerResultsScreen(score, RoomId.Value.Value, PlaylistItem);
|
||||
return leaderboard.TeamScores.Count == 2
|
||||
? new MultiplayerTeamResultsScreen(score, RoomId.Value.Value, PlaylistItem, leaderboard.TeamScores)
|
||||
: new MultiplayerResultsScreen(score, RoomId.Value.Value, PlaylistItem);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
@ -0,0 +1,152 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
public class MultiplayerTeamResultsScreen : MultiplayerResultsScreen
|
||||
{
|
||||
private readonly SortedDictionary<int, BindableInt> teamScores;
|
||||
|
||||
private Container winnerBackground;
|
||||
private Drawable winnerText;
|
||||
|
||||
public MultiplayerTeamResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem, SortedDictionary<int, BindableInt> teamScores)
|
||||
: base(score, roomId, playlistItem)
|
||||
{
|
||||
if (teamScores.Count != 2)
|
||||
throw new NotSupportedException(@"This screen currently only supports 2 teams");
|
||||
|
||||
this.teamScores = teamScores;
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
const float winner_background_half_height = 250;
|
||||
|
||||
VerticalScrollContent.Anchor = VerticalScrollContent.Origin = Anchor.TopCentre;
|
||||
VerticalScrollContent.Scale = new Vector2(0.9f);
|
||||
VerticalScrollContent.Y = 75;
|
||||
|
||||
var redScore = teamScores.First().Value;
|
||||
var blueScore = teamScores.Last().Value;
|
||||
|
||||
LocalisableString winner;
|
||||
Colour4 winnerColour;
|
||||
|
||||
int comparison = redScore.Value.CompareTo(blueScore.Value);
|
||||
|
||||
if (comparison < 0)
|
||||
{
|
||||
// team name should eventually be coming from the multiplayer match state.
|
||||
winner = MultiplayerTeamResultsScreenStrings.TeamWins(@"Blue");
|
||||
winnerColour = colours.TeamColourBlue;
|
||||
}
|
||||
else if (comparison > 0)
|
||||
{
|
||||
// team name should eventually be coming from the multiplayer match state.
|
||||
winner = MultiplayerTeamResultsScreenStrings.TeamWins(@"Red");
|
||||
winnerColour = colours.TeamColourRed;
|
||||
}
|
||||
else
|
||||
{
|
||||
winner = MultiplayerTeamResultsScreenStrings.TheTeamsAreTied;
|
||||
winnerColour = Colour4.White.Opacity(0.5f);
|
||||
}
|
||||
|
||||
AddRangeInternal(new Drawable[]
|
||||
{
|
||||
new MatchScoreDisplay
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
Team1Score = { BindTarget = redScore },
|
||||
Team2Score = { BindTarget = blueScore },
|
||||
},
|
||||
winnerBackground = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Alpha = 0,
|
||||
Children = new[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = winner_background_half_height,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Colour = ColourInfo.GradientVertical(Colour4.Black.Opacity(0), Colour4.Black.Opacity(0.4f))
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = winner_background_half_height,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.TopCentre,
|
||||
Colour = ColourInfo.GradientVertical(Colour4.Black.Opacity(0.4f), Colour4.Black.Opacity(0))
|
||||
}
|
||||
}
|
||||
},
|
||||
(winnerText = new OsuSpriteText
|
||||
{
|
||||
Alpha = 0,
|
||||
Font = OsuFont.Torus.With(size: 80, weight: FontWeight.Bold),
|
||||
Text = winner,
|
||||
Blending = BlendingParameters.Additive
|
||||
}).WithEffect(new GlowEffect
|
||||
{
|
||||
Colour = winnerColour,
|
||||
}).With(e =>
|
||||
{
|
||||
e.Anchor = Anchor.Centre;
|
||||
e.Origin = Anchor.Centre;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
using (BeginDelayedSequence(300))
|
||||
{
|
||||
const double fade_in_duration = 600;
|
||||
|
||||
winnerText.FadeInFromZero(fade_in_duration, Easing.InQuint);
|
||||
winnerBackground.FadeInFromZero(fade_in_duration, Easing.InQuint);
|
||||
|
||||
winnerText
|
||||
.ScaleTo(10)
|
||||
.ScaleTo(1, 600, Easing.InQuad)
|
||||
.Then()
|
||||
.ScaleTo(1.02f, 1600, Easing.OutQuint)
|
||||
.FadeOut(5000, Easing.InQuad);
|
||||
winnerBackground.Delay(2200).FadeOut(2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -104,7 +104,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
base.LoadComplete();
|
||||
|
||||
Team1Score.BindValueChanged(_ => updateScores());
|
||||
Team2Score.BindValueChanged(_ => updateScores());
|
||||
Team2Score.BindValueChanged(_ => updateScores(), true);
|
||||
}
|
||||
|
||||
private void updateScores()
|
||||
|
@ -40,6 +40,8 @@ namespace osu.Game.Screens.Ranking
|
||||
|
||||
protected ScorePanelList ScorePanelList { get; private set; }
|
||||
|
||||
protected VerticalScrollContainer VerticalScrollContent { get; private set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private Player player { get; set; }
|
||||
|
||||
@ -77,7 +79,7 @@ namespace osu.Game.Screens.Ranking
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
new VerticalScrollContainer
|
||||
VerticalScrollContent = new VerticalScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
ScrollbarVisible = false,
|
||||
@ -343,7 +345,7 @@ namespace osu.Game.Screens.Ranking
|
||||
{
|
||||
}
|
||||
|
||||
private class VerticalScrollContainer : OsuScrollContainer
|
||||
protected class VerticalScrollContainer : OsuScrollContainer
|
||||
{
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
@ -351,6 +353,8 @@ namespace osu.Game.Screens.Ranking
|
||||
|
||||
public VerticalScrollContainer()
|
||||
{
|
||||
Masking = false;
|
||||
|
||||
base.Content.Add(content = new Container { RelativeSizeAxes = Axes.X });
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user