mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 18:27:26 +08:00
Make RoomsContainer/DrawableRoom not resolve via DI
This commit is contained in:
parent
3a1154c00e
commit
00be7f4cca
@ -24,12 +24,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneDrawableRoom : OsuTestScene
|
||||
{
|
||||
[Cached]
|
||||
private readonly Bindable<Room> selectedRoom = new Bindable<Room>();
|
||||
|
||||
[Cached]
|
||||
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
|
||||
|
||||
private readonly Bindable<Room> selectedRoom = new Bindable<Room>();
|
||||
|
||||
[Test]
|
||||
public void TestMultipleStatuses()
|
||||
{
|
||||
@ -153,7 +152,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
}));
|
||||
}
|
||||
|
||||
return new DrawableLoungeRoom(room) { MatchingFilter = true };
|
||||
return new DrawableLoungeRoom(room)
|
||||
{
|
||||
MatchingFilter = true,
|
||||
SelectedRoom = { BindTarget = selectedRoom }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 0.5f,
|
||||
SelectedRoom = { BindTarget = SelectedRoom }
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -23,16 +23,13 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
{
|
||||
public class RoomsContainer : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
private readonly IBindableList<Room> rooms = new BindableList<Room>();
|
||||
|
||||
private readonly FillFlowContainer<DrawableLoungeRoom> roomFlow;
|
||||
public readonly Bindable<Room> SelectedRoom = new Bindable<Room>();
|
||||
public readonly Bindable<FilterCriteria> Filter = new Bindable<FilterCriteria>();
|
||||
|
||||
public IReadOnlyList<DrawableRoom> Rooms => roomFlow.FlowingChildren.Cast<DrawableRoom>().ToArray();
|
||||
|
||||
public readonly Bindable<FilterCriteria> Filter = new Bindable<FilterCriteria>();
|
||||
|
||||
[Resolved]
|
||||
private Bindable<Room> selectedRoom { get; set; }
|
||||
private readonly IBindableList<Room> rooms = new BindableList<Room>();
|
||||
private readonly FillFlowContainer<DrawableLoungeRoom> roomFlow;
|
||||
|
||||
[Resolved]
|
||||
private IRoomManager roomManager { get; set; }
|
||||
@ -112,9 +109,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
private void addRooms(IEnumerable<Room> rooms)
|
||||
{
|
||||
foreach (var room in rooms)
|
||||
{
|
||||
roomFlow.Add(new DrawableLoungeRoom(room));
|
||||
}
|
||||
roomFlow.Add(new DrawableLoungeRoom(room) { SelectedRoom = { BindTarget = SelectedRoom } });
|
||||
|
||||
applyFilterCriteria(Filter?.Value);
|
||||
}
|
||||
@ -126,8 +121,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
roomFlow.RemoveAll(d => d.Room == r);
|
||||
|
||||
// selection may have a lease due to being in a sub screen.
|
||||
if (!selectedRoom.Disabled)
|
||||
selectedRoom.Value = null;
|
||||
if (!SelectedRoom.Disabled)
|
||||
SelectedRoom.Value = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,8 +134,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (!selectedRoom.Disabled)
|
||||
selectedRoom.Value = null;
|
||||
if (!SelectedRoom.Disabled)
|
||||
SelectedRoom.Value = null;
|
||||
return base.OnClick(e);
|
||||
}
|
||||
|
||||
@ -202,26 +197,26 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
|
||||
private void selectNext(int direction)
|
||||
{
|
||||
if (selectedRoom.Disabled)
|
||||
if (SelectedRoom.Disabled)
|
||||
return;
|
||||
|
||||
var visibleRooms = Rooms.AsEnumerable().Where(r => r.IsPresent);
|
||||
|
||||
Room room;
|
||||
|
||||
if (selectedRoom.Value == null)
|
||||
if (SelectedRoom.Value == null)
|
||||
room = visibleRooms.FirstOrDefault()?.Room;
|
||||
else
|
||||
{
|
||||
if (direction < 0)
|
||||
visibleRooms = visibleRooms.Reverse();
|
||||
|
||||
room = visibleRooms.SkipWhile(r => r.Room != selectedRoom.Value).Skip(1).FirstOrDefault()?.Room;
|
||||
room = visibleRooms.SkipWhile(r => r.Room != SelectedRoom.Value).Skip(1).FirstOrDefault()?.Room;
|
||||
}
|
||||
|
||||
// we already have a valid selection only change selection if we still have a room to switch to.
|
||||
if (room != null)
|
||||
selectedRoom.Value = room;
|
||||
SelectedRoom.Value = room;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -34,11 +34,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
private const float transition_duration = 60;
|
||||
private const float selection_border_width = 4;
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private LoungeSubScreen lounge { get; set; }
|
||||
public readonly Bindable<Room> SelectedRoom = new Bindable<Room>();
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private Bindable<Room> selectedRoom { get; set; }
|
||||
private LoungeSubScreen lounge { get; set; }
|
||||
|
||||
private Sample sampleSelect;
|
||||
private Sample sampleJoin;
|
||||
@ -89,7 +88,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
else
|
||||
Alpha = 0;
|
||||
|
||||
selectedRoom.BindValueChanged(updateSelectedRoom, true);
|
||||
SelectedRoom.BindValueChanged(updateSelectedRoom, true);
|
||||
}
|
||||
|
||||
private void updateSelectedRoom(ValueChangedEvent<Room> selected)
|
||||
@ -135,7 +134,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
if (selectedRoom.Value != Room)
|
||||
if (SelectedRoom.Value != Room)
|
||||
return false;
|
||||
|
||||
switch (action)
|
||||
@ -152,14 +151,14 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool ShouldBeConsideredForInput(Drawable child) => selectedRoom.Value == Room || child is HoverSounds;
|
||||
protected override bool ShouldBeConsideredForInput(Drawable child) => SelectedRoom.Value == Room || child is HoverSounds;
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (Room != selectedRoom.Value)
|
||||
if (Room != SelectedRoom.Value)
|
||||
{
|
||||
sampleSelect?.Play();
|
||||
selectedRoom.Value = Room;
|
||||
SelectedRoom.Value = Room;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
ScrollbarOverlapsContent = false,
|
||||
Child = roomsContainer = new RoomsContainer
|
||||
{
|
||||
Filter = { BindTarget = filter }
|
||||
Filter = { BindTarget = filter },
|
||||
SelectedRoom = { BindTarget = selectedRoom }
|
||||
}
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user