1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 14:42:56 +08:00

Merge pull request #196 from peppy/carousel-fixes

Carousel improvements.
This commit is contained in:
Thomas Müller 2016-11-26 09:38:32 +01:00 committed by GitHub
commit c9965a1fd8
8 changed files with 168 additions and 71 deletions

@ -1 +1 @@
Subproject commit 60e210c1aa62a114fb08e50797f8f839da326cc3 Subproject commit cc614047de3471a2d2b4b988fed550fc946016b9

View File

@ -35,14 +35,8 @@ namespace osu.Game.Beatmaps.Drawables
switch (state) switch (state)
{ {
case BeatmapGroupState.Expanded: case BeatmapGroupState.Expanded:
//if (!difficulties.Children.All(d => IsLoaded))
// Task.WhenAll(difficulties.Children.Select(d => d.Preload(Game))).ContinueWith(t => difficulties.Show());
//else
foreach (BeatmapPanel panel in BeatmapPanels) foreach (BeatmapPanel panel in BeatmapPanels)
{
panel.Hidden = false;
panel.FadeIn(250); panel.FadeIn(250);
}
Header.State = PanelSelectedState.Selected; Header.State = PanelSelectedState.Selected;
if (SelectedPanel != null) if (SelectedPanel != null)
@ -54,11 +48,7 @@ namespace osu.Game.Beatmaps.Drawables
SelectedPanel.State = PanelSelectedState.NotSelected; SelectedPanel.State = PanelSelectedState.NotSelected;
foreach (BeatmapPanel panel in BeatmapPanels) foreach (BeatmapPanel panel in BeatmapPanels)
{
panel.Hidden = true;
panel.FadeOut(250); panel.FadeOut(250);
}
break; break;
} }
} }
@ -76,6 +66,7 @@ namespace osu.Game.Beatmaps.Drawables
BeatmapPanels = beatmap.BeatmapSetInfo.Beatmaps.Select(b => new BeatmapPanel(b) BeatmapPanels = beatmap.BeatmapSetInfo.Beatmaps.Select(b => new BeatmapPanel(b)
{ {
Alpha = 0,
GainedSelection = panelGainedSelection, GainedSelection = panelGainedSelection,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
}).ToList(); }).ToList();

View File

