Implement DashboardBeatmapListing component

This commit is contained in:
Andrei Zavatski
2020-08-01 07:04:39 +03:00
parent 7624804edf
commit b5f688e63a
8 changed files with 287 additions and 85 deletions

View File

@ -0,0 +1,144 @@
// 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.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Game.Overlays.Dashboard.Dashboard;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Framework.Allocation;
using osu.Game.Users;
using System;
using osu.Framework.Graphics.Shapes;
using System.Collections.Generic;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneDashboardBeatmapListing : OsuTestScene
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
private readonly Container content;
public TestSceneDashboardBeatmapListing()
{
Add(content = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Y,
Width = 300,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4
},
new DashboardBeatmapListing(new_beatmaps, popular_beatmaps)
}
});
}
protected override void LoadComplete()
{
base.LoadComplete();
AddStep("Set width to 500", () => content.ResizeWidthTo(500, 500));
AddStep("Set width to 300", () => content.ResizeWidthTo(300, 500));
}
private static readonly List<BeatmapSetInfo> new_beatmaps = new List<BeatmapSetInfo>
{
new BeatmapSetInfo
{
Metadata = new BeatmapMetadata
{
Title = "Very Long Title (TV size) [TATOE]",
Artist = "This artist has a really long name how is this possible",
Author = new User
{
Username = "author",
Id = 100
}
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new BeatmapSetOnlineCovers
{
Cover = "https://assets.ppy.sh/beatmaps/1189904/covers/cover.jpg?1595456608",
},
Ranked = DateTimeOffset.Now
}
},
new BeatmapSetInfo
{
Metadata = new BeatmapMetadata
{
Title = "Very Long Title (TV size) [TATOE]",
Artist = "This artist has a really long name how is this possible",
Author = new User
{
Username = "author",
Id = 100
}
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new BeatmapSetOnlineCovers
{
Cover = "https://assets.ppy.sh/beatmaps/1189904/covers/cover.jpg?1595456608",
},
Ranked = DateTimeOffset.MinValue
}
}
};
private static readonly List<BeatmapSetInfo> popular_beatmaps = new List<BeatmapSetInfo>
{
new BeatmapSetInfo
{
Metadata = new BeatmapMetadata
{
Title = "Title",
Artist = "Artist",
Author = new User
{
Username = "author",
Id = 100
}
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new BeatmapSetOnlineCovers
{
Cover = "https://assets.ppy.sh/beatmaps/1079428/covers/cover.jpg?1595295586",
},
FavouriteCount = 100
}
},
new BeatmapSetInfo
{
Metadata = new BeatmapMetadata
{
Title = "Title 2",
Artist = "Artist 2",
Author = new User
{
Username = "someone",
Id = 100
}
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new BeatmapSetOnlineCovers
{
Cover = "https://assets.ppy.sh/beatmaps/1079428/covers/cover.jpg?1595295586",
},
FavouriteCount = 10
}
}
};
}
}

View File

@ -1,83 +0,0 @@
// 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.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Game.Overlays.Dashboard.Dashboard;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Framework.Allocation;
using osu.Game.Users;
using System;
using osuTK;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneDashboardBeatmapPanel : OsuTestScene
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
public TestSceneDashboardBeatmapPanel()
{
Add(new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Y,
Width = 300,
Spacing = new Vector2(0, 10),
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new DashboardNewBeatmapPanel(new_beatmap_set),
new DashboardPopularBeatmapPanel(popular_beatmap_set)
}
});
}
private static readonly BeatmapSetInfo new_beatmap_set = new BeatmapSetInfo
{
Metadata = new BeatmapMetadata
{
Title = "Very Long Title (TV size) [TATOE]",
Artist = "This artist has a really long name how is this possible",
Author = new User
{
Username = "author",
Id = 100
}
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new BeatmapSetOnlineCovers
{
Cover = "https://assets.ppy.sh/beatmaps/1189904/covers/cover.jpg?1595456608",
},
Ranked = DateTimeOffset.Now
}
};
private static readonly BeatmapSetInfo popular_beatmap_set = new BeatmapSetInfo
{
Metadata = new BeatmapMetadata
{
Title = "Title",
Artist = "Artist",
Author = new User
{
Username = "author",
Id = 100
}
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new BeatmapSetOnlineCovers
{
Cover = "https://assets.ppy.sh/beatmaps/1189904/covers/cover.jpg?1595456608",
},
FavouriteCount = 100
}
};
}
}

