mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:03:13 +08:00
Add joining/parting room requests
This commit is contained in:
parent
9031896484
commit
822225577b
@ -28,7 +28,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
{
|
||||
private const float transition_duration = 100;
|
||||
|
||||
public readonly Bindable<Room> Room = new Bindable<Room>();
|
||||
public readonly IBindable<Room> Room = new Bindable<Room>();
|
||||
|
||||
private readonly MarginPadding contentPadding = new MarginPadding { Horizontal = 20, Vertical = 10 };
|
||||
private readonly Bindable<string> nameBind = new Bindable<string>();
|
||||
|
@ -17,10 +17,12 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
{
|
||||
public class RoomsContainer : CompositeDrawable, IHasFilterableChildren
|
||||
{
|
||||
public Action<Room> OpenRequested;
|
||||
public Action<Room> JoinRequested;
|
||||
|
||||
private readonly Bindable<Room> selectedRoom = new Bindable<Room>();
|
||||
public IBindable<Room> SelectedRoom => selectedRoom;
|
||||
|
||||
private readonly IBindableCollection<Room> rooms = new BindableCollection<Room>();
|
||||
private readonly Bindable<Room> currentRoom = new Bindable<Room>();
|
||||
|
||||
private readonly FillFlowContainer<DrawableRoom> roomFlow;
|
||||
|
||||
@ -44,15 +46,12 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
currentRoom.BindTo(manager.Current);
|
||||
rooms.BindTo(manager.Rooms);
|
||||
|
||||
rooms.ItemsAdded += addRooms;
|
||||
rooms.ItemsRemoved += removeRooms;
|
||||
|
||||
addRooms(rooms);
|
||||
|
||||
currentRoom.BindValueChanged(selectRoom, true);
|
||||
}
|
||||
|
||||
private FilterCriteria currentFilter;
|
||||
@ -100,8 +99,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
|
||||
roomFlow.Remove(toRemove);
|
||||
|
||||
if (currentRoom.Value == r)
|
||||
currentRoom.Value = null;
|
||||
selectRoom(null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,12 +108,11 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
var drawable = roomFlow.FirstOrDefault(r => r.Room == room);
|
||||
|
||||
if (drawable != null && drawable.State == SelectionState.Selected)
|
||||
OpenRequested?.Invoke(room);
|
||||
JoinRequested?.Invoke(room);
|
||||
else
|
||||
{
|
||||
currentRoom.Value = room;
|
||||
roomFlow.Children.ForEach(r => r.State = r.Room == room ? SelectionState.Selected : SelectionState.NotSelected);
|
||||
}
|
||||
|
||||
selectedRoom.Value = room;
|
||||
}
|
||||
|
||||
public IEnumerable<string> FilterTerms => Enumerable.Empty<string>();
|
||||
|
@ -56,7 +56,7 @@ namespace osu.Game.Screens.Multi.Lounge
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Child = rooms = new RoomsContainer { OpenRequested = Open }
|
||||
Child = rooms = new RoomsContainer { JoinRequested = r => manager?.JoinRoom(r) }
|
||||
},
|
||||
},
|
||||
inspector = new RoomInspector
|
||||
@ -68,10 +68,10 @@ namespace osu.Game.Screens.Multi.Lounge
|
||||
},
|
||||
},
|
||||
},
|
||||
manager = new RoomManager()
|
||||
manager = new RoomManager { OpenRequested = Open }
|
||||
};
|
||||
|
||||
inspector.Room.BindTo(manager.Current);
|
||||
inspector.Room.BindTo(rooms.SelectedRoom);
|
||||
|
||||
Filter.Search.Current.ValueChanged += s => filterRooms();
|
||||
Filter.Tabs.Current.ValueChanged += t => filterRooms();
|
||||
@ -103,15 +103,17 @@ namespace osu.Game.Screens.Multi.Lounge
|
||||
|
||||
protected override bool OnExiting(Screen next)
|
||||
{
|
||||
manager?.PartRoom();
|
||||
|
||||
Filter.Search.HoldFocus = false;
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
||||
protected override void OnResuming(Screen last)
|
||||
{
|
||||
base.OnResuming(last);
|
||||
manager?.PartRoom();
|
||||
|
||||
Filter.Search.HoldFocus = true;
|
||||
base.OnResuming(last);
|
||||
}
|
||||
|
||||
protected override void OnSuspending(Screen next)
|
||||
|
@ -10,7 +10,6 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Screens.Multi.Match.Components;
|
||||
using osu.Game.Screens.Multi.Play;
|
||||
@ -52,12 +51,12 @@ namespace osu.Game.Screens.Multi.Match
|
||||
[Resolved]
|
||||
private BeatmapManager beatmapManager { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private APIAccess api { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuGame game { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private RoomManager manager { get; set; }
|
||||
|
||||
public MatchScreen(Room room, Action<Screen> pushGameplayScreen)
|
||||
{
|
||||
this.room = room;
|
||||
|
@ -27,6 +27,7 @@ namespace osu.Game.Screens.Multi
|
||||
public override bool AllowBeatmapRulesetChange => currentScreen?.AllowBeatmapRulesetChange ?? base.AllowBeatmapRulesetChange;
|
||||
|
||||
private readonly OsuButton createButton;
|
||||
private readonly LoungeScreen loungeScreen;
|
||||
|
||||
private OsuScreen currentScreen;
|
||||
|
||||
@ -37,7 +38,6 @@ namespace osu.Game.Screens.Multi
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
};
|
||||
|
||||
LoungeScreen loungeScreen;
|
||||
waves.AddRange(new Drawable[]
|
||||
{
|
||||
new Container
|
||||
@ -102,6 +102,9 @@ namespace osu.Game.Screens.Multi
|
||||
if (track != null)
|
||||
track.Looping = false;
|
||||
|
||||
loungeScreen.MakeCurrent();
|
||||
loungeScreen.Exit();
|
||||
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@ -16,15 +17,18 @@ using osu.Game.Online.API;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Multi.Lounge.Components;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Screens.Multi
|
||||
{
|
||||
public class RoomManager : PollingComponent
|
||||
{
|
||||
public Action<Room> OpenRequested;
|
||||
|
||||
public IBindableCollection<Room> Rooms => rooms;
|
||||
private readonly BindableCollection<Room> rooms = new BindableCollection<Room>();
|
||||
|
||||
public readonly Bindable<Room> Current = new Bindable<Room>();
|
||||
private Room currentRoom;
|
||||
|
||||
private FilterCriteria currentFilter = new FilterCriteria();
|
||||
|
||||
@ -47,12 +51,40 @@ namespace osu.Game.Screens.Multi
|
||||
room.Host.Value = api.LocalUser;
|
||||
|
||||
var req = new CreateRoomRequest(room);
|
||||
|
||||
req.Success += result => addRoom(room, result);
|
||||
req.Failure += exception => Logger.Log($"Failed to create room: {exception}");
|
||||
|
||||
api.Queue(req);
|
||||
}
|
||||
|
||||
private JoinRoomRequest currentJoinRoomRequest;
|
||||
|
||||
public void JoinRoom(Room room)
|
||||
{
|
||||
currentJoinRoomRequest?.Cancel();
|
||||
currentJoinRoomRequest = null;
|
||||
|
||||
currentJoinRoomRequest = new JoinRoomRequest(room, api.LocalUser.Value);
|
||||
currentJoinRoomRequest.Success += () =>
|
||||
{
|
||||
currentRoom = room;
|
||||
OpenRequested?.Invoke(room);
|
||||
};
|
||||
|
||||
currentJoinRoomRequest.Failure += exception => Logger.Log($"Failed to join room: {exception}");
|
||||
|
||||
api.Queue(currentJoinRoomRequest);
|
||||
}
|
||||
|
||||
public void PartRoom()
|
||||
{
|
||||
if (currentRoom == null)
|
||||
return;
|
||||
|
||||
api.Queue(new PartRoomRequest(currentRoom, api.LocalUser.Value));
|
||||
currentRoom = null;
|
||||
}
|
||||
|
||||
public void Filter(FilterCriteria criteria)
|
||||
{
|
||||
currentFilter = criteria;
|
||||
@ -141,6 +173,48 @@ namespace osu.Game.Screens.Multi
|
||||
protected override string Target => "rooms";
|
||||
}
|
||||
|
||||
private class JoinRoomRequest : APIRequest
|
||||
{
|
||||
private readonly Room room;
|
||||
private readonly User user;
|
||||
|
||||
public JoinRoomRequest(Room room, User user)
|
||||
{
|
||||
this.room = room;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
req.Method = HttpMethod.Put;
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => $"rooms/{room.RoomID.Value}/users/{user.Id}";
|
||||
}
|
||||
|
||||
private class PartRoomRequest : APIRequest
|
||||
{
|
||||
private readonly Room room;
|
||||
private readonly User user;
|
||||
|
||||
public PartRoomRequest(Room room, User user)
|
||||
{
|
||||
this.room = room;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
req.Method = HttpMethod.Delete;
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => $"rooms/{room.RoomID.Value}/users/{user.Id}";
|
||||
}
|
||||
|
||||
private class GetRoomsRequest : APIRequest<List<Room>>
|
||||
{
|
||||
private readonly PrimaryFilter primaryFilter;
|
||||
|
Loading…
Reference in New Issue
Block a user