@ -2,11 +2,14 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System; using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.MathUtils;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -22,6 +25,8 @@ namespace osu.Game.Beatmaps.Drawables
public Action<BeatmapPanel> GainedSelection; public Action<BeatmapPanel> GainedSelection;
Color4 deselectedColour = new Color4(20, 43, 51, 255);
protected override void Selected() protected override void Selected()
{ {
base.Selected(); base.Selected();
@ -36,7 +41,7 @@ namespace osu.Game.Beatmaps.Drawables
{ {
base.Deselected(); base.Deselected();
background.Colour = new Color4(20, 43, 51, 255); background.Colour = deselectedColour;
} }
public BeatmapPanel(BeatmapInfo beatmap) public BeatmapPanel(BeatmapInfo beatmap)
@ -44,12 +49,18 @@ namespace osu.Game.Beatmaps.Drawables
Beatmap = beatmap; Beatmap = beatmap;
Height *= 0.60f; Height *= 0.60f;
Children = new Framework.Graphics.Drawable[] Children = new Drawable[]
{ {
background = new Box background = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
new Triangles
{
RelativeSizeAxes = Axes.Both,
BlendingMode = BlendingMode.Additive,
Colour = deselectedColour,
},
new FlowContainer new FlowContainer
{ {
Padding = new MarginPadding(5), Padding = new MarginPadding(5),
@ -57,7 +68,7 @@ namespace osu.Game.Beatmaps.Drawables
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Children = new Framework.Graphics.Drawable[] Children = new Drawable[]
{ {
new DifficultyIcon(FontAwesome.fa_dot_circle_o, new Color4(159, 198, 0, 255)) new DifficultyIcon(FontAwesome.fa_dot_circle_o, new Color4(159, 198, 0, 255))
{ {
@ -71,7 +82,7 @@ namespace osu.Game.Beatmaps.Drawables
Spacing = new Vector2(0, 5), Spacing = new Vector2(0, 5),
Direction = FlowDirection.VerticalOnly, Direction = FlowDirection.VerticalOnly,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[] Children = new Drawable[]
{ {
new FlowContainer new FlowContainer
{ {
@ -113,5 +124,45 @@ namespace osu.Game.Beatmaps.Drawables
} }
}; };
} }
public class Triangles : Container
{
private Texture triangle;
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
triangle = textures.Get(@"Play/osu/triangle@2x");
}
protected override void LoadComplete()
{
base.LoadComplete();
for (int i = 0; i < 10; i++)
{
Add(new Sprite
{
Texture = triangle,
Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.Both,
Position = new Vector2(RNG.NextSingle(), RNG.NextSingle()),
Scale = new Vector2(RNG.NextSingle() * 0.4f + 0.2f),
Alpha = RNG.NextSingle() * 0.3f
});
}
}
protected override void Update()
{
base.Update();
foreach (Drawable d in Children)
{
d.Position -= new Vector2(0, (float)(d.Scale.X * (Time.Elapsed / 880)));
if (d.DrawPosition.Y + d.DrawSize.Y * d.Scale.Y < 0)
d.MoveToY(1);
}
}
}
} }
} }

View File

@ -27,7 +27,6 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapSetHeader(WorkingBeatmap beatmap) public BeatmapSetHeader(WorkingBeatmap beatmap)
{ {
this.beatmap = beatmap; this.beatmap = beatmap;
Hidden = false;
Children = new Drawable[] Children = new Drawable[]
{ {
@ -72,6 +71,12 @@ namespace osu.Game.Beatmaps.Drawables
}; };
} }
protected override void LoadComplete()
{
base.LoadComplete();
FadeInFromZero(250);
}
protected override void Selected() protected override void Selected()
{ {
base.Selected(); base.Selected();

View File

@ -4,6 +4,7 @@
using osu.Framework; using osu.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input; using osu.Framework.Input;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
@ -14,7 +15,12 @@ namespace osu.Game.Beatmaps.Drawables
{ {
public const float MAX_HEIGHT = 80; public const float MAX_HEIGHT = 80;
public bool Hidden = true; public override bool RemoveWhenNotAlive => false;
public bool IsOnScreen;
public override bool IsAlive => IsOnScreen && base.IsAlive;
private Container nestedContainer; private Container nestedContainer;
protected override Container<Drawable> Content => nestedContainer; protected override Container<Drawable> Content => nestedContainer;
@ -42,7 +48,6 @@ namespace osu.Game.Beatmaps.Drawables
{ {
base.LoadComplete(); base.LoadComplete();
applyState(); applyState();
FadeInFromZero(250);
} }
private void applyState() private void applyState()

View File

@ -16,10 +16,27 @@ namespace osu.Game.Screens.Select
{ {
class BeatmapInfoWedge : Container class BeatmapInfoWedge : Container
{ {
private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0);
private Container beatmapInfoContainer; private Container beatmapInfoContainer;
private BaseGame game; private BaseGame game;
public BeatmapInfoWedge()
{
Shear = wedged_container_shear;
Masking = true;
BorderColour = new Color4(221, 255, 255, 255);
BorderThickness = 2.5f;
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Glow,
Colour = new Color4(130, 204, 255, 150),
Radius = 20,
Roundness = 15,
};
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BaseGame game) private void load(BaseGame game)
{ {
@ -35,8 +52,6 @@ namespace osu.Game.Screens.Select
float newDepth = lastContainer?.Depth - 1 ?? 0; float newDepth = lastContainer?.Depth - 1 ?? 0;
FadeIn(250);
BeatmapSetInfo beatmapSetInfo = beatmap.BeatmapSetInfo; BeatmapSetInfo beatmapSetInfo = beatmap.BeatmapSetInfo;
BeatmapInfo beatmapInfo = beatmap.BeatmapInfo; BeatmapInfo beatmapInfo = beatmap.BeatmapInfo;
@ -126,6 +141,8 @@ namespace osu.Game.Screens.Select
} }
}).Preload(game, delegate(Drawable d) }).Preload(game, delegate(Drawable d)
{ {
FadeIn(250);
lastContainer?.FadeOut(250); lastContainer?.FadeOut(250);
lastContainer?.Expire(); lastContainer?.Expire();

View File

@ -10,39 +10,85 @@ using osu.Game.Database;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Lists;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Framework.Timing;
namespace osu.Game.Screens.Select namespace osu.Game.Screens.Select
{ {
class CarouselContainer : ScrollContainer class CarouselContainer : ScrollContainer
{ {
private Container<Panel> scrollableContent; private Container<Panel> scrollableContent;
private List<BeatmapGroup> groups = new List<BeatmapGroup>(); private List<BeatmapGroup> groups = new List<BeatmapGroup>();
private List<Panel> panels = new List<Panel>();
public BeatmapGroup SelectedGroup { get; private set; } public BeatmapGroup SelectedGroup { get; private set; }
public BeatmapPanel SelectedPanel { get; private set; } public BeatmapPanel SelectedPanel { get; private set; }
private List<float> yPositions = new List<float>();
public CarouselContainer()
{
DistanceDecayJump = 0.01;
Add(scrollableContent = new Container<Panel> private List<float> yPositions = new List<float>();
private CarouselLifetimeList<Panel> Lifetime;
public CarouselContainer()
{
DistanceDecayJump = 0.01;
Add(scrollableContent = new Container<Panel>(Lifetime = new CarouselLifetimeList<Panel>(DepthComparer))
{
RelativeSizeAxes = Axes.X,
});
}
internal class CarouselLifetimeList<T> : LifetimeList<Panel>
{
public CarouselLifetimeList(IComparer<Panel> comparer)
: base(comparer)
{
}
public int StartIndex;
public int EndIndex;
public override bool Update(FrameTimeInfo time)
{ {
RelativeSizeAxes = Axes.X, bool anyAliveChanged = false;
});
}
//check existing items to make sure they haven't died.
foreach (var item in AliveItems.ToArray())
{
item.UpdateTime(time);
if (!item.IsAlive)
{
//todo: make this more efficient
int i = IndexOf(item);
anyAliveChanged |= CheckItem(item, ref i);
}
}
//handle custom range
for (int i = StartIndex; i < EndIndex; i++)
{
var item = this[i];
item.UpdateTime(time);
anyAliveChanged |= CheckItem(item, ref i);
}
return anyAliveChanged;
}
}
public void AddGroup(BeatmapGroup group) public void AddGroup(BeatmapGroup group)
{ {
group.State = BeatmapGroupState.Collapsed; group.State = BeatmapGroupState.Collapsed;
groups.Add(group); groups.Add(group);
panels.Add(group.Header);
group.Header.Depth = scrollableContent.Children.Count();
scrollableContent.Add(group.Header);
foreach (BeatmapPanel panel in group.BeatmapPanels) foreach (BeatmapPanel panel in group.BeatmapPanels)
panels.Add(panel); {
panel.Depth = scrollableContent.Children.Count();
scrollableContent.Add(panel);
}
computeYPositions(); computeYPositions();
} }
@ -74,6 +120,7 @@ namespace osu.Game.Screens.Select
if (group.State == BeatmapGroupState.Expanded) if (group.State == BeatmapGroupState.Expanded)
{ {
group.Header.MoveToX(-100, 500, EasingTypes.OutExpo); group.Header.MoveToX(-100, 500, EasingTypes.OutExpo);
var headerY = group.Header.Position.Y;
foreach (BeatmapPanel panel in group.BeatmapPanels) foreach (BeatmapPanel panel in group.BeatmapPanels)
{ {
@ -82,6 +129,10 @@ namespace osu.Game.Screens.Select
panel.MoveToX(-50, 500, EasingTypes.OutExpo); panel.MoveToX(-50, 500, EasingTypes.OutExpo);
//on first display we want to begin hidden under our group's header.
if (panel.Alpha == 0)
panel.MoveToY(headerY);
movePanel(panel, true, ref currentY); movePanel(panel, true, ref currentY);
} }
} }
@ -119,11 +170,7 @@ namespace osu.Game.Screens.Select
public void SelectGroup(BeatmapGroup group, BeatmapPanel panel) public void SelectGroup(BeatmapGroup group, BeatmapPanel panel)
{ {
if (SelectedGroup != null && SelectedGroup != group) if (SelectedGroup != null && SelectedGroup != group)
{
SelectedGroup.State = BeatmapGroupState.Collapsed; SelectedGroup.State = BeatmapGroupState.Collapsed;
foreach (BeatmapPanel p in group.BeatmapPanels)
p.MoveToY(group.Header.Position.Y);
}
SelectedGroup = group; SelectedGroup = group;
panel.State = PanelSelectedState.Selected; panel.State = PanelSelectedState.Selected;
@ -133,7 +180,7 @@ namespace osu.Game.Screens.Select
ScrollTo(selectedY); ScrollTo(selectedY);
} }
private static float offsetX(Panel panel, float dist, float halfHeight) private static float offsetX(float dist, float halfHeight)
{ {
// The radius of the circle the carousel moves on. // The radius of the circle the carousel moves on.
const float CIRCLE_RADIUS = 4; const float CIRCLE_RADIUS = 4;
@ -143,28 +190,16 @@ namespace osu.Game.Screens.Select
return 125 + x; return 125 + x;
} }
private void addPanel(int index)
{
Panel panel = panels[index];
if (panel.Hidden)
return;
if (!scrollableContent.Contains(panel))
{
panel.Depth = index + (panel is BeatmapSetHeader ? panels.Count : 0);
scrollableContent.Add(panel);
}
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
float drawHeight = DrawHeight; float drawHeight = DrawHeight;
scrollableContent.RemoveAll(delegate (Panel p)
Lifetime.AliveItems.ForEach(delegate (Panel p)
{ {
float panelPosY = p.Position.Y; float panelPosY = p.Position.Y;
return panelPosY < Current - p.DrawHeight || panelPosY > Current + drawHeight || !IsVisible; p.IsOnScreen = panelPosY >= Current - p.DrawHeight && panelPosY <= Current + drawHeight;
}); });
int firstIndex = yPositions.BinarySearch(Current - Panel.MAX_HEIGHT); int firstIndex = yPositions.BinarySearch(Current - Panel.MAX_HEIGHT);
@ -172,19 +207,24 @@ namespace osu.Game.Screens.Select
int lastIndex = yPositions.BinarySearch(Current + drawHeight); int lastIndex = yPositions.BinarySearch(Current + drawHeight);
if (lastIndex < 0) lastIndex = ~lastIndex; if (lastIndex < 0) lastIndex = ~lastIndex;
for (int i = firstIndex; i < lastIndex; ++i) Lifetime.StartIndex = firstIndex;
addPanel(i); Lifetime.EndIndex = lastIndex;
float halfHeight = drawHeight / 2; float halfHeight = drawHeight / 2;
foreach (Panel panel in scrollableContent.Children)
for (int i = firstIndex; i < lastIndex; ++i)
{ {
var panel = Lifetime[i];
panel.IsOnScreen = true;
float panelDrawY = panel.Position.Y - Current + panel.DrawHeight / 2; float panelDrawY = panel.Position.Y - Current + panel.DrawHeight / 2;
float dist = Math.Abs(1f - panelDrawY / halfHeight); float dist = Math.Abs(1f - panelDrawY / halfHeight);
// Setting the origin position serves as an additive position on top of potential // Setting the origin position serves as an additive position on top of potential
// local transformation we may want to apply (e.g. when a panel gets selected, we // local transformation we may want to apply (e.g. when a panel gets selected, we
// may want to smoothly transform it leftwards.) // may want to smoothly transform it leftwards.)
panel.OriginPosition = new Vector2(-offsetX(panel, dist, halfHeight), 0); panel.OriginPosition = new Vector2(-offsetX(dist, halfHeight), 0);
// We are applying a multiplicative alpha (which is internally done by nesting an // We are applying a multiplicative alpha (which is internally done by nesting an
// additional container and setting that container's alpha) such that we can // additional container and setting that container's alpha) such that we can

View File

@ -38,7 +38,6 @@ namespace osu.Game.Screens.Select
private TrackManager trackManager; private TrackManager trackManager;
private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 225); private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 225);
private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0);
private static readonly Vector2 wedged_container_start_position = new Vector2(0, 50); private static readonly Vector2 wedged_container_start_position = new Vector2(0, 50);
private BeatmapInfoWedge beatmapInfoWedge; private BeatmapInfoWedge beatmapInfoWedge;
@ -105,18 +104,7 @@ namespace osu.Game.Screens.Select
Position = wedged_container_start_position, Position = wedged_container_start_position,
Size = wedged_container_size, Size = wedged_container_size,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Shear = wedged_container_shear,
Margin = new MarginPadding { Top = 20, Right = 20, }, Margin = new MarginPadding { Top = 20, Right = 20, },
Masking = true,
BorderColour = new Color4(221, 255, 255, 255),
BorderThickness = 2.5f,
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Glow,
Colour = new Color4(130, 204, 255, 150),
Radius = 20,
Roundness = 15,
},
}, },
new Container new Container
{ {