2018-04-13 09:19:50 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using OpenTK;
|
2018-05-18 05:57:12 +00:00
|
|
|
|
using osu.Framework.Configuration;
|
2018-06-21 07:19:07 +00:00
|
|
|
|
using osu.Game.Audio;
|
2018-05-28 11:43:47 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
|
{
|
2018-06-21 07:19:07 +00:00
|
|
|
|
public class OsuFocusedOverlayContainer : FocusedOverlayContainer, IPreviewTrackOwner
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
private SampleChannel samplePopIn;
|
|
|
|
|
private SampleChannel samplePopOut;
|
|
|
|
|
|
2018-06-21 07:47:05 +00:00
|
|
|
|
protected virtual bool PlaySamplesOnStateChange => true;
|
|
|
|
|
|
2018-06-21 07:19:07 +00:00
|
|
|
|
private PreviewTrackManager previewTrackManager;
|
|
|
|
|
|
2018-06-06 06:49:27 +00:00
|
|
|
|
protected readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
|
2018-05-18 05:57:12 +00:00
|
|
|
|
|
2018-06-21 07:19:07 +00:00
|
|
|
|
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
|
{
|
|
|
|
|
var dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
|
|
|
|
|
dependencies.CacheAs<IPreviewTrackOwner>(this);
|
|
|
|
|
return dependencies;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-20 08:57:15 +00:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2018-06-21 07:19:07 +00:00
|
|
|
|
private void load(OsuGame osuGame, AudioManager audio, PreviewTrackManager previewTrackManager)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-06-21 07:19:07 +00:00
|
|
|
|
this.previewTrackManager = previewTrackManager;
|
|
|
|
|
|
2018-05-21 07:42:29 +00:00
|
|
|
|
if (osuGame != null)
|
2018-06-06 06:49:27 +00:00
|
|
|
|
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
|
2018-05-21 07:42:29 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
samplePopIn = audio.Sample.Get(@"UI/overlay-pop-in");
|
|
|
|
|
samplePopOut = audio.Sample.Get(@"UI/overlay-pop-out");
|
|
|
|
|
|
2018-06-29 09:33:28 +00:00
|
|
|
|
StateChanged += onStateChanged;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether mouse input should be blocked screen-wide while this overlay is visible.
|
2018-06-15 08:07:07 +00:00
|
|
|
|
/// Performing mouse actions outside of the valid extents will hide the overlay.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual bool BlockScreenWideMouse => BlockPassThroughMouse;
|
|
|
|
|
|
|
|
|
|
// receive input outside our bounds so we can trigger a close event on ourselves.
|
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => BlockScreenWideMouse || base.ReceiveMouseInputAt(screenSpacePos);
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (!base.ReceiveMouseInputAt(state.Mouse.NativeState.Position))
|
|
|
|
|
{
|
|
|
|
|
State = Visibility.Hidden;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnClick(state);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-29 09:33:28 +00:00
|
|
|
|
private void onStateChanged(Visibility visibility)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-06-06 06:10:09 +00:00
|
|
|
|
switch (visibility)
|
2018-05-20 08:57:15 +00:00
|
|
|
|
{
|
2018-06-06 06:10:09 +00:00
|
|
|
|
case Visibility.Visible:
|
2018-06-06 06:49:27 +00:00
|
|
|
|
if (OverlayActivationMode != OverlayActivation.Disabled)
|
2018-06-21 07:47:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (PlaySamplesOnStateChange) samplePopIn?.Play();
|
|
|
|
|
}
|
2018-06-06 06:10:09 +00:00
|
|
|
|
else
|
|
|
|
|
State = Visibility.Hidden;
|
|
|
|
|
break;
|
|
|
|
|
case Visibility.Hidden:
|
2018-06-21 07:47:05 +00:00
|
|
|
|
if (PlaySamplesOnStateChange) samplePopOut?.Play();
|
2018-06-06 06:10:09 +00:00
|
|
|
|
break;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-21 07:19:07 +00:00
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
base.PopOut();
|
2018-06-22 03:35:43 +00:00
|
|
|
|
previewTrackManager.StopAnyPlaying(this);
|
2018-06-21 07:19:07 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|