Skip to content

Commit

Permalink
Merge pull request #262 from andy840119/andy840119/step-two
Browse files Browse the repository at this point in the history
Add lyric editor's step two.
  • Loading branch information
andy840119 authored Nov 28, 2020
2 parents ee74438 + 4baa9c2 commit 3b2e3b5
Show file tree
Hide file tree
Showing 22 changed files with 410 additions and 33 deletions.
42 changes: 38 additions & 4 deletions osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneImportLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
using osu.Game.Rulesets.Karaoke.Tests.Resources;
using osu.Game.Screens.Edit;
using osu.Game.Tests.Visual;
using System;
using System.IO;
using System.Linq;

namespace osu.Game.Rulesets.Karaoke.Tests.Edit
{
Expand All @@ -27,7 +29,7 @@ public class TestSceneImportLyric : EditorClockTestScene
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };

private DialogOverlay dialogOverlay;
private ImportLyricScreen screen;
private TestImportLyricScreen screen;
private ImportLyricManager importManager;

public TestSceneImportLyric()
Expand All @@ -53,11 +55,43 @@ private void load()
Dependencies.Cache(importManager);
}

[SetUp]
public void SetUp() => Schedule(() =>
[Test]
public void TestGoToStep() => Schedule(() =>
{
var temp = TestResources.GetTestLrcForImport("default");
Child = screen = new ImportLyricScreen(new FileInfo(temp));
Child = screen = new TestImportLyricScreen(new FileInfo(temp));

var steps = (ImportLyricStep[])Enum.GetValues(typeof(ImportLyricStep));
foreach (var step in steps)
{
AddStep($"go to step {Enum.GetName(typeof(ImportLyricStep), step)}", () => { screen.GoToStep(step); });
}
});

private class TestImportLyricScreen : ImportLyricScreen
{
public TestImportLyricScreen(FileInfo fileInfo)
: base(fileInfo)
{
}

public void GoToStep(ImportLyricStep step)
{
if (ScreenStack.CurrentScreen is IImportLyricSubScreen lyricSubScreen)
{
if (step == lyricSubScreen.Step)
return;

if (step <= lyricSubScreen.Step)
return;

var totalSteps = ((ImportLyricStep[])Enum.GetValues(typeof(ImportLyricStep))).Where(x => x > lyricSubScreen.Step && x <= step);
foreach (var gotoStep in totalSteps)
{
ScreenStack.Push(gotoStep);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
using osu.Game.Rulesets.Karaoke.Edit.ImportLyric;
using osu.Game.Rulesets.Karaoke.Edit.LyricEditor;
using osu.Game.Rulesets.Karaoke.Tests.Beatmaps;
using osu.Game.Rulesets.Karaoke.Tests.Resources;
using osu.Game.Screens.Edit;
using osu.Game.Tests.Visual;
using System.IO;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics;

namespace osu.Game.Rulesets.Karaoke.Tests.Edit
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Timing;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric.AssignLanguage
{
public class AssignLanguageSubScreen : ImportLyricSubScreen
public class AssignLanguageSubScreen : ImportLyricSubScreenWithTopNavigation
{
public override string Title => "Language";

Expand All @@ -15,9 +19,77 @@ public class AssignLanguageSubScreen : ImportLyricSubScreen

public override IconUsage Icon => FontAwesome.Solid.Globe;

protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
dependencies.CacheAs<IAdjustableClock>(clock);
dependencies.CacheAs<IFrameBasedClock>(clock);

return dependencies;
}

protected override TopNavigation CreateNavigation()
=> new AssignLanguageNavigation(this);

protected override Drawable CreateContent()
{
return new LyricEditor
{
RelativeSizeAxes = Axes.Both,
Mode = Mode.EditMode,
LyricFastEditMode = LyricFastEditMode.Language,
FontSize = 26
};
}

protected override void LoadComplete()
{
base.LoadComplete();
Navigation.State = NavigationState.Initial;
AskForAutoAssignLanguage();
}

public override void Complete()
{
ScreenStack.Push(ImportLyricStep.GenerateRuby);
}

protected void AskForAutoAssignLanguage()
{
DialogOverlay.Push(new UseLanguageDetectorPopupDialog(ok =>
{
// todo : call manager to do that.
}));
}

public class AssignLanguageNavigation : TopNavigation
{
public AssignLanguageNavigation(ImportLyricSubScreen screen)
: base(screen)
{
}

protected override void UpdateState(NavigationState value)
{
base.UpdateState(value);

switch (value)
{
case NavigationState.Initial:
NavigationText = "Try to select left side to mark lyric's language.";
break;
case NavigationState.Working:
NavigationText = "Almost there/";
break;
case NavigationState.Done:
NavigationText = "Cool! Seems all lyric has it's own language. Go to next step to generate ruby.";
break;
case NavigationState.Error:
NavigationText = "Oops, seems cause some error in here.";
break;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using System;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric.AssignLanguage
{
public class UseLanguageDetectorPopupDialog : PopupDialog
{
public UseLanguageDetectorPopupDialog(Action<bool> okAction = null)
{
Icon = FontAwesome.Solid.Globe;
HeaderText = "LanguageDetector";
BodyText = $"Would you like to use language detector to auto assign each lyric's language?";
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"OK",
Action = () => okAction?.Invoke(true),
},
new PopupDialogCancelButton
{
Text = @"Cancel",
Action = () => okAction?.Invoke(false),
},
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric.GenerateRuby
{
public class GenerateRubySubScreen : ImportLyricSubScreen
public class GenerateRubySubScreen : ImportLyricSubScreenWithTopNavigation
{
public override string Title => "Generate ruby";

Expand All @@ -15,9 +17,30 @@ public class GenerateRubySubScreen : ImportLyricSubScreen

public override IconUsage Icon => FontAwesome.Solid.Gem;

protected override TopNavigation CreateNavigation()
=> new GenerateRubyNavigation(this);

protected override Drawable CreateContent()
=> new Container();

public override void Complete()
{
ScreenStack.Push(ImportLyricStep.GenerateTimeTag);
}

public class GenerateRubyNavigation : TopNavigation
{
public GenerateRubyNavigation(ImportLyricSubScreen screen)
: base(screen)
{
}

protected override void UpdateState(NavigationState value)
{
base.UpdateState(value);

// todo : update text
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric.GenerateTimeTag
{
public class GenerateTimeTagSubScreen : ImportLyricSubScreen
public class GenerateTimeTagSubScreen : ImportLyricSubScreenWithTopNavigation
{
public override string Title => "Generate time tag";

Expand All @@ -15,9 +17,30 @@ public class GenerateTimeTagSubScreen : ImportLyricSubScreen

public override IconUsage Icon => FontAwesome.Solid.Tag;

protected override TopNavigation CreateNavigation()
=> new GenerateTimeTagNavigation(this);

protected override Drawable CreateContent()
=> new Container();

public override void Complete()
{
ScreenStack.Push(ImportLyricStep.Success);
}

public class GenerateTimeTagNavigation : TopNavigation
{
public GenerateTimeTagNavigation(ImportLyricSubScreen screen)
: base(screen)
{
}

protected override void UpdateState(NavigationState value)
{
base.UpdateState(value);

// todo : update text
}
}
}
}
10 changes: 5 additions & 5 deletions osu.Game.Rulesets.Karaoke/Edit/ImportLyric/ImportLyricScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class ImportLyricScreen : EditorScreen
private readonly ImportLyricWaveContainer waves;

[Cached]
private readonly ImportLyricSubScreenStack screenStack;
protected ImportLyricSubScreenStack ScreenStack { get; private set; }

public ImportLyricScreen(FileInfo fileInfo)
: this()
{
if (!(screenStack.CurrentScreen is DragFileSubScreen dragFileSubScreen))
if (!(ScreenStack.CurrentScreen is DragFileSubScreen dragFileSubScreen))
throw new ScreenStack.ScreenNotInStackException($"{nameof(DragFileSubScreen)} does not in the screen.");

dragFileSubScreen.ImportLyricFile(fileInfo);
Expand All @@ -49,13 +49,13 @@ public ImportLyricScreen()
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Header.HEIGHT },
Child = screenStack = new ImportLyricSubScreenStack { RelativeSizeAxes = Axes.Both }
Child = ScreenStack = new ImportLyricSubScreenStack { RelativeSizeAxes = Axes.Both }
},
new Header(screenStack),
new Header(ScreenStack),
}
};

screenStack.Push(ImportLyricStep.ImportLyric);
ScreenStack.Push(ImportLyricStep.ImportLyric);
}

protected override void LoadComplete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using osu.Framework.Screens;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Graphics.Overlays.Dialog;
using osu.Game.Screens;
using System;

Expand Down Expand Up @@ -83,12 +82,7 @@ public override void OnSuspending(IScreen next)

public virtual void CanRollBack(IImportLyricSubScreen rollBackScreen, Action<bool> callBack)
{
DialogOverlay.Push(new OkPopupDialog(callBack)
{
Icon = rollBackScreen.Icon,
HeaderText = rollBackScreen.ShortTitle,
BodyText = $"Will roll-back to step '{rollBackScreen.Title}'",
});
DialogOverlay.Push(new RollBackPopupDialog(rollBackScreen, callBack));
}

public override string ToString() => Title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ public class ImportLyricSubScreenStack : OsuScreenStack
{
public void Push(ImportLyricStep step)
{
if (CurrentScreen is IImportLyricSubScreen lyricSubScreen)
{
if (step == lyricSubScreen.Step)
throw new ScreenNotCurrentException("Cannot push same screen.");

if (step <= lyricSubScreen.Step)
throw new ScreenNotCurrentException("Cannot push pervious then current screen.");

if (step != ImportLyricStep.GenerateRuby && step - lyricSubScreen.Step > 1)
throw new ScreenNotCurrentException("Only generate ruby step can be skipped.");
}

switch (step)
{
case ImportLyricStep.ImportLyric:
Expand Down
Loading

0 comments on commit 3b2e3b5

Please sign in to comment.