Skip to content

Commit

Permalink
Merge spectator list classes into one skinnable
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Jan 17, 2025
1 parent c8b38f0 commit abf4b7b
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public CatchLegacySkinTransformer(ISkin skin)
return new DefaultSkinComponentsContainer(container =>
{
var keyCounter = container.OfType<LegacyKeyCounterDisplay>().FirstOrDefault();
var spectatorList = container.OfType<SkinnableSpectatorList>().FirstOrDefault();
var spectatorList = container.OfType<SpectatorList>().FirstOrDefault();

if (keyCounter != null)
{
Expand All @@ -69,7 +69,7 @@ public CatchLegacySkinTransformer(ISkin skin)
Children = new Drawable[]
{
new LegacyKeyCounterDisplay(),
new SkinnableSpectatorList(),
new SpectatorList(),
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ManiaArgonSkinTransformer(ISkin skin, IBeatmap beatmap)
return new DefaultSkinComponentsContainer(container =>
{
var combo = container.ChildrenOfType<ArgonManiaComboCounter>().FirstOrDefault();
var spectatorList = container.OfType<SkinnableSpectatorList>().FirstOrDefault();
var spectatorList = container.OfType<SpectatorList>().FirstOrDefault();

if (combo != null)
{
Expand All @@ -56,7 +56,7 @@ public ManiaArgonSkinTransformer(ISkin skin, IBeatmap beatmap)
})
{
new ArgonManiaComboCounter(),
new SkinnableSpectatorList
new SpectatorList
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override Drawable GetDrawableComponent(ISkinComponentLookup lookup)
return new DefaultSkinComponentsContainer(container =>
{
var combo = container.ChildrenOfType<LegacyManiaComboCounter>().FirstOrDefault();
var spectatorList = container.OfType<SkinnableSpectatorList>().FirstOrDefault();
var spectatorList = container.OfType<SpectatorList>().FirstOrDefault();

if (combo != null)
{
Expand All @@ -115,7 +115,7 @@ public override Drawable GetDrawableComponent(ISkinComponentLookup lookup)
})
{
new LegacyManiaComboCounter(),
new SkinnableSpectatorList(),
new SpectatorList(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public OsuLegacySkinTransformer(ISkin skin)
}

var combo = container.OfType<LegacyDefaultComboCounter>().FirstOrDefault();
var spectatorList = container.OfType<SkinnableSpectatorList>().FirstOrDefault();
var spectatorList = container.OfType<SpectatorList>().FirstOrDefault();

Vector2 pos = new Vector2();

Expand All @@ -96,7 +96,7 @@ public OsuLegacySkinTransformer(ISkin skin)
{
new LegacyDefaultComboCounter(),
new LegacyKeyCounterDisplay(),
new SkinnableSpectatorList(),
new SpectatorList(),
}
};
}
Expand Down
Binary file modified osu.Game.Tests/Resources/Archives/modified-argon-20250116.osk
Binary file not shown.
47 changes: 33 additions & 14 deletions osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,72 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.Spectator;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Tests.Visual.Spectator;

namespace osu.Game.Tests.Visual.Gameplay
{
[TestFixture]
public partial class TestSceneSpectatorList : OsuTestScene
{
private readonly BindableList<SpectatorUser> spectators = new BindableList<SpectatorUser>();
private readonly Bindable<LocalUserPlayingState> localUserPlayingState = new Bindable<LocalUserPlayingState>();

private int counter;

[Test]
public void TestBasics()
{
SpectatorList list = null!;
AddStep("create spectator list", () => Child = list = new SpectatorList
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", () =>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Spectators = { BindTarget = spectators },
UserPlayingState = { BindTarget = localUserPlayingState }
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,
}
}
};
});

AddStep("start playing", () => localUserPlayingState.Value = LocalUserPlayingState.Playing);
AddStep("start playing", () => playingState.Value = LocalUserPlayingState.Playing);

AddRepeatStep("add a user", () =>
{
int id = Interlocked.Increment(ref counter);
spectators.Add(new SpectatorUser
((ISpectatorClient)client).UserStartedWatching([new SpectatorUser

Check failure on line 60 in osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorList.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Line break is missing around expression braces in osu.Game.Tests\Visual\Gameplay\TestSceneSpectatorList.cs on line 60
{
OnlineID = id,
Username = $"User {id}"
});
}]);

Check failure on line 64 in osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorList.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Line break is missing around expression braces in osu.Game.Tests\Visual\Gameplay\TestSceneSpectatorList.cs on line 64
}, 10);

AddRepeatStep("remove random user", () => spectators.RemoveAt(RNG.Next(0, spectators.Count)), 5);
AddRepeatStep("remove random user", () => ((ISpectatorClient)client).UserEndedWatching(client.WatchingUsers[RNG.Next(client.WatchingUsers.Count)].OnlineID), 5);

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));

AddStep("enter break", () => localUserPlayingState.Value = LocalUserPlayingState.Break);
AddStep("stop playing", () => localUserPlayingState.Value = LocalUserPlayingState.NotPlaying);
AddStep("enter break", () => playingState.Value = LocalUserPlayingState.Break);
AddStep("stop playing", () => playingState.Value = LocalUserPlayingState.NotPlaying);
}
}
}
17 changes: 5 additions & 12 deletions osu.Game/Screens/Play/HUD/SpectatorList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace osu.Game.Screens.Play.HUD
{
public partial class SpectatorList : CompositeDrawable
public partial class SpectatorList : CompositeDrawable, ISerialisableDrawable
{
private const int max_spectators_displayed = 10;

Expand All @@ -44,7 +44,7 @@ public partial class SpectatorList : CompositeDrawable
private DrawablePool<SpectatorListEntry> pool = null!;

[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, SpectatorClient client, GameplayState gameplayState)
{
AutoSizeAxes = Axes.Y;

Expand Down Expand Up @@ -73,6 +73,9 @@ private void load(OsuColour colours)
};

HeaderColour.Value = Header.Colour;

((IBindableList<SpectatorUser>)Spectators).BindTo(client.WatchingUsers);
((IBindable<LocalUserPlayingState>)UserPlayingState).BindTo(gameplayState.PlayingState);
}

protected override void LoadComplete()
Expand Down Expand Up @@ -236,17 +239,7 @@ private void updateEnabledState()
linkCompiler.Enabled.Value = UserPlayingState.Value != LocalUserPlayingState.Playing;
}
}
}

