1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:52:56 +08:00

Merge pull request #15247 from peppy/beatmap-metadata-container-interface

Refactor `BeatmapMetadataContainer` and usages to use interface types
This commit is contained in:
Dan Balasescu 2021-10-22 22:42:23 +09:00 committed by GitHub
commit 9bb0d32fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 61 deletions

View File

@ -2,8 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using Newtonsoft.Json;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
namespace osu.Game.Online.API.Requests.Responses
{
@ -16,17 +14,19 @@ namespace osu.Game.Online.API.Requests.Responses
public int PlayCount { get; set; }
[JsonProperty("beatmap")]
private BeatmapInfo beatmapInfo { get; set; }
private APIBeatmap beatmap { get; set; }
[JsonProperty]
private APIBeatmapSet beatmapSet { get; set; }
public BeatmapInfo GetBeatmapInfo(RulesetStore rulesets)
public APIBeatmap BeatmapInfo
{
BeatmapSetInfo setInfo = beatmapSet.ToBeatmapSet(rulesets);
beatmapInfo.BeatmapSet = setInfo;
beatmapInfo.Metadata = setInfo.Metadata;
return beatmapInfo;
get
{
// old osu-web code doesn't nest set.
beatmap.BeatmapSet = BeatmapSet;
return beatmap;
}
}
[JsonProperty("beatmapset")]
public APIBeatmapSet BeatmapSet { get; set; }
}
}

View File

@ -15,9 +15,9 @@ namespace osu.Game.Overlays.Profile.Sections
/// </summary>
public abstract class BeatmapMetadataContainer : OsuHoverContainer
{
private readonly BeatmapInfo beatmapInfo;
private readonly IBeatmapInfo beatmapInfo;
protected BeatmapMetadataContainer(BeatmapInfo beatmapInfo)
protected BeatmapMetadataContainer(IBeatmapInfo beatmapInfo)
: base(HoverSampleSet.Submit)
{
this.beatmapInfo = beatmapInfo;
@ -30,10 +30,7 @@ namespace osu.Game.Overlays.Profile.Sections
{
Action = () =>
{
if (beatmapInfo.OnlineBeatmapID != null)
beatmapSetOverlay?.FetchAndShowBeatmap(beatmapInfo.OnlineBeatmapID.Value);
else if (beatmapInfo.BeatmapSet?.OnlineBeatmapSetID != null)
beatmapSetOverlay?.FetchAndShowBeatmapSet(beatmapInfo.BeatmapSet.OnlineBeatmapSetID.Value);
beatmapSetOverlay?.FetchAndShowBeatmap(beatmapInfo.OnlineID);
};
Child = new FillFlowContainer
@ -43,6 +40,6 @@ namespace osu.Game.Overlays.Profile.Sections
};
}
protected abstract Drawable[] CreateText(BeatmapInfo beatmapInfo);
protected abstract Drawable[] CreateText(IBeatmapInfo beatmapInfo);
}
}

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -13,6 +14,7 @@ using osu.Game.Graphics.Sprites;
using osuTK;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.Profile.Sections.Historical
@ -22,13 +24,11 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
private const int cover_width = 100;
private const int corner_radius = 6;
private readonly BeatmapInfo beatmapInfo;
private readonly int playCount;
private readonly APIUserMostPlayedBeatmap mostPlayed;
public DrawableMostPlayedBeatmap(BeatmapInfo beatmapInfo, int playCount)
public DrawableMostPlayedBeatmap(APIUserMostPlayedBeatmap mostPlayed)
{
this.beatmapInfo = beatmapInfo;
this.playCount = playCount;
this.mostPlayed = mostPlayed;
RelativeSizeAxes = Axes.X;
Height = 50;
@ -46,7 +46,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
{
RelativeSizeAxes = Axes.Y,
Width = cover_width,
BeatmapSet = beatmapInfo.BeatmapSet,
BeatmapSet = mostPlayed.BeatmapSet,
},
new Container
{
@ -77,7 +77,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new MostPlayedBeatmapMetadataContainer(beatmapInfo),
new MostPlayedBeatmapMetadataContainer(mostPlayed.BeatmapInfo),
new LinkFlowContainer(t =>
{
t.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular);
@ -89,11 +89,11 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
}.With(d =>
{
d.AddText("mapped by ");
d.AddUserLink(beatmapInfo.Metadata.Author);
d.AddUserLink(mostPlayed.BeatmapSet.Author);
}),
}
},
new PlayCountText(playCount)
new PlayCountText(mostPlayed.PlayCount)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight
@ -120,26 +120,41 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
private class MostPlayedBeatmapMetadataContainer : BeatmapMetadataContainer
{
public MostPlayedBeatmapMetadataContainer(BeatmapInfo beatmapInfo)
public MostPlayedBeatmapMetadataContainer(IBeatmapInfo beatmapInfo)
: base(beatmapInfo)
{
}
protected override Drawable[] CreateText(BeatmapInfo beatmapInfo) => new Drawable[]
protected override Drawable[] CreateText(IBeatmapInfo beatmapInfo)
{
new OsuSpriteText
var metadata = beatmapInfo.Metadata;
Debug.Assert(metadata != null);
return new Drawable[]
{
Text = new RomanisableString(
$"{beatmapInfo.Metadata.TitleUnicode ?? beatmapInfo.Metadata.Title} [{beatmapInfo.Version}] ",
$"{beatmapInfo.Metadata.Title ?? beatmapInfo.Metadata.TitleUnicode} [{beatmapInfo.Version}] "),
Font = OsuFont.GetFont(weight: FontWeight.Bold)
},
new OsuSpriteText
{
Text = "by " + new RomanisableString(beatmapInfo.Metadata.ArtistUnicode, beatmapInfo.Metadata.Artist),
Font = OsuFont.GetFont(weight: FontWeight.Regular)
},
};
new OsuSpriteText
{
Text = new RomanisableString(metadata.TitleUnicode, metadata.Title),
Font = OsuFont.GetFont(weight: FontWeight.Bold)
},
new OsuSpriteText
{
Text = $" [{beatmapInfo.DifficultyName}]",
Font = OsuFont.GetFont(weight: FontWeight.Bold)
},
new OsuSpriteText
{
Text = " by ",
Font = OsuFont.GetFont(weight: FontWeight.Regular)
},
new OsuSpriteText
{
Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist),
Font = OsuFont.GetFont(weight: FontWeight.Regular)
},
};
}
}
private class PlayCountText : CompositeDrawable, IHasTooltip

