2019-01-24 17:43:03 +09:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2016-10-26 18:45:48 +09:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-01-11 19:03:31 +09:00
|
|
|
|
using osu.Framework.Input;
|
2017-08-22 14:44:13 +09:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-03-30 19:42:40 +09:00
|
|
|
|
using osu.Framework.Input.Events;
|
2017-08-22 14:44:13 +09:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-03-03 19:08:35 +01:00
|
|
|
|
namespace osu.Game.Overlays.Volume
|
2016-10-26 18:45:48 +09:00
|
|
|
|
{
|
2019-08-27 18:42:49 +09:00
|
|
|
|
public class VolumeControlReceptor : Container, IScrollBindingHandler<GlobalAction>, IHandleGlobalKeyboardInput
|
2016-10-26 18:45:48 +09:00
|
|
|
|
{
|
2017-08-22 14:44:13 +09:00
|
|
|
|
public Func<GlobalAction, bool> ActionRequested;
|
2018-07-05 16:50:04 +09:00
|
|
|
|
public Func<GlobalAction, float, bool, bool> ScrollActionRequested;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-09-16 18:26:12 +09:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2021-04-14 13:10:45 +09:00
|
|
|
|
{
|
2021-09-16 18:26:12 +09:00
|
|
|
|
switch (e.Action)
|
2021-04-14 13:10:45 +09:00
|
|
|
|
{
|
|
|
|
|
case GlobalAction.DecreaseVolume:
|
|
|
|
|
case GlobalAction.IncreaseVolume:
|
|
|
|
|
case GlobalAction.ToggleMute:
|
2021-07-04 14:47:07 +02:00
|
|
|
|
case GlobalAction.NextVolumeMeter:
|
|
|
|
|
case GlobalAction.PreviousVolumeMeter:
|
2021-09-16 18:26:12 +09:00
|
|
|
|
ActionRequested?.Invoke(e.Action);
|
2021-04-14 13:10:45 +09:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 18:26:12 +09:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2021-04-14 13:10:45 +09:00
|
|
|
|
{
|
|
|
|
|
}
|
2020-03-02 18:59:38 +09:00
|
|
|
|
|
2021-03-30 19:42:40 +09:00
|
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
|
|
|
|
{
|
2021-04-18 23:50:09 +09:00
|
|
|
|
if (e.ScrollDelta.Y == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-03-30 19:42:40 +09:00
|
|
|
|
// forward any unhandled mouse scroll events to the volume control.
|
|
|
|
|
ScrollActionRequested?.Invoke(GlobalAction.IncreaseVolume, e.ScrollDelta.Y, e.IsPrecise);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 18:26:12 +09:00
|
|
|
|
public bool OnScroll(KeyBindingScrollEvent<GlobalAction> e) =>
|
|
|
|
|
ScrollActionRequested?.Invoke(e.Action, e.ScrollAmount, e.IsPrecise) ?? false;
|
2016-10-26 18:45:48 +09:00
|
|
|
|
}
|
|
|
|
|
}
|