mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 21:25:36 +08:00
Fix first playlist item not getting selected
This commit is contained in:
parent
b92f1ad68d
commit
61d539dc67
@ -3,19 +3,28 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Screens;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Screens.Multi;
|
||||||
using osu.Game.Screens.Multi.Match;
|
using osu.Game.Screens.Multi.Match;
|
||||||
using osu.Game.Screens.Multi.Match.Components;
|
using osu.Game.Screens.Multi.Match.Components;
|
||||||
|
using osu.Game.Tests.Beatmaps;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
using osuTK.Input;
|
||||||
|
using Header = osu.Game.Screens.Multi.Match.Components.Header;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Multiplayer
|
namespace osu.Game.Tests.Visual.Multiplayer
|
||||||
{
|
{
|
||||||
public class TestSceneMatchSubScreen : ScreenTestScene
|
public class TestSceneMatchSubScreen : MultiplayerTestScene
|
||||||
{
|
{
|
||||||
protected override bool UseOnlineAPI => true;
|
protected override bool UseOnlineAPI => true;
|
||||||
|
|
||||||
@ -27,8 +36,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
typeof(Footer)
|
typeof(Footer)
|
||||||
};
|
};
|
||||||
|
|
||||||
[Cached]
|
[Cached(typeof(IRoomManager))]
|
||||||
private readonly Bindable<Room> currentRoom = new Bindable<Room>();
|
private readonly TestRoomManager roomManager = new TestRoomManager();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapManager beatmaps { get; set; }
|
private BeatmapManager beatmaps { get; set; }
|
||||||
@ -36,51 +45,77 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private RulesetStore rulesets { get; set; }
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
public TestSceneMatchSubScreen()
|
private TestMatchSubScreen match;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup() => Schedule(() =>
|
||||||
{
|
{
|
||||||
currentRoom.Value = new Room();
|
Room.CopyFrom(new Room());
|
||||||
|
});
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetupSteps()
|
||||||
|
{
|
||||||
|
AddStep("load match", () => LoadScreen(match = new TestMatchSubScreen(Room)));
|
||||||
|
AddUntilStep("wait for load", () => match.IsCurrentScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestShowRoom()
|
public void TestPlaylistItemSelectedOnCreate()
|
||||||
{
|
{
|
||||||
AddStep(@"show", () =>
|
AddStep("set room properties", () =>
|
||||||
{
|
{
|
||||||
currentRoom.Value.RoomID.Value = 1;
|
Room.Name.Value = "my awesome room";
|
||||||
currentRoom.Value.Availability.Value = RoomAvailability.Public;
|
Room.Host.Value = new User { Id = 2, Username = "peppy" };
|
||||||
currentRoom.Value.Duration.Value = TimeSpan.FromHours(24);
|
Room.Playlist.Add(new PlaylistItem
|
||||||
currentRoom.Value.Host.Value = new User { Username = "peppy", Id = 2 };
|
|
||||||
currentRoom.Value.Name.Value = "super secret room";
|
|
||||||
currentRoom.Value.Participants.AddRange(new[]
|
|
||||||
{
|
{
|
||||||
new User { Username = "peppy", Id = 2 },
|
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
|
||||||
new User { Username = "smoogipoo", Id = 1040328 }
|
Ruleset = { Value = new OsuRuleset().RulesetInfo }
|
||||||
});
|
});
|
||||||
currentRoom.Value.Playlist.Add(new PlaylistItem
|
|
||||||
{
|
|
||||||
Beatmap = { Value = beatmaps.GetAllUsableBeatmapSets()[0].Beatmaps[0] },
|
|
||||||
Ruleset = { Value = rulesets.GetRuleset(2) },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
LoadScreen(new MatchSubScreen(currentRoom.Value));
|
AddStep("move mouse to create button", () =>
|
||||||
|
{
|
||||||
|
var footer = match.ChildrenOfType<Footer>().Single();
|
||||||
|
InputManager.MoveMouseTo(footer.ChildrenOfType<OsuButton>().Single());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
||||||
|
|
||||||
|
AddAssert("first playlist item selected", () => match.SelectedItem.Value == Room.Playlist[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
private class TestMatchSubScreen : MatchSubScreen
|
||||||
public void TestShowSettings()
|
|
||||||
{
|
{
|
||||||
AddStep(@"show", () =>
|
public new Bindable<PlaylistItem> SelectedItem => base.SelectedItem;
|
||||||
|
|
||||||
|
public TestMatchSubScreen(Room room)
|
||||||
|
: base(room)
|
||||||
{
|
{
|
||||||
currentRoom.Value.RoomID.Value = null;
|
}
|
||||||
LoadScreen(new MatchSubScreen(currentRoom.Value));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
private class TestRoomManager : IRoomManager
|
||||||
|
{
|
||||||
|
public event Action RoomsUpdated
|
||||||
|
{
|
||||||
|
add => throw new NotImplementedException();
|
||||||
|
remove => throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IBindableList<Room> Rooms { get; } = new BindableList<Room>();
|
||||||
|
|
||||||
|
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||||
|
{
|
||||||
|
room.RoomID.Value = 1;
|
||||||
|
onSuccess?.Invoke(room);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => onSuccess?.Invoke(room);
|
||||||
|
|
||||||
|
public void PartRoom()
|
||||||
{
|
{
|
||||||
var dependencies = new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent));
|
}
|
||||||
dependencies.Model.BindTo(currentRoom);
|
|
||||||
return dependencies;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,8 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private Multiplayer multiplayer { get; set; }
|
private Multiplayer multiplayer { get; set; }
|
||||||
|
|
||||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
protected readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
||||||
|
|
||||||
private LeaderboardChatDisplay leaderboardChatDisplay;
|
private LeaderboardChatDisplay leaderboardChatDisplay;
|
||||||
private MatchSettingsOverlay settingsOverlay;
|
private MatchSettingsOverlay settingsOverlay;
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
Padding = new MarginPadding { Horizontal = 5 },
|
Padding = new MarginPadding { Horizontal = 5 },
|
||||||
Child = new OverlinedPlaylist(true) // Temporarily always allow selection
|
Child = new OverlinedPlaylist(true) // Temporarily always allow selection
|
||||||
{
|
{
|
||||||
SelectedItem = { BindTarget = selectedItem }
|
SelectedItem = { BindTarget = SelectedItem }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
@ -143,7 +144,7 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
new Footer
|
new Footer
|
||||||
{
|
{
|
||||||
OnStart = onStart,
|
OnStart = onStart,
|
||||||
SelectedItem = { BindTarget = selectedItem }
|
SelectedItem = { BindTarget = SelectedItem }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -171,11 +172,17 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
if (id.NewValue == null)
|
if (id.NewValue == null)
|
||||||
settingsOverlay.Show();
|
settingsOverlay.Show();
|
||||||
else
|
else
|
||||||
|
{
|
||||||
settingsOverlay.Hide();
|
settingsOverlay.Hide();
|
||||||
|
|
||||||
|
// Set the first playlist item.
|
||||||
|
// This is scheduled since updating the room and playlist may happen in an arbitrary order (via Room.CopyFrom()).
|
||||||
|
Schedule(() => SelectedItem.Value = playlist.FirstOrDefault());
|
||||||
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
selectedItem.BindValueChanged(selectedItemChanged);
|
SelectedItem.BindValueChanged(selectedItemChanged);
|
||||||
selectedItem.Value = playlist.FirstOrDefault();
|
SelectedItem.Value = playlist.FirstOrDefault();
|
||||||
|
|
||||||
beatmapManager.ItemAdded += beatmapAdded;
|
beatmapManager.ItemAdded += beatmapAdded;
|
||||||
}
|
}
|
||||||
@ -200,7 +207,7 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
|
|
||||||
private void updateWorkingBeatmap()
|
private void updateWorkingBeatmap()
|
||||||
{
|
{
|
||||||
var beatmap = selectedItem.Value?.Beatmap.Value;
|
var beatmap = SelectedItem.Value?.Beatmap.Value;
|
||||||
|
|
||||||
// Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info
|
// Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info
|
||||||
var localBeatmap = beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID);
|
var localBeatmap = beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID);
|
||||||
@ -222,7 +229,7 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case GameTypeTimeshift _:
|
case GameTypeTimeshift _:
|
||||||
multiplayer?.Start(() => new TimeshiftPlayer(selectedItem.Value)
|
multiplayer?.Start(() => new TimeshiftPlayer(SelectedItem.Value)
|
||||||
{
|
{
|
||||||
Exited = () => leaderboardChatDisplay.RefreshScores()
|
Exited = () => leaderboardChatDisplay.RefreshScores()
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user