mirror of
https://github.com/ppy/osu
synced 2024-12-15 03:16:17 +00:00
Add Localisation
Also add Labels for what is displayed, and prefix/suffix for Labels Add a Prefix and Suffix for Values
This commit is contained in:
parent
975eed964e
commit
ed7e3a29e2
@ -1,45 +1,80 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
#nullable disable
|
using System;
|
||||||
|
|
||||||
using System.Text;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Extensions;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Localisation;
|
||||||
|
using osu.Game.Resources.Localisation.Web;
|
||||||
|
|
||||||
namespace osu.Game.Skinning.Components
|
namespace osu.Game.Skinning.Components
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class BeatmapInfoDrawable : Container, ISkinnableDrawable
|
public class BeatmapInfoDrawable : Container, ISkinnableDrawable, IHasTooltip
|
||||||
{
|
{
|
||||||
public bool UsesFixedAnchor { get; set; }
|
public bool UsesFixedAnchor { get; set; }
|
||||||
|
|
||||||
[SettingSource("Tracked Beatmap Info", "Which part of the BeatmapInformation should be tracked")]
|
[SettingSource("Tracked Beatmap Info", "Which part of the BeatmapInformation should be tracked")]
|
||||||
public Bindable<BeatmapInfo> Type { get; } = new Bindable<BeatmapInfo>(BeatmapInfo.StarRating);
|
public Bindable<BeatmapInfo> Type { get; } = new Bindable<BeatmapInfo>(BeatmapInfo.StarRating);
|
||||||
|
|
||||||
|
[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();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<WorkingBeatmap> beatmap { get; set; }
|
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
||||||
|
|
||||||
private readonly OsuSpriteText text;
|
private readonly OsuSpriteText text;
|
||||||
|
|
||||||
|
public LocalisableString TooltipText { get; set; }
|
||||||
|
private LocalisableString value;
|
||||||
|
private LocalisableString labelText;
|
||||||
|
|
||||||
public BeatmapInfoDrawable()
|
public BeatmapInfoDrawable()
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
text = new OsuSpriteText
|
text = new OsuSpriteText
|
||||||
{
|
{
|
||||||
Text = "BeatInfoDrawable",
|
Text = "BeatInfoDrawable",
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.CentreLeft,
|
||||||
Font = OsuFont.Default.With(size: 40)
|
Font = OsuFont.Default.With(size: 40)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -49,6 +84,45 @@ namespace osu.Game.Skinning.Components
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
Type.BindValueChanged(update, true);
|
Type.BindValueChanged(update, true);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(ValueChangedEvent<BeatmapInfo> type)
|
private void update(ValueChangedEvent<BeatmapInfo> type)
|
||||||
@ -58,105 +132,167 @@ namespace osu.Game.Skinning.Components
|
|||||||
case BeatmapInfo.CircleSize:
|
case BeatmapInfo.CircleSize:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.CircleSize.ToString("F2");
|
double cs = bm.NewValue.BeatmapInfo.Difficulty.CircleSize;
|
||||||
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsCs;
|
||||||
|
value = cs.ToString("F2");
|
||||||
|
updateLabel();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.HPDrain:
|
case BeatmapInfo.HPDrain:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.DrainRate.ToString("F2");
|
double hp = bm.NewValue.BeatmapInfo.Difficulty.DrainRate;
|
||||||
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsDrain;
|
||||||
|
value = hp.ToString("F2");
|
||||||
|
updateLabel();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.Accuracy:
|
case BeatmapInfo.Accuracy:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty.ToString("F2");
|
double od = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty;
|
||||||
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsAccuracy;
|
||||||
|
value = od.ToString("F2");
|
||||||
|
updateLabel();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.ApproachRate:
|
case BeatmapInfo.ApproachRate:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate.ToString("F2");
|
double ar = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate;
|
||||||
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsAr;
|
||||||
|
value = ar.ToString("F2");
|
||||||
|
updateLabel();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.StarRating:
|
case BeatmapInfo.StarRating:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.StarRating.ToString("F2");
|
double sr = bm.NewValue.BeatmapInfo.StarRating;
|
||||||
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsStars;
|
||||||
|
value = sr.ToString("F2");
|
||||||
|
updateLabel();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.Song:
|
case BeatmapInfo.Song:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Title;
|
string title = bm.NewValue.BeatmapInfo.Metadata.Title;
|
||||||
|
//todo: no Song Title localisation?
|
||||||
|
labelText = TooltipText = "Song Title";
|
||||||
|
value = title;
|
||||||
|
updateLabel();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.Artist:
|
case BeatmapInfo.Artist:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Artist;
|
string artist = bm.NewValue.BeatmapInfo.Metadata.Artist;
|
||||||
|
//todo: Localize Artist
|
||||||
|
labelText = "Artist";
|
||||||
|
TooltipText = BeatmapsetsStrings.ShowDetailsByArtist(artist);
|
||||||
|
value = artist;
|
||||||
|
updateLabel();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.Difficulty:
|
case BeatmapInfo.Difficulty:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.DifficultyName;
|
string diff = bm.NewValue.BeatmapInfo.DifficultyName;
|
||||||
|
//todo: no Difficulty name localisation?
|
||||||
|
labelText = TooltipText = "Difficulty";
|
||||||
|
text.Current.Value = diff;
|
||||||
|
updateLabel();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.Mapper:
|
case BeatmapInfo.Mapper:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.Metadata.Author.Username;
|
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();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.Length:
|
case BeatmapInfo.Length:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
const long ms_to_s = 1000;
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsTotalLength(TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration());
|
||||||
double length = bm.NewValue.BeatmapInfo.Length;
|
value = TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration();
|
||||||
double rawS = length / ms_to_s;
|
updateLabel();
|
||||||
double rawM = rawS / 60;
|
}, true);
|
||||||
double rawH = rawM / 60;
|
break;
|
||||||
double rawD = rawH / 24;
|
|
||||||
|
|
||||||
long s = (long)rawS % 60;
|
case BeatmapInfo.Status:
|
||||||
long m = (long)rawM % 60;
|
beatmap.BindValueChanged(bm =>
|
||||||
long h = (long)rawH % 24;
|
{
|
||||||
long d = (long)rawD;
|
BeatmapOnlineStatus status = bm.NewValue.BeatmapInfo.Status;
|
||||||
StringBuilder builder = new StringBuilder();
|
//todo: no Localizasion for None Beatmap Online Status
|
||||||
|
//todo: no Localization for Status?
|
||||||
|
labelText = "Status";
|
||||||
|
|
||||||
if (d != 0)
|
switch (status)
|
||||||
{
|
{
|
||||||
builder.Append(d.ToString("D2"));
|
case BeatmapOnlineStatus.Approved:
|
||||||
builder.Append(":");
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h != 0 || d != 0)
|
updateLabel();
|
||||||
{
|
|
||||||
builder.Append(h.ToString("D2"));
|
|
||||||
builder.Append(":");
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.Append(m.ToString("D2"));
|
|
||||||
builder.Append(":");
|
|
||||||
builder.Append(s.ToString("D2"));
|
|
||||||
text.Current.Value = builder.ToString();
|
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BeatmapInfo.BPM:
|
case BeatmapInfo.BPM:
|
||||||
beatmap.BindValueChanged(bm =>
|
beatmap.BindValueChanged(bm =>
|
||||||
{
|
{
|
||||||
text.Current.Value = bm.NewValue.BeatmapInfo.BPM.ToString("F2");
|
labelText = TooltipText = BeatmapsetsStrings.ShowStatsBpm;
|
||||||
|
value = bm.NewValue.BeatmapInfo.BPM.ToString("F2");
|
||||||
|
updateLabel();
|
||||||
}, true);
|
}, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -175,6 +311,7 @@ namespace osu.Game.Skinning.Components
|
|||||||
Difficulty,
|
Difficulty,
|
||||||
Mapper,
|
Mapper,
|
||||||
Length,
|
Length,
|
||||||
|
Status,
|
||||||
BPM,
|
BPM,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user