1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:07:44 +08:00

Initial implementation of a beatmap carousell and various minor improvements to song select.

No big optimizations yet, but groundwork is laid out.
This commit is contained in:
Thomas Müller 2016-11-20 20:34:16 +01:00
parent 40805ad32c
commit c6d688898f
13 changed files with 268 additions and 162 deletions

@ -1 +1 @@
Subproject commit 8afa4fa7ae9bbd5f357f859b1cc944c78286751a
Subproject commit 611037f88bd2e64e40ca1a3a385c14fd0a012bf2

View File

@ -6,7 +6,7 @@ using osu.Desktop.VisualTests.Platform;
using osu.Framework.GameModes.Testing;
using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Screens.Play;
using osu.Game.Screens.Select;
namespace osu.Desktop.VisualTests.Tests
{

View File

@ -17,7 +17,7 @@ using osu.Framework.Allocation;
namespace osu.Game.Beatmaps.Drawable
{
class BeatmapGroup : Container, IStateful<BeatmapGroupState>
class BeatmapGroup : IStateful<BeatmapGroupState>
{
public BeatmapPanel SelectedPanel;
@ -27,8 +27,7 @@ namespace osu.Game.Beatmaps.Drawable
public Action<BeatmapGroup, BeatmapInfo> SelectionChanged;
private BeatmapSetInfo beatmapSet;
private BeatmapSetHeader header;
private FlowContainer difficulties;
public BeatmapSetHeader Header;
private BeatmapGroupState state;
@ -43,24 +42,24 @@ namespace osu.Game.Beatmaps.Drawable
switch (state)
{
case BeatmapGroupState.Expanded:
FadeTo(1, 250);
//if (!difficulties.Children.All(d => IsLoaded))
// Task.WhenAll(difficulties.Children.Select(d => d.Preload(Game))).ContinueWith(t => difficulties.Show());
//else
difficulties.Show();
foreach (BeatmapPanel panel in BeatmapPanels)
panel.Show();
header.State = PanelSelectedState.Selected;
Header.State = PanelSelectedState.Selected;
if (SelectedPanel != null)
SelectedPanel.State = PanelSelectedState.Selected;
break;
case BeatmapGroupState.Collapsed:
FadeTo(0.8f, 250);
header.State = PanelSelectedState.NotSelected;
Header.State = PanelSelectedState.NotSelected;
if (SelectedPanel != null)
SelectedPanel.State = PanelSelectedState.NotSelected;
difficulties.Hide();
foreach (BeatmapPanel panel in BeatmapPanels)
panel.Hide();
break;
}
}
@ -70,54 +69,21 @@ namespace osu.Game.Beatmaps.Drawable
{
this.beatmapSet = beatmapSet;
Alpha = 0;
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
Children = new[]
Header = new BeatmapSetHeader(beatmapSet, working)
{
new FlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FlowDirection.VerticalOnly,
Children = new Framework.Graphics.Drawable[]
{
header = new BeatmapSetHeader(beatmapSet, working)
{
GainedSelection = headerGainedSelection,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
difficulties = new FlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = 5 },
Padding = new MarginPadding { Left = 75 },
Spacing = new Vector2(0, 5),
Direction = FlowDirection.VerticalOnly,
}
}
}
GainedSelection = headerGainedSelection,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
};
}
[BackgroundDependencyLoader]
private void load(BaseGame game)
{
BeatmapPanels = beatmapSet.Beatmaps.Select(b => new BeatmapPanel(b)
{
GainedSelection = panelGainedSelection,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.X,
}).ToList();
//for the time being, let's completely load the difficulty panels in the background.
//this likely won't scale so well, but allows us to completely async the loading flow.
Task.WhenAll(BeatmapPanels.Select(panel => panel.Preload(game, p => difficulties.Add(panel)))).Wait();
}).ToList();
}
private void headerGainedSelection(BeatmapSetHeader panel)

View File

@ -11,12 +11,14 @@ using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Colour;
namespace osu.Game.Beatmaps.Drawable
{
class BeatmapPanel : Panel
{
public BeatmapInfo Beatmap;
private Sprite background;
public Action<BeatmapPanel> GainedSelection;
@ -24,6 +26,17 @@ namespace osu.Game.Beatmaps.Drawable
{
base.Selected();
GainedSelection?.Invoke(this);
background.ColourInfo = ColourInfo.GradientVertical(
new Color4(20, 43, 51, 255),
new Color4(40, 86, 102, 255));
}
protected override void Deselected()
{
base.Deselected();
background.Colour = new Color4(20, 43, 51, 255);
}
public BeatmapPanel(BeatmapInfo beatmap)
@ -33,11 +46,9 @@ namespace osu.Game.Beatmaps.Drawable
Children = new Framework.Graphics.Drawable[]
{
new Box
background = new Box
{
Colour = new Color4(40, 86, 102, 255), // TODO: gradient
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
},
new FlowContainer
{

View File

@ -10,10 +10,10 @@ using osu.Game.Database;
using osu.Game.Graphics;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Game.Configuration;
using osu.Framework.Graphics.Colour;
namespace osu.Game.Beatmaps.Drawable
{
@ -28,15 +28,13 @@ namespace osu.Game.Beatmaps.Drawable
protected override void Selected()
{
base.Selected();
Width = 1;
GainedSelection?.Invoke(this);
}
protected override void Deselected()
{
base.Deselected();
Width = 0.8f;
}
[BackgroundDependencyLoader]
@ -66,36 +64,83 @@ namespace osu.Game.Beatmaps.Drawable
this.beatmapSet = beatmapSet;
Children = new Framework.Graphics.Drawable[]
{
working.Background == null ? new Box{ RelativeSizeAxes = Axes.Both, Colour = new Color4(20, 20, 20, 255) } : new Sprite
{
Texture = working.Background,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1366 / working.Background.Width * 0.6f),
Colour = new Color4(200, 200, 200, 255),
new BufferedContainer
{
CacheDrawnFrameBuffer = true,
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
working.Background == null ? new Box{ RelativeSizeAxes = Axes.Both, Colour = new Color4(200, 200, 200, 255) } : new Sprite
{
Texture = working.Background,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1366 / working.Background.Width * 0.6f),
},
new FlowContainer
{
Direction = FlowDirection.HorizontalOnly,
RelativeSizeAxes = Axes.Both,
// This makes the gradient not be perfectly horizontal, but diagonal at a ~40° angle
Shear = new Vector2(0.8f, 0),
Alpha = 0.5f,
Children = new[]
{
// The left half with no gradient applied
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Width = 0.4f,
},
// Piecewise-linear gradient with 3 segments to make it appear smoother
new Box
{
RelativeSizeAxes = Axes.Both,
ColourInfo = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
Width = 0.05f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
ColourInfo = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)),
Width = 0.2f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
ColourInfo = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
Width = 0.05f,
},
}
},
}
},
new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0, 2),
Padding = new MarginPadding { Top = 10, Left = 15, Right = 10, Bottom = 10 },
Padding = new MarginPadding { Top = 5, Left = 18, Right = 10, Bottom = 10 },
AutoSizeAxes = Axes.Both,
Children = new[]
{
title = new SpriteText
{
Font = @"Exo2.0-SemiBoldItalic",
Font = @"Exo2.0-BoldItalic",
Text = beatmapSet.Metadata.Title,
TextSize = 22
TextSize = 22,
Shadow = true,
},
artist = new SpriteText
{
Font = @"Exo2.0-MediumItalic",
Margin = new MarginPadding { Top = -1 },
Font = @"Exo2.0-SemiBoldItalic",
Text = beatmapSet.Metadata.Artist,
TextSize = 16
TextSize = 17,
Shadow = true,
},
new FlowContainer
{
Margin = new MarginPadding { Top = 5 },
AutoSizeAxes = Axes.Both,
Children = new[]
{
@ -106,8 +151,6 @@ namespace osu.Game.Beatmaps.Drawable
}
}
};
Deselected();
}
}
}

