Skip to content

Commit

Permalink
Merge pull request #2218 from andy840119/fix-import-lyric-dim-issue
Browse files Browse the repository at this point in the history
Fix import screen loading weird in the production.
  • Loading branch information
andy840119 authored Apr 14, 2024
2 parents 07a604f + a15ee2d commit 3a83d29
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private static void openLyricImporter(IScreen? screen, IImportBeatmapChangeHandl
return;

var importer = new LyricImporter();
importer.OnImportFinished += importBeatmapChangeHandler.Import;
importer.OnImportFinished = importBeatmapChangeHandler.Import;
screen.Push(importer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Screens;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Beatmaps;
Expand Down Expand Up @@ -135,4 +137,18 @@ protected override MenuItem[] GenerateMenuItems(KaraokeBeatmapEditorScreenMode s
_ => Array.Empty<MenuItem>(),
};
}

public override void OnSuspending(ScreenTransitionEvent e)
{
// add fade-in/out effect for the lyric importer.
this.FadeOutFromOne(250);
base.OnSuspending(e);
}

public override void OnResuming(ScreenTransitionEvent e)
{
// add fade-in/out effect for the lyric importer.
base.OnResuming(e);
this.FadeInFromZero(250, Easing.OutQuint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ protected override void ApplyCaretPosition(CreateRubyTagCaretPosition caret)

// should not continuous showing the caret position if move the caret by keyboard.
if (Type == DrawableCaretType.Caret)
this.HidePopover();
{
// todo: should wait until layer is attached to the parent.
// use quick way to fix this because it will cause crash if open the
Schedule(this.HidePopover);
}
}

protected override bool OnClick(ClickEvent e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Configuration;
Expand All @@ -18,10 +20,10 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Import.Lyrics;
[Cached(typeof(IImportStateResolver))]
public partial class ImportLyricOverlay : FullscreenOverlay<ImportLyricHeader>, IImportStateResolver
{
public Action? OnImportCancelled;

public Action<IBeatmap>? OnImportFinished;

public Action? OverlayClosed;

[Cached]
protected LyricImporterSubScreenStack ScreenStack { get; private set; }

Expand All @@ -40,6 +42,8 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl

public bool IsFirstStep() => ScreenStack.IsFirstStep();

protected override bool DimMainContent => false;

public ImportLyricOverlay()
: base(OverlayColourScheme.Pink)
{
Expand Down Expand Up @@ -106,13 +110,47 @@ private void load()

protected override ImportLyricHeader CreateHeader() => new();

public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat)
return false;

switch (e.Action)
{
case GlobalAction.Back:
if (!IsFirstStep())
{
// go to previous step.
ScreenStack.Pop();
}
else
{
Cancel();
}

return true;

default:
return base.OnPressed(e);
}
}

public void Cancel()
{
OnImportCancelled?.Invoke();
Hide();
}

public void Finish()
{
OnImportFinished?.Invoke(editorBeatmap);
Hide();
}

protected override void PopOutComplete()
{
if (LoadState < LoadState.Ready)
return;

OverlayClosed?.Invoke();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Input.Bindings;
using osu.Game.Screens.Play;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Import.Lyrics;

public partial class LyricImporter : ScreenWithBeatmapBackground, IKeyBindingHandler<GlobalAction>
public partial class LyricImporter : ScreenWithBeatmapBackground
{
private readonly ImportLyricOverlay importLyricOverlay;

// Hide the back button because we cannot show it only in the first step.
public override bool AllowBackButton => false;

public event Action<IBeatmap>? OnImportFinished;
public override bool HideOverlaysOnEnter => true;

public override bool DisallowExternalBeatmapRulesetChanges => true;

public override bool? ApplyModTrackAdjustments => false;

public Action<IBeatmap>? OnImportFinished;

public LyricImporter()
{
InternalChild = importLyricOverlay = new ImportLyricOverlay
{
OnImportCancelled = this.Exit,
OnImportFinished = b =>
{
this.Exit();
OnImportFinished?.Invoke(b);
},
OverlayClosed = this.Exit,
};
}

Expand All @@ -38,34 +39,4 @@ protected override void LoadComplete()
base.LoadComplete();
importLyricOverlay.Show();
}

public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat)
return false;

switch (e.Action)
{
case GlobalAction.Back:
if (importLyricOverlay.IsFirstStep())
{
// the better UX behavior should be move to the previous step.
// But it will not asking.
return false;

// todo: implement.
// ScreenStack.Exit();
}

this.Exit();
return true;

default:
return false;
}
}

public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// 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 System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Screens;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Import.Lyrics.AssignLanguage;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Import.Lyrics.DragFile;
Expand Down Expand Up @@ -78,6 +80,12 @@ public void Pop(IScreen screen)
}
}

public void Pop()
{
stack.Pop();
stack.Peek().MakeCurrent();
}

public bool IsFirstStep()
{
return CurrentStep == LyricImporterStep.ImportLyric;
Expand Down
9 changes: 3 additions & 6 deletions osu.Game.Rulesets.Karaoke/UI/KaraokeSettingsSubsection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ public KaraokeSettingsSubsection(Ruleset ruleset)
{
}

[Resolved]
protected OsuGame Game { get; private set; } = null!;

private KaraokeChangelogOverlay? changelogOverlay;

[BackgroundDependencyLoader]
private void load(IPerformFromScreenRunner performer)
private void load(OsuGame game, IPerformFromScreenRunner performer)
{
var config = (KaraokeRulesetConfigManager)Config;

Expand Down Expand Up @@ -80,8 +77,8 @@ private void load(IPerformFromScreenRunner performer)
{
try
{
var displayContainer = Game.GetChangelogPlacementContainer();
var settingOverlay = Game.GetSettingsOverlay();
var displayContainer = game.GetChangelogPlacementContainer();
var settingOverlay = game.GetSettingsOverlay();
if (displayContainer == null)
return;

Expand Down

0 comments on commit 3a83d29

Please sign in to comment.