Skip to content

Commit

Permalink
Merge pull request #1471 from andy840119/combine-manage-and-typing-mode
Browse files Browse the repository at this point in the history
Combine manage and typing mode.
  • Loading branch information
andy840119 authored Jul 25, 2022
2 parents 97ebb40 + b3bf3f7 commit bc46bf4
Show file tree
Hide file tree
Showing 29 changed files with 305 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private void load()
Dependencies.Cache(new EditorBeatmap(beatmap));
Dependencies.Cache(new EditorClock());
Dependencies.CacheAs(state = new TestLyricEditorState());
Dependencies.CacheAs<ITextingModeState>(new TextingModeState());
Dependencies.CacheAs<ITimeTagModeState>(new TimeTagModeState());
Dependencies.Cache(new KaraokeRulesetLyricEditorConfigManager());

Expand All @@ -81,7 +82,7 @@ public void TestChangeFromViewModeToEditMode()
{
// change from view mode to another mode that contains algorithm.
changeMode(LyricEditorMode.View);
changeMode(LyricEditorMode.Manage);
changeMode(LyricEditorMode.Texting);

// get the action
assertCaretPosition(Assert.IsNotNull);
Expand All @@ -92,7 +93,7 @@ public void TestChangeFromViewModeToEditMode()
public void TestChangeFromEditModeToViewMode()
{
// change from edit mode to view mode for checking that caret position should be clear.
changeMode(LyricEditorMode.Manage);
changeMode(LyricEditorMode.Texting);
changeMode(LyricEditorMode.View);

// get the action
Expand All @@ -104,7 +105,7 @@ public void TestChangeFromEditModeToViewMode()
public void TestChangeFromEditModeToEditMode()
{
// change from edit mode to view mode for checking that caret position should be clear.
changeMode(LyricEditorMode.Manage);
changeMode(LyricEditorMode.Texting);
changeMode(LyricEditorMode.EditRuby);

// get the action
Expand All @@ -130,7 +131,7 @@ public void MovingCaretWithViewMode()
[Test]
public void MovingCaretWithEditMode()
{
changeMode(LyricEditorMode.Manage);
changeMode(LyricEditorMode.Texting);
movingCaret(MovingCaretAction.First);

// get the action
Expand Down Expand Up @@ -158,7 +159,7 @@ public void MovingCaretByLyricWithViewMode()
[Test]
public void MovingCaretByLyricWithEditMode()
{
changeMode(LyricEditorMode.Manage);
changeMode(LyricEditorMode.Texting);

var targetLyric = getLyricFromBeatmap(1);
movingCaretByLyric(targetLyric);
Expand Down Expand Up @@ -201,7 +202,7 @@ public void MovingCaretByCaretPositionWithEditMode()
[Test]
public void MovingCaretByCaretPositionWithWrongCaretPosition()
{
changeMode(LyricEditorMode.Manage);
changeMode(LyricEditorMode.Texting);

var targetLyric = getLyricFromBeatmap(1);

Expand Down Expand Up @@ -247,7 +248,7 @@ public void MovingHoverCaretByCaretPositionWithEditMode()
[Test]
public void MovingHoverCaretByCaretPositionWithWrongCaretPosition()
{
changeMode(LyricEditorMode.Manage);
changeMode(LyricEditorMode.Texting);

var targetLyric = getLyricFromBeatmap(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ public void TestViewMode()
}

[Test]
public void TestManageMode()
public void TestTextingMode()
{
switchToMode(LyricEditorMode.Manage);
}

[Test]
public void TestTypingMode()
{
switchToMode(LyricEditorMode.Typing);
switchToMode(LyricEditorMode.Texting);
clickEditModeButtons<TextingEditMode>();
}

[Test]
Expand Down
18 changes: 18 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Utils/EnumUtilsTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Utils;

Expand Down Expand Up @@ -40,6 +41,16 @@ public void TestGetNextValue(TestEnum current, TestEnum expected)
Assert.AreEqual(expected, actual);
}

[TestCase(TestEnum.Enum1, TestEnum.Enum1)]
[TestCase(TestEnum.Enum2, TestEnum.Enum2)]
[TestCase(TestEnum2.Enum1, TestEnum.Enum1)]
[TestCase(TestEnum2.Enum2, TestEnum.Enum2)]
public void TestCasting(Enum current, TestEnum? expected)
{
var actual = EnumUtils.Casting<TestEnum>(current);
Assert.AreEqual(expected, actual);
}

public enum TestEnum
{
Enum1,
Expand All @@ -48,5 +59,12 @@ public enum TestEnum

Enum3,
}

public enum TestEnum2
{
Enum1,

Enum2,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public LyricEditorModeMenu(Bindable<LyricEditorMode> config, string text)
protected override IEnumerable<LyricEditorMode> ValidEnums => new[]
{
LyricEditorMode.View,
LyricEditorMode.Manage,
LyricEditorMode.Typing,
LyricEditorMode.Texting,
LyricEditorMode.Language,
LyricEditorMode.EditRuby,
LyricEditorMode.EditRomaji,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using osu.Framework.Bindables;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric.EditLyric
Expand Down Expand Up @@ -50,12 +51,12 @@ protected override LocalisableString GetNavigationText(NavigationState value)

case NavigationState.Working:
case NavigationState.Done:
var mode = Screen.LyricEditorMode;
var mode = Screen.GetLyricEditorModeState<TextingEditMode>();

return mode switch
{
LyricEditorMode.Manage => $"Cool! Try switching to [{typing_mode}] if you want to edit lyric.",
LyricEditorMode.Typing => $"Cool! Try switching to [{cutting_mode}] if you want to cut or combine lyric.",
TextingEditMode.Manage => $"Cool! Try switching to [{typing_mode}] if you want to edit lyric.",
TextingEditMode.Typing => $"Cool! Try switching to [{cutting_mode}] if you want to cut or combine lyric.",
_ => throw new InvalidEnumArgumentException(nameof(mode))
};

Expand All @@ -74,8 +75,8 @@ private class EditLyricTextFlowContainer : NavigationTextContainer
{
public EditLyricTextFlowContainer(EditLyricStepScreen screen)
{
AddLinkFactory(cutting_mode, "cutting mode", () => screen.SwitchLyricEditorMode(LyricEditorMode.Manage));
AddLinkFactory(typing_mode, "typing mode", () => screen.SwitchLyricEditorMode(LyricEditorMode.Typing));
AddLinkFactory(cutting_mode, "cutting mode", () => screen.SwitchToEditModeState(TextingEditMode.Manage));
AddLinkFactory(typing_mode, "typing mode", () => screen.SwitchToEditModeState(TextingEditMode.Typing));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected override Drawable CreateContent()
=> base.CreateContent().With(_ =>
{
// todo : will cause text update because has ScheduleAfterChildren in lyric editor.
SwitchLyricEditorMode(LyricEditorMode.Manage);
SwitchLyricEditorMode(LyricEditorMode.Texting);
});

public override void Complete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Game.Rulesets.Karaoke.Edit.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes;
using osu.Game.Rulesets.Karaoke.Utils;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric
{
Expand Down Expand Up @@ -37,9 +38,15 @@ protected override Drawable CreateContent()
public LyricEditorMode LyricEditorMode
=> lyricEditor.Mode;

public T GetLyricEditorModeState<T>() where T : Enum
=> lyricEditor.GetLyricEditorModeState<T>();

public virtual void SwitchLyricEditorMode(LyricEditorMode mode)
=> lyricEditor.SwitchMode(mode);

public void SwitchToEditModeState<T>(T mode) where T : Enum
=> lyricEditor.SwitchToEditModeState(mode);

protected void PrepareAutoGenerate()
{
lyricEditor.PrepareAutoGenerate();
Expand All @@ -51,6 +58,8 @@ private class ImportLyricEditor : LyricEditor
private LyricImporterSubScreenStack screenStack { get; set; }

private ILyricSelectionState lyricSelectionState { get; set; }

private ITextingModeState textingModeState { get; set; }
private ILanguageModeState languageModeState { get; set; }
private IEditRubyModeState editRubyModeState { get; set; }
private IEditRomajiModeState editRomajiModeState { get; set; }
Expand All @@ -71,17 +80,43 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
{
var dependencies = base.CreateChildDependencies(parent);
lyricSelectionState = dependencies.Get<ILyricSelectionState>();
textingModeState = dependencies.Get<ITextingModeState>();
languageModeState = dependencies.Get<ILanguageModeState>();
editRubyModeState = dependencies.Get<IEditRubyModeState>();
editRomajiModeState = dependencies.Get<IEditRomajiModeState>();
return dependencies;
}

public T GetLyricEditorModeState<T>() where T : Enum
{
switch (typeof(T))
{
case Type t when t == typeof(TextingEditMode):
return EnumUtils.Casting<T>(textingModeState.EditMode);

default:
throw new NotSupportedException();
}
}

public void SwitchToEditModeState<T>(T mode) where T : Enum
{
switch (typeof(T))
{
case Type t when t == typeof(TextingEditMode):
textingModeState.ChangeEditMode(EnumUtils.Casting<TextingEditMode>(mode));
break;

default:
throw new NotSupportedException();
}
}

public override void NavigateToFix(LyricEditorMode mode)
{
switch (mode)
{
case LyricEditorMode.Typing:
case LyricEditorMode.Texting:
screenStack.Pop(LyricImporterStep.EditLyric);
break;

Expand Down
8 changes: 6 additions & 2 deletions osu.Game.Rulesets.Karaoke/Edit/ImportLyric/TopNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ private void load()

protected void TriggerStateChange()
{
state = GetState(editorBeatmap.HitObjects.OfType<Lyric>().ToArray());
updateNavigationDisplayInfo(state);
// wait for a bit until lyric editor's all property loaded.
ScheduleAfterChildren(() =>
{
state = GetState(editorBeatmap.HitObjects.OfType<Lyric>().ToArray());
updateNavigationDisplayInfo(state);
});
}

private void updateNavigationDisplayInfo(NavigationState value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void load(OsuColour colours, ILyricEditorState state, ILyricSelectionSta

float getPrefixSpacing()
{
bool containsHandler = state.Mode == LyricEditorMode.Manage;
bool containsHandler = state.Mode == LyricEditorMode.Texting;
return LyricEditor.LYRIC_LIST_PADDING + (containsHandler ? DrawableLyricEditListItem.HANDLER_WIDTH : 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DrawableLyricEditList()
return;

// should not move the position in manage lyric mode.
if (bindableMode.Value == LyricEditorMode.Manage)
if (bindableMode.Value == LyricEditorMode.Texting)
return;

// move to target position if auto focus.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DrawableLyricEditListItem(Lyric item)
bindableMode.BindValueChanged(e =>
{
// Only draggable in edit mode.
ShowDragHandle.Value = e.NewValue == LyricEditorMode.Manage;
ShowDragHandle.Value = e.NewValue == LyricEditorMode.Texting;

// should remove extend when switch mode.
removeExtend();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected class InvalidLyricTextAlertTextContainer : InvalidLyricAlertTextContai

public InvalidLyricTextAlertTextContainer()
{
SwitchToEditorMode(edit_mode, "typing mode", LyricEditorMode.Typing);
SwitchToEditorMode(edit_mode, "typing mode", LyricEditorMode.Texting);
Text = $"Seems some lyric has no texts, go to [{edit_mode}] to fill the text.";
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Components;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Manage
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Texting
{
public class ManageDeleteSubsection : SelectLyricButton
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#nullable disable

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Manage
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Texting
{
public enum ManageEditModeSpecialAction
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Components;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Manage
namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Texting
{
public class ManageSwitchSpecialActionSection : SpecialActionSection<ManageEditModeSpecialAction>
{
Expand All @@ -16,9 +16,9 @@ public class ManageSwitchSpecialActionSection : SpecialActionSection<ManageEditM
protected override string SwitchActionDescription => "Copy, delete or move the lyrics.";

[BackgroundDependencyLoader]
private void load(IManageModeState manageModeState)
private void load(ITextingModeState textingModeState)
{
BindTo(manageModeState);
BindTo(textingModeState);
}

protected override void UpdateActionArea(ManageEditModeSpecialAction action)
Expand Down
Loading

0 comments on commit bc46bf4

Please sign in to comment.