2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-06-29 01:18:12 +08:00
|
|
|
|
// 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;
|
2017-12-30 19:45:41 +08:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using OpenTK;
|
2017-06-29 01:18:12 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
|
{
|
|
|
|
|
public class OsuFocusedOverlayContainer : FocusedOverlayContainer
|
|
|
|
|
{
|
|
|
|
|
private SampleChannel samplePopIn;
|
|
|
|
|
private SampleChannel samplePopOut;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
2017-11-25 22:11:18 +08:00
|
|
|
|
samplePopIn = audio.Sample.Get(@"UI/overlay-pop-in");
|
|
|
|
|
samplePopOut = audio.Sample.Get(@"UI/overlay-pop-out");
|
2017-06-29 01:18:12 +08:00
|
|
|
|
|
2017-09-04 08:10:04 +08:00
|
|
|
|
StateChanged += onStateChanged;
|
2017-06-29 01:18:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-30 19:45:41 +08:00
|
|
|
|
/// <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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDragStart(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (!base.ReceiveMouseInputAt(state.Mouse.NativeState.Position))
|
|
|
|
|
{
|
|
|
|
|
State = Visibility.Hidden;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnDragStart(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-30 20:10:40 +08:00
|
|
|
|
protected override bool OnDrag(InputState state) => State == Visibility.Hidden;
|
|
|
|
|
|
2017-09-04 08:10:04 +08:00
|
|
|
|
private void onStateChanged(Visibility visibility)
|
2017-06-29 01:18:12 +08:00
|
|
|
|
{
|
2017-09-04 08:10:04 +08:00
|
|
|
|
switch (visibility)
|
2017-06-29 01:18:12 +08:00
|
|
|
|
{
|
|
|
|
|
case Visibility.Visible:
|
|
|
|
|
samplePopIn?.Play();
|
|
|
|
|
break;
|
|
|
|
|
case Visibility.Hidden:
|
|
|
|
|
samplePopOut?.Play();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|