View File

@ -33,7 +33,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
protected override APIRequest<List<APIUserMostPlayedBeatmap>> CreateRequest() =>
new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
protected override Drawable CreateDrawableItem(APIUserMostPlayedBeatmap model) =>
new DrawableMostPlayedBeatmap(model.GetBeatmapInfo(Rulesets), model.PlayCount);
protected override Drawable CreateDrawableItem(APIUserMostPlayedBeatmap mostPlayed) =>
new DrawableMostPlayedBeatmap(mostPlayed);
}
}

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
@ -245,30 +246,42 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
private class ScoreBeatmapMetadataContainer : BeatmapMetadataContainer
{
public ScoreBeatmapMetadataContainer(BeatmapInfo beatmapInfo)
public ScoreBeatmapMetadataContainer(IBeatmapInfo beatmapInfo)
: base(beatmapInfo)
{
}
protected override Drawable[] CreateText(BeatmapInfo beatmapInfo) => new Drawable[]
protected override Drawable[] CreateText(IBeatmapInfo beatmapInfo)
{
new OsuSpriteText
var metadata = beatmapInfo.Metadata;
Debug.Assert(metadata != null);
return new Drawable[]
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = new RomanisableString(
$"{beatmapInfo.Metadata.TitleUnicode ?? beatmapInfo.Metadata.Title} ",
$"{beatmapInfo.Metadata.Title ?? beatmapInfo.Metadata.TitleUnicode} "),
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold, italics: true)
},
new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = "by " + new RomanisableString(beatmapInfo.Metadata.ArtistUnicode, beatmapInfo.Metadata.Artist),
Font = OsuFont.GetFont(size: 12, italics: true)
},
};
new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = new RomanisableString(metadata.TitleUnicode, metadata.Title),
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold, italics: true)
},
new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = " by ",
Font = OsuFont.GetFont(size: 12, italics: true)
},
new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist),
Font = OsuFont.GetFont(size: 12, italics: true)
},
};
}
}
}
}