Skip to content

Commit

Permalink
Merge pull request #2284 from andy840119/add-translation-edit-section
Browse files Browse the repository at this point in the history
Add translation edit section to the editor.
  • Loading branch information
andy840119 authored Sep 14, 2024
2 parents ca6b07e + ea468b2 commit c554285
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 19 deletions.
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 osu.Game.Rulesets.Karaoke/Edit/Setup/Components/LanguageList.cs
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 osu.Game.Rulesets.Karaoke/Edit/Setup/KaraokeTranslationSection.cs
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;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
using System.Globalization;
using osu.Framework.Bindables;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Components.UserInterfaceV2;
namespace osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2;

public partial class LanguageSelectorPopover : OsuPopover
{
Expand Down
1 change: 1 addition & 0 deletions osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public override StatisticItem[] CreateStatisticsForScore(ScoreInfo score, IBeatm
public override IEnumerable<SetupSection> CreateEditorSetupSections() => new SetupSection[]
{
new KaraokeSingerSection(),
new KaraokeTranslationSection(),
new KaraokeNoteSection(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Components.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States;
using osu.Game.Rulesets.Karaoke.Utils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Components.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Utils;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.Language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Components.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Translations.Components;

Expand Down
14 changes: 0 additions & 14 deletions osu.Game.Rulesets.Karaoke/Screens/Settings/SettingsLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Utils;
Expand Down Expand Up @@ -42,17 +41,4 @@ public LanguageSelectionButton()
public Popover GetPopover()
=> new LanguageSelectorPopover(Current);
}

private partial class LanguageSelectorPopover : OsuPopover
{
public LanguageSelectorPopover(Bindable<CultureInfo?> bindableCultureInfo)
{
Child = new LanguageSelector
{
Width = 260,
Height = 400,
Current = bindableCultureInfo,
};
}
}
}

0 comments on commit c554285

Please sign in to comment.