mirror of
https://github.com/ppy/osu.git
synced 2025-03-04 06:12:57 +08:00
Refactor BeatmapMetadataContainer
and usages to use interface types
This commit is contained in:
parent
28d8820976
commit
c701579c69
@ -2,8 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Rulesets;
|
|
||||||
|
|
||||||
namespace osu.Game.Online.API.Requests.Responses
|
namespace osu.Game.Online.API.Requests.Responses
|
||||||
{
|
{
|
||||||
@ -16,17 +14,19 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
public int PlayCount { get; set; }
|
public int PlayCount { get; set; }
|
||||||
|
|
||||||
[JsonProperty("beatmap")]
|
[JsonProperty("beatmap")]
|
||||||
private BeatmapInfo beatmapInfo { get; set; }
|
private APIBeatmap beatmap { get; set; }
|
||||||
|
|
||||||
[JsonProperty]
|
public APIBeatmap BeatmapInfo
|
||||||
private APIBeatmapSet beatmapSet { get; set; }
|
|
||||||
|
|
||||||
public BeatmapInfo GetBeatmapInfo(RulesetStore rulesets)
|
|
||||||
{
|
{
|
||||||
BeatmapSetInfo setInfo = beatmapSet.ToBeatmapSet(rulesets);
|
get
|
||||||
beatmapInfo.BeatmapSet = setInfo;
|
{
|
||||||
beatmapInfo.Metadata = setInfo.Metadata;
|
// old osu-web code doesn't nest set.
|
||||||
return beatmapInfo;
|
beatmap.BeatmapSet = BeatmapSet;
|
||||||
|
return beatmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonProperty("beatmapset")]
|
||||||
|
public APIBeatmapSet BeatmapSet { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class BeatmapMetadataContainer : OsuHoverContainer
|
public abstract class BeatmapMetadataContainer : OsuHoverContainer
|
||||||
{
|
{
|
||||||
private readonly BeatmapInfo beatmapInfo;
|
private readonly IBeatmapInfo beatmapInfo;
|
||||||
|
|
||||||
protected BeatmapMetadataContainer(BeatmapInfo beatmapInfo)
|
protected BeatmapMetadataContainer(IBeatmapInfo beatmapInfo)
|
||||||
: base(HoverSampleSet.Submit)
|
: base(HoverSampleSet.Submit)
|
||||||
{
|
{
|
||||||
this.beatmapInfo = beatmapInfo;
|
this.beatmapInfo = beatmapInfo;
|
||||||
@ -30,10 +30,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
{
|
{
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
if (beatmapInfo.OnlineBeatmapID != null)
|
beatmapSetOverlay?.FetchAndShowBeatmap(beatmapInfo.OnlineID);
|
||||||
beatmapSetOverlay?.FetchAndShowBeatmap(beatmapInfo.OnlineBeatmapID.Value);
|
|
||||||
else if (beatmapInfo.BeatmapSet?.OnlineBeatmapSetID != null)
|
|
||||||
beatmapSetOverlay?.FetchAndShowBeatmapSet(beatmapInfo.BeatmapSet.OnlineBeatmapSetID.Value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Child = new FillFlowContainer
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -13,6 +14,7 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Resources.Localisation.Web;
|
using osu.Game.Resources.Localisation.Web;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile.Sections.Historical
|
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 cover_width = 100;
|
||||||
private const int corner_radius = 6;
|
private const int corner_radius = 6;
|
||||||
|
|
||||||
private readonly BeatmapInfo beatmapInfo;
|
private readonly APIUserMostPlayedBeatmap mostPlayed;
|
||||||
private readonly int playCount;
|
|
||||||
|
|
||||||
public DrawableMostPlayedBeatmap(BeatmapInfo beatmapInfo, int playCount)
|
public DrawableMostPlayedBeatmap(APIUserMostPlayedBeatmap mostPlayed)
|
||||||
{
|
{
|
||||||
this.beatmapInfo = beatmapInfo;
|
this.mostPlayed = mostPlayed;
|
||||||
this.playCount = playCount;
|
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
Height = 50;
|
Height = 50;
|
||||||
@ -46,7 +46,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Width = cover_width,
|
Width = cover_width,
|
||||||
BeatmapSet = beatmapInfo.BeatmapSet,
|
BeatmapSet = mostPlayed.BeatmapSet,
|
||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
@ -77,7 +77,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
|
|||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new MostPlayedBeatmapMetadataContainer(beatmapInfo),
|
new MostPlayedBeatmapMetadataContainer(mostPlayed.BeatmapInfo),
|
||||||
new LinkFlowContainer(t =>
|
new LinkFlowContainer(t =>
|
||||||
{
|
{
|
||||||
t.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular);
|
t.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular);
|
||||||
@ -89,11 +89,11 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
|
|||||||
}.With(d =>
|
}.With(d =>
|
||||||
{
|
{
|
||||||
d.AddText("mapped by ");
|
d.AddText("mapped by ");
|
||||||
d.AddUserLink(beatmapInfo.Metadata.Author);
|
d.AddUserLink(mostPlayed.BeatmapSet.Author);
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new PlayCountText(playCount)
|
new PlayCountText(mostPlayed.PlayCount)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreRight,
|
Anchor = Anchor.CentreRight,
|
||||||
Origin = Anchor.CentreRight
|
Origin = Anchor.CentreRight
|
||||||
@ -120,27 +120,42 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
|
|||||||
|
|
||||||
private class MostPlayedBeatmapMetadataContainer : BeatmapMetadataContainer
|
private class MostPlayedBeatmapMetadataContainer : BeatmapMetadataContainer
|
||||||
{
|
{
|
||||||
public MostPlayedBeatmapMetadataContainer(BeatmapInfo beatmapInfo)
|
public MostPlayedBeatmapMetadataContainer(IBeatmapInfo beatmapInfo)
|
||||||
: base(beatmapInfo)
|
: base(beatmapInfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable[] CreateText(BeatmapInfo beatmapInfo) => new Drawable[]
|
protected override Drawable[] CreateText(IBeatmapInfo beatmapInfo)
|
||||||
|
{
|
||||||
|
var metadata = beatmapInfo.Metadata;
|
||||||
|
|
||||||
|
Debug.Assert(metadata != null);
|
||||||
|
|
||||||
|
return new Drawable[]
|
||||||
{
|
{
|
||||||
new OsuSpriteText
|
new OsuSpriteText
|
||||||
{
|
{
|
||||||
Text = new RomanisableString(
|
Text = new RomanisableString(metadata.TitleUnicode, metadata.Title),
|
||||||
$"{beatmapInfo.Metadata.TitleUnicode ?? beatmapInfo.Metadata.Title} [{beatmapInfo.Version}] ",
|
|
||||||
$"{beatmapInfo.Metadata.Title ?? beatmapInfo.Metadata.TitleUnicode} [{beatmapInfo.Version}] "),
|
|
||||||
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
||||||
},
|
},
|
||||||
new OsuSpriteText
|
new OsuSpriteText
|
||||||
{
|
{
|
||||||
Text = "by " + new RomanisableString(beatmapInfo.Metadata.ArtistUnicode, beatmapInfo.Metadata.Artist),
|
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)
|
Font = OsuFont.GetFont(weight: FontWeight.Regular)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class PlayCountText : CompositeDrawable, IHasTooltip
|
private class PlayCountText : CompositeDrawable, IHasTooltip
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
|
|||||||
protected override APIRequest<List<APIUserMostPlayedBeatmap>> CreateRequest() =>
|
protected override APIRequest<List<APIUserMostPlayedBeatmap>> CreateRequest() =>
|
||||||
new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
|
new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
|
||||||
|
|
||||||
protected override Drawable CreateDrawableItem(APIUserMostPlayedBeatmap model) =>
|
protected override Drawable CreateDrawableItem(APIUserMostPlayedBeatmap mostPlayed) =>
|
||||||
new DrawableMostPlayedBeatmap(model.GetBeatmapInfo(Rulesets), model.PlayCount);
|
new DrawableMostPlayedBeatmap(mostPlayed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -245,30 +246,42 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
|||||||
|
|
||||||
private class ScoreBeatmapMetadataContainer : BeatmapMetadataContainer
|
private class ScoreBeatmapMetadataContainer : BeatmapMetadataContainer
|
||||||
{
|
{
|
||||||
public ScoreBeatmapMetadataContainer(BeatmapInfo beatmapInfo)
|
public ScoreBeatmapMetadataContainer(IBeatmapInfo beatmapInfo)
|
||||||
: base(beatmapInfo)
|
: base(beatmapInfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable[] CreateText(BeatmapInfo beatmapInfo) => new Drawable[]
|
protected override Drawable[] CreateText(IBeatmapInfo beatmapInfo)
|
||||||
|
{
|
||||||
|
var metadata = beatmapInfo.Metadata;
|
||||||
|
|
||||||
|
Debug.Assert(metadata != null);
|
||||||
|
|
||||||
|
return new Drawable[]
|
||||||
{
|
{
|
||||||
new OsuSpriteText
|
new OsuSpriteText
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
Text = new RomanisableString(
|
Text = new RomanisableString(metadata.TitleUnicode, metadata.Title),
|
||||||
$"{beatmapInfo.Metadata.TitleUnicode ?? beatmapInfo.Metadata.Title} ",
|
|
||||||
$"{beatmapInfo.Metadata.Title ?? beatmapInfo.Metadata.TitleUnicode} "),
|
|
||||||
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold, italics: true)
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold, italics: true)
|
||||||
},
|
},
|
||||||
new OsuSpriteText
|
new OsuSpriteText
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
Text = "by " + new RomanisableString(beatmapInfo.Metadata.ArtistUnicode, beatmapInfo.Metadata.Artist),
|
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)
|
Font = OsuFont.GetFont(size: 12, italics: true)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user