-
Notifications
You must be signed in to change notification settings - Fork 16
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 #2242 from andy840119/implement-switch-create-type…
…-section Implement switch create type section
- Loading branch information
Showing
7 changed files
with
258 additions
and
31 deletions.
There are no files selected for viewing
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
60 changes: 43 additions & 17 deletions
60
...sets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/CreateTimeTagActionSection.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 |
---|---|---|
@@ -1,62 +1,88 @@ | ||
// 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 osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Input.Bindings; | ||
using osu.Framework.Input.Events; | ||
using osu.Framework.Localisation; | ||
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; | ||
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.CaretPosition; | ||
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States; | ||
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States.Modes; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.TimeTags; | ||
|
||
// todo: this section will display the action for creating time-tag. | ||
// will the visual part of https://github.com/karaoke-dev/karaoke/discussions/2225#discussioncomment-9244747 | ||
public partial class CreateTimeTagActionSection : EditorSection, IKeyBindingHandler<KaraokeEditAction> | ||
{ | ||
protected override LocalisableString Title => "Action"; | ||
|
||
[Resolved] | ||
private ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler { get; set; } = null!; | ||
|
||
[Resolved] | ||
private ILyricCaretState lyricCaretState { get; set; } = null!; | ||
private readonly IBindable<ICaretPosition?> bindableCaretPosition = new Bindable<ICaretPosition?>(); | ||
private readonly Bindable<CreateTimeTagType> bindableCreateType = new(); | ||
|
||
public CreateTimeTagActionSection() | ||
{ | ||
Children = new[] | ||
{ | ||
new CreateTimeTagTypeSubsection | ||
{ | ||
Current = bindableCreateType, | ||
}, | ||
}; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(IEditTimeTagModeState editTimeTagModeState, ILyricCaretState lyricCaretState) | ||
{ | ||
bindableCaretPosition.BindTo(lyricCaretState.BindableCaretPosition); | ||
bindableCreateType.BindTo(editTimeTagModeState.BindableCreateType); | ||
} | ||
|
||
public bool OnPressed(KeyBindingPressEvent<KaraokeEditAction> e) | ||
{ | ||
var action = e.Action; | ||
var caretPosition = lyricCaretState.CaretPosition; | ||
var caretPosition = bindableCaretPosition.Value; | ||
|
||
return caretPosition switch | ||
if (caretPosition is not CreateRemoveTimeTagCaretPosition createRemoveTimeTagCaretPosition) | ||
return false; | ||
|
||
if (LyricEditor.ToMovingCaretAction(e.Action) != null) | ||
{ | ||
CreateRemoveTimeTagCaretPosition timeTagIndexCaretPosition => processCreateTimeTagAction(timeTagIndexCaretPosition, action), | ||
_ => throw new NotSupportedException(nameof(caretPosition)), | ||
}; | ||
bindableCreateType.Value = CreateTimeTagType.Keyboard; | ||
return false; | ||
} | ||
|
||
if (createTimeTagByKeyboard(createRemoveTimeTagCaretPosition.CharIndex, action)) | ||
{ | ||
bindableCreateType.Value = CreateTimeTagType.Keyboard; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private bool processCreateTimeTagAction(CreateRemoveTimeTagCaretPosition createRemoveTimeTagCaretPosition, KaraokeEditAction action) | ||
private bool createTimeTagByKeyboard(int charIndex, KaraokeEditAction action) | ||
{ | ||
int index = createRemoveTimeTagCaretPosition.CharIndex; | ||
|
||
switch (action) | ||
{ | ||
case KaraokeEditAction.CreateStartTimeTag: | ||
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(index)); | ||
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(charIndex)); | ||
return true; | ||
|
||
case KaraokeEditAction.CreateEndTimeTag: | ||
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(index, TextIndex.IndexState.End)); | ||
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(charIndex, TextIndex.IndexState.End)); | ||
return true; | ||
|
||
case KaraokeEditAction.RemoveStartTimeTag: | ||
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(index)); | ||
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(charIndex)); | ||
return true; | ||
|
||
case KaraokeEditAction.RemoveEndTimeTag: | ||
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(index, TextIndex.IndexState.End)); | ||
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(charIndex, TextIndex.IndexState.End)); | ||
return true; | ||
|
||
default: | ||
|
155 changes: 155 additions & 0 deletions
155
...ets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/CreateTimeTagTypeSubsection.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,155 @@ | ||
// 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.Generic; | ||
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.Localisation; | ||
using osu.Game.Graphics; | ||
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States.Modes; | ||
using osu.Game.Rulesets.Karaoke.Screens.Edit.Components.Markdown; | ||
using osuTK; | ||
using osuTK.Graphics; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.TimeTags; | ||
|
||
public partial class CreateTimeTagTypeSubsection : SwitchSubsection<CreateTimeTagType> | ||
{ | ||
protected override SwitchTabControl CreateTabControl() | ||
=> new CreateTimeTagTypeTabControl(); | ||
|
||
protected override DescriptionFormat GetDescription(CreateTimeTagType mode) => | ||
mode switch | ||
{ | ||
CreateTimeTagType.Mouse => "Use mouse to move the caret, and click the button in the UI to create/remove the start/end time tag. It's for the beginner.", | ||
CreateTimeTagType.HotkeyThenPress => "Press the hotkey to prepare create/remove the start/end time tag. This kind of create mode is still implementing.", | ||
CreateTimeTagType.Keyboard => new DescriptionFormat | ||
{ | ||
Text = | ||
$"Use [{DescriptionFormat.LINK_KEY_ACTION}](navigate_time_tag) to control caret position, press [{DescriptionFormat.LINK_KEY_ACTION}](create_time_tag) to create new time-tag and press [{DescriptionFormat.LINK_KEY_ACTION}](remove_time_tag) to delete exist time-tag.", | ||
Actions = new Dictionary<string, IDescriptionAction> | ||
{ | ||
{ | ||
"navigate_time_tag", new InputKeyDescriptionAction | ||
{ | ||
Text = "Keyboard", | ||
AdjustableActions = new List<KaraokeEditAction> | ||
{ | ||
KaraokeEditAction.MoveToPreviousLyric, | ||
KaraokeEditAction.MoveToNextLyric, | ||
KaraokeEditAction.MoveToPreviousIndex, | ||
KaraokeEditAction.MoveToNextIndex, | ||
}, | ||
} | ||
}, | ||
{ | ||
"create_time_tag", new InputKeyDescriptionAction | ||
{ | ||
Text = "Create Time-tag keys", | ||
AdjustableActions = new List<KaraokeEditAction> | ||
{ | ||
KaraokeEditAction.CreateStartTimeTag, | ||
KaraokeEditAction.CreateEndTimeTag, | ||
}, | ||
} | ||
}, | ||
{ | ||
"remove_time_tag", new InputKeyDescriptionAction | ||
{ | ||
Text = "Remove Time-tag keys", | ||
AdjustableActions = new List<KaraokeEditAction> | ||
{ | ||
KaraokeEditAction.RemoveStartTimeTag, | ||
KaraokeEditAction.RemoveEndTimeTag, | ||
}, | ||
} | ||
}, | ||
}, | ||
}, | ||
_ => throw new InvalidOperationException(nameof(mode)), | ||
}; | ||
|
||
private partial class CreateTimeTagTypeTabControl : SwitchTabControl | ||
{ | ||
protected override SwitchTabItem CreateStepButton(OsuColour colours, CreateTimeTagType value) | ||
{ | ||
return value switch | ||
{ | ||
CreateTimeTagType.Mouse => new CreateTimeTagTypeTabButton(value) | ||
{ | ||
Icon = FontAwesome.Solid.MousePointer, | ||
TooltipText = "Mouse", | ||
SelectedColour = colours.Green, | ||
UnSelectedColour = colours.GreenDarker, | ||
}, | ||
CreateTimeTagType.HotkeyThenPress => new CreateTimeTagTypeTabButton(value) | ||
{ | ||
Icon = FontAwesome.Solid.PencilAlt, | ||
TooltipText = "Keyboard + Mouse", | ||
SelectedColour = colours.Yellow, | ||
UnSelectedColour = colours.YellowDarker, | ||
}, | ||
CreateTimeTagType.Keyboard => new CreateTimeTagTypeTabButton(value) | ||
{ | ||
Icon = FontAwesome.Solid.Keyboard, | ||
TooltipText = "Keyboard", | ||
SelectedColour = colours.Blue, | ||
UnSelectedColour = colours.BlueDarker, | ||
}, | ||
_ => throw new ArgumentOutOfRangeException(nameof(value), value, null), | ||
}; | ||
} | ||
|
||
private partial class CreateTimeTagTypeTabButton : SwitchTabItem, IHasTooltip | ||
{ | ||
private readonly Box background; | ||
private readonly SpriteIcon spriteIcon; | ||
|
||
public CreateTimeTagTypeTabButton(CreateTimeTagType value) | ||
: base(value) | ||
{ | ||
Child = new Container | ||
{ | ||
Masking = true, | ||
CornerRadius = 15, | ||
RelativeSizeAxes = Axes.Both, | ||
Children = new Drawable[] | ||
{ | ||
background = new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
}, | ||
spriteIcon = new SpriteIcon | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Size = new Vector2(25), | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
public IconUsage Icon | ||
{ | ||
get => spriteIcon.Icon; | ||
set => spriteIcon.Icon = value; | ||
} | ||
|
||
public LocalisableString TooltipText { get; init; } | ||
|
||
public Color4 SelectedColour { get; init; } | ||
|
||
public Color4 UnSelectedColour { get; init; } | ||
|
||
protected override void UpdateState() | ||
{ | ||
background.Colour = Active.Value ? SelectedColour : UnSelectedColour; | ||
Child.Alpha = Active.Value ? 0.8f : 0.4f; | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/States/Modes/CreateTimeTagType.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,25 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States.Modes; | ||
|
||
public enum CreateTimeTagType | ||
{ | ||
/// <summary> | ||
/// Use mouse to move the caret, and click the button in the UI to create/remove the start/end time tag. | ||
/// It's the slowest way to create the time tag. | ||
/// </summary> | ||
Mouse, | ||
|
||
/// <summary> | ||
/// Press the hotkey to prepare create/remove the start/end time tag, click the character in the lyric to confirm. | ||
/// It might be useful for those english-like lyric. | ||
/// </summary> | ||
HotkeyThenPress, | ||
|
||
/// <summary> | ||
/// Use keyboard to move the caret, and press hotkey to create/remove the start/end time tag. | ||
/// It's the fastest way to create the time tag for Japanese/Chinses lyric. | ||
/// </summary> | ||
Keyboard, | ||
} |
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