View File

@ -0,0 +1,43 @@
// 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.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osuTK;
namespace osu.Game.Overlays.Dashboard.Dashboard
{
public class DashboardBeatmapListing : CompositeDrawable
{
private readonly List<BeatmapSetInfo> newBeatmaps;
private readonly List<BeatmapSetInfo> popularBeatmaps;
public DashboardBeatmapListing(List<BeatmapSetInfo> newBeatmaps, List<BeatmapSetInfo> popularBeatmaps)
{
this.newBeatmaps = newBeatmaps;
this.popularBeatmaps = popularBeatmaps;
}
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = new FillFlowContainer<DrawableBeatmapsList>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 10),
Children = new DrawableBeatmapsList[]
{
new DrawableNewBeatmapsList(newBeatmaps),
new DrawablePopularBeatmapsList(popularBeatmaps)
}
};
}
}
}

View File

@ -114,7 +114,7 @@ namespace osu.Game.Overlays.Dashboard.Dashboard
Direction = FillDirection.Horizontal,
Spacing = new Vector2(3, 0),
Margin = new MarginPadding { Top = 2 },
Children = new Drawable[]
Children = new[]
{
new LinkFlowContainer(f => f.Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold))
{

View File

@ -1,6 +1,7 @@
// 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 osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
@ -14,7 +15,7 @@ namespace osu.Game.Overlays.Dashboard.Dashboard
{
}
protected override Drawable CreateInfo() => new DrawableDate(SetInfo.OnlineInfo.Ranked.Value, 10, false)
protected override Drawable CreateInfo() => new DrawableDate(SetInfo.OnlineInfo.Ranked ?? DateTimeOffset.Now, 10, false)
{
Colour = ColourProvider.Foreground1
};

View File

@ -0,0 +1,57 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
namespace osu.Game.Overlays.Dashboard.Dashboard
{
public abstract class DrawableBeatmapsList : CompositeDrawable
{
private readonly List<BeatmapSetInfo> beatmaps;
protected DrawableBeatmapsList(List<BeatmapSetInfo> beatmaps)
{
this.beatmaps = beatmaps;
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
FillFlowContainer flow;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = flow = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 10),
Children = new Drawable[]
{
new OsuSpriteText
{
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
Colour = colourProvider.Light1,
Text = CreateTitle(),
Padding = new MarginPadding { Left = 10 }
}
}
};
flow.AddRange(beatmaps.Select(CreateBeatmapPanel));
}
protected abstract string CreateTitle();
protected abstract DashboardBeatmapPanel CreateBeatmapPanel(BeatmapSetInfo setInfo);
}
}

View File

@ -0,0 +1,20 @@
// 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.Collections.Generic;
using osu.Game.Beatmaps;
namespace osu.Game.Overlays.Dashboard.Dashboard
{
public class DrawableNewBeatmapsList : DrawableBeatmapsList
{
public DrawableNewBeatmapsList(List<BeatmapSetInfo> beatmaps)
: base(beatmaps)
{
}
protected override DashboardBeatmapPanel CreateBeatmapPanel(BeatmapSetInfo setInfo) => new DashboardNewBeatmapPanel(setInfo);
protected override string CreateTitle() => "New Ranked Beatmaps";
}
}

View File

@ -0,0 +1,20 @@
// 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.Collections.Generic;
using osu.Game.Beatmaps;
namespace osu.Game.Overlays.Dashboard.Dashboard
{
public class DrawablePopularBeatmapsList : DrawableBeatmapsList
{
public DrawablePopularBeatmapsList(List<BeatmapSetInfo> beatmaps)
: base(beatmaps)
{
}
protected override DashboardBeatmapPanel CreateBeatmapPanel(BeatmapSetInfo setInfo) => new DashboardPopularBeatmapPanel(setInfo);
protected override string CreateTitle() => "Popular Beatmaps";
}
}