1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +08:00

Clean up DirectPanel and it's subclasses

This commit is contained in:
DrabWeb 2017-05-19 12:52:23 -03:00
parent a5fa7e1a7d
commit 3b8cadd4df
6 changed files with 67 additions and 81 deletions

View File

@ -6,7 +6,7 @@ using osu.Framework.Graphics.Sprites;
namespace osu.Game.Beatmaps.Drawables namespace osu.Game.Beatmaps.Drawables
{ {
internal class BeatmapBackgroundSprite : Sprite public class BeatmapBackgroundSprite : Sprite
{ {
private readonly WorkingBeatmap working; private readonly WorkingBeatmap working;

View File

@ -9,7 +9,7 @@ using OpenTK.Graphics;
namespace osu.Game.Beatmaps.Drawables namespace osu.Game.Beatmaps.Drawables
{ {
internal class DifficultyColouredContainer : Container, IHasAccentColour public class DifficultyColouredContainer : Container, IHasAccentColour
{ {
public Color4 AccentColour { get; set; } public Color4 AccentColour { get; set; }

View File

@ -11,7 +11,7 @@ using OpenTK.Graphics;
namespace osu.Game.Beatmaps.Drawables namespace osu.Game.Beatmaps.Drawables
{ {
internal class DifficultyIcon : DifficultyColouredContainer public class DifficultyIcon : DifficultyColouredContainer
{ {
private readonly BeatmapInfo beatmap; private readonly BeatmapInfo beatmap;

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// 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.Collections.Generic;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -8,6 +9,8 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -19,20 +22,6 @@ namespace osu.Game.Overlays.Direct
private readonly float horizontal_padding = 10; private readonly float horizontal_padding = 10;
private readonly float vertical_padding = 5; private readonly float vertical_padding = 5;
private readonly Sprite background;
private readonly OsuSpriteText title, artist, authorPrefix, author, source;
private readonly Statistic playCount, favouriteCount;
private readonly FillFlowContainer difficultyIcons;
protected override Sprite Background => background;
protected override OsuSpriteText Title => title;
protected override OsuSpriteText Artist => artist;
protected override OsuSpriteText Author => author;
protected override OsuSpriteText Source => source;
protected override Statistic PlayCount => playCount;
protected override Statistic FavouriteCount => favouriteCount;
protected override FillFlowContainer DifficultyIcons => difficultyIcons;
public DirectGridPanel(BeatmapSetInfo beatmap) : base(beatmap) public DirectGridPanel(BeatmapSetInfo beatmap) : base(beatmap)
{ {
Height = 140 + vertical_padding; //full height of all the elements plus vertical padding (autosize uses the image) Height = 140 + vertical_padding; //full height of all the elements plus vertical padding (autosize uses the image)
@ -45,7 +34,11 @@ namespace osu.Game.Overlays.Direct
Radius = 3f, Radius = 3f,
Colour = Color4.Black.Opacity(0.25f), Colour = Color4.Black.Opacity(0.25f),
}; };
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, LocalisationEngine localisation)
{
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -53,7 +46,7 @@ namespace osu.Game.Overlays.Direct
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4.Black, Colour = Color4.Black,
}, },
background = new Sprite new Sprite
{ {
FillMode = FillMode.Fill, FillMode = FillMode.Fill,
}, },
@ -79,13 +72,15 @@ namespace osu.Game.Overlays.Direct
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Children = new[] Children = new[]
{ {
title = new OsuSpriteText new OsuSpriteText
{ {
Text = localisation.GetUnicodePreference(SetInfo.Metadata.TitleUnicode, SetInfo.Metadata.Title),
TextSize = 18, TextSize = 18,
Font = @"Exo2.0-BoldItalic", Font = @"Exo2.0-BoldItalic",
}, },
artist = new OsuSpriteText new OsuSpriteText
{ {
Text = localisation.GetUnicodePreference(SetInfo.Metadata.ArtistUnicode, SetInfo.Metadata.Artist),
Font = @"Exo2.0-BoldItalic", Font = @"Exo2.0-BoldItalic",
}, },
}, },
@ -114,29 +109,36 @@ namespace osu.Game.Overlays.Direct
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Children = new[] Children = new[]
{ {
authorPrefix = new OsuSpriteText new OsuSpriteText
{ {
Text = @"mapped by ", Text = @"mapped by ",
TextSize = 14, TextSize = 14,
Shadow = false, Shadow = false,
Colour = colours.Gray5,
}, },
author = new OsuSpriteText new OsuSpriteText
{ {
Text = SetInfo.Metadata.Author,
TextSize = 14, TextSize = 14,
Font = @"Exo2.0-SemiBoldItalic", Font = @"Exo2.0-SemiBoldItalic",
Shadow = false, Shadow = false,
Colour = colours.BlueDark,
}, },
}, },
}, },
source = new OsuSpriteText new OsuSpriteText
{ {
Text = $@"from {SetInfo.Metadata.Source}",
TextSize = 14, TextSize = 14,
Shadow = false, Shadow = false,
Colour = colours.Gray5,
}, },
difficultyIcons = new FillFlowContainer new FillFlowContainer
{ {
AutoSizeAxes = Axes.X,
Height = 20,
Margin = new MarginPadding { Top = vertical_padding, Bottom = vertical_padding }, Margin = new MarginPadding { Top = vertical_padding, Bottom = vertical_padding },
AutoSizeAxes = Axes.Both, Children = DifficultyIcons,
}, },
}, },
}, },
@ -153,22 +155,14 @@ namespace osu.Game.Overlays.Direct
Margin = new MarginPadding { Top = vertical_padding, Right = vertical_padding }, Margin = new MarginPadding { Top = vertical_padding, Right = vertical_padding },
Children = new[] Children = new[]
{ {
playCount = new Statistic(FontAwesome.fa_play_circle) new Statistic(FontAwesome.fa_play_circle)
{ {
Margin = new MarginPadding { Right = 1 }, Margin = new MarginPadding { Right = 1 },
}, },
favouriteCount = new Statistic(FontAwesome.fa_heart), new Statistic(FontAwesome.fa_heart),
}, },
}, },
}; };
} }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
authorPrefix.Colour = colours.Gray5;
Author.Colour = colours.BlueDark;
Source.Colour = colours.Gray5;
}
} }
} }

View File

@ -11,6 +11,8 @@ using osu.Framework.Graphics.Colour;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Database; using osu.Game.Database;
using osu.Framework.Allocation;
using osu.Framework.Localisation;
namespace osu.Game.Overlays.Direct namespace osu.Game.Overlays.Direct
{ {
@ -20,20 +22,6 @@ namespace osu.Game.Overlays.Direct
private readonly float vertical_padding = 5; private readonly float vertical_padding = 5;
private readonly float height = 70; private readonly float height = 70;
private readonly Sprite background;
private readonly OsuSpriteText title, artist, author, source;
private readonly Statistic playCount, favouriteCount;
private readonly FillFlowContainer difficultyIcons;
protected override Sprite Background => background;
protected override OsuSpriteText Title => title;
protected override OsuSpriteText Artist => artist;
protected override OsuSpriteText Author => author;
protected override OsuSpriteText Source => source;
protected override Statistic PlayCount => playCount;
protected override Statistic FavouriteCount => favouriteCount;
protected override FillFlowContainer DifficultyIcons => difficultyIcons;
public DirectListPanel(BeatmapSetInfo beatmap) : base(beatmap) public DirectListPanel(BeatmapSetInfo beatmap) : base(beatmap)
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -47,7 +35,11 @@ namespace osu.Game.Overlays.Direct
Radius = 3f, Radius = 3f,
Colour = Color4.Black.Opacity(0.25f), Colour = Color4.Black.Opacity(0.25f),
}; };
}
[BackgroundDependencyLoader]
private void load(LocalisationEngine localisation)
{
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -55,7 +47,7 @@ namespace osu.Game.Overlays.Direct
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4.Black, Colour = Color4.Black,
}, },
background = new Sprite new Sprite
{ {
FillMode = FillMode.Fill, FillMode = FillMode.Fill,
}, },
@ -76,19 +68,23 @@ namespace osu.Game.Overlays.Direct
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Children = new Drawable[] Children = new Drawable[]
{ {
title = new OsuSpriteText new OsuSpriteText
{ {
Current = localisation.GetUnicodePreference(SetInfo.Metadata.TitleUnicode, SetInfo.Metadata.Title),
TextSize = 18, TextSize = 18,
Font = @"Exo2.0-BoldItalic", Font = @"Exo2.0-BoldItalic",
}, },
artist = new OsuSpriteText new OsuSpriteText
{ {
Current = localisation.GetUnicodePreference(SetInfo.Metadata.ArtistUnicode, SetInfo.Metadata.Artist),
Font = @"Exo2.0-BoldItalic", Font = @"Exo2.0-BoldItalic",
}, },
difficultyIcons = new FillFlowContainer new FillFlowContainer
{ {
AutoSizeAxes = Axes.X,
Height = 20,
Margin = new MarginPadding { Top = vertical_padding, Bottom = vertical_padding }, Margin = new MarginPadding { Top = vertical_padding, Bottom = vertical_padding },
AutoSizeAxes = Axes.Both, Children = DifficultyIcons,
}, },
}, },
}, },
@ -101,11 +97,11 @@ namespace osu.Game.Overlays.Direct
Margin = new MarginPadding { Right = (height - vertical_padding * 2) + vertical_padding }, Margin = new MarginPadding { Right = (height - vertical_padding * 2) + vertical_padding },
Children = new Drawable[] Children = new Drawable[]
{ {
playCount = new Statistic(FontAwesome.fa_play_circle) new Statistic(FontAwesome.fa_play_circle)
{ {
Margin = new MarginPadding { Right = 1 }, Margin = new MarginPadding { Right = 1 },
}, },
favouriteCount = new Statistic(FontAwesome.fa_heart), new Statistic(FontAwesome.fa_heart),
new FillFlowContainer new FillFlowContainer
{ {
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
@ -119,15 +115,17 @@ namespace osu.Game.Overlays.Direct
Text = @"mapped by ", Text = @"mapped by ",
TextSize = 14, TextSize = 14,
}, },
author = new OsuSpriteText new OsuSpriteText
{ {
Text = SetInfo.Metadata.Author,
TextSize = 14, TextSize = 14,
Font = @"Exo2.0-SemiBoldItalic", Font = @"Exo2.0-SemiBoldItalic",
}, },
}, },
}, },
source = new OsuSpriteText new OsuSpriteText
{ {
Text = $@"from {SetInfo.Metadata.Source}",
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
TextSize = 14, TextSize = 14,
@ -143,6 +141,7 @@ namespace osu.Game.Overlays.Direct
}, },
}, },
}; };
} }
private class DownloadButton : ClickableContainer private class DownloadButton : ClickableContainer

