1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 12:53:11 +08:00

Merge remote-tracking branch 'refs/remotes/ppy/master' into profile-beatmaps-section

This commit is contained in:
EVAST9919 2017-11-09 20:02:47 +03:00
commit 68c4da0810
16 changed files with 185 additions and 60 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Lists;
@ -85,6 +86,9 @@ namespace osu.Game.Beatmaps.ControlPoints
private T binarySearch<T>(SortedList<T> list, double time, T prePoint = null)
where T : ControlPoint, new()
{
if (list == null)
throw new ArgumentNullException(nameof(list));
if (list.Count == 0)
return new T();

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
@ -12,6 +13,9 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapBackgroundSprite(WorkingBeatmap working)
{
if (working == null)
throw new ArgumentNullException(nameof(working));
this.working = working;
}

View File

@ -72,6 +72,11 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapGroup(BeatmapSetInfo beatmapSet, BeatmapManager manager)
{
if (beatmapSet == null)
throw new ArgumentNullException(nameof(beatmapSet));
if (manager == null)
throw new ArgumentNullException(nameof(manager));
BeatmapSet = beatmapSet;
WorkingBeatmap beatmap = manager.GetWorkingBeatmap(BeatmapSet.Beatmaps.FirstOrDefault());

View File

@ -73,6 +73,9 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapPanel(BeatmapInfo beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
Beatmap = beatmap;
Height *= 0.60f;

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
@ -12,6 +13,9 @@ namespace osu.Game.Beatmaps.Drawables
private readonly BeatmapSetInfo set;
public BeatmapSetCover(BeatmapSetInfo set)
{
if (set == null)
throw new ArgumentNullException(nameof(set));
this.set = set;
}

View File

@ -36,6 +36,9 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapSetHeader(WorkingBeatmap beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
this.beatmap = beatmap;
Children = new Drawable[]
@ -88,6 +91,9 @@ namespace osu.Game.Beatmaps.Drawables
[BackgroundDependencyLoader]
private void load(LocalisationEngine localisation)
{
if (localisation == null)
throw new ArgumentNullException(nameof(localisation));
title.Current = localisation.GetUnicodePreference(beatmap.Metadata.TitleUnicode, beatmap.Metadata.Title);
artist.Current = localisation.GetUnicodePreference(beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist);
}
@ -154,6 +160,9 @@ namespace osu.Game.Beatmaps.Drawables
public void AddDifficultyIcons(IEnumerable<BeatmapPanel> panels)
{
if (panels == null)
throw new ArgumentNullException(nameof(panels));
foreach (var p in panels)
difficultyIcons.Add(new DifficultyIcon(p.Beatmap));
}

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
@ -23,6 +24,9 @@ namespace osu.Game.Beatmaps.Drawables
[BackgroundDependencyLoader]
private void load(OsuColour palette)
{
if (palette == null)
throw new ArgumentNullException(nameof(palette));
this.palette = palette;
AccentColour = getColour(beatmap);
}
@ -39,6 +43,9 @@ namespace osu.Game.Beatmaps.Drawables
private DifficultyRating getDifficultyRating(BeatmapInfo beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
var rating = beatmap.StarDifficulty;
if (rating < 1.5) return DifficultyRating.Easy;

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics;
@ -15,6 +16,9 @@ namespace osu.Game.Beatmaps.Drawables
public DifficultyIcon(BeatmapInfo beatmap) : base(beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
this.beatmap = beatmap;
Size = new Vector2(20);
}

View File

@ -18,6 +18,9 @@ namespace osu.Game.Beatmaps.Formats
public static BeatmapDecoder GetDecoder(StreamReader stream)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
string line;
do { line = stream.ReadLine()?.Trim(); }
while (line != null && line.Length == 0);

View File

@ -70,6 +70,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleGeneral(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
var metadata = beatmap.BeatmapInfo.Metadata;
@ -129,6 +134,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleEditor(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
switch (pair.Key)
@ -153,6 +163,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleMetadata(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
var metadata = beatmap.BeatmapInfo.Metadata;
@ -194,6 +209,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleDifficulty(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
var difficulty = beatmap.BeatmapInfo.BaseDifficulty;
@ -226,6 +246,9 @@ namespace osu.Game.Beatmaps.Formats
/// <param name="line">The line which may contains variables.</param>
private void decodeVariables(ref string line)
{
if (line == null)
throw new ArgumentNullException(nameof(line));
while (line.IndexOf('$') >= 0)
{
string origLine = line;
@ -244,6 +267,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleEvents(Beatmap beatmap, string line, ref StoryboardSprite storyboardSprite, ref CommandTimelineGroup timelineGroup)
{
if (line == null)
throw new ArgumentNullException(nameof(line));
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
var depth = 0;
while (line.StartsWith(" ") || line.StartsWith("_"))
{
@ -469,6 +497,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleTimingPoints(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
string[] split = line.Split(',');
double time = double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo);
@ -555,6 +588,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleColours(Beatmap beatmap, string line, ref bool hasCustomColours)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
string[] split = pair.Value.Split(',');
@ -587,6 +625,9 @@ namespace osu.Game.Beatmaps.Formats
private void handleVariables(string line)
{
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, '=');
variables[pair.Key] = pair.Value;
}
@ -603,6 +644,11 @@ namespace osu.Game.Beatmaps.Formats
protected override void ParseFile(StreamReader stream, Beatmap beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (stream == null)
throw new ArgumentNullException(nameof(stream));
beatmap.BeatmapInfo.BeatmapVersion = beatmapVersion;
Section section = Section.None;
@ -679,6 +725,9 @@ namespace osu.Game.Beatmaps.Formats
private KeyValuePair<string, string> splitKeyVal(string line, char separator)
{
if (line == null)
throw new ArgumentNullException(nameof(line));
var split = line.Trim().Split(new[] { separator }, 2);
return new KeyValuePair<string, string>

View File

@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using OpenTK;
using osu.Framework.Allocation;
@ -33,6 +32,9 @@ namespace osu.Game.Overlays.Profile
{
this.user = user;
int[] userRanks = user.RankHistory?.Data ?? new[] { user.Statistics.Rank };
ranks = userRanks.SkipWhile(x => x == 0).ToArray();
Padding = new MarginPadding { Vertical = padding };
Children = new Drawable[]
{
@ -58,19 +60,21 @@ namespace osu.Game.Overlays.Profile
Font = @"Exo2.0-RegularItalic",
TextSize = secondary_textsize
},
graph = new RankChartLineGraph
};
if (ranks.Length > 0)
{
Add(graph = new RankChartLineGraph
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.X,
Y = -secondary_textsize,
DefaultValueCount = 90,
BallRelease = updateRankTexts,
BallMove = showHistoryRankTexts
}
};
DefaultValueCount = ranks.Length,
});
ranks = user.RankHistory?.Data ?? new[] { user.Statistics.Rank };
graph.OnBallMove += showHistoryRankTexts;
}
}
private void updateRankTexts()
@ -82,7 +86,8 @@ namespace osu.Game.Overlays.Profile
private void showHistoryRankTexts(int dayIndex)
{
rankText.Text = ranks[dayIndex] > 0 ? $"#{ranks[dayIndex]:#,0}" : "no rank";
rankText.Text = $"#{ranks[dayIndex]:#,0}";
dayIndex++;
relativeText.Text = dayIndex == ranks.Length ? "Now" : $"{ranks.Length - dayIndex} days ago";
//plural should be handled in a general way
}
@ -90,14 +95,15 @@ namespace osu.Game.Overlays.Profile
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
graph.Colour = colours.Yellow;
if (user.Statistics.Rank > 0)
if (graph != null)
{
graph.Colour = colours.Yellow;
// use logarithmic coordinates
graph.Values = ranks.Select(x => -(float)Math.Log(x));
graph.ResetBall();
graph.SetStaticBallPosition();
}
updateRankTexts();
}
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
@ -110,67 +116,78 @@ namespace osu.Game.Overlays.Profile
return base.Invalidate(invalidation, source, shallPropagate);
}
protected override bool OnHover(InputState state)
{
graph?.UpdateBallPosition(state.Mouse.Position.X);
graph?.ShowBall();
return base.OnHover(state);
}
protected override bool OnMouseMove(InputState state)
{
graph?.UpdateBallPosition(state.Mouse.Position.X);
return base.OnMouseMove(state);
}
protected override void OnHoverLost(InputState state)
{
if (graph != null)
{
graph.HideBall();
updateRankTexts();
}
base.OnHoverLost(state);
}
private class RankChartLineGraph : LineGraph
{
private readonly CircularContainer ball;
private bool ballShown;
private const double fade_duration = 200;
private const double transform_duration = 100;
private readonly CircularContainer staticBall;
private readonly CircularContainer movingBall;
public Action<int> BallMove;
public Action BallRelease;
public Action<int> OnBallMove;
public RankChartLineGraph()
{
Add(ball = new CircularContainer
Add(staticBall = new CircularContainer
{
Origin = Anchor.Centre,
Size = new Vector2(8),
Masking = true,
Origin = Anchor.Centre,
Alpha = 0,
RelativePositionAxes = Axes.Both,
Children = new Drawable[]
{
new Box { RelativeSizeAxes = Axes.Both }
}
Child = new Box { RelativeSizeAxes = Axes.Both }
});
Add(movingBall = new CircularContainer
{
Origin = Anchor.Centre,
Size = new Vector2(8),
Alpha = 0,
Masking = true,
RelativePositionAxes = Axes.Both,
Child = new Box { RelativeSizeAxes = Axes.Both }
});
}
public void ResetBall()
public void SetStaticBallPosition() => staticBall.Position = new Vector2(1, GetYPosition(Values.Last()));
public void UpdateBallPosition(float mouseXPosition)
{
ball.MoveTo(new Vector2(1, GetYPosition(Values.Last())), ballShown ? transform_duration : 0, Easing.OutQuint);
ball.Show();
BallRelease();
ballShown = true;
int index = calculateIndex(mouseXPosition);
movingBall.Position = calculateBallPosition(index);
OnBallMove.Invoke(index);
}
protected override bool OnMouseMove(InputState state)
{
if (ballShown)
{
var values = (IList<float>)Values;
var position = ToLocalSpace(state.Mouse.NativeState.Position);
int count = Math.Max(values.Count, DefaultValueCount);
int index = (int)Math.Round(position.X / DrawWidth * (count - 1));
if (index >= count - values.Count)
{
int i = index + values.Count - count;
float y = GetYPosition(values[i]);
if (Math.Abs(y * DrawHeight - position.Y) <= 8f)
{
ball.MoveTo(new Vector2(index / (float)(count - 1), y), transform_duration, Easing.OutQuint);
BallMove(i);
}
}
}
return base.OnMouseMove(state);
}
public void ShowBall() => movingBall.FadeIn(fade_duration);
protected override void OnHoverLost(InputState state)
public void HideBall() => movingBall.FadeOut(fade_duration);
private int calculateIndex(float mouseXPosition) => (int)Math.Round(mouseXPosition / DrawWidth * (DefaultValueCount - 1));
private Vector2 calculateBallPosition(int index)
{
if (ballShown)
ResetBall();
base.OnHoverLost(state);
float y = GetYPosition(Values.ElementAt(index));
return new Vector2(index / (float)(DefaultValueCount - 1), y);
}
}
}

View File

@ -263,17 +263,15 @@ namespace osu.Game.Screens.Menu
logo.ScaleTo(0.5f, 200, Easing.In);
trackingPosition = false;
logo
.MoveTo(iconTrackingPosition, lastState == MenuState.EnteringMode ? 0 : 200, Easing.In)
.OnComplete(o =>
{
trackingPosition = true;
if (logo.Scale.X > 0.5f)
{
o.Impact();
toolbar?.Show();
}
o.Impact();
toolbar?.Show();
});
break;
default:

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -25,6 +26,9 @@ namespace osu.Game.Users
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
if (textures == null)
throw new ArgumentNullException(nameof(textures));
Texture texture = null;
if (user != null && user.Id > 1) texture = textures.Get($@"https://a.ppy.sh/{user.Id}");
if (texture == null) texture = textures.Get(@"Online/avatar-guest");

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
@ -45,6 +46,9 @@ namespace osu.Game.Users
[BackgroundDependencyLoader]
private void load(TextureStore ts)
{
if (ts == null)
throw new ArgumentNullException(nameof(ts));
textures = ts;
sprite.Texture = textures.Get($@"Flags/{flagName}");
}

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
@ -19,6 +20,9 @@ namespace osu.Game.Users
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
if (textures == null)
throw new ArgumentNullException(nameof(textures));
if (!string.IsNullOrEmpty(user.CoverUrl))
Texture = textures.Get(user.CoverUrl);
}

View File

@ -38,6 +38,9 @@ namespace osu.Game.Users
public UserPanel(User user)
{
if (user == null)
throw new ArgumentNullException(nameof(user));
this.user = user;
Height = height - status_height;
@ -173,6 +176,9 @@ namespace osu.Game.Users
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, UserProfileOverlay profile)
{
if (colours == null)
throw new ArgumentNullException(nameof(colours));
Status.ValueChanged += displayStatus;
Status.ValueChanged += status => statusBg.FadeColour(status?.GetAppropriateColour(colours) ?? colours.Gray5, 500, Easing.OutQuint);