public partial class SkinnableSpectatorList : SpectatorList, ISerialisableDrawable
{
public bool UsesFixedAnchor { get; set; }

[BackgroundDependencyLoader]
private void load(SpectatorClient client, GameplayState gameplayState)
{
((IBindableList<SpectatorUser>)Spectators).BindTo(client.WatchingUsers);
((IBindable<LocalUserPlayingState>)UserPlayingState).BindTo(gameplayState.PlayingState);
}
}
}
4 changes: 2 additions & 2 deletions osu.Game/Skinning/ArgonSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
return new DefaultSkinComponentsContainer(container =>
{
var comboCounter = container.OfType<ArgonComboCounter>().FirstOrDefault();
var spectatorList = container.OfType<SkinnableSpectatorList>().FirstOrDefault();
var spectatorList = container.OfType<SpectatorList>().FirstOrDefault();

Vector2 pos = new Vector2(36, -66);

Expand All @@ -135,7 +135,7 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
Origin = Anchor.BottomLeft,
Scale = new Vector2(1.3f),
},
new SkinnableSpectatorList
new SpectatorList
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Skinning/LegacySkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ protected override void ParseConfigurationStream(Stream stream)
return new DefaultSkinComponentsContainer(container =>
{
var combo = container.OfType<LegacyDefaultComboCounter>().FirstOrDefault();
var spectatorList = container.OfType<SkinnableSpectatorList>().FirstOrDefault();
var spectatorList = container.OfType<SpectatorList>().FirstOrDefault();

Vector2 pos = new Vector2();

Expand All @@ -389,7 +389,7 @@ protected override void ParseConfigurationStream(Stream stream)
})
{
new LegacyDefaultComboCounter(),
new SkinnableSpectatorList(),
new SpectatorList(),
};
}

Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Skinning/TrianglesSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public TrianglesSkin(SkinInfo skin, IStorageResourceProvider resources)
var ppCounter = container.OfType<PerformancePointsCounter>().FirstOrDefault();
var songProgress = container.OfType<DefaultSongProgress>().FirstOrDefault();
var keyCounter = container.OfType<DefaultKeyCounterDisplay>().FirstOrDefault();
var spectatorList = container.OfType<SkinnableSpectatorList>().FirstOrDefault();
var spectatorList = container.OfType<SpectatorList>().FirstOrDefault();

if (score != null)
{
Expand Down Expand Up @@ -177,7 +177,7 @@ public TrianglesSkin(SkinInfo skin, IStorageResourceProvider resources)
new BarHitErrorMeter(),
new BarHitErrorMeter(),
new TrianglesPerformancePointsCounter(),
new SkinnableSpectatorList(),
new SpectatorList(),
}
};

Expand Down

0 comments on commit abf4b7b

Please sign in to comment.