Implement the match beatmap detail area

This commit is contained in:
smoogipoo 2020-02-14 17:20:38 +09:00
parent 25e399f11b
commit 5ec9f454d5
5 changed files with 216 additions and 1 deletions

View File

@ -0,0 +1,67 @@
// 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.
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.Multi.Components;
using osuTK;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneMatchBeatmapDetailArea : MultiplayerTestScene
{
[Resolved]
private BeatmapManager beatmapManager { get; set; }
[Resolved]
private RulesetStore rulesetStore { get; set; }
private MatchBeatmapDetailArea detailArea;
[SetUp]
public void Setup() => Schedule(() =>
{
Room.Playlist.Clear();
Child = detailArea = new MatchBeatmapDetailArea
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(500),
CreateNewItem = createNewItem
};
});
private void createNewItem()
{
var set = beatmapManager.GetAllUsableBeatmapSetsEnumerable().First();
var rulesets = rulesetStore.AvailableRulesets.ToList();
var beatmap = set.Beatmaps[RNG.Next(0, set.Beatmaps.Count)];
beatmap.BeatmapSet = set;
beatmap.Metadata = set.Metadata;
Room.Playlist.Add(new PlaylistItem
{
ID = Room.Playlist.Count,
Beatmap = { Value = beatmap },
Ruleset = { Value = rulesets[RNG.Next(0, rulesets.Count)] },
RequiredMods =
{
new OsuModHardRock(),
new OsuModDoubleTime(),
new OsuModAutoplay()
}
});
}
}
}

View File

@ -0,0 +1,37 @@
// 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.
using System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Game.Beatmaps;
using osu.Game.Screens.Multi.Components;
using osu.Game.Screens.Select;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneMatchSongSelect : MultiplayerTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(MatchSongSelect),
typeof(MatchBeatmapDetailArea),
};
[Resolved]
private BeatmapManager beatmapManager { get; set; }
[SetUp]
public void Setup() => Schedule(() =>
{
Room.Playlist.Clear();
});
[Test]
public void TestLoadSongSelect()
{
AddStep("create song select", () => LoadScreen(new MatchSongSelect()));
}
}
}

View File

@ -0,0 +1,12 @@
// 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.
using osu.Game.Screens.Select;
namespace osu.Game.Screens.Multi.Components
{
public class BeatmapDetailAreaPlaylistTabItem : BeatmapDetailAreaTabItem
{
public override string Name => "Playlist";
}
}

View File

@ -0,0 +1,98 @@
// 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.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Select;
using osuTK;
namespace osu.Game.Screens.Multi.Components
{
public class MatchBeatmapDetailArea : BeatmapDetailArea
{
public Action CreateNewItem;
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
[Resolved(typeof(Room))]
protected BindableList<PlaylistItem> Playlist { get; private set; }
private readonly Drawable playlistArea;
private readonly DrawableRoomPlaylist playlist;
public MatchBeatmapDetailArea()
{
Add(playlistArea = new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Vertical = 10 },
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Bottom = 10 },
Child = playlist = new DrawableRoomPlaylist(true, false)
{
RelativeSizeAxes = Axes.Both,
}
}
},
new Drawable[]
{
new TriangleButton
{
Text = "create new item",
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
Action = () => CreateNewItem?.Invoke()
}
},
},
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.Absolute, 50),
}
}
});
}
protected override void LoadComplete()
{
base.LoadComplete();
playlist.Items.BindTo(Playlist);
playlist.SelectedItem.BindTo(SelectedItem);
}
protected override void OnTabChanged(BeatmapDetailAreaTabItem tab, bool selectedMods)
{
base.OnTabChanged(tab, selectedMods);
switch (tab)
{
case BeatmapDetailAreaPlaylistTabItem _:
playlistArea.Show();
break;
default:
playlistArea.Hide();
break;
}
}
protected override BeatmapDetailAreaTabItem[] CreateTabItems() => base.CreateTabItems().Prepend(new BeatmapDetailAreaPlaylistTabItem()).ToArray();
}
}

View File

@ -12,6 +12,7 @@
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Multi;
using osu.Game.Screens.Multi.Components;
namespace osu.Game.Screens.Select
{
@ -35,7 +36,7 @@ public MatchSongSelect()
Padding = new MarginPadding { Horizontal = HORIZONTAL_OVERFLOW_PADDING };
}
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new PlayBeatmapDetailArea(); // Todo: Temporary
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new MatchBeatmapDetailArea();
protected override bool OnStart()
{