Make Header and it's components updateable.

This commit is contained in:
DrabWeb
2017-09-13 18:25:23 -03:00
parent 63c50f82eb
commit d83cd3ecf9
7 changed files with 176 additions and 91 deletions

View File

@ -16,20 +16,53 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
{ {
private const float height = 50; private const float height = 50;
public AuthorInfo(BeatmapSetOnlineInfo info) private readonly UpdateableAvatar avatar;
private readonly FillFlowContainer fields;
private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get { return beatmapSet; }
set
{
if (value == beatmapSet) return;
beatmapSet = value;
var i = BeatmapSet.OnlineInfo;
avatar.User = i.Author;
fields.Children = new Drawable[]
{
new Field("made by", i.Author.Username, @"Exo2.0-RegularItalic"),
new Field("submitted on", i.Submitted.ToString(@"MMM d, yyyy"), @"Exo2.0-Bold")
{
Margin = new MarginPadding { Top = 5 },
},
};
if (i.Ranked.HasValue)
{
fields.Add(new Field("ranked on ", i.Ranked.Value.ToString(@"MMM d, yyyy"), @"Exo2.0-Bold"));
}
else if (i.LastUpdated.HasValue)
{
fields.Add(new Field("last updated on ", i.LastUpdated.Value.ToString(@"MMM d, yyyy"), @"Exo2.0-Bold"));
}
}
}
public AuthorInfo()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Height = height; Height = height;
FillFlowContainer fields;
Children = new Drawable[] Children = new Drawable[]
{ {
new UpdateableAvatar avatar = new UpdateableAvatar
{ {
Size = new Vector2(height), Size = new Vector2(height),
CornerRadius = 3, CornerRadius = 3,
Masking = true, Masking = true,
User = info.Author,
EdgeEffect = new EdgeEffectParameters EdgeEffect = new EdgeEffectParameters
{ {
Colour = Color4.Black.Opacity(0.25f), Colour = Color4.Black.Opacity(0.25f),
@ -43,25 +76,8 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Padding = new MarginPadding { Left = height + 5 }, Padding = new MarginPadding { Left = height + 5 },
Children = new Drawable[]
{
new Field("made by", info.Author.Username, @"Exo2.0-RegularItalic"),
new Field("submitted on", info.Submitted.ToString(@"MMM d, yyyy"), @"Exo2.0-Bold")
{
Margin = new MarginPadding { Top = 5 },
},
},
}, },
}; };
if (info.Ranked.HasValue)
{
fields.Add(new Field("ranked on ", info.Ranked.Value.ToString(@"MMM d, yyyy"), @"Exo2.0-Bold"));
}
else if (info.LastUpdated.HasValue)
{
fields.Add(new Field("last updated on ", info.LastUpdated.Value.ToString(@"MMM d, yyyy"), @"Exo2.0-Bold"));
}
} }
private class Field : FillFlowContainer private class Field : FillFlowContainer

View File

@ -15,7 +15,20 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
{ {
public class BasicStats : Container public class BasicStats : Container
{ {
private readonly Statistic length, circleCount, sliderCount; private readonly Statistic length, bpm, circleCount, sliderCount;
private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get { return beatmapSet; }
set
{
if (value == beatmapSet) return;
beatmapSet = value;
bpm.Value = BeatmapSet.OnlineInfo.BPM.ToString(@"0.##");
}
}
private BeatmapInfo beatmap; private BeatmapInfo beatmap;
public BeatmapInfo Beatmap public BeatmapInfo Beatmap
@ -32,7 +45,7 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
} }
} }
public BasicStats(BeatmapSetInfo set) public BasicStats()
{ {
Child = new FillFlowContainer Child = new FillFlowContainer
{ {
@ -42,11 +55,7 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
Children = new[] Children = new[]
{ {
length = new Statistic(FontAwesome.fa_clock_o, "Length") { Width = 0.25f }, length = new Statistic(FontAwesome.fa_clock_o, "Length") { Width = 0.25f },
new Statistic(FontAwesome.fa_circle, "BPM") bpm = new Statistic(FontAwesome.fa_circle, "BPM") { Width = 0.25f },
{
Width = 0.25f,
Value = set.OnlineInfo.BPM.ToString(@"0.##"),
},
circleCount = new Statistic(FontAwesome.fa_circle_o, "Circle Count") { Width = 0.25f }, circleCount = new Statistic(FontAwesome.fa_circle_o, "Circle Count") { Width = 0.25f },
sliderCount = new Statistic(FontAwesome.fa_circle, "Slider Count") { Width = 0.25f }, sliderCount = new Statistic(FontAwesome.fa_circle, "Slider Count") { Width = 0.25f },
}, },

View File

@ -28,10 +28,42 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
private readonly DifficultiesContainer difficulties; private readonly DifficultiesContainer difficulties;
private readonly OsuSpriteText version, starRating; private readonly OsuSpriteText version, starRating;
private readonly Statistic plays, favourites;
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>(); public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public BeatmapPicker(BeatmapSetInfo set) private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get { return beatmapSet; }
set
{
if (value == beatmapSet) return;
beatmapSet = value;
Beatmap.Value = BeatmapSet.Beatmaps.First();
plays.Value = BeatmapSet.OnlineInfo.PlayCount;
favourites.Value = BeatmapSet.OnlineInfo.FavouriteCount;
difficulties.ChildrenEnumerable = BeatmapSet.Beatmaps.Select(b => new DifficultySelectorButton(b)
{
State = DifficultySelectorState.NotSelected,
OnHovered = beatmap =>
{
showBeatmap(beatmap);
starRating.Text = beatmap.StarDifficulty.ToString("Star Difficulty 0.##");
starRating.FadeIn(100);
},
OnClicked = beatmap =>
{
Beatmap.Value = beatmap;
},
});
updateDifficultyButtons();
}
}
public BeatmapPicker()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -89,36 +121,19 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
Margin = new MarginPadding { Top = 5 }, Margin = new MarginPadding { Top = 5 },
Children = new[] Children = new[]
{ {
new Statistic(FontAwesome.fa_play_circle, set.OnlineInfo.PlayCount), plays = new Statistic(FontAwesome.fa_play_circle),
new Statistic(FontAwesome.fa_heart, set.OnlineInfo.FavouriteCount), favourites = new Statistic(FontAwesome.fa_heart),
}, },
}, },
}, },
}, },
}; };
Beatmap.Value = set.Beatmaps.First();
Beatmap.ValueChanged += b => Beatmap.ValueChanged += b =>
{ {
showBeatmap(b); showBeatmap(b);
updateDifficultyButtons(); updateDifficultyButtons();
}; };
difficulties.ChildrenEnumerable = set.Beatmaps.Select(b => new DifficultySelectorButton(b)
{
State = DifficultySelectorState.NotSelected,
OnHovered = beatmap =>
{
showBeatmap(beatmap);
starRating.Text = beatmap.StarDifficulty.ToString("Star Difficulty 0.##");
starRating.FadeIn(100);
},
OnClicked = beatmap =>
{
Beatmap.Value = beatmap;
},
});
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -261,7 +276,7 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
} }
} }
public Statistic(FontAwesome icon, int value = 0) public Statistic(FontAwesome icon)
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal; Direction = FillDirection.Horizontal;
@ -285,8 +300,6 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
TextSize = 14, TextSize = 14,
}, },
}; };
Value = value;
} }
} }

