-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2284 from andy840119/add-translation-edit-section
Add translation edit section to the editor.
- Loading branch information
Showing
9 changed files
with
279 additions
and
19 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
osu.Game.Rulesets.Karaoke/Edit/Setup/Components/LabelledLanguageList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Globalization; | ||
using osu.Framework.Bindables; | ||
using osu.Game.Graphics.UserInterfaceV2; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Setup.Components; | ||
|
||
public partial class LabelledLanguageList : LabelledDrawable<LanguageList> | ||
{ | ||
public LabelledLanguageList() | ||
: base(true) | ||
{ | ||
} | ||
|
||
public BindableList<CultureInfo> Languages => Component.Languages; | ||
|
||
protected override LanguageList CreateComponent() => new(); | ||
} |
190 changes: 190 additions & 0 deletions
190
osu.Game.Rulesets.Karaoke/Edit/Setup/Components/LanguageList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Specialized; | ||
using System.Globalization; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Extensions; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Cursor; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Graphics.UserInterface; | ||
using osu.Game.Graphics; | ||
using osu.Game.Graphics.Sprites; | ||
using osu.Game.Graphics.UserInterface; | ||
using osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2; | ||
using osu.Game.Rulesets.Karaoke.Utils; | ||
using osuTK; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Setup.Components; | ||
|
||
/// <summary> | ||
/// A component which displays a collection of <see cref="CultureInfo"/> | ||
/// </summary> | ||
public partial class LanguageList : CompositeDrawable | ||
{ | ||
public BindableList<CultureInfo> Languages { get; } = new(); | ||
|
||
private FillFlowContainer languages = null!; | ||
|
||
private const int fade_duration = 200; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
RelativeSizeAxes = Axes.X; | ||
AutoSizeAxes = Axes.Y; | ||
AutoSizeDuration = fade_duration; | ||
AutoSizeEasing = Easing.OutQuint; | ||
|
||
InternalChild = languages = new FillFlowContainer | ||
{ | ||
RelativeSizeAxes = Axes.X, | ||
AutoSizeAxes = Axes.Y, | ||
Spacing = new Vector2(8), | ||
Direction = FillDirection.Full, | ||
}; | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
Languages.BindCollectionChanged((_, args) => | ||
{ | ||
if (args.Action != NotifyCollectionChangedAction.Replace) | ||
updateSingers(); | ||
}, true); | ||
FinishTransforms(true); | ||
} | ||
|
||
private void updateSingers() | ||
{ | ||
languages.Clear(); | ||
|
||
foreach (CultureInfo language in Languages) | ||
{ | ||
languages.Add(new LanguageDisplay | ||
{ | ||
Current = { Value = language }, | ||
DeleteRequested = languageDeletionRequested, | ||
}); | ||
} | ||
|
||
languages.Add(new AddLanguageButton | ||
{ | ||
Action = languageInsertionRequested, | ||
}); | ||
} | ||
|
||
private void languageInsertionRequested(CultureInfo language) | ||
{ | ||
if (!Languages.Contains(language)) | ||
Languages.Add(language); | ||
} | ||
|
||
private void languageDeletionRequested(CultureInfo language) => Languages.Remove(language); | ||
|
||
private partial class LanguageDisplay : CompositeDrawable, IHasCurrentValue<CultureInfo> | ||
{ | ||
/// <summary> | ||
/// Invoked when the user has requested the corresponding to this <see cref="CultureInfo"/> | ||
/// </summary> | ||
public Action<CultureInfo>? DeleteRequested; | ||
|
||
private readonly BindableWithCurrent<CultureInfo> current = new(); | ||
|
||
public Bindable<CultureInfo> Current | ||
{ | ||
get => current.Current; | ||
set => current.Current = value; | ||
} | ||
|
||
private readonly Box background; | ||
private readonly OsuSpriteText languageName; | ||
|
||
public LanguageDisplay() | ||
{ | ||
AutoSizeAxes = Axes.X; | ||
Height = 30; | ||
Masking = true; | ||
CornerRadius = 5; | ||
|
||
InternalChildren = new Drawable[] | ||
{ | ||
background = new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
}, | ||
languageName = new OsuSpriteText | ||
{ | ||
Anchor = Anchor.CentreLeft, | ||
Origin = Anchor.CentreLeft, | ||
Padding = new MarginPadding { Left = 10, Right = 32 }, | ||
}, | ||
new IconButton | ||
{ | ||
Icon = FontAwesome.Solid.Times, | ||
Anchor = Anchor.CentreRight, | ||
Origin = Anchor.CentreRight, | ||
Size = new Vector2(16), | ||
Margin = new MarginPadding { Right = 10 }, | ||
Action = () => | ||
{ | ||
DeleteRequested?.Invoke(Current.Value); | ||
}, | ||
}, | ||
}; | ||
|
||
current.BindValueChanged(x => | ||
{ | ||
languageName.Text = CultureInfoUtils.GetLanguageDisplayText(x.NewValue); | ||
}); | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(OsuColour colours) | ||
{ | ||
background.Colour = colours.BlueDarker; | ||
languageName.Colour = colours.BlueLighter; | ||
} | ||
} | ||
|
||
internal partial class AddLanguageButton : CompositeDrawable, IHasPopover | ||
{ | ||
public Action<CultureInfo>? Action; | ||
|
||
private readonly Bindable<CultureInfo?> currentLanguage = new(); | ||
|
||
public AddLanguageButton() | ||
{ | ||
InternalChild = new IconButton | ||
{ | ||
Action = this.ShowPopover, | ||
Icon = FontAwesome.Solid.Plus, | ||
}; | ||
|
||
currentLanguage.BindValueChanged(e => | ||
{ | ||
this.HidePopover(); | ||
|
||
var language = e.NewValue; | ||
if (language == null) | ||
return; | ||
|
||
Action?.Invoke(language); | ||
|
||
currentLanguage.Value = null; | ||
}); | ||
} | ||
|
||
public Popover GetPopover() => new LanguageSelectorPopover(currentLanguage) | ||
{ | ||
EnableEmptyOption = false, | ||
}; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
osu.Game.Rulesets.Karaoke/Edit/Setup/KaraokeTranslationSection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Specialized; | ||
using System.Globalization; | ||
using System.Linq; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Localisation; | ||
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps; | ||
using osu.Game.Rulesets.Karaoke.Edit.Setup.Components; | ||
using osu.Game.Screens.Edit.Setup; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Setup; | ||
|
||
public partial class KaraokeTranslationSection : SetupSection | ||
{ | ||
public override LocalisableString Title => "Translation"; | ||
|
||
[Cached(typeof(IBeatmapTranslationsChangeHandler))] | ||
private readonly BeatmapTranslationsChangeHandler changeHandler = new(); | ||
|
||
private LabelledLanguageList singerList = null!; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
AddInternal(changeHandler); | ||
|
||
Children = new Drawable[] | ||
{ | ||
singerList = new LabelledLanguageList | ||
{ | ||
Label = "Translation list", | ||
Description = "All the lyric translation in beatmap.", | ||
FixedLabelWidth = LABEL_WIDTH, | ||
}, | ||
}; | ||
|
||
singerList.Languages.AddRange(changeHandler.Languages); | ||
singerList.Languages.BindCollectionChanged((_, args) => | ||
{ | ||
switch (args.Action) | ||
{ | ||
case NotifyCollectionChangedAction.Add: | ||
foreach (var language in args.NewItems?.Cast<CultureInfo>() ?? Array.Empty<CultureInfo>()) | ||
{ | ||
changeHandler.Add(language); | ||
} | ||
|
||
break; | ||
|
||
case NotifyCollectionChangedAction.Remove: | ||
foreach (var language in args.OldItems?.Cast<CultureInfo>() ?? Array.Empty<CultureInfo>()) | ||
{ | ||
changeHandler.Remove(language); | ||
} | ||
|
||
break; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters