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

147 lines
4.7 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;
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-10 18:20:41 +08:00
public class LoungeScreen : MultiplayerScreen
2018-05-22 11:07:04 +08:00
{
protected readonly FilterControl Filter;
2018-05-22 11:07:04 +08:00
private readonly Container content;
2018-05-22 11:33:41 +08:00
private readonly SearchContainer search;
private readonly RoomsContainer rooms;
private readonly Action<Screen> pushGameplayScreen;
2018-05-22 11:07:04 +08:00
[Cached]
private readonly RoomManager manager;
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
public LoungeScreen(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 ScrollContainer
{
RelativeSizeAxes = Axes.Both,
Width = 0.55f,
Padding = new MarginPadding
{
Vertical = 35 - DrawableRoom.SELECTION_BORDER_WIDTH,
Right = 20 - DrawableRoom.SELECTION_BORDER_WIDTH
},
2018-05-22 11:33:41 +08:00
Child = search = new SearchContainer
2018-05-22 11:07:04 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = rooms = new RoomsContainer { OpenRequested = openRoom }
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,
},
},
},
manager = new RoomManager()
2018-05-22 11:07:04 +08:00
};
2018-05-22 11:24:39 +08:00
inspector.Room.BindTo(manager.Current);
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-05-22 11:24:39 +08:00
return base.OnExiting(next);
}
protected override void OnResuming(Screen last)
{
base.OnResuming(last);
2018-05-22 12:22:23 +08:00
Filter.Search.HoldFocus = true;
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
}
2018-05-22 11:33:41 +08:00
private void filterRooms()
{
2018-12-03 17:30:26 +08:00
if (Filter.Tabs.Current.Value == LoungeTab.Create)
{
Filter.Tabs.Current.Value = LoungeTab.Public;
openRoom(new Room());
}
2018-12-03 17:30:26 +08:00
2018-05-22 12:22:23 +08:00
search.SearchTerm = Filter.Search.Current.Value ?? string.Empty;
2018-05-22 11:33:41 +08:00
rooms.Filter(Filter.CreateCriteria());
2018-05-22 11:33:41 +08:00
}
private void openRoom(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;
Push(new MatchScreen(room, s => pushGameplayScreen?.Invoke(s)));
2018-05-22 11:33:41 +08:00
}
2018-05-22 11:07:04 +08:00
}
}