1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-05 02:23:38 +08:00

Fix cases where the bindable is resolved directly

This commit is contained in:
Dan Balasescu
2024-11-13 16:38:49 +09:00
Unverified
parent 99762da7b8
commit 5b2568d18b
4 changed files with 47 additions and 23 deletions
@@ -63,7 +63,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
SelectedRoom.Value = new Room { RoomID = 3 };
Child = new MatchLeaderboard
Child = new MatchLeaderboard(SelectedRoom.Value)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
@@ -1,9 +1,8 @@
// 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.ComponentModel;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards;
@@ -13,30 +12,44 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
{
public partial class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIUserScoreAggregate>
{
[Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<long?> roomId { get; set; } = null!;
private readonly Room room;
[BackgroundDependencyLoader]
private void load()
public MatchLeaderboard(Room room)
{
roomId.BindValueChanged(id =>
{
if (id.NewValue == null)
return;
this.room = room;
}
SetScores(null);
RefetchScores();
}, true);
protected override void LoadComplete()
{
base.LoadComplete();
room.PropertyChanged += onRoomPropertyChanged;
fetchInitialScores();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.RoomID))
fetchInitialScores();
}
private void fetchInitialScores()
{
if (room.RoomID == null)
return;
SetScores(null);
RefetchScores();
}
protected override bool IsOnlineScope => true;
protected override APIRequest? FetchScores(CancellationToken cancellationToken)
{
if (roomId.Value == null)
if (room.RoomID == null)
return null;
var req = new GetRoomLeaderboardRequest(roomId.Value ?? 0);
var req = new GetRoomLeaderboardRequest(room.RoomID.Value);
req.Success += r => Schedule(() =>
{
@@ -52,6 +65,12 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
protected override LeaderboardScore CreateDrawableScore(APIUserScoreAggregate model, int index) => new MatchLeaderboardScore(model, index);
protected override LeaderboardScore CreateDrawableTopScore(APIUserScoreAggregate model) => new MatchLeaderboardScore(model, model.Position, false);
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
}
public enum MatchLeaderboardScope
@@ -323,7 +323,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
Padding = new MarginPadding { Horizontal = OsuScreen.HORIZONTAL_OVERFLOW_PADDING },
Children = new Drawable[]
{
ApplyButton = new CreateOrUpdateButton
ApplyButton = new CreateOrUpdateButton(room)
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
@@ -471,13 +471,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
public partial class CreateOrUpdateButton : RoundedButton
{
[Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<long?> roomId { get; set; } = null!;
private readonly Room room;
protected override void LoadComplete()
public CreateOrUpdateButton(Room room)
{
base.LoadComplete();
roomId.BindValueChanged(id => Text = id.NewValue == null ? "Create" : "Update", true);
this.room = room;
}
[BackgroundDependencyLoader]
@@ -485,6 +483,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
{
BackgroundColour = colours.YellowDark;
}
protected override void Update()
{
base.Update();
Text = room.RoomID == null ? "Create" : "Update";
}
}
private enum StartMode
@@ -201,7 +201,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{
new OverlinedHeader("Leaderboard")
},
new Drawable[] { leaderboard = new MatchLeaderboard { RelativeSizeAxes = Axes.Both }, },
new Drawable[] { leaderboard = new MatchLeaderboard(Room) { RelativeSizeAxes = Axes.Both }, },
},
RowDimensions = new[]
{