2022-11-02 03:46:32 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-11-02 20:00:45 +08:00
|
|
|
using System;
|
2022-11-02 03:46:32 +08:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-11-02 20:00:45 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Localisation;
|
2022-11-02 04:19:01 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2022-11-02 03:46:32 +08:00
|
|
|
using osu.Game.Configuration;
|
2022-11-02 20:00:45 +08:00
|
|
|
using osu.Game.Extensions;
|
2022-11-02 03:46:32 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-11-02 20:00:45 +08:00
|
|
|
using osu.Game.Localisation;
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2022-11-02 03:46:32 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning.Components
|
|
|
|
{
|
|
|
|
[UsedImplicitly]
|
2022-11-02 20:00:45 +08:00
|
|
|
public class BeatmapInfoDrawable : Container, ISkinnableDrawable, IHasTooltip
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
|
|
|
[SettingSource("Tracked Beatmap Info", "Which part of the BeatmapInformation should be tracked")]
|
|
|
|
public Bindable<BeatmapInfo> Type { get; } = new Bindable<BeatmapInfo>(BeatmapInfo.StarRating);
|
|
|
|
|
2022-11-02 20:00:45 +08:00
|
|
|
[SettingSource("Show Label", "Should a Label be shown, as to which status is currently Displayed?")]
|
|
|
|
public BindableBool ShowLabel { get; } = new BindableBool(true);
|
|
|
|
|
|
|
|
[SettingSource("Show Value first?", "Should the Value be shown first?")]
|
|
|
|
public BindableBool ValueBeforeLabel { get; } = new BindableBool();
|
|
|
|
|
|
|
|
[SettingSource("Label Prefix", "Add something to be shown before the label")]
|
|
|
|
public Bindable<string> LabelPrefix { get; set; } = new Bindable<string>("");
|
|
|
|
|
|
|
|
[SettingSource("Show Label Prefix", "Should the Label Prefix be included?")]
|
|
|
|
public BindableBool ShowLabelPrefix { get; } = new BindableBool();
|
|
|
|
|
|
|
|
[SettingSource("Label Suffix", "Add something to be shown after the label")]
|
|
|
|
public Bindable<string> LabelSuffix { get; set; } = new Bindable<string>(": ");
|
|
|
|
|
|
|
|
[SettingSource("Show Label Suffix", "Should the Label Suffix be included?")]
|
|
|
|
public BindableBool ShowLabelSuffix { get; } = new BindableBool(true);
|
|
|
|
|
|
|
|
[SettingSource("Value Prefix", "Add something to be shown before the Value")]
|
|
|
|
public Bindable<string> ValuePrefix { get; set; } = new Bindable<string>("");
|
|
|
|
|
|
|
|
[SettingSource("Show Value Prefix", "Should the Value Prefix be included?")]
|
|
|
|
public BindableBool ShowValuePrefix { get; } = new BindableBool();
|
|
|
|
|
|
|
|
[SettingSource("Value Suffix", "Add something to be shown after the Value")]
|
|
|
|
public Bindable<string> ValueSuffix { get; set; } = new Bindable<string>("");
|
|
|
|
|
|
|
|
[SettingSource("Show Value Suffix", "Should the Value Suffix be included?")]
|
|
|
|
public BindableBool ShowValueSuffix { get; } = new BindableBool();
|
|
|
|
|
2022-11-02 03:46:32 +08:00
|
|
|
[Resolved]
|
2022-11-02 20:00:45 +08:00
|
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
2022-11-02 03:46:32 +08:00
|
|
|
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
2022-11-02 20:00:45 +08:00
|
|
|
public LocalisableString TooltipText { get; set; }
|
|
|
|
private LocalisableString value;
|
|
|
|
private LocalisableString labelText;
|
|
|
|
|
2022-11-02 03:46:32 +08:00
|
|
|
public BeatmapInfoDrawable()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
text = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "BeatInfoDrawable",
|
2022-11-02 20:00:45 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-11-02 03:46:32 +08:00
|
|
|
Font = OsuFont.Default.With(size: 40)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
Type.BindValueChanged(update, true);
|
2022-11-02 20:00:45 +08:00
|
|
|
ShowLabel.BindValueChanged(ignored => updateLabel());
|
|
|
|
ValueBeforeLabel.BindValueChanged(ignored => updateLabel());
|
|
|
|
LabelPrefix.BindValueChanged(ignored => updateLabel());
|
|
|
|
ShowLabelPrefix.BindValueChanged(ignored => updateLabel());
|
|
|
|
LabelSuffix.BindValueChanged(ignored => updateLabel());
|
|
|
|
ShowLabelSuffix.BindValueChanged(ignored => updateLabel());
|
|
|
|
ValuePrefix.BindValueChanged(ignored => updateLabel());
|
|
|
|
ShowValuePrefix.BindValueChanged(ignored => updateLabel());
|
|
|
|
ValueSuffix.BindValueChanged(ignored => updateLabel());
|
|
|
|
ShowValueSuffix.BindValueChanged(ignored => updateLabel());
|
|
|
|
}
|
|
|
|
|
|
|
|
private LocalisableString getLabelText()
|
|
|
|
{
|
|
|
|
if (!ShowLabel.Value) return new LocalisableString("");
|
|
|
|
|
|
|
|
return LocalisableString.Format("{0}{1}{2}",
|
|
|
|
ShowLabelPrefix.Value ? LabelPrefix.Value : "",
|
|
|
|
labelText,
|
|
|
|
ShowLabelSuffix.Value ? LabelSuffix.Value : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
private LocalisableString getValueText()
|
|
|
|
{
|
|
|
|
return LocalisableString.Format("{0}{1}{2}",
|
|
|
|
ShowValuePrefix.Value ? ValuePrefix.Value : "",
|
|
|
|
value,
|
|
|
|
ShowValueSuffix.Value ? ValueSuffix.Value : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateLabel()
|
|
|
|
{
|
|
|
|
text.Text = LocalisableString.Format(
|
|
|
|
ValueBeforeLabel.Value ? "{1}{0}" : "{0}{1}",
|
|
|
|
getLabelText(),
|
|
|
|
getValueText()
|
|
|
|
);
|
|
|
|
Width = text.Width;
|
|
|
|
Height = text.Height;
|
2022-11-02 03:46:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void update(ValueChangedEvent<BeatmapInfo> type)
|
|
|
|
{
|
|
|
|
switch (type.NewValue)
|
|
|
|
{
|
|
|
|
case BeatmapInfo.CircleSize:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
double cs = bm.NewValue.BeatmapInfo.Difficulty.CircleSize;
|
|
|
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsCs;
|
|
|
|
value = cs.ToString("F2");
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.HPDrain:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
double hp = bm.NewValue.BeatmapInfo.Difficulty.DrainRate;
|
|
|
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsDrain;
|
|
|
|
value = hp.ToString("F2");
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.Accuracy:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
double od = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty;
|
|
|
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsAccuracy;
|
|
|
|
value = od.ToString("F2");
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.ApproachRate:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
double ar = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate;
|
|
|
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsAr;
|
|
|
|
value = ar.ToString("F2");
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.StarRating:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
double sr = bm.NewValue.BeatmapInfo.StarRating;
|
|
|
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsStars;
|
|
|
|
value = sr.ToString("F2");
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.Song:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
string title = bm.NewValue.BeatmapInfo.Metadata.Title;
|
|
|
|
//todo: no Song Title localisation?
|
|
|
|
labelText = TooltipText = "Song Title";
|
|
|
|
value = title;
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.Artist:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
string artist = bm.NewValue.BeatmapInfo.Metadata.Artist;
|
|
|
|
//todo: Localize Artist
|
|
|
|
labelText = "Artist";
|
|
|
|
TooltipText = BeatmapsetsStrings.ShowDetailsByArtist(artist);
|
|
|
|
value = artist;
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.Difficulty:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
string diff = bm.NewValue.BeatmapInfo.DifficultyName;
|
|
|
|
//todo: no Difficulty name localisation?
|
|
|
|
labelText = TooltipText = "Difficulty";
|
|
|
|
text.Current.Value = diff;
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.Mapper:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
string mapper = bm.NewValue.BeatmapInfo.Metadata.Author.Username;
|
|
|
|
//todo: is there a good alternative, to ShowDetailsMappedBy?
|
|
|
|
labelText = "Mapper";
|
|
|
|
TooltipText = BeatmapsetsStrings.ShowDetailsMappedBy(mapper);
|
|
|
|
value = mapper;
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.Length:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsTotalLength(TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration());
|
|
|
|
value = TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration();
|
|
|
|
updateLabel();
|
|
|
|
}, true);
|
|
|
|
break;
|
2022-11-02 03:46:32 +08:00
|
|
|
|
2022-11-02 20:00:45 +08:00
|
|
|
case BeatmapInfo.Status:
|
|
|
|
beatmap.BindValueChanged(bm =>
|
|
|
|
{
|
|
|
|
BeatmapOnlineStatus status = bm.NewValue.BeatmapInfo.Status;
|
|
|
|
//todo: no Localizasion for None Beatmap Online Status
|
|
|
|
//todo: no Localization for Status?
|
|
|
|
labelText = "Status";
|
|
|
|
|
|
|
|
switch (status)
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
case BeatmapOnlineStatus.Approved:
|
|
|
|
value = BeatmapsetsStrings.ShowStatusApproved;
|
|
|
|
//todo: is this correct?
|
|
|
|
TooltipText = BeatmapsetsStrings.ShowDetailsDateApproved(bm.NewValue.BeatmapSetInfo.DateRanked.ToString());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapOnlineStatus.Graveyard:
|
|
|
|
value = BeatmapsetsStrings.ShowStatusGraveyard;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapOnlineStatus.Loved:
|
|
|
|
value = BeatmapsetsStrings.ShowStatusLoved;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapOnlineStatus.None:
|
|
|
|
value = "None";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapOnlineStatus.Pending:
|
|
|
|
value = BeatmapsetsStrings.ShowStatusPending;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapOnlineStatus.Qualified:
|
|
|
|
value = BeatmapsetsStrings.ShowStatusQualified;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapOnlineStatus.Ranked:
|
|
|
|
value = BeatmapsetsStrings.ShowStatusRanked;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapOnlineStatus.LocallyModified:
|
|
|
|
value = SongSelectStrings.LocallyModified;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapOnlineStatus.WIP:
|
|
|
|
value = BeatmapsetsStrings.ShowStatusWip;
|
|
|
|
break;
|
2022-11-02 03:46:32 +08:00
|
|
|
}
|
|
|
|
|
2022-11-02 20:00:45 +08:00
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BeatmapInfo.BPM:
|
2022-11-02 04:19:01 +08:00
|
|
|
beatmap.BindValueChanged(bm =>
|
2022-11-02 03:46:32 +08:00
|
|
|
{
|
2022-11-02 20:00:45 +08:00
|
|
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsBpm;
|
|
|
|
value = bm.NewValue.BeatmapInfo.BPM.ToString("F2");
|
|
|
|
updateLabel();
|
2022-11-02 03:46:32 +08:00
|
|
|
}, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum BeatmapInfo
|
|
|
|
{
|
|
|
|
CircleSize,
|
|
|
|
HPDrain,
|
2022-11-02 03:54:52 +08:00
|
|
|
Accuracy,
|
2022-11-02 03:46:32 +08:00
|
|
|
ApproachRate,
|
|
|
|
StarRating,
|
|
|
|
Song,
|
|
|
|
Artist,
|
|
|
|
Difficulty,
|
|
|
|
Mapper,
|
|
|
|
Length,
|
2022-11-02 20:00:45 +08:00
|
|
|
Status,
|
2022-11-02 03:46:32 +08:00
|
|
|
BPM,
|
|
|
|
}
|
|
|
|
}
|