1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 04:17:18 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomSubScreen.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

257 lines
12 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-05-28 21:01:56 -03:00
2022-06-17 16:37:17 +09:00
#nullable disable
2020-05-28 22:25:00 +09:00
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
2018-12-06 12:21:30 +09:00
using osu.Framework.Allocation;
2019-02-21 19:04:31 +09:00
using osu.Framework.Bindables;
2018-05-28 22:11:01 -03:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Game.Graphics.Cursor;
using osu.Game.Input;
2020-12-25 13:38:11 +09:00
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Match;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Users;
using osuTK;
2018-05-28 21:01:56 -03:00
namespace osu.Game.Screens.OnlinePlay.Playlists
2018-05-28 21:01:56 -03:00
{
2020-12-25 13:11:21 +09:00
public partial class PlaylistsRoomSubScreen : RoomSubScreen
2018-05-28 21:01:56 -03:00
{
2019-02-07 19:52:33 +09:00
public override string Title { get; }
2019-02-05 19:00:01 +09:00
public override string ShortTitle => "playlist";
private readonly IBindable<bool> isIdle = new BindableBool();
private MatchLeaderboard leaderboard;
private SelectionPollingComponent selectionPollingComponent;
private FillFlowContainer progressSection;
2020-12-25 13:11:21 +09:00
public PlaylistsRoomSubScreen(Room room)
2021-08-18 16:35:18 +09:00
: base(room, false) // Editing is temporarily not allowed.
2019-02-11 19:11:34 +09:00
{
Title = room.RoomID.Value == null ? "New playlist" : room.Name.Value;
Activity.Value = new UserActivity.InLobby(room);
2019-02-11 19:11:34 +09:00
}
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] IdleTracker idleTracker)
2019-02-11 19:11:34 +09:00
{
if (idleTracker != null)
isIdle.BindTo(idleTracker.IsIdle);
2021-08-19 16:40:27 +09:00
AddInternal(selectionPollingComponent = new SelectionPollingComponent(Room));
}
protected override void LoadComplete()
{
base.LoadComplete();
isIdle.BindValueChanged(_ => updatePollingRate(), true);
RoomId.BindValueChanged(id =>
{
if (id.NewValue != null)
{
// Set the first playlist item.
// This is scheduled since updating the room and playlist may happen in an arbitrary order (via Room.CopyFrom()).
Schedule(() => SelectedItem.Value = Room.Playlist.FirstOrDefault());
}
}, true);
2022-06-24 21:25:23 +09:00
Room.MaxAttempts.BindValueChanged(_ => progressSection.Alpha = Room.MaxAttempts.Value != null ? 1 : 0, true);
}
protected override Drawable CreateMainContent() => new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 5, Vertical = 10 },
Child = new OsuContextMenuContainer
2019-02-11 19:11:34 +09:00
{
RelativeSizeAxes = Axes.Both,
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.Absolute, 10),
new Dimension(),
new Dimension(GridSizeMode.Absolute, 10),
new Dimension(),
},
Content = new[]
{
new Drawable[]
2018-12-14 19:52:03 +09:00
{
// Playlist items column
new Container
2018-12-14 19:52:03 +09:00
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = 5 },
Child = new GridContainer
2020-02-14 20:48:09 +09:00
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[] { new OverlinedPlaylistHeader(), },
new Drawable[]
2020-06-25 18:59:14 +09:00
{
new DrawableRoomPlaylist
{
RelativeSizeAxes = Axes.Both,
Items = { BindTarget = Room.Playlist },
SelectedItem = { BindTarget = SelectedItem },
AllowSelection = true,
AllowShowingResults = true,
RequestResults = item =>
{
Debug.Assert(RoomId.Value != null);
ParentScreen?.Push(new PlaylistsResultsScreen(null, RoomId.Value.Value, item, false));
}
}
},
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
}
}
},
// Spacer
null,
// Middle column (mods and leaderboard)
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new[]
{
UserModsSection = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Alpha = 0,
Margin = new MarginPadding { Bottom = 10 },
Children = new Drawable[]
{
new OverlinedHeader("Extra mods"),
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0),
Children = new Drawable[]
{
new UserModSelectButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Width = 90,
Text = "Select",
Action = ShowUserModSelect,
},
new ModDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Current = UserMods,
Scale = new Vector2(0.8f),
},
}
}
}
},
},
new Drawable[]
{
progressSection = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Alpha = 0,
Margin = new MarginPadding { Bottom = 10 },
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OverlinedHeader("Progress"),
new RoomLocalUserInfo(),
}
},
},
new Drawable[]
{
new OverlinedHeader("Leaderboard")
},
new Drawable[] { leaderboard = new MatchLeaderboard { RelativeSizeAxes = Axes.Both }, },
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
}
},
// Spacer
null,
// Main right column
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[] { new OverlinedHeader("Chat") },
new Drawable[] { new MatchChatDisplay(Room) { RelativeSizeAxes = Axes.Both } }
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
}
},
},
},
}
}
};
2021-08-18 20:21:29 +09:00
protected override Drawable CreateFooter() => new PlaylistsRoomFooter
{
OnStart = StartPlay
};
2021-08-19 16:40:27 +09:00
protected override RoomSettingsOverlay CreateRoomSettingsOverlay(Room room) => new PlaylistsRoomSettingsOverlay(room)
2019-02-11 19:11:34 +09:00
{
EditPlaylist = () =>
{
if (this.IsCurrentScreen())
2021-08-24 13:29:19 +09:00
this.Push(new PlaylistsSongSelect(Room));
},
};
2021-08-18 20:21:29 +09:00
private void updatePollingRate()
{
selectionPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 30000 : 5000;
Logger.Log($"Polling adjusted (selection: {selectionPollingComponent.TimeBetweenPolls.Value})");
}
protected override Screen CreateGameplayScreen() => new PlayerLoader(() => new PlaylistsPlayer(Room, SelectedItem.Value)
2021-08-18 20:21:29 +09:00
{
Exited = () => leaderboard.RefetchScores()
2021-08-18 20:21:29 +09:00
});
2018-05-28 21:01:56 -03:00
}
}