View File

@ -26,8 +26,26 @@ namespace osu.Game.Beatmaps.Drawable
BorderColour = new Color4(221, 255, 255, 255);
RelativeSizeAxes = Axes.X;
}
Deselected();
protected override void LoadComplete()
{
base.LoadComplete();
applyState();
FadeInFromZero(250);
}
private void applyState()
{
switch (state)
{
case PanelSelectedState.NotSelected:
Deselected();
break;
case PanelSelectedState.Selected:
Selected();
break;
}
}
private PanelSelectedState state = PanelSelectedState.NotSelected;
@ -41,15 +59,7 @@ namespace osu.Game.Beatmaps.Drawable
if (state == value) return;
state = value;
switch (state)
{
case PanelSelectedState.NotSelected:
Deselected();
break;
case PanelSelectedState.Selected:
Selected();
break;
}
applyState();
}
}

View File

@ -15,6 +15,7 @@ using osu.Game.Screens.Edit;
using osu.Game.Screens.Multiplayer;
using osu.Game.Screens.Play;
using OpenTK;
using osu.Game.Screens.Select;
namespace osu.Game.Screens.Menu
{

View File

@ -7,6 +7,7 @@ using osu.Framework.GameModes;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Play;
using OpenTK.Graphics;
using osu.Game.Screens.Select;
namespace osu.Game.Screens.Multiplayer
{

View File

@ -0,0 +1,124 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Caching;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Game.Beatmaps.Drawable;
using osu.Game.Database;
using System;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Screens.Select
{
class CarousellContainer : ScrollContainer
{
private Container<Panel> scrollableContent;
private List<BeatmapGroup> groups = new List<BeatmapGroup>();
public BeatmapGroup SelectedGroup { get; private set; }
private Cached yPositions = new Cached();
public CarousellContainer()
{
Add(scrollableContent = new Container<Panel>
{
Padding = new MarginPadding { Left = 25, Top = 25, Bottom = 25 },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
});
}
public void AddGroup(BeatmapGroup group)
{
group.State = BeatmapGroupState.Collapsed;
groups.Add(group);
yPositions.Invalidate();
}
private void computeYPositions()
{
float currentY = 0;
foreach (BeatmapGroup group in groups)
{
group.Header.Position = new Vector2(group.Header.Position.X, currentY);
currentY += group.Header.DrawSize.Y + 5;
if (group.State == BeatmapGroupState.Expanded)
{
foreach (BeatmapPanel panel in group.BeatmapPanels)
{
panel.Position = new Vector2(panel.Position.X, currentY);
currentY += panel.DrawSize.Y + 5;
}
}
}
}
public void SelectBeatmap(BeatmapInfo beatmap)
{
foreach (BeatmapGroup group in groups)
{
var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
if (panel != null)
SelectGroup(group, panel);
}
}
public void SelectGroup(BeatmapGroup group, BeatmapPanel panel)
{
if (SelectedGroup != null && SelectedGroup != group)
SelectedGroup.State = BeatmapGroupState.Collapsed;
SelectedGroup = group;
panel.State = PanelSelectedState.Selected;
yPositions.Invalidate();
}
protected override void UpdateLayout()
{
base.UpdateLayout();
if (!yPositions.EnsureValid())
yPositions.Refresh(computeYPositions);
}
protected override void Update()
{
base.Update();
scrollableContent.Clear(false);
foreach (BeatmapGroup group in groups)
{
scrollableContent.Add(group.Header);
if (group.State == BeatmapGroupState.Expanded)
foreach (BeatmapPanel panel in group.BeatmapPanels)
scrollableContent.Add(panel);
}
foreach (Panel panel in scrollableContent.Children)
{
if (panel.Position.Y < 0)
continue;
Vector2 panelPosLocal = panel.Position;
Vector2 panelPos = panel.ToSpaceOfOtherDrawable(panel.DrawSize / 2.0f, this);
float halfHeight = DrawSize.Y / 2;
float dist = Math.Abs(panelPos.Y - halfHeight);
panel.Position = new Vector2(
(panel is BeatmapSetHeader && panel.State == PanelSelectedState.Selected ? 0 : 100) + dist * 0.1f, panelPosLocal.Y);
panel.Alpha = MathHelper.Clamp(1.75f - 1.5f * dist / halfHeight, 0, 1);
}
}
}
}

View File

@ -4,8 +4,9 @@
using System;
using System.Collections.Generic;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Edit;
namespace osu.Game.Screens.Edit
namespace osu.Game.Screens.Select
{
class EditSongSelect : GameModeWhiteBox
{

View File

@ -3,7 +3,7 @@
using osu.Game.Screens.Backgrounds;
namespace osu.Game.Screens.Multiplayer
namespace osu.Game.Screens.Select
{
class MatchSongSelect : GameModeWhiteBox
{

View File

@ -22,20 +22,17 @@ using osu.Game.Screens.Backgrounds;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Game.Screens.Play;
namespace osu.Game.Screens.Play
namespace osu.Game.Screens.Select
{
public class PlaySongSelect : OsuGameMode
{
private Bindable<PlayMode> playMode;
private BeatmapDatabase database;
private BeatmapGroup selectedBeatmapGroup;
private BeatmapInfo selectedBeatmapInfo;
protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap);
private ScrollContainer scrollContainer;
private FlowContainer beatmapSetFlow;
private CarousellContainer carousell;
private TrackManager trackManager;
private Container backgroundWedgesContainer;
@ -83,23 +80,12 @@ namespace osu.Game.Screens.Play
},
}
},
scrollContainer = new ScrollContainer
carousell = new CarousellContainer
{
RelativeSizeAxes = Axes.Y,
Size = new Vector2(scrollWidth, 1),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Children = new Drawable[]
{
beatmapSetFlow = new FlowContainer
{
Padding = new MarginPadding { Left = 25, Top = 25, Bottom = 25 + bottomToolHeight },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0, 5),
}
}
},
wedgedContainer = new Container
{
@ -146,7 +132,7 @@ namespace osu.Game.Screens.Play
Colour = new Color4(238, 51, 153, 255),
Action = () => Push(new Player
{
BeatmapInfo = selectedBeatmapGroup.SelectedPanel.Beatmap,
BeatmapInfo = carousell.SelectedGroup.SelectedPanel.Beatmap,
PreferredPlayMode = playMode.Value
})
},
@ -163,17 +149,17 @@ namespace osu.Game.Screens.Play
playMode = game.PlayMode;
playMode.ValueChanged += playMode_ValueChanged;
// Temporary:
scrollContainer.Padding = new MarginPadding { Top = ToolbarPadding };
carousell.Padding = new MarginPadding { Top = ToolbarPadding };
}
if (database == null)
database = beatmaps;
database.BeatmapSetAdded += s => Schedule(() => addBeatmapSet(s));
database.BeatmapSetAdded += s => Schedule(() => addBeatmapSet(s, game));
trackManager = audio.Track;
Task.Factory.StartNew(addBeatmapSets);
Task.Factory.StartNew(() => addBeatmapSets(game));
}
protected override void OnEntering(GameMode last)
@ -352,21 +338,7 @@ namespace osu.Game.Screens.Play
private void selectBeatmap(BeatmapInfo beatmap)
{
if (beatmap.Equals(selectedBeatmapInfo))
return;
//this is VERY temporary logic.
beatmapSetFlow.Children.Cast<BeatmapGroup>().Any(b =>
{
var panel = b.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
if (panel != null)
{
panel.State = PanelSelectedState.Selected;
return true;
}
return false;
});
carousell.SelectBeatmap(beatmap);
}
/// <summary>
@ -374,22 +346,10 @@ namespace osu.Game.Screens.Play
/// </summary>
private void selectionChanged(BeatmapGroup group, BeatmapInfo beatmap)
{
selectedBeatmapInfo = beatmap;
if (!beatmap.Equals(Beatmap?.BeatmapInfo))
{
Beatmap = database.GetWorkingBeatmap(beatmap, Beatmap);
}
ensurePlayingSelected();
if (selectedBeatmapGroup == group)
return;
if (selectedBeatmapGroup != null)
selectedBeatmapGroup.State = BeatmapGroupState.Collapsed;
selectedBeatmapGroup = group;
}
private async Task ensurePlayingSelected()
@ -408,7 +368,7 @@ namespace osu.Game.Screens.Play
});
}
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
private void addBeatmapSet(BeatmapSetInfo beatmapSet, OsuGame game)
{
beatmapSet = database.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
beatmapSet.Beatmaps.ForEach(b => database.GetChildren(b));
@ -418,39 +378,27 @@ namespace osu.Game.Screens.Play
var group = new BeatmapGroup(beatmapSet, working) { SelectionChanged = selectionChanged };
group.Preload(Game, g =>
//for the time being, let's completely load the difficulty panels in the background.
//this likely won't scale so well, but allows us to completely async the loading flow.
Task.WhenAll(group.BeatmapPanels.Select(panel => panel.Preload(game))).ContinueWith(task => Schedule(delegate
{
beatmapSetFlow.Add(group);
carousell.AddGroup(group);
if (Beatmap == null)
{
if (beatmapSetFlow.Children.Count() == 1)
{
group.State = BeatmapGroupState.Expanded;
return;
}
}
carousell.SelectBeatmap(beatmapSet.Beatmaps.First());
else
{
if (selectedBeatmapInfo?.Equals(Beatmap.BeatmapInfo) != true)
{
var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(Beatmap.BeatmapInfo));
if (panel != null)
{
panel.State = PanelSelectedState.Selected;
return;
}
}
var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(Beatmap.BeatmapInfo));
if (panel != null)
carousell.SelectGroup(group, panel);
}
group.State = BeatmapGroupState.Collapsed;
});
}));
}
private void addBeatmapSets()
private void addBeatmapSets(OsuGame game)
{
foreach (var beatmapSet in database.Query<BeatmapSetInfo>())
addBeatmapSet(beatmapSet);
addBeatmapSet(beatmapSet, game);
}
}
}

