2018-04-13 17:19:50 +08: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 13:57:12 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
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
|
|
|
|
|
{
|
|
|
|
|
public class OsuFocusedOverlayContainer : FocusedOverlayContainer
|
|
|
|
|
{
|
|
|
|
|
private SampleChannel samplePopIn;
|
|
|
|
|
private SampleChannel samplePopOut;
|
|
|
|
|
|
2018-05-28 19:43:47 +08:00
|
|
|
|
private readonly Bindable<OverlayActivation> allowOverlays = new Bindable<OverlayActivation>(OverlayActivation.All);
|
2018-05-18 13:57:12 +08:00
|
|
|
|
|
2018-05-20 16:57:15 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2018-05-18 13:57:12 +08:00
|
|
|
|
private void load(OsuGame osuGame, AudioManager audio)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-05-21 15:42:29 +08:00
|
|
|
|
if (osuGame != null)
|
2018-05-28 19:43:47 +08:00
|
|
|
|
allowOverlays.BindTo(osuGame.AllowOverlays);
|
2018-05-21 15:42:29 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
samplePopIn = audio.Sample.Get(@"UI/overlay-pop-in");
|
|
|
|
|
samplePopOut = audio.Sample.Get(@"UI/overlay-pop-out");
|
|
|
|
|
|
|
|
|
|
StateChanged += onStateChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether mouse input should be blocked screen-wide while this overlay is visible.
|
|
|
|
|
/// Performing mouse actions outside of the valid extents will hide the overlay but pass the events through.
|
|
|
|
|
/// </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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onStateChanged(Visibility visibility)
|
|
|
|
|
{
|
2018-05-28 19:43:47 +08:00
|
|
|
|
if (allowOverlays == OverlayActivation.All)
|
2018-05-20 16:57:15 +08:00
|
|
|
|
{
|
2018-05-21 15:42:29 +08:00
|
|
|
|
switch (visibility)
|
|
|
|
|
{
|
|
|
|
|
case Visibility.Visible:
|
|
|
|
|
samplePopIn?.Play();
|
|
|
|
|
break;
|
|
|
|
|
case Visibility.Hidden:
|
|
|
|
|
samplePopOut?.Play();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-05-21 15:42:29 +08:00
|
|
|
|
else
|
|
|
|
|
State = Visibility.Hidden;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|