mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 01:17:35 +09:00
192 lines
6.2 KiB
C#
192 lines
6.2 KiB
C#
// 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.Collections.Generic;
|
|
using System.Linq;
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Input;
|
|
using osu.Framework.Screens;
|
|
using osu.Game.Graphics.UserInterface;
|
|
using osu.Game.Online.Multiplayer;
|
|
using osu.Game.Overlays.SearchableList;
|
|
using osu.Game.Screens.Multi.Components;
|
|
using OpenTK;
|
|
|
|
namespace osu.Game.Screens.Multi.Screens.Lounge
|
|
{
|
|
public class Lounge : MultiplayerScreen
|
|
{
|
|
private readonly Container content;
|
|
private readonly SearchContainer search;
|
|
|
|
protected readonly FilterControl Filter;
|
|
protected readonly FillFlowContainer<DrawableRoom> RoomsContainer;
|
|
protected readonly RoomInspector Inspector;
|
|
|
|
public override string Title => "Lounge";
|
|
|
|
protected override Container<Drawable> TransitionContent => content;
|
|
|
|
private IEnumerable<Room> rooms;
|
|
public IEnumerable<Room> Rooms
|
|
{
|
|
get { return rooms; }
|
|
set
|
|
{
|
|
if (Equals(value, rooms)) return;
|
|
rooms = value;
|
|
|
|
var enumerable = rooms.ToList();
|
|
|
|
RoomsContainer.Children = enumerable.Select(r => new DrawableRoom(r)
|
|
{
|
|
Action = didSelect,
|
|
}).ToList();
|
|
|
|
if (!enumerable.Contains(Inspector.Room))
|
|
Inspector.Room = null;
|
|
|
|
filterRooms();
|
|
}
|
|
}
|
|
|
|
public Lounge()
|
|
{
|
|
Children = new Drawable[]
|
|
{
|
|
Filter = new FilterControl(),
|
|
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
|
|
},
|
|
Child = search = new SearchContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Child = RoomsContainer = new RoomsFilterContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Direction = FillDirection.Vertical,
|
|
Spacing = new Vector2(10 - DrawableRoom.SELECTION_BORDER_WIDTH * 2),
|
|
},
|
|
},
|
|
},
|
|
Inspector = new RoomInspector
|
|
{
|
|
Anchor = Anchor.TopRight,
|
|
Origin = Anchor.TopRight,
|
|
RelativeSizeAxes = Axes.Both,
|
|
Width = 0.45f,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
Filter.Search.Current.ValueChanged += s => filterRooms();
|
|
Filter.Tabs.Current.ValueChanged += t => filterRooms();
|
|
Filter.Search.Exit += Exit;
|
|
}
|
|
|
|
protected override void UpdateAfterChildren()
|
|
{
|
|
base.UpdateAfterChildren();
|
|
|
|
content.Padding = new MarginPadding
|
|
{
|
|
Top = Filter.DrawHeight,
|
|
Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH,
|
|
Right = SearchableListOverlay.WIDTH_PADDING,
|
|
};
|
|
}
|
|
|
|
protected override void OnFocus(InputState state)
|
|
{
|
|
GetContainingInputManager().ChangeFocus(Filter.Search);
|
|
}
|
|
|
|
protected override void OnEntering(Screen last)
|
|
{
|
|
base.OnEntering(last);
|
|
Filter.Search.HoldFocus = true;
|
|
}
|
|
|
|
protected override bool OnExiting(Screen next)
|
|
{
|
|
Filter.Search.HoldFocus = false;
|
|
return base.OnExiting(next);
|
|
}
|
|
|
|
protected override void OnResuming(Screen last)
|
|
{
|
|
base.OnResuming(last);
|
|
Filter.Search.HoldFocus = true;
|
|
}
|
|
|
|
protected override void OnSuspending(Screen next)
|
|
{
|
|
base.OnSuspending(next);
|
|
Filter.Search.HoldFocus = false;
|
|
}
|
|
|
|
private void filterRooms()
|
|
{
|
|
search.SearchTerm = Filter.Search.Current.Value ?? string.Empty;
|
|
|
|
foreach (DrawableRoom r in RoomsContainer.Children)
|
|
{
|
|
r.MatchingFilter = r.MatchingFilter &&
|
|
r.Room.Availability.Value == (RoomAvailability)Filter.Tabs.Current.Value;
|
|
}
|
|
}
|
|
|
|
private void didSelect(DrawableRoom room)
|
|
{
|
|
RoomsContainer.Children.ForEach(c =>
|
|
{
|
|
if (c != room)
|
|
c.State = SelectionState.NotSelected;
|
|
});
|
|
|
|
Inspector.Room = room.Room;
|
|
|
|
// open the room if its selected and is clicked again
|
|
if (room.State == SelectionState.Selected)
|
|
Push(new Match());
|
|
}
|
|
|
|
private class RoomsFilterContainer : FillFlowContainer<DrawableRoom>, IHasFilterableChildren
|
|
{
|
|
public IEnumerable<string> FilterTerms => new string[] { };
|
|
public IEnumerable<IFilterable> FilterableChildren => Children;
|
|
|
|
public bool MatchingFilter
|
|
{
|
|
set
|
|
{
|
|
if (value)
|
|
InvalidateLayout();
|
|
}
|
|
}
|
|
|
|
public RoomsFilterContainer()
|
|
{
|
|
LayoutDuration = 200;
|
|
LayoutEasing = Easing.OutQuint;
|
|
}
|
|
}
|
|
}
|
|
}
|