2019-09-11 16:34:28 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-07-01 14:52:47 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-06-21 15:19:07 +08:00
|
|
|
|
using osu.Game.Audio;
|
2018-07-01 14:52:47 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-05-28 19:43:47 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
|
{
|
2019-08-21 17:16:30 +08:00
|
|
|
|
[Cached(typeof(IPreviewTrackOwner))]
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public abstract partial class OsuFocusedOverlayContainer : FocusedOverlayContainer, IPreviewTrackOwner, IKeyBindingHandler<GlobalAction>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-01-19 16:11:40 +08:00
|
|
|
|
private Sample samplePopIn;
|
|
|
|
|
private Sample samplePopOut;
|
2021-01-15 13:53:29 +08:00
|
|
|
|
protected virtual string PopInSampleName => "UI/overlay-pop-in";
|
|
|
|
|
protected virtual string PopOutSampleName => "UI/overlay-pop-out";
|
2023-08-17 10:37:07 +08:00
|
|
|
|
protected virtual double PopInOutSampleBalance => 0;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
protected override bool BlockNonPositionalInput => true;
|
2018-07-13 19:40:49 +08:00
|
|
|
|
|
2019-03-02 13:48:05 +08:00
|
|
|
|
/// <summary>
|
2021-05-03 14:08:34 +08:00
|
|
|
|
/// Temporary to allow for overlays in the main screen content to not dim themselves.
|
2019-03-02 13:48:05 +08:00
|
|
|
|
/// Should be eventually replaced by dimming which is aware of the target dim container (traverse parent for certain interface type?).
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual bool DimMainContent => true;
|
|
|
|
|
|
2019-03-01 11:20:31 +08:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
2022-05-05 21:47:10 +08:00
|
|
|
|
private IOverlayManager overlayManager { get; set; }
|
2019-03-01 11:20:31 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private PreviewTrackManager previewTrackManager { get; set; }
|
2018-06-21 15:19:07 +08:00
|
|
|
|
|
2020-08-28 02:07:24 +08:00
|
|
|
|
protected readonly IBindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
|
2018-05-18 13:57:12 +08:00
|
|
|
|
|
2018-05-20 16:57:15 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2019-03-01 11:20:31 +08:00
|
|
|
|
private void load(AudioManager audio)
|
2019-09-11 18:06:31 +08:00
|
|
|
|
{
|
2021-01-15 13:53:29 +08:00
|
|
|
|
samplePopIn = audio.Samples.Get(PopInSampleName);
|
|
|
|
|
samplePopOut = audio.Samples.Get(PopOutSampleName);
|
2019-09-11 18:06:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2022-05-05 21:47:10 +08:00
|
|
|
|
if (overlayManager != null)
|
|
|
|
|
OverlayActivationMode.BindTo(overlayManager.OverlayActivationMode);
|
2019-09-11 18:12:55 +08:00
|
|
|
|
|
|
|
|
|
OverlayActivationMode.BindValueChanged(mode =>
|
2019-09-11 16:34:28 +08:00
|
|
|
|
{
|
|
|
|
|
if (mode.NewValue == OverlayActivation.Disabled)
|
|
|
|
|
State.Value = Visibility.Hidden;
|
2019-09-11 18:12:55 +08:00
|
|
|
|
}, true);
|
2018-05-21 15:42:29 +08:00
|
|
|
|
|
2019-09-11 18:06:31 +08:00
|
|
|
|
base.LoadComplete();
|
2019-07-26 18:00:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether mouse input should be blocked screen-wide while this overlay is visible.
|
2018-06-15 16:07:07 +08:00
|
|
|
|
/// Performing mouse actions outside of the valid extents will hide the overlay.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// </summary>
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public virtual bool BlockScreenWideMouse => BlockPositionalInput;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
// receive input outside our bounds so we can trigger a close event on ourselves.
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => BlockScreenWideMouse || base.ReceivePositionalInputAt(screenSpacePos);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-02 04:02:47 +08:00
|
|
|
|
private bool closeOnMouseUp;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-02 04:02:47 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2019-08-29 11:07:58 +08:00
|
|
|
|
{
|
2019-12-02 04:54:37 +08:00
|
|
|
|
closeOnMouseUp = !base.ReceivePositionalInputAt(e.ScreenSpaceMousePosition);
|
2019-09-06 17:27:54 +08:00
|
|
|
|
|
2019-12-02 04:02:47 +08:00
|
|
|
|
return base.OnMouseDown(e);
|
2019-08-29 11:07:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
2019-08-29 11:07:58 +08:00
|
|
|
|
{
|
2019-12-02 04:02:47 +08:00
|
|
|
|
if (closeOnMouseUp && !base.ReceivePositionalInputAt(e.ScreenSpaceMousePosition))
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Hide();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
|
base.OnMouseUp(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-11 00:30:42 +08:00
|
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
|
|
|
|
{
|
|
|
|
|
// allow for controlling volume when alt is held.
|
|
|
|
|
// mostly for compatibility with osu-stable.
|
|
|
|
|
if (e.AltPressed) return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2018-07-01 14:52:47 +08:00
|
|
|
|
{
|
2021-11-18 11:35:47 +08:00
|
|
|
|
if (e.Repeat)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
switch (e.Action)
|
2018-07-01 14:52:47 +08:00
|
|
|
|
{
|
2018-07-13 19:37:49 +08:00
|
|
|
|
case GlobalAction.Back:
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Hide();
|
2018-07-13 19:37:49 +08:00
|
|
|
|
return true;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2018-07-13 19:37:49 +08:00
|
|
|
|
case GlobalAction.Select:
|
|
|
|
|
return true;
|
2018-07-01 14:52:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2020-01-22 12:22:34 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-07-01 14:52:47 +08:00
|
|
|
|
|
2019-08-06 13:21:34 +08:00
|
|
|
|
protected override void UpdateState(ValueChangedEvent<Visibility> state)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2021-06-11 23:26:33 +08:00
|
|
|
|
bool didChange = state.NewValue != state.OldValue;
|
|
|
|
|
|
2019-06-11 13:28:52 +08:00
|
|
|
|
switch (state.NewValue)
|
2018-05-20 16:57:15 +08:00
|
|
|
|
{
|
2018-06-06 14:10:09 +08:00
|
|
|
|
case Visibility.Visible:
|
2019-09-11 16:34:03 +08:00
|
|
|
|
if (OverlayActivationMode.Value == OverlayActivation.Disabled)
|
2018-06-21 15:47:05 +08:00
|
|
|
|
{
|
2020-09-09 17:07:58 +08:00
|
|
|
|
// todo: visual/audible feedback that this operation could not complete.
|
2019-09-11 16:34:03 +08:00
|
|
|
|
State.Value = Visibility.Hidden;
|
|
|
|
|
return;
|
2018-06-21 15:47:05 +08:00
|
|
|
|
}
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2023-08-17 10:37:07 +08:00
|
|
|
|
if (didChange && samplePopIn != null)
|
|
|
|
|
{
|
|
|
|
|
samplePopIn.Balance.Value = PopInOutSampleBalance;
|
|
|
|
|
samplePopIn.Play();
|
|
|
|
|
}
|
2020-09-09 17:05:44 +08:00
|
|
|
|
|
2022-05-05 21:47:10 +08:00
|
|
|
|
if (BlockScreenWideMouse && DimMainContent) overlayManager?.ShowBlockingOverlay(this);
|
2018-06-06 14:10:09 +08:00
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2018-06-06 14:10:09 +08:00
|
|
|
|
case Visibility.Hidden:
|
2023-08-17 10:37:07 +08:00
|
|
|
|
if (didChange && samplePopOut != null)
|
|
|
|
|
{
|
|
|
|
|
samplePopOut.Balance.Value = PopInOutSampleBalance;
|
|
|
|
|
samplePopOut.Play();
|
|
|
|
|
}
|
2020-09-09 17:05:44 +08:00
|
|
|
|
|
2022-05-05 21:47:10 +08:00
|
|
|
|
if (BlockScreenWideMouse) overlayManager?.HideBlockingOverlay(this);
|
2018-06-06 14:10:09 +08:00
|
|
|
|
break;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2019-09-11 16:34:03 +08:00
|
|
|
|
|
|
|
|
|
base.UpdateState(state);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-06-21 15:19:07 +08:00
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2018-06-22 11:35:43 +08:00
|
|
|
|
previewTrackManager.StopAnyPlaying(this);
|
2018-06-21 15:19:07 +08:00
|
|
|
|
}
|
2019-03-01 11:20:31 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
2022-05-05 21:47:10 +08:00
|
|
|
|
overlayManager?.HideBlockingOverlay(this);
|
2019-03-01 11:20:31 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|