1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 02:22:56 +08:00
osu-lazer/osu.Game/Graphics/Containers/OsuFocusedOverlayContainer.cs

114 lines
3.8 KiB
C#
Raw Normal View History

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 OpenTK;
using osu.Framework.Configuration;
using osu.Framework.Input.Bindings;
2018-07-21 10:38:28 +08:00
using osu.Framework.Input.States;
using osu.Game.Audio;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Graphics.Containers
{
public class OsuFocusedOverlayContainer : FocusedOverlayContainer, IPreviewTrackOwner, IKeyBindingHandler<GlobalAction>
2018-04-13 17:19:50 +08:00
{
private SampleChannel samplePopIn;
private SampleChannel samplePopOut;
protected virtual bool PlaySamplesOnStateChange => true;
2018-07-13 19:40:49 +08:00
protected override bool BlockPassThroughKeyboard => true;
private PreviewTrackManager previewTrackManager;
2018-07-13 19:40:49 +08:00
2018-06-06 14:49:27 +08:00
protected readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
2018-07-11 16:07:14 +08:00
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
2018-07-11 16:07:14 +08:00
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs<IPreviewTrackOwner>(this);
return dependencies;
}
[BackgroundDependencyLoader(true)]
private void load(OsuGame osuGame, AudioManager audio, PreviewTrackManager previewTrackManager)
2018-04-13 17:19:50 +08:00
{
this.previewTrackManager = previewTrackManager;
if (osuGame != null)
2018-06-06 14:49:27 +08:00
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
2018-04-13 17:19:50 +08:00
samplePopIn = audio.Sample.Get(@"UI/overlay-pop-in");
samplePopOut = audio.Sample.Get(@"UI/overlay-pop-out");
2018-06-29 17:33:28 +08:00
StateChanged += onStateChanged;
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>
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);
}
public virtual bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
State = Visibility.Hidden;
return true;
case GlobalAction.Select:
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => false;
2018-06-29 17:33:28 +08:00
private void onStateChanged(Visibility visibility)
2018-04-13 17:19:50 +08:00
{
2018-06-06 14:10:09 +08:00
switch (visibility)
{
2018-06-06 14:10:09 +08:00
case Visibility.Visible:
2018-06-06 14:49:27 +08:00
if (OverlayActivationMode != OverlayActivation.Disabled)
{
if (PlaySamplesOnStateChange) samplePopIn?.Play();
}
2018-06-06 14:10:09 +08:00
else
State = Visibility.Hidden;
break;
case Visibility.Hidden:
if (PlaySamplesOnStateChange) samplePopOut?.Play();
2018-06-06 14:10:09 +08:00
break;
2018-04-13 17:19:50 +08:00
}
}
protected override void PopOut()
{
base.PopOut();
previewTrackManager.StopAnyPlaying(this);
}
2018-04-13 17:19:50 +08:00
}
}