1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:07:25 +08:00

Add ToRomanisableString()

This commit is contained in:
PercyDan54 2021-04-18 09:52:25 +08:00
parent 512cec3458
commit cfaaf2e83e
No known key found for this signature in database
GPG Key ID: 6AEA7C525131BAF3
3 changed files with 17 additions and 13 deletions

View File

@ -7,6 +7,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Newtonsoft.Json;
using osu.Framework.Localisation;
using osu.Framework.Testing;
using osu.Game.Database;
using osu.Game.IO.Serialization;
@ -127,6 +128,8 @@ namespace osu.Game.Beatmaps
// Metadata
public string Version { get; set; }
public string VersionString => string.IsNullOrEmpty(Version) ? string.Empty : $"[{Version}]";
[JsonProperty("difficulty_rating")]
public double StarDifficulty { get; set; }
@ -143,11 +146,12 @@ namespace osu.Game.Beatmaps
Version
}.Concat(Metadata?.SearchableTerms ?? Enumerable.Empty<string>()).Where(s => !string.IsNullOrEmpty(s)).ToArray();
public override string ToString()
{
string version = string.IsNullOrEmpty(Version) ? string.Empty : $"[{Version}]";
public override string ToString() => $"{Metadata ?? BeatmapSet?.Metadata} {VersionString}".Trim();
return $"{Metadata ?? BeatmapSet?.Metadata} {version}".Trim();
public RomanisableString ToRomanisableString()
{
var metadata = (Metadata ?? BeatmapSet?.Metadata).ToRomanisableString() ?? new RomanisableString(null, null);
return new RomanisableString($"{metadata.GetPreferred(true)} {VersionString}".Trim(), $"{metadata.GetPreferred(false)} {VersionString}".Trim());
}
public bool Equals(BeatmapInfo other)

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Newtonsoft.Json;
using osu.Framework.Localisation;
using osu.Framework.Testing;
using osu.Game.Database;
using osu.Game.Users;
@ -71,6 +72,12 @@ namespace osu.Game.Beatmaps
return $"{Artist} - {Title} {author}".Trim();
}
public RomanisableString ToRomanisableString()
{
string author = Author == null ? string.Empty : $"({Author})";
return new RomanisableString($"{ArtistUnicode} - {TitleUnicode} {author}".Trim(), $"{Artist} - {Title} {author}".Trim());
}
[JsonIgnore]
public string[] SearchableTerms => new[]
{

View File

@ -107,18 +107,11 @@ namespace osu.Game.Screens.OnlinePlay
private void refresh()
{
var beatmapMetadata = Item.Beatmap.Value.Metadata ?? Item.Beatmap.Value.BeatmapSet?.Metadata;
difficultyIconContainer.Child = new DifficultyIcon(beatmap.Value, ruleset.Value, requiredMods) { Size = new Vector2(32) };
beatmapText.Clear();
var text = new List<SpriteText>
{
new OsuSpriteText { Text = new RomanisableString(beatmapMetadata.ArtistUnicode, beatmapMetadata.Artist) },
new OsuSpriteText { Text = " - " },
new OsuSpriteText { Text = new RomanisableString(beatmapMetadata.TitleUnicode, beatmapMetadata.Title) },
new OsuSpriteText { Text = $" ({beatmapMetadata.Author}) [{Item.Beatmap.Value.Version}]" }
};
beatmapText.AddLink(text, LinkAction.OpenBeatmap, Item.Beatmap.Value.OnlineBeatmapID.ToString());
beatmapText.AddLink(new List<SpriteText>{ new OsuSpriteText { Text = Item.Beatmap.Value.ToRomanisableString() } }
, LinkAction.OpenBeatmap, Item.Beatmap.Value.OnlineBeatmapID.ToString());
authorText.Clear();