1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 18:42:56 +08:00

remove inner classes and make User property a bindable

This commit is contained in:
Jorolf 2017-10-25 20:07:12 +02:00
parent a2dfef301a
commit 0449639f41
7 changed files with 79 additions and 127 deletions

View File

@ -41,7 +41,7 @@ namespace osu.Game.Tests.Visual
} }
}); });
AddStep("Show cookiezi", () => ranks.User = new User { Id = 124493 }); AddStep("Show cookiezi", () => ranks.User.Value = new User { Id = 124493 });
} }
} }
} }

View File

@ -9,6 +9,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Users; using osu.Game.Users;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Configuration;
namespace osu.Game.Overlays.Profile namespace osu.Game.Overlays.Profile
{ {
@ -22,13 +23,7 @@ namespace osu.Game.Overlays.Profile
protected override Container<Drawable> Content => content; protected override Container<Drawable> Content => content;
public virtual User User public readonly Bindable<User> User = new Bindable<User>();
{
get { return user; }
set { user = value; }
}
private User user;
protected ProfileSection() protected ProfileSection()
{ {

View File

@ -17,13 +17,7 @@ namespace osu.Game.Overlays.Profile.Sections
public HistoricalSection() public HistoricalSection()
{ {
Child = recent = new ScoreContainer.TotalScoreContainer(ScoreType.Recent, "Recent Plays (24h)", "No performance records. :("); Child = recent = new ScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)");
}
public override User User
{
get { return base.User; }
set { base.User = recent.User = value; }
} }
} }
} }

View File

