1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 00:07:24 +08:00
osu-lazer/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs

152 lines
5.0 KiB
C#
Raw Normal View History

2018-05-22 11:07:04 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
2018-05-22 11:07:04 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-05-22 11:24:39 +08:00
using osu.Framework.Screens;
using osu.Game.Graphics.UserInterface;
2018-05-22 11:07:04 +08:00
using osu.Game.Online.Multiplayer;
using osu.Game.Overlays.SearchableList;
2018-12-10 18:20:41 +08:00
using osu.Game.Screens.Multi.Lounge.Components;
using osu.Game.Screens.Multi.Match;
2018-05-22 11:07:04 +08:00
2018-12-10 18:20:41 +08:00
namespace osu.Game.Screens.Multi.Lounge
2018-05-22 11:07:04 +08:00
{
2018-12-26 19:05:57 +08:00
public class LoungeSubScreen : MultiplayerSubScreen
2018-05-22 11:07:04 +08:00
{
protected readonly FilterControl Filter;
2018-05-22 11:07:04 +08:00
private readonly Container content;
private readonly RoomsContainer rooms;
private readonly Action<Screen> pushGameplayScreen;
private readonly ProcessingOverlay processingOverlay;
2018-05-22 11:07:04 +08:00
2018-12-22 13:14:14 +08:00
[Resolved(CanBeNull = true)]
private IRoomManager roomManager { get; set; }
2018-05-22 11:07:04 +08:00
2018-05-29 15:23:29 +08:00
public override string Title => "Lounge";
2018-05-28 12:02:06 +08:00
2018-12-07 15:20:05 +08:00
protected override Drawable TransitionContent => content;
2018-05-22 11:07:04 +08:00
2018-12-26 19:05:57 +08:00
public LoungeSubScreen(Action<Screen> pushGameplayScreen)
2018-05-22 11:07:04 +08:00
{
this.pushGameplayScreen = pushGameplayScreen;
RoomInspector inspector;
2018-05-22 11:07:04 +08:00
Children = new Drawable[]
{
2018-12-03 17:30:26 +08:00
Filter = new FilterControl { Depth = -1 },
2018-05-22 11:07:04 +08:00
content = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Container
2018-05-22 11:07:04 +08:00
{
RelativeSizeAxes = Axes.Both,
Width = 0.55f,
Children = new Drawable[]
2018-05-22 11:07:04 +08:00
{
new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarOverlapsContent = false,
Padding = new MarginPadding(10),
Child = new SearchContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = rooms = new RoomsContainer { JoinRequested = joinRequested }
},
},
processingOverlay = new ProcessingOverlay { Alpha = 0 }
}
2018-05-22 11:07:04 +08:00
},
inspector = new RoomInspector
2018-05-22 11:07:04 +08:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Width = 0.45f,
},
},
},
2018-05-22 11:07:04 +08:00
};
2018-05-22 11:24:39 +08:00
2018-12-20 19:58:34 +08:00
inspector.Room.BindTo(rooms.SelectedRoom);
2018-05-22 12:22:23 +08:00
Filter.Search.Current.ValueChanged += s => filterRooms();
Filter.Tabs.Current.ValueChanged += t => filterRooms();
Filter.Search.Exit += Exit;
2018-05-22 11:07:04 +08:00
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
content.Padding = new MarginPadding
{
2018-05-22 12:22:23 +08:00
Top = Filter.DrawHeight,
2018-05-22 11:07:04 +08:00
Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH,
Right = SearchableListOverlay.WIDTH_PADDING,
};
}
2018-10-02 11:02:47 +08:00
protected override void OnFocus(FocusEvent e)
2018-05-22 11:24:39 +08:00
{
2018-05-22 12:22:23 +08:00
GetContainingInputManager().ChangeFocus(Filter.Search);
2018-05-22 11:24:39 +08:00
}
protected override void OnEntering(Screen last)
{
base.OnEntering(last);
2018-05-22 12:22:23 +08:00
Filter.Search.HoldFocus = true;
2018-05-22 11:24:39 +08:00
}
protected override bool OnExiting(Screen next)
{
2018-05-22 12:22:23 +08:00
Filter.Search.HoldFocus = false;
2018-12-26 19:05:57 +08:00
// no base call; don't animate
return false;
2018-05-22 11:24:39 +08:00
}
protected override void OnSuspending(Screen next)
{
base.OnSuspending(next);
2018-05-22 12:22:23 +08:00
Filter.Search.HoldFocus = false;
2018-05-22 11:24:39 +08:00
}
private void filterRooms()
{
rooms.Filter(Filter.CreateCriteria());
2018-12-22 13:14:14 +08:00
roomManager?.Filter(Filter.CreateCriteria());
}
2018-05-22 11:33:41 +08:00
private void joinRequested(Room room)
{
processingOverlay.Show();
roomManager?.JoinRoom(room, r =>
{
2018-12-26 20:21:26 +08:00
Push(room);
processingOverlay.Hide();
}, _ => processingOverlay.Hide());
}
2018-12-26 19:21:30 +08:00
/// <summary>
/// Push a room as a new subscreen.
/// </summary>
public void Push(Room room)
2018-12-04 14:26:06 +08:00
{
// Handles the case where a room is clicked 3 times in quick succession
2018-12-04 14:26:06 +08:00
if (!IsCurrentScreen)
return;
2018-12-26 19:05:57 +08:00
Push(new MatchSubScreen(room, s => pushGameplayScreen?.Invoke(s)));
2018-05-22 11:33:41 +08:00
}
2018-05-22 11:07:04 +08:00
}
}