View File

@ -103,7 +103,8 @@
<Compile Include="Screens\Multiplayer\Lobby.cs" />
<Compile Include="Screens\Multiplayer\Match.cs" />
<Compile Include="Screens\Multiplayer\MatchCreate.cs" />
<Compile Include="Screens\Multiplayer\MatchSongSelect.cs" />
<Compile Include="Screens\Select\CarousellContainer.cs" />
<Compile Include="Screens\Select\MatchSongSelect.cs" />
<Compile Include="Screens\OsuGameMode.cs" />
<Compile Include="Screens\Play\ModSelect.cs" />
<Compile Include="Beatmaps\Drawable\BeatmapGroup.cs" />
@ -114,11 +115,11 @@
<Compile Include="Modes\Ruleset.cs" />
<Compile Include="Screens\Ranking\Results.cs" />
<Compile Include="Screens\Direct\OnlineListing.cs" />
<Compile Include="Screens\Play\PlaySongSelect.cs" />
<Compile Include="Screens\Select\PlaySongSelect.cs" />
<Compile Include="Modes\UI\HitRenderer.cs" />
<Compile Include="Modes\UI\Playfield.cs" />
<Compile Include="Modes\UI\ScoreOverlay.cs" />
<Compile Include="Screens\Edit\EditSongSelect.cs" />
<Compile Include="Screens\Select\EditSongSelect.cs" />
<Compile Include="Modes\UI\ComboCounter.cs" />
<Compile Include="Modes\UI\ComboResultCounter.cs" />
<Compile Include="Graphics\UserInterface\RollingCounter.cs" />