Skip to content

Commit

Permalink
Merge pull request #2201 from andy840119/move-display-translation-con…
Browse files Browse the repository at this point in the history
…fig-into-mod

Move the display translation/prefer language from config into mode
  • Loading branch information
andy840119 authored Mar 24, 2024
2 parents 58273d8 + 3ad5a8c commit 900ffb9
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 192 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 NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Mods;
using osu.Game.Rulesets.Karaoke.Tests.Beatmaps;

namespace osu.Game.Rulesets.Karaoke.Tests.Mods;

public partial class TestSceneKaraokeModTranslation : KaraokeModTestScene
{
[Test]
public void TestAllPanelExist() => CreateModTest(new ModTestData
{
Mod = new KaraokeModTranslation(),
Autoplay = false,
Beatmap = new TestKaraokeBeatmap(new RulesetInfo()),
PassCondition = () => true,
});
}
1 change: 0 additions & 1 deletion osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public TestSceneLyric()
private void load()
{
var config = Dependencies.Get<KaraokeRulesetConfigManager>();
config.SetValue(KaraokeRulesetSetting.UseTranslate, true);
config.SetValue(KaraokeRulesetSetting.PreferLanguage, cultureInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ protected override void InitialiseDefaults()
SetDefault(KaraokeRulesetSetting.LyricAlpha, 1, 0.2, 1, 0.01);

// Translate
SetDefault(KaraokeRulesetSetting.UseTranslate, true);
SetDefault(KaraokeRulesetSetting.PreferLanguage, new CultureInfo("en-US"));

// Pitch
Expand Down Expand Up @@ -112,7 +111,6 @@ protected BindableFontUsage SetDefault(KaraokeRulesetSetting setting, FontUsage
new TrackedSetting<double>(KaraokeRulesetSetting.ScrollTime, v => new SettingDescription(v, "Scroll Time", $"{v}ms")),
new TrackedSetting<bool>(KaraokeRulesetSetting.DisplayNoteRubyText, b => new SettingDescription(b, "Toggle display", b ? "Show" : "Hide")),
new TrackedSetting<bool>(KaraokeRulesetSetting.ShowCursor, b => new SettingDescription(b, "Cursor display", b ? "Show" : "Hide")),
new TrackedSetting<bool>(KaraokeRulesetSetting.UseTranslate, b => new SettingDescription(b, "Display translate", b ? "Show" : "Hide")),
new TrackedSetting<CultureInfo>(KaraokeRulesetSetting.PreferLanguage, c => new SettingDescription(c, "Translate language", CultureInfoUtils.GetLanguageDisplayText(c))),
new TrackedSetting<string>(KaraokeRulesetSetting.MicrophoneDevice, d => new SettingDescription(d, "Change to the new microphone device", d)),
};
Expand All @@ -129,7 +127,6 @@ public enum KaraokeRulesetSetting
LyricAlpha,

// Translate
UseTranslate,
PreferLanguage,

// Pitch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Configuration;
using osu.Game.Rulesets.Karaoke.Graphics.Sprites;

namespace osu.Game.Rulesets.Karaoke.Configuration;

public class KaraokeRulesetEditConfigManager : InMemoryConfigManager<KaraokeRulesetEditSetting>
{
protected override void InitialiseDefaults()
{
base.InitialiseDefaults();

// Lyric display.
SetDefault(KaraokeRulesetEditSetting.DisplayTranslate, true);
}
}

public enum KaraokeRulesetEditSetting
{
// Lyric display type
DisplayTranslate,
}
16 changes: 0 additions & 16 deletions osu.Game.Rulesets.Karaoke/Configuration/KaraokeSessionStatics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.UI.Components;

Expand All @@ -21,14 +17,6 @@ public KaraokeSessionStatics(KaraokeRulesetConfigManager config, IBeatmap? beatm
{
rulesetConfigManager = config;

// Translate
bool useTranslate = getValue<bool>(KaraokeRulesetSetting.UseTranslate);
var preferLanguage = getValue<CultureInfo>(KaraokeRulesetSetting.PreferLanguage);
var availableTranslate = beatmap?.AvailableTranslates();
var selectedLanguage = availableTranslate?.FirstOrDefault(t => EqualityComparer<CultureInfo>.Default.Equals(t, preferLanguage)) ?? availableTranslate?.FirstOrDefault();
SetDefault(KaraokeRulesetSession.UseTranslate, useTranslate);
SetDefault(KaraokeRulesetSession.PreferLanguage, selectedLanguage);

// Pitch
bool overridePitch = getValue<bool>(KaraokeRulesetSetting.OverridePitchAtGameplay);
int pitchValue = getValue<int>(KaraokeRulesetSetting.Pitch);
Expand Down Expand Up @@ -59,10 +47,6 @@ public KaraokeSessionStatics(KaraokeRulesetConfigManager config, IBeatmap? beatm

public enum KaraokeRulesetSession
{
// Translate
UseTranslate,
PreferLanguage,

// Pitch
Pitch,
VocalPitch,
Expand Down

This file was deleted.

12 changes: 0 additions & 12 deletions osu.Game.Rulesets.Karaoke/Edit/DrawableKaraokeEditorRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.UI;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
Expand All @@ -15,26 +12,17 @@ namespace osu.Game.Rulesets.Karaoke.Edit;

public partial class DrawableKaraokeEditorRuleset : DrawableKaraokeRuleset
{
private readonly Bindable<bool> bindableDisplayTranslateToggle = new();

public new IScrollingInfo ScrollingInfo => base.ScrollingInfo;

protected override bool DisplayNotePlayfield => true;

public DrawableKaraokeEditorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod>? mods)
: base(ruleset, beatmap, mods)
{
bindableDisplayTranslateToggle.BindValueChanged(x => { Session.SetValue(KaraokeRulesetSession.UseTranslate, x.NewValue); });
}

protected override Playfield CreatePlayfield() => new KaraokeEditorPlayfield();

[BackgroundDependencyLoader]
private void load(KaraokeRulesetEditConfigManager editConfigManager)
{
editConfigManager.BindWith(KaraokeRulesetEditSetting.DisplayTranslate, bindableDisplayTranslateToggle);
}

// todo: use default adjustment container because DrawableEditorRulesetWrapper will create it but contains no KaraokeRulesetConfigManager
public override PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => new();
}
5 changes: 1 addition & 4 deletions osu.Game.Rulesets.Karaoke/Edit/KaraokeHitObjectComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ protected void CreateMenuBar()
{
new("Config")
{
Items = new MenuItem[]
{
new LyricDisplayPreviewMenuItem(editConfigManager, "Lyric display preview"),
},
Items = Array.Empty<MenuItem>(),
},
new("Tools")
{
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 @@ -144,6 +144,7 @@ public override IEnumerable<Mod> GetModsFor(ModType type) =>
{
new KaraokeModNoFail(),
new KaraokeModLyricConfiguration(),
new KaraokeModTranslation(),
},
ModType.DifficultyIncrease => new Mod[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ public static class KaraokeSettingsSubsectionStrings
public static LocalisableString ShowCursorWhilePlayingTooltip =>
new TranslatableString(getKey(@"show_cursor_while_playing_tooltip"), @"Will not showing the cursor while gameplay if not select this option.");

/// <summary>
/// "Translate"
/// </summary>
public static LocalisableString Translate => new TranslatableString(getKey(@"translate"), @"Translate");

/// <summary>
/// "Show the translation under the lyric if contains in the beatmap."
/// </summary>
public static LocalisableString TranslateTooltip => new TranslatableString(getKey(@"translate_tooltip"), @"Show the translation under the lyric if contains in the beatmap.");

/// <summary>
/// "Prefer language"
/// </summary>
Expand Down
39 changes: 39 additions & 0 deletions osu.Game.Rulesets.Karaoke/Mods/KaraokeModTranslation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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.Allocation;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Objects.Drawables;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Drawables;

namespace osu.Game.Rulesets.Karaoke.Mods;

public class KaraokeModTranslation : Mod, IApplicableToDrawableHitObject
{
public override string Name => "Translation";

public override LocalisableString Description => "Display prefer translation by ruleset configuration.";

public override double ScoreMultiplier => 1.0f;

public override string Acronym => "LT";

public void ApplyToDrawableHitObject(DrawableHitObject drawable)
{
if (drawable is not DrawableLyric drawableLyric)
return;

var preferLanguage = getPreferLanguage(drawableLyric.Dependencies);
drawableLyric.ChangePreferTranslationLanguage(preferLanguage);
return;

static CultureInfo? getPreferLanguage(IReadOnlyDependencyContainer dependencyContainer)
{
var config = dependencyContainer.Get<KaraokeRulesetConfigManager>();
return config.Get<CultureInfo?>(KaraokeRulesetSetting.PreferLanguage);
}
}
}
27 changes: 11 additions & 16 deletions osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public partial class DrawableLyric : DrawableKaraokeHitObject
private Container<DrawableKaraokeSpriteText> lyricPieces = null!;
private OsuSpriteText translateText = null!;

private KaraokeRulesetConfigManager? config { get; set; }

private readonly BindableBool useTranslateBindable = new();
private readonly Bindable<CultureInfo> preferLanguageBindable = new();

Expand Down Expand Up @@ -55,7 +53,7 @@ public DrawableLyric(Lyric? hitObject)
}

[BackgroundDependencyLoader(true)]
private void load(KaraokeSessionStatics? session)
private void load(KaraokeRulesetConfigManager? config)
{
AutoSizeAxes = Axes.Both;

Expand All @@ -69,19 +67,6 @@ private void load(KaraokeSessionStatics? session)
Origin = Anchor.TopLeft,
});

if (session != null)
{
// gameplay.
session.BindWith(KaraokeRulesetSession.UseTranslate, useTranslateBindable);
session.BindWith(KaraokeRulesetSession.PreferLanguage, preferLanguageBindable);
}
else if (config != null)
{
// preview lyric effect.
config.BindWith(KaraokeRulesetSetting.UseTranslate, useTranslateBindable);
config.BindWith(KaraokeRulesetSetting.PreferLanguage, preferLanguageBindable);
}

useTranslateBindable.BindValueChanged(_ => applyTranslate(), true);
preferLanguageBindable.BindValueChanged(_ => applyTranslate(), true);

Expand Down Expand Up @@ -117,6 +102,16 @@ public void ChangeDisplayProperty(LyricDisplayProperty lyricDisplayProperty)
lyricPieces.ForEach(x => x.DisplayProperty = lyricDisplayProperty);
}

public void ChangePreferTranslationLanguage(CultureInfo? language)
{
if (language != null && translateTextBindable.TryGetValue(language, out string? translate))
translateText.Text = translate;
else
{
translateText.Text = string.Empty;
}
}

protected override void OnApply()
{
base.OnApply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Screens.Settings.Previews;
using osu.Game.Rulesets.Karaoke.Screens.Settings.Previews.Gameplay;
Expand All @@ -23,11 +22,6 @@ private void load()
{
Children = new Drawable[]
{
new SettingsCheckbox
{
LabelText = "Translate",
Current = Config.GetBindable<bool>(KaraokeRulesetSetting.UseTranslate),
},
new SettingsLanguage
{
LabelText = "Prefer language",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
}

[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, StyleManager manager)
private void load(OverlayColourProvider colourProvider)
{
Masking = true;
CornerRadius = 15;
Expand Down
14 changes: 1 addition & 13 deletions osu.Game.Rulesets.Karaoke/UI/HUD/GeneralSettingOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,8 @@ public virtual void OnReleased(KeyBindingReleaseEvent<KaraokeAction> e)
}

[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, KaraokeSessionStatics session)
private void load(KaraokeSessionStatics session)
{
// Add translate group if this beatmap has translate
if (beatmap.Value.Beatmap.AnyTranslate())
{
Add(new TranslateSettings
{
Expanded =
{
Value = false,
},
});
}

session.BindWith(KaraokeRulesetSession.Pitch, bindablePitch);
session.BindWith(KaraokeRulesetSession.VocalPitch, bindableVocalPitch);
session.BindWith(KaraokeRulesetSession.ScoringPitch, bindableScoringPitch);
Expand Down
7 changes: 0 additions & 7 deletions osu.Game.Rulesets.Karaoke/UI/KaraokeSettingsSubsection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ private void load(IPerformFromScreenRunner performer)
TooltipText = KaraokeSettingsSubsectionStrings.ShowCursorWhilePlayingTooltip,
Current = config.GetBindable<bool>(KaraokeRulesetSetting.ShowCursor),
},
// Translate
new SettingsCheckbox
{
LabelText = KaraokeSettingsSubsectionStrings.Translate,
TooltipText = KaraokeSettingsSubsectionStrings.TranslateTooltip,
Current = config.GetBindable<bool>(KaraokeRulesetSetting.UseTranslate),
},
// Device
new SettingsMicrophoneDeviceDropdown
{
Expand Down
Loading

0 comments on commit 900ffb9

Please sign in to comment.