@ -20,14 +20,14 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
{ {
public class DrawableScore : Container public class DrawableScore : Container
{ {
private readonly FillFlowContainer<OsuSpriteText> stats; protected readonly FillFlowContainer<OsuSpriteText> Stats;
private readonly FillFlowContainer metadata; private readonly FillFlowContainer metadata;
private readonly ModContainer modContainer; private readonly ModContainer modContainer;
private readonly Score score; protected readonly Score Score;
private DrawableScore(Score score) public DrawableScore(Score score)
{ {
this.score = score; this.Score = score;
Children = new Drawable[] Children = new Drawable[]
{ {
@ -37,7 +37,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Width = 60, Width = 60,
FillMode = FillMode.Fit, FillMode = FillMode.Fit,
}, },
stats = new FillFlowContainer<OsuSpriteText> Stats = new FillFlowContainer<OsuSpriteText>
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
@ -75,9 +75,9 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay) private void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay)
{ {
stats.Add(new OsuSpriteText Stats.Add(new OsuSpriteText
{ {
Text = $"accuracy: {score.Accuracy:P2}", Text = $"accuracy: {Score.Accuracy:P2}",
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
Colour = colour.GrayA, Colour = colour.GrayA,
@ -91,7 +91,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Action = () => Action = () =>
{ {
if (score.Beatmap.OnlineBeatmapSetID.HasValue) beatmapSetOverlay.ShowBeatmapSet(score.Beatmap.OnlineBeatmapSetID.Value); if (Score.Beatmap.OnlineBeatmapSetID.HasValue) beatmapSetOverlay.ShowBeatmapSet(Score.Beatmap.OnlineBeatmapSetID.Value);
}, },
Child = new FillFlowContainer Child = new FillFlowContainer
{ {
@ -101,15 +101,15 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
new OsuSpriteText new OsuSpriteText
{ {
Current = locale.GetUnicodePreference( Current = locale.GetUnicodePreference(
$"{score.Beatmap.Metadata.TitleUnicode ?? score.Beatmap.Metadata.Title} [{score.Beatmap.Version}] ", $"{Score.Beatmap.Metadata.TitleUnicode ?? Score.Beatmap.Metadata.Title} [{Score.Beatmap.Version}] ",
$"{score.Beatmap.Metadata.Title ?? score.Beatmap.Metadata.TitleUnicode} [{score.Beatmap.Version}] " $"{Score.Beatmap.Metadata.Title ?? Score.Beatmap.Metadata.TitleUnicode} [{Score.Beatmap.Version}] "
), ),
TextSize = 15, TextSize = 15,
Font = "Exo2.0-SemiBoldItalic", Font = "Exo2.0-SemiBoldItalic",
}, },
new OsuSpriteText new OsuSpriteText
{ {
Current = locale.GetUnicodePreference(score.Beatmap.Metadata.ArtistUnicode, score.Beatmap.Metadata.Artist), Current = locale.GetUnicodePreference(Score.Beatmap.Metadata.ArtistUnicode, Score.Beatmap.Metadata.Artist),
TextSize = 12, TextSize = 12,
Padding = new MarginPadding { Top = 3 }, Padding = new MarginPadding { Top = 3 },
Font = "Exo2.0-RegularItalic", Font = "Exo2.0-RegularItalic",
@ -118,7 +118,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
}, },
}); });
foreach (Mod mod in score.Mods) foreach (Mod mod in Score.Mods)
modContainer.Add(new ModIcon(mod) modContainer.Add(new ModIcon(mod)
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
@ -135,61 +135,60 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
yield return new Vector2(DrawWidth * i * (count == 1 ? 0 : 1f / (count - 1)), 0); yield return new Vector2(DrawWidth * i * (count == 1 ? 0 : 1f / (count - 1)), 0);
} }
} }
}
public class PPScore : DrawableScore
{
private readonly double? weight;
public class PPScore : DrawableScore public PPScore(Score score, double? weight = null) : base(score)
{ {
private readonly double? weight; this.weight = weight;
public PPScore(Score score, double? weight = null) : base(score)
{
this.weight = weight;
}
[BackgroundDependencyLoader]
private new void load(OsuColour colour)
{
double pp = score.PP ?? 0;
stats.Add(new OsuSpriteText
{
Text = $"{pp:0}pp",
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
TextSize = 18,
Font = "Exo2.0-BoldItalic",
});
if (weight.HasValue)
{
stats.Add(new OsuSpriteText
{
Text = $"weighted: {pp * weight:0}pp ({weight:P0})",
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Colour = colour.GrayA,
TextSize = 11,
Font = "Exo2.0-RegularItalic",
});
}
}
} }
public class TotalScore : DrawableScore [BackgroundDependencyLoader]
private new void load(OsuColour colour)
{ {
public TotalScore(Score score) : base(score) double pp = Score.PP ?? 0;
{ } Stats.Add(new OsuSpriteText
[BackgroundDependencyLoader]
private new void load()
{ {
stats.Add(new OsuSpriteText Text = $"{pp:0}pp",
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
TextSize = 18,
Font = "Exo2.0-BoldItalic",
});
if (weight.HasValue)
{
Stats.Add(new OsuSpriteText
{ {
Text = score.TotalScore.ToString("#,###"), Text = $"weighted: {pp * weight:0}pp ({weight:P0})",
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
TextSize = 18, Colour = colour.GrayA,
Font = "Exo2.0-BoldItalic", TextSize = 11,
Font = "Exo2.0-RegularItalic",
}); });
} }
} }
} }
public class TotalScore : DrawableScore
{
public TotalScore(Score score) : base(score)
{ }
[BackgroundDependencyLoader]
private new void load()
{
Stats.Add(new OsuSpriteText
{
Text = Score.TotalScore.ToString("#,###"),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
TextSize = 18,
Font = "Exo2.0-BoldItalic",
});
}
}
} }

View File

@ -3,6 +3,7 @@
using OpenTK; using OpenTK;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -17,36 +18,36 @@ using System.Linq;
namespace osu.Game.Overlays.Profile.Sections.Ranks namespace osu.Game.Overlays.Profile.Sections.Ranks
{ {
public abstract class ScoreContainer : FillFlowContainer public class ScoreContainer : FillFlowContainer
{ {
private readonly FillFlowContainer<DrawableScore> scoreContainer; private readonly FillFlowContainer<DrawableScore> scoreContainer;
private readonly OsuSpriteText missing; private readonly OsuSpriteText missing;
private readonly OsuHoverContainer showMoreButton; private readonly OsuHoverContainer showMoreButton;
private readonly LoadingAnimation showMoreLoading; private readonly LoadingAnimation showMoreLoading;
private readonly bool includeWeight;
private readonly ScoreType type; private readonly ScoreType type;
private int visiblePages; private int visiblePages;
private User user; private readonly Bindable<User> user;
private RulesetStore rulesets; private RulesetStore rulesets;
private APIAccess api; private APIAccess api;
public User User private void setUser(User newUser)
{ {
set visiblePages = 0;
{ scoreContainer.Clear();
user = value; showMoreButton.Hide();
visiblePages = 0; missing.Show();
scoreContainer.Clear(); showMore();
showMoreButton.Hide();
missing.Show();
showMore();
}
} }
private ScoreContainer(ScoreType type, string header, string missingText) public ScoreContainer(ScoreType type, Bindable<User> user, string header, bool includeWeight = false)
{ {
this.type = type; this.type = type;
this.includeWeight = includeWeight;
this.user = user;
user.ValueChanged += setUser;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -89,7 +90,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
missing = new OsuSpriteText missing = new OsuSpriteText
{ {
TextSize = 14, TextSize = 14,
Text = missingText, Text = type == ScoreType.Recent ? "No performance records. :(" : "No awesome performance records yet. :(",
}, },
}; };
} }
@ -103,7 +104,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
private void showMore() private void showMore()
{ {
var req = new GetUserScoresRequest(user.Id, type, visiblePages++ * 5); var req = new GetUserScoresRequest(user.Value.Id, type, visiblePages++ * 5);
showMoreLoading.Show(); showMoreLoading.Show();
showMoreButton.Hide(); showMoreButton.Hide();
@ -121,7 +122,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
missing.Hide(); missing.Hide();
foreach (OnlineScore score in scores) foreach (OnlineScore score in scores)
{ {
var drawableScore = CreateScore(score, scoreContainer.Count); var drawableScore = type == ScoreType.Recent ? (DrawableScore)new TotalScore(score) : new PPScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null);
drawableScore.RelativeSizeAxes = Axes.X; drawableScore.RelativeSizeAxes = Axes.X;
drawableScore.Height = 60; drawableScore.Height = 60;
scoreContainer.Add(drawableScore); scoreContainer.Add(drawableScore);
@ -131,27 +132,5 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Schedule(() => { api.Queue(req); }); Schedule(() => { api.Queue(req); });
} }
protected abstract DrawableScore CreateScore(OnlineScore score, int index);
public class PPScoreContainer : ScoreContainer
{
private readonly bool includeWeight;
public PPScoreContainer(ScoreType type, string header, string missing, bool includeWeight = false) : base(type, header, missing)
{
this.includeWeight = includeWeight;
}
protected override DrawableScore CreateScore(OnlineScore score, int index) => new DrawableScore.PPScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null);
}
public class TotalScoreContainer : ScoreContainer
{
public TotalScoreContainer(ScoreType type, string header, string missing) : base(type, header, missing)
{ }
protected override DrawableScore CreateScore(OnlineScore score, int index) => new DrawableScore.TotalScore(score);
}
} }
} }

View File

@ -20,24 +20,9 @@ namespace osu.Game.Overlays.Profile.Sections
{ {
Children = new Drawable[] Children = new Drawable[]
{ {
best = new ScoreContainer.PPScoreContainer(ScoreType.Best, "Best Performance", "No awesome performance records yet. :(", true), best = new ScoreContainer(ScoreType.Best, User, "Best Performance", true),
first = new ScoreContainer.PPScoreContainer(ScoreType.Firsts, "First Place Ranks", "No awesome performance records yet. :("), first = new ScoreContainer(ScoreType.Firsts, User, "First Place Ranks"),
}; };
} }
public override User User
{
get
{
return base.User;
}
set
{
base.User = value;
best.User = value;
first.User = value;
}
}
} }
} }

View File

@ -175,7 +175,7 @@ namespace osu.Game.Overlays
var sec = sections.FirstOrDefault(s => s.Identifier == id); var sec = sections.FirstOrDefault(s => s.Identifier == id);
if (sec != null) if (sec != null)
{ {
sec.User = user; sec.User.Value = user;
sectionsContainer.Add(sec); sectionsContainer.Add(sec);
tabs.AddItem(sec); tabs.AddItem(sec);