1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +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.Users;
using OpenTK.Graphics;
using osu.Framework.Configuration;
namespace osu.Game.Overlays.Profile
{
@ -22,13 +23,7 @@ namespace osu.Game.Overlays.Profile
protected override Container<Drawable> Content => content;
public virtual User User
{
get { return user; }
set { user = value; }
}
private User user;
public readonly Bindable<User> User = new Bindable<User>();
protected ProfileSection()
{

View File

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

View File

@ -20,14 +20,14 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
{
public class DrawableScore : Container
{
private readonly FillFlowContainer<OsuSpriteText> stats;
protected readonly FillFlowContainer<OsuSpriteText> Stats;
private readonly FillFlowContainer metadata;
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[]
{
@ -37,7 +37,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Width = 60,
FillMode = FillMode.Fit,
},
stats = new FillFlowContainer<OsuSpriteText>
Stats = new FillFlowContainer<OsuSpriteText>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
@ -75,9 +75,9 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
[BackgroundDependencyLoader]
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,
Origin = Anchor.TopRight,
Colour = colour.GrayA,
@ -91,7 +91,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
AutoSizeAxes = Axes.Both,
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
{
@ -101,15 +101,15 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
new OsuSpriteText
{
Current = locale.GetUnicodePreference(
$"{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.TitleUnicode ?? Score.Beatmap.Metadata.Title} [{Score.Beatmap.Version}] ",
$"{Score.Beatmap.Metadata.Title ?? Score.Beatmap.Metadata.TitleUnicode} [{Score.Beatmap.Version}] "
),
TextSize = 15,
Font = "Exo2.0-SemiBoldItalic",
},
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,
Padding = new MarginPadding { Top = 3 },
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)
{
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);
}
}
}
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;
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",
});
}
}
this.weight = weight;
}
public class TotalScore : DrawableScore
[BackgroundDependencyLoader]
private new void load(OsuColour colour)
{
public TotalScore(Score score) : base(score)
{ }
[BackgroundDependencyLoader]
private new void load()
double pp = Score.PP ?? 0;
Stats.Add(new OsuSpriteText
{
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,
Origin = Anchor.TopRight,
TextSize = 18,
Font = "Exo2.0-BoldItalic",
Colour = colour.GrayA,
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 osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
@ -17,36 +18,36 @@ using System.Linq;
namespace osu.Game.Overlays.Profile.Sections.Ranks
{
public abstract class ScoreContainer : FillFlowContainer
public class ScoreContainer : FillFlowContainer
{
private readonly FillFlowContainer<DrawableScore> scoreContainer;
private readonly OsuSpriteText missing;
private readonly OsuHoverContainer showMoreButton;
private readonly LoadingAnimation showMoreLoading;
private readonly bool includeWeight;
private readonly ScoreType type;
private int visiblePages;
private User user;
private readonly Bindable<User> user;
private RulesetStore rulesets;
private APIAccess api;
public User User
private void setUser(User newUser)
{
set
{
user = value;
visiblePages = 0;
scoreContainer.Clear();
showMoreButton.Hide();
missing.Show();
showMore();
}
visiblePages = 0;
scoreContainer.Clear();
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.includeWeight = includeWeight;
this.user = user;
user.ValueChanged += setUser;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
@ -89,7 +90,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
missing = new OsuSpriteText
{
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()
{
var req = new GetUserScoresRequest(user.Id, type, visiblePages++ * 5);
var req = new GetUserScoresRequest(user.Value.Id, type, visiblePages++ * 5);
showMoreLoading.Show();
showMoreButton.Hide();
@ -121,7 +122,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
missing.Hide();
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.Height = 60;
scoreContainer.Add(drawableScore);
@ -131,27 +132,5 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
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[]
{
best = new ScoreContainer.PPScoreContainer(ScoreType.Best, "Best Performance", "No awesome performance records yet. :(", true),
first = new ScoreContainer.PPScoreContainer(ScoreType.Firsts, "First Place Ranks", "No awesome performance records yet. :("),
best = new ScoreContainer(ScoreType.Best, User, "Best Performance", true),
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);
if (sec != null)
{
sec.User = user;
sec.User.Value = user;
sectionsContainer.Add(sec);
tabs.AddItem(sec);