Skip to content

Commit

Permalink
Merge pull request #1458 from andy840119/show-the-fucking-toast
Browse files Browse the repository at this point in the history
Should show the toast after copied or pasted.
  • Loading branch information
andy840119 authored Jul 23, 2022
2 parents d3fdc4e + a8b3cf5 commit 06e1917
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 29 deletions.
39 changes: 39 additions & 0 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/ClipboardToast.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.ComponentModel;
using osu.Framework.Extensions;
using osu.Framework.Localisation;
using osu.Game.Overlays.OSD;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics
{
public class ClipboardToast : Toast
{
public ClipboardToast(LyricEditorMode mode, ClipboardAction action)
: base(getDescription(), getValue(action), getShortcut(mode, action))
{
}

private static LocalisableString getDescription()
=> "Lyric editor";

private static LocalisableString getValue(ClipboardAction action)
=> action.GetDescription();

private static LocalisableString getShortcut(LyricEditorMode mode, ClipboardAction action)
=> $"Lyric has been {action.GetDescription().ToLower()} in the {action.GetDescription().ToLower()} mode.";
}

public enum ClipboardAction
{
[Description("Cut")]
Cut,

[Description("Copy")]
Copy,

[Description("Paste")]
Paste
}
}
45 changes: 35 additions & 10 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Singers;
Expand All @@ -26,6 +27,9 @@ public class LyricEditorClipboard : Component, ILyricEditorClipboard
[Resolved, AllowNull]
private GameHost host { get; set; }

[Resolved(canBeNull: true)]
private OnScreenDisplay? onScreenDisplay { get; set; }

[Resolved, AllowNull]
private ILyricCaretState lyricCaretState { get; set; }

Expand Down Expand Up @@ -96,7 +100,7 @@ public bool Cut()
if (!cut)
return false;

// todo: show the toast.
onScreenDisplay?.Display(new ClipboardToast(bindableMode.Value, ClipboardAction.Cut));
return true;
}

Expand All @@ -110,7 +114,7 @@ public bool Copy()
if (!copy)
return false;

// todo: show the toast.
onScreenDisplay?.Display(new ClipboardToast(bindableMode.Value, ClipboardAction.Copy));
return true;
}

Expand All @@ -127,7 +131,7 @@ public bool Paste()
if (!paste)
return false;

// todo: show the toast.
onScreenDisplay?.Display(new ClipboardToast(bindableMode.Value, ClipboardAction.Paste));
return true;
}

Expand All @@ -154,16 +158,25 @@ private bool performCut()

case LyricEditorMode.EditRuby:
var rubies = editRubyModeState.SelectedItems;
if (!rubies.Any())
return false;

lyricRubyTagsChangeHandler.RemoveAll(rubies);
return true;

case LyricEditorMode.EditRomaji:
var romajies = editRomajiModeState.SelectedItems;
if (!romajies.Any())
return false;

lyricRomajiTagsChangeHandler.RemoveAll(romajies);
return true;

case LyricEditorMode.EditTimeTag:
var timeTags = timeTagModeState.SelectedItems;
if (!timeTags.Any())
return false;

lyricTimeTagsChangeHandler.RemoveAll(timeTags);
return true;

Expand Down Expand Up @@ -203,18 +216,30 @@ private bool performCopy(Lyric lyric)
return true;

case LyricEditorMode.EditRuby:
saveObjectToTheClipboardContent(editRubyModeState.SelectedItems);
copyObjectToClipboard(editRubyModeState.SelectedItems);
var rubies = editRubyModeState.SelectedItems;
if (!rubies.Any())
return false;

saveObjectToTheClipboardContent(rubies);
copyObjectToClipboard(rubies);
return true;

case LyricEditorMode.EditRomaji:
saveObjectToTheClipboardContent(editRomajiModeState.SelectedItems);
copyObjectToClipboard(editRomajiModeState.SelectedItems);
var romajies = editRomajiModeState.SelectedItems;
if (!romajies.Any())
return false;

saveObjectToTheClipboardContent(romajies);
copyObjectToClipboard(romajies);
return true;

case LyricEditorMode.EditTimeTag:
saveObjectToTheClipboardContent(timeTagModeState.SelectedItems);
copyObjectToClipboard(timeTagModeState.SelectedItems);
var timeTags = timeTagModeState.SelectedItems;
if (!timeTags.Any())
return false;

saveObjectToTheClipboardContent(timeTags);
copyObjectToClipboard(timeTags);
return true;

case LyricEditorMode.EditNote:
Expand Down Expand Up @@ -244,7 +269,7 @@ private bool performPaste(Lyric lyric)
return false;

lyricsChangeHandler.AddBelowToSelection(pasteLyric);
return false;
return true;

case LyricEditorMode.Typing:
return false;
Expand Down
25 changes: 6 additions & 19 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#nullable disable

using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
Expand Down Expand Up @@ -141,30 +140,18 @@ public override bool OnPressed(KeyBindingPressEvent<KaraokeEditAction> e)
public class LyricEditorEditModeToast : Toast
{
public LyricEditorEditModeToast(LyricEditorMode mode)
: base(getDescription(mode), getValue(mode), getShortcut())
: base(getDescription(), getValue(mode), getShortcut(mode))
{
}

private static LocalisableString getDescription(LyricEditorMode mode) =>
mode switch
{
LyricEditorMode.View => "View the lyric",
LyricEditorMode.Manage => "Manage the lyric",
LyricEditorMode.Typing => "Typing...",
LyricEditorMode.Language => "Manage the language in the lyric.",
LyricEditorMode.EditRuby => "Create/edit/delete the ruby",
LyricEditorMode.EditRomaji => "Create/edit/delete the romaji",
LyricEditorMode.EditTimeTag => "Create/edit/delete the time-tag.",
LyricEditorMode.EditNote => "Create the notes for scoring.",
LyricEditorMode.Singer => "Assign the singer to lyric.",
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null)
};
private static LocalisableString getDescription()
=> "Lyric editor";

private static LocalisableString getValue(LyricEditorMode mode)
=> mode.GetDescription();
=> $"{mode.GetDescription()} Mode";

private static LocalisableString getShortcut()
=> "Switch edit mode";
private static LocalisableString getShortcut(LyricEditorMode mode)
=> $"Switch to the {mode.GetDescription()} mode";
}
}
}

0 comments on commit 06e1917

Please sign in to comment.