2025-01-14 20:24:31 +08:00
// 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.Threading ;
using NUnit.Framework ;
using osu.Framework.Bindables ;
using osu.Framework.Graphics ;
using osu.Framework.Utils ;
2025-01-17 18:16:35 +08:00
using osu.Game.Beatmaps ;
2025-01-14 20:24:31 +08:00
using osu.Game.Graphics ;
2025-01-14 21:44:13 +08:00
using osu.Game.Online.Spectator ;
2025-01-17 18:16:35 +08:00
using osu.Game.Rulesets.Osu ;
using osu.Game.Rulesets.Osu.Scoring ;
2025-01-14 20:24:31 +08:00
using osu.Game.Screens.Play ;
using osu.Game.Screens.Play.HUD ;
2025-01-17 18:16:35 +08:00
using osu.Game.Tests.Visual.Spectator ;
2025-01-14 20:24:31 +08:00
namespace osu.Game.Tests.Visual.Gameplay
{
[TestFixture]
public partial class TestSceneSpectatorList : OsuTestScene
{
private int counter ;
[Test]
public void TestBasics ( )
{
SpectatorList list = null ! ;
2025-01-17 18:16:35 +08:00
Bindable < LocalUserPlayingState > playingState = new Bindable < LocalUserPlayingState > ( ) ;
GameplayState gameplayState = new GameplayState ( new Beatmap ( ) , new OsuRuleset ( ) , healthProcessor : new OsuHealthProcessor ( 0 ) , localUserPlayingState : playingState ) ;
TestSpectatorClient client = new TestSpectatorClient ( ) ;
AddStep ( "create spectator list" , ( ) = >
2025-01-14 20:24:31 +08:00
{
2025-01-17 18:16:35 +08:00
Children = new Drawable [ ]
{
client ,
new DependencyProvidingContainer
{
RelativeSizeAxes = Axes . Both ,
CachedDependencies =
[
( typeof ( GameplayState ) , gameplayState ) ,
( typeof ( SpectatorClient ) , client )
] ,
Child = list = new SpectatorList
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
}
}
} ;
2025-01-14 20:24:31 +08:00
} ) ;
2025-01-17 18:16:35 +08:00
AddStep ( "start playing" , ( ) = > playingState . Value = LocalUserPlayingState . Playing ) ;
2025-01-16 17:56:21 +08:00
AddRepeatStep ( "add a user" , ( ) = >
2025-01-14 20:24:31 +08:00
{
int id = Interlocked . Increment ( ref counter ) ;
2025-01-17 18:16:35 +08:00
( ( ISpectatorClient ) client ) . UserStartedWatching ( [
new SpectatorUser
{
OnlineID = id ,
Username = $"User {id}"
}
] ) ;
2025-01-16 17:56:21 +08:00
} , 10 ) ;
2025-01-17 18:16:35 +08:00
AddRepeatStep ( "remove random user" , ( ) = > ( ( ISpectatorClient ) client ) . UserEndedWatching ( client . WatchingUsers [ RNG . Next ( client . WatchingUsers . Count ) ] . OnlineID ) , 5 ) ;
2025-01-16 17:56:21 +08:00
2025-01-14 20:24:31 +08:00
AddStep ( "change font to venera" , ( ) = > list . Font . Value = Typeface . Venera ) ;
AddStep ( "change font to torus" , ( ) = > list . Font . Value = Typeface . Torus ) ;
AddStep ( "change header colour" , ( ) = > list . HeaderColour . Value = new Colour4 ( RNG . NextSingle ( ) , RNG . NextSingle ( ) , RNG . NextSingle ( ) , 1 ) ) ;
2025-01-16 17:56:21 +08:00
2025-01-17 18:16:35 +08:00
AddStep ( "enter break" , ( ) = > playingState . Value = LocalUserPlayingState . Break ) ;
AddStep ( "stop playing" , ( ) = > playingState . Value = LocalUserPlayingState . NotPlaying ) ;
2025-01-14 20:24:31 +08:00
}
}
}