2018-01-05 11:21:19 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 04:59:30 +00:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 09:56:20 +00:00
|
|
|
|
|
2016-10-06 18:05:26 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-10-26 09:45:48 +00:00
|
|
|
|
using osu.Framework.Threading;
|
2016-10-12 17:45:42 +00:00
|
|
|
|
using OpenTK;
|
2016-11-23 11:26:46 +00:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Allocation;
|
2018-01-17 16:15:13 +00:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-08-22 05:44:13 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2016-10-06 18:05:26 +00:00
|
|
|
|
|
2016-10-26 09:45:48 +00:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface.Volume
|
2016-10-06 18:05:26 +00:00
|
|
|
|
{
|
2017-11-21 02:49:42 +00:00
|
|
|
|
public class VolumeControl : OverlayContainer
|
2016-10-06 18:05:26 +00:00
|
|
|
|
{
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly VolumeMeter volumeMeterMaster;
|
2018-01-17 19:43:08 +00:00
|
|
|
|
private readonly IconButton muteIcon;
|
2016-10-26 09:45:48 +00:00
|
|
|
|
|
2017-09-10 23:27:29 +00:00
|
|
|
|
protected override bool BlockPassThroughMouse => false;
|
2016-10-12 19:17:53 +00:00
|
|
|
|
|
2016-10-22 08:50:42 +00:00
|
|
|
|
public VolumeControl()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2016-10-26 09:45:48 +00:00
|
|
|
|
Anchor = Anchor.BottomRight;
|
|
|
|
|
Origin = Anchor.BottomRight;
|
2016-11-12 17:34:36 +00:00
|
|
|
|
|
2016-11-23 07:12:21 +00:00
|
|
|
|
Children = new Drawable[]
|
2016-11-12 17:34:36 +00:00
|
|
|
|
{
|
2017-03-01 18:33:01 +00:00
|
|
|
|
new FillFlowContainer
|
2016-11-23 07:12:21 +00:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
Margin = new MarginPadding { Left = 10, Right = 10, Top = 30, Bottom = 30 },
|
2017-03-01 18:33:01 +00:00
|
|
|
|
Spacing = new Vector2(15, 0),
|
2016-11-23 07:12:21 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-01-31 08:36:53 +00:00
|
|
|
|
new Container
|
2018-01-17 20:09:46 +00:00
|
|
|
|
{
|
2018-01-31 08:36:53 +00:00
|
|
|
|
Size = new Vector2(IconButton.BUTTON_SIZE),
|
|
|
|
|
Child = muteIcon = new IconButton
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Icon = FontAwesome.fa_volume_up,
|
|
|
|
|
Action = () => Adjust(GlobalAction.ToggleMute),
|
|
|
|
|
}
|
2018-01-17 20:09:46 +00:00
|
|
|
|
},
|
2016-11-23 07:12:21 +00:00
|
|
|
|
volumeMeterMaster = new VolumeMeter("Master"),
|
|
|
|
|
volumeMeterEffect = new VolumeMeter("Effects"),
|
|
|
|
|
volumeMeterMusic = new VolumeMeter("Music")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-10-22 08:50:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 17:34:36 +00:00
|
|
|
|
protected override void LoadComplete()
|
2016-10-06 18:05:26 +00:00
|
|
|
|
{
|
2016-11-12 17:34:36 +00:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2018-01-31 09:00:44 +00:00
|
|
|
|
volumeMeterMaster.Bindable.ValueChanged += _ => settingChanged();
|
|
|
|
|
volumeMeterEffect.Bindable.ValueChanged += _ => settingChanged();
|
|
|
|
|
volumeMeterMusic.Bindable.ValueChanged += _ => settingChanged();
|
|
|
|
|
muted.ValueChanged += _ => settingChanged();
|
2016-10-13 14:52:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 05:44:13 +00:00
|
|
|
|
public bool Adjust(GlobalAction action)
|
2016-10-06 18:05:26 +00:00
|
|
|
|
{
|
2017-08-22 05:44:13 +00:00
|
|
|
|
switch (action)
|
2016-11-15 06:22:14 +00:00
|
|
|
|
{
|
2017-08-22 05:44:13 +00:00
|
|
|
|
case GlobalAction.DecreaseVolume:
|
|
|
|
|
if (State == Visibility.Hidden)
|
|
|
|
|
Show();
|
|
|
|
|
else
|
|
|
|
|
volumeMeterMaster.Decrease();
|
|
|
|
|
return true;
|
|
|
|
|
case GlobalAction.IncreaseVolume:
|
|
|
|
|
if (State == Visibility.Hidden)
|
|
|
|
|
Show();
|
|
|
|
|
else
|
|
|
|
|
volumeMeterMaster.Increase();
|
|
|
|
|
return true;
|
2018-01-16 16:46:54 +00:00
|
|
|
|
case GlobalAction.ToggleMute:
|
2018-01-20 10:45:04 +00:00
|
|
|
|
Show();
|
2018-01-31 07:56:26 +00:00
|
|
|
|
muted.Toggle();
|
2018-01-16 16:46:54 +00:00
|
|
|
|
return true;
|
2016-11-15 06:22:14 +00:00
|
|
|
|
}
|
2016-10-26 09:45:48 +00:00
|
|
|
|
|
2017-08-22 05:44:13 +00:00
|
|
|
|
return false;
|
2016-10-06 18:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 09:00:44 +00:00
|
|
|
|
private void settingChanged()
|
2017-09-10 23:27:29 +00:00
|
|
|
|
{
|
|
|
|
|
Show();
|
|
|
|
|
schedulePopOut();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 09:00:44 +00:00
|
|
|
|
private readonly BindableDouble muteAdjustment = new BindableDouble();
|
2018-01-17 16:15:13 +00:00
|
|
|
|
|
2018-01-18 16:23:02 +00:00
|
|
|
|
private readonly BindableBool muted = new BindableBool();
|
|
|
|
|
|
2016-11-23 11:26:46 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
2017-02-27 03:24:50 +00:00
|
|
|
|
volumeMeterMaster.Bindable.BindTo(audio.Volume);
|
|
|
|
|
volumeMeterEffect.Bindable.BindTo(audio.VolumeSample);
|
|
|
|
|
volumeMeterMusic.Bindable.BindTo(audio.VolumeTrack);
|
2018-01-18 16:23:02 +00:00
|
|
|
|
|
|
|
|
|
muted.ValueChanged += mute =>
|
|
|
|
|
{
|
|
|
|
|
if (mute)
|
2018-01-20 10:45:04 +00:00
|
|
|
|
{
|
2018-01-31 09:00:44 +00:00
|
|
|
|
audio.AddAdjustment(AdjustableProperty.Volume, muteAdjustment);
|
2018-01-20 10:45:04 +00:00
|
|
|
|
muteIcon.Icon = FontAwesome.fa_volume_off;
|
|
|
|
|
}
|
2018-01-18 16:23:02 +00:00
|
|
|
|
else
|
2018-01-20 10:45:04 +00:00
|
|
|
|
{
|
2018-01-31 09:00:44 +00:00
|
|
|
|
audio.RemoveAdjustment(AdjustableProperty.Volume, muteAdjustment);
|
2018-01-20 10:45:04 +00:00
|
|
|
|
muteIcon.Icon = FontAwesome.fa_volume_up;
|
|
|
|
|
}
|
2018-01-18 16:23:02 +00:00
|
|
|
|
};
|
2016-11-23 11:26:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 01:59:19 +00:00
|
|
|
|
private ScheduledDelegate popOutDelegate;
|
2016-10-26 09:45:48 +00:00
|
|
|
|
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly VolumeMeter volumeMeterEffect;
|
|
|
|
|
private readonly VolumeMeter volumeMeterMusic;
|
2016-11-23 07:12:21 +00:00
|
|
|
|
|
2016-10-26 09:45:48 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
2017-02-25 12:12:39 +00:00
|
|
|
|
ClearTransforms();
|
2017-07-14 16:18:12 +00:00
|
|
|
|
this.FadeIn(100);
|
2016-10-26 09:45:48 +00:00
|
|
|
|
|
|
|
|
|
schedulePopOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2017-07-14 16:18:12 +00:00
|
|
|
|
this.FadeOut(100);
|
2016-10-26 09:45:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void schedulePopOut()
|
2016-10-06 18:05:26 +00:00
|
|
|
|
{
|
2016-10-26 09:45:48 +00:00
|
|
|
|
popOutDelegate?.Cancel();
|
2017-07-17 13:51:21 +00:00
|
|
|
|
this.Delay(1000).Schedule(Hide, out popOutDelegate);
|
2016-10-06 18:05:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-21 02:49:42 +00:00
|
|
|
|
}
|