osu/osu.Game/Overlays/Profile/Sections/RanksSection.cs

167 lines
5.6 KiB
C#
Raw Normal View History

2017-06-07 14:49:14 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-07-26 16:55:37 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
2017-07-26 16:55:37 +00:00
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Profile.Sections.Ranks;
2017-07-28 22:31:52 +00:00
using osu.Game.Rulesets.Scoring;
2017-07-26 16:55:37 +00:00
using System;
using System.Linq;
2017-07-26 16:55:37 +00:00
2017-07-13 04:53:45 +00:00
namespace osu.Game.Overlays.Profile.Sections
2017-06-07 14:49:14 +00:00
{
public class RanksSection : ProfileSection
{
public override string Title => "Ranks";
2017-06-15 15:47:34 +00:00
public override string Identifier => "top_ranks";
2017-07-26 16:55:37 +00:00
private readonly ScoreFlowContainer best, first;
private readonly OsuSpriteText bestMissing, firstMissing;
2017-07-26 16:55:37 +00:00
public RanksSection()
{
Children = new Drawable[]
{
new OsuSpriteText
{
2017-07-26 16:55:37 +00:00
TextSize = 15,
Text = "Best Performance",
Font = "Exo2.0-RegularItalic",
Margin = new MarginPadding { Top = 10, Bottom = 10 },
2017-07-26 16:55:37 +00:00
},
best = new ScoreFlowContainer
2017-07-26 16:55:37 +00:00
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
},
bestMissing = new OsuSpriteText
{
TextSize = 14,
Text = "No awesome performance records yet. :(",
},
new OsuSpriteText
{
2017-07-26 16:55:37 +00:00
TextSize = 15,
Text = "First Place Ranks",
Font = "Exo2.0-RegularItalic",
Margin = new MarginPadding { Top = 20, Bottom = 10 },
2017-07-26 16:55:37 +00:00
},
first = new ScoreFlowContainer
2017-07-26 16:55:37 +00:00
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
},
firstMissing = new OsuSpriteText
{
TextSize = 14,
Text = "No awesome performance records yet. :(",
2017-07-26 16:55:37 +00:00
},
};
}
public Score[] ScoresBest
2017-07-26 16:55:37 +00:00
{
set
{
best.Clear();
if (value.Length == 0)
2017-07-26 16:55:37 +00:00
{
bestMissing.Show();
}
else
{
bestMissing.Hide();
int i = 0;
foreach (Score score in value)
2017-07-26 16:55:37 +00:00
{
best.Add(new DrawableScore(score, Math.Pow(0.95, i))
{
RelativeSizeAxes = Axes.X,
Height = 60,
Alpha = 0,
});
i++;
}
2017-07-26 16:55:37 +00:00
}
best.ShowMore();
2017-07-26 16:55:37 +00:00
}
}
public Score[] ScoresFirst
2017-07-26 16:55:37 +00:00
{
set
{
first.Clear();
if (value.Length == 0)
{
firstMissing.Show();
}
else
{
firstMissing.Hide();
foreach (Score score in value)
first.Add(new DrawableScore(score)
{
RelativeSizeAxes = Axes.X,
Height = 60,
Alpha = 0,
});
}
first.ShowMore();
}
}
2017-08-09 17:20:41 +00:00
public class ScoreFlowContainer : Container<DrawableScore>
{
private FillFlowContainer<DrawableScore> scores;
private OsuClickableContainer showMoreText;
protected override Container<DrawableScore> Content => scores;
protected override void LoadComplete()
{
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Children = new Drawable[]
2017-07-26 16:55:37 +00:00
{
2017-07-29 13:16:31 +00:00
scores = new FillFlowContainer<DrawableScore>
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
},
},
};
}
public override void Clear(bool disposeChildren)
{
base.Clear(disposeChildren);
2017-08-09 20:58:06 +00:00
if (showMoreText == null)
((FillFlowContainer)InternalChild).Add(showMoreText = new OsuHoverContainer
{
Action = ShowMore,
AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Child = new OsuSpriteText
{
TextSize = 14,
Text = "show more",
}
});
else
showMoreText.Show();
}
2017-08-09 16:57:55 +00:00
public void ShowMore() => showMoreText.Alpha = Children.Where(d => !d.IsPresent).Where((d, i) => (d.Alpha = i < 5 ? 1 : 0) == 0).Any() ? 1 : 0;
2017-07-26 16:55:37 +00:00
}
2017-06-07 14:49:14 +00:00
}
}