From 10f5b927f44c10a4a8cc3db465174bf94a3975a1 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 6 Dec 2020 13:43:05 +0900 Subject: [PATCH] Use badge if in small size. --- .../Components/Badges/LanguageInfoBadge.cs | 32 ++++++++++++++ .../Lyrics/Components/Badges/TimeInfoBadge.cs | 44 ------------------- .../Edit/Lyrics/DrawableLyricEditListItem.cs | 12 ++++- osu.Game.Rulesets.Karaoke/Objects/Lyric.cs | 12 ++++- 4 files changed, 53 insertions(+), 47 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs delete mode 100644 osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/TimeInfoBadge.cs diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs new file mode 100644 index 000000000..1cbb890ac --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs @@ -0,0 +1,32 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Game.Graphics; +using osu.Game.Rulesets.Karaoke.Objects; + +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges +{ + public class LanguageInfoBadge : Badge + { + public LanguageInfoBadge(Lyric lyric) + : base(lyric) + { + lyric.LanguageBindable.BindValueChanged(value => + { + var language = value.NewValue; + + if (language == null) + BadgeText = "None"; + else + BadgeText = language.DisplayName; + }, true); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BadgeColour = colours.BlueDarker; + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/TimeInfoBadge.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/TimeInfoBadge.cs deleted file mode 100644 index 7446cee34..000000000 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/TimeInfoBadge.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using osu.Framework.Allocation; -using osu.Framework.Input.Events; -using osu.Framework.Timing; -using osu.Game.Extensions; -using osu.Game.Graphics; -using osu.Game.Rulesets.Karaoke.Objects; - -namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges -{ - public class TimeInfoBadge : Badge - { - [Resolved] - private IAdjustableClock adjustableClock { get; set; } - - public TimeInfoBadge(Lyric lyric) - : base(lyric) - { - lyric.StartTimeBindable.BindValueChanged(value => { changeTime(); }, true); - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - BadgeColour = colours.Gray7; - } - - protected override bool OnClick(ClickEvent e) - { - adjustableClock.Seek(Lyric.StartTime); - return base.OnClick(e); - } - - private void changeTime() - { - BadgeText = $"{getTime(Lyric.StartTime)} - {getTime(Lyric.EndTime)}"; - - static string getTime(double time) => time.ToEditorFormattedString(); - } - } -} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs index 7c51d16ae..055f88b12 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs @@ -9,6 +9,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Badges; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Components.Infos; using osu.Game.Rulesets.Karaoke.Objects; using osuTK; @@ -76,7 +77,9 @@ protected override Drawable CreateContent() { new Container { + // todo : cannot use relative size to both because it will cause size cannot roll-back if make lyric smaller. RelativeSizeAxes = Axes.X, + Height = min_height, Children = new Drawable[] { headerBackground = new Box @@ -93,12 +96,19 @@ protected override Drawable CreateContent() Anchor = Anchor.TopRight, Origin = Anchor.TopRight, Spacing = new Vector2(5), - Children = new [] + Children = new Drawable[] { new TimeInfoContainer(Model) { RelativeSizeAxes = Axes.X, Height = 36, + }, + + // todo : in small display size use badge. + // in larger size should use real icon. + new LanguageInfoBadge(Model) + { + Margin = new MarginPadding{ Right = 5 } } } }, diff --git a/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs b/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs index d0a62db74..b78fb337a 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs @@ -122,13 +122,21 @@ public int LayoutIndex [JsonIgnore] public readonly Bindable TranslateTextBindable = new Bindable(); - public CultureInfo Language { get; set; } - /// /// Translates /// public IDictionary Translates { get; set; } = new Dictionary(); + + [JsonIgnore] + public readonly Bindable LanguageBindable = new Bindable(); + + public CultureInfo Language + { + get => LanguageBindable.Value; + set => LanguageBindable.Value = value; + } + /// /// Display target translate ///