View File

@ -14,10 +14,24 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
{ {
public class Details : FillFlowContainer public class Details : FillFlowContainer
{ {
private readonly PreviewButton preview;
private readonly BasicStats basic; private readonly BasicStats basic;
private readonly AdvancedStats advanced; private readonly AdvancedStats advanced;
private readonly UserRatings ratings; private readonly UserRatings ratings;
private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get { return beatmapSet; }
set
{
if (value == beatmapSet) return;
beatmapSet = value;
basic.BeatmapSet = preview.BeatmapSet = BeatmapSet;
}
}
private BeatmapInfo beatmap; private BeatmapInfo beatmap;
public BeatmapInfo Beatmap public BeatmapInfo Beatmap
{ {
@ -32,7 +46,7 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
} }
} }
public Details(BeatmapSetInfo set) public Details()
{ {
Width = OnlineBeatmapSetOverlay.RIGHT_WIDTH; Width = OnlineBeatmapSetOverlay.RIGHT_WIDTH;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -40,17 +54,13 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
Children = new Drawable[] Children = new Drawable[]
{ {
new AsyncLoadWrapper(new PreviewButton(set) preview = new PreviewButton
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
})
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}, },
new DetailBox new DetailBox
{ {
Child = basic = new BasicStats(set) Child = basic = new BasicStats()
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,

View File

@ -24,10 +24,50 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
private const float buttons_spacing = 5; private const float buttons_spacing = 5;
private readonly Box tabsBg; private readonly Box tabsBg;
private readonly Container coverContainer;
private readonly OsuSpriteText title, artist;
private readonly AuthorInfo author;
private readonly Details details;
private DelayedLoadWrapper cover;
public readonly BeatmapPicker Picker; public readonly BeatmapPicker Picker;
public Header(BeatmapSetInfo set) private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get { return beatmapSet; }
set
{
if (value == beatmapSet) return;
beatmapSet = value;
Picker.BeatmapSet = author.BeatmapSet = details.BeatmapSet = BeatmapSet;
title.Text = BeatmapSet.Metadata.Title;
artist.Text = BeatmapSet.Metadata.Artist;
if (cover != null)
cover.FadeOut(400, Easing.Out);
coverContainer.Add(cover = new DelayedLoadWrapper(new BeatmapSetCover(BeatmapSet)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
OnLoadComplete = d =>
{
d.FadeInFromZero(400, Easing.Out);
},
})
{
RelativeSizeAxes = Axes.Both,
TimeBeforeLoad = 300
});
}
}
public Header()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Height = 400; Height = 400;
@ -42,7 +82,6 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
Container noVideoButtons; Container noVideoButtons;
FillFlowContainer videoButtons; FillFlowContainer videoButtons;
Details details;
Children = new Drawable[] Children = new Drawable[]
{ {
new Container new Container
@ -73,20 +112,9 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4.Black, Colour = Color4.Black,
}, },
new DelayedLoadWrapper(new BeatmapSetCover(set) coverContainer = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
OnLoadComplete = d =>
{
d.FadeInFromZero(400, Easing.Out);
},
})
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
TimeBeforeLoad = 300
}, },
new Box new Box
{ {
@ -109,17 +137,15 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 113, Height = 113,
Child = Picker = new BeatmapPicker(set), Child = Picker = new BeatmapPicker(),
}, },
new OsuSpriteText title = new OsuSpriteText
{ {
Text = set.Metadata.Title,
Font = @"Exo2.0-BoldItalic", Font = @"Exo2.0-BoldItalic",
TextSize = 37, TextSize = 37,
}, },
new OsuSpriteText artist = new OsuSpriteText
{ {
Text = set.Metadata.Artist,
Font = @"Exo2.0-SemiBoldItalic", Font = @"Exo2.0-SemiBoldItalic",
TextSize = 25, TextSize = 25,
}, },
@ -128,7 +154,7 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = 20 }, Margin = new MarginPadding { Top = 20 },
Child = new AuthorInfo(set.OnlineInfo), Child = author = new AuthorInfo(),
}, },
new Container new Container
{ {
@ -168,7 +194,7 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
}, },
}, },
}, },
details = new Details(set) details = new Details
{ {
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight, Origin = Anchor.BottomRight,

View File

@ -19,13 +19,27 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
{ {
public class PreviewButton : OsuClickableContainer public class PreviewButton : OsuClickableContainer
{ {
private readonly BeatmapSetInfo set;
private readonly Box bg, progress; private readonly Box bg, progress;
private readonly SpriteIcon icon; private readonly SpriteIcon icon;
private AudioManager audio; private AudioManager audio;
private Track preview; private Track preview;
private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get { return beatmapSet; }
set
{
if (value == beatmapSet) return;
beatmapSet = value;
Playing = false;
preview = null;
loadPreview();
}
}
private bool playing; private bool playing;
public bool Playing public bool Playing
{ {
@ -35,6 +49,8 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
if (value == playing) return; if (value == playing) return;
playing = value; playing = value;
if (progress == null) return;
if (Playing) if (Playing)
{ {
icon.Icon = FontAwesome.fa_stop; icon.Icon = FontAwesome.fa_stop;
@ -52,9 +68,8 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
} }
} }
public PreviewButton(BeatmapSetInfo set) public PreviewButton()
{ {
this.set = set;
Height = 42; Height = 42;
Children = new Drawable[] Children = new Drawable[]
@ -95,8 +110,6 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
{ {
this.audio = audio; this.audio = audio;
progress.Colour = colours.Yellow; progress.Colour = colours.Yellow;
loadPreview();
} }
protected override void Update() protected override void Update()
@ -130,9 +143,9 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
private void loadPreview() private void loadPreview()
{ {
if (preview?.HasCompleted ?? true) if (preview == null || (preview?.HasCompleted ?? true) && BeatmapSet != null)
{ {
preview = audio.Track.Get(set.OnlineInfo.Preview); preview = audio.Track.Get(BeatmapSet.OnlineInfo.Preview);
preview.Volume.Value = 0.5; preview.Volume.Value = 0.5;
} }
else else

View File

@ -1,7 +1,6 @@
// 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.Linq;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -62,14 +61,14 @@ namespace osu.Game.Overlays
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Children = new Drawable[] Children = new Drawable[]
{ {
// header = new Header(), header = new Header(),
info = new Info(), info = new Info(),
}, },
}, },
}, },
}; };
// header.Picker.Beatmap.ValueChanged += b => info.Beatmap = b; header.Picker.Beatmap.ValueChanged += b => info.Beatmap = b;
} }
protected override void PopIn() protected override void PopIn()
@ -86,8 +85,7 @@ namespace osu.Game.Overlays
public void ShowBeatmapSet(BeatmapSetInfo set) public void ShowBeatmapSet(BeatmapSetInfo set)
{ {
/*header.BeatmapSet = */info.BeatmapSet = set; header.BeatmapSet = info.BeatmapSet = set;
info.Beatmap = set.Beatmaps.Last();
Show(); Show();
} }