View File

@ -1,12 +1,11 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// 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.Collections.Generic;
using OpenTK; using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -16,32 +15,26 @@ namespace osu.Game.Overlays.Direct
{ {
public abstract class DirectPanel : Container public abstract class DirectPanel : Container
{ {
protected virtual Sprite Background { get; } protected readonly BeatmapSetInfo SetInfo;
protected virtual OsuSpriteText Title { get; }
protected virtual OsuSpriteText Artist { get; }
protected virtual OsuSpriteText Author { get; }
protected virtual OsuSpriteText Source { get; }
protected virtual Statistic PlayCount { get; }
protected virtual Statistic FavouriteCount { get; }
protected virtual FillFlowContainer DifficultyIcons { get; }
private BeatmapSetInfo setInfo; protected IEnumerable<DifficultyIcon> DifficultyIcons
{
get
{
var icons = new List<DifficultyIcon>();
[BackgroundDependencyLoader] foreach (var b in SetInfo.Beatmaps)
private void load(LocalisationEngine localisation) icons.Add(new DifficultyIcon(b));
{
Title.Current = localisation.GetUnicodePreference(setInfo.Metadata.TitleUnicode, setInfo.Metadata.Title);
Artist.Current = localisation.GetUnicodePreference(setInfo.Metadata.ArtistUnicode, setInfo.Metadata.Artist);
Author.Text = setInfo.Metadata.Author;
Source.Text = @"from " + setInfo.Metadata.Source;
foreach (var b in setInfo.Beatmaps) return icons;
DifficultyIcons.Add(new DifficultyIcon(b)); }
} }
//todo: Direct panel backgrounds
public DirectPanel(BeatmapSetInfo setInfo) public DirectPanel(BeatmapSetInfo setInfo)
{ {
this.setInfo = setInfo; SetInfo = setInfo;
} }
public class Statistic : FillFlowContainer public class Statistic : FillFlowContainer