1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:47:26 +08:00
osu-lazer/osu.Game/Overlays/VolumeOverlay.cs

148 lines
5.0 KiB
C#
Raw Normal View History

// 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;
2018-03-04 02:08:35 +08:00
using osu.Framework.Audio;
using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
2018-03-04 02:08:35 +08:00
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
2018-03-04 02:08:35 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Threading;
2018-03-04 02:08:35 +08:00
using osu.Game.Graphics;
using osu.Game.Input.Bindings;
2018-03-04 02:08:35 +08:00
using osu.Game.Overlays.Volume;
using OpenTK;
using OpenTK.Graphics;
2018-03-04 02:08:35 +08:00
namespace osu.Game.Overlays
{
2018-03-04 02:08:35 +08:00
public class VolumeOverlay : OverlayContainer
{
2018-03-04 02:08:35 +08:00
private const float offset = 10;
private VolumeMeter volumeMeterMaster;
private VolumeMeter volumeMeterEffect;
private VolumeMeter volumeMeterMusic;
private MuteButton muteButton;
protected override bool BlockPassThroughMouse => false;
2016-10-13 03:17:53 +08:00
2018-03-04 02:08:35 +08:00
private readonly BindableDouble muteAdjustment = new BindableDouble();
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours)
2016-10-22 16:50:42 +08:00
{
2018-03-04 02:25:34 +08:00
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
2018-03-04 02:08:35 +08:00
AddRange(new Drawable[]
{
2018-03-04 02:08:35 +08:00
new Box
{
RelativeSizeAxes = Axes.Y,
Width = 300,
2018-03-07 13:07:04 +08:00
Colour = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.75f), Color4.Black.Opacity(0))
2018-03-04 02:08:35 +08:00
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
2018-03-04 02:08:35 +08:00
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
2018-03-04 02:08:35 +08:00
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Spacing = new Vector2(0, offset),
Margin = new MarginPadding { Left = offset },
Children = new Drawable[]
{
2018-03-04 02:31:29 +08:00
volumeMeterEffect = new VolumeMeter("EFFECTS", 125, colours.BlueDarker)
{
2018-03-04 02:08:35 +08:00
Margin = new MarginPadding { Top = 100 + MuteButton.HEIGHT } //to counter the mute button and re-center the volume meters
},
2018-03-04 02:31:29 +08:00
volumeMeterMaster = new VolumeMeter("MASTER", 150, colours.PinkDarker),
volumeMeterMusic = new VolumeMeter("MUSIC", 125, colours.BlueDarker),
2018-03-04 02:08:35 +08:00
muteButton = new MuteButton
{
Margin = new MarginPadding { Top = 100 }
}
}
2018-03-04 02:08:35 +08:00
},
});
volumeMeterMaster.Bindable.BindTo(audio.Volume);
volumeMeterEffect.Bindable.BindTo(audio.VolumeSample);
volumeMeterMusic.Bindable.BindTo(audio.VolumeTrack);
muteButton.Current.ValueChanged += mute =>
{
if (mute)
audio.AddAdjustment(AdjustableProperty.Volume, muteAdjustment);
else
audio.RemoveAdjustment(AdjustableProperty.Volume, muteAdjustment);
};
2016-10-22 16:50:42 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
volumeMeterMaster.Bindable.ValueChanged += _ => settingChanged();
volumeMeterEffect.Bindable.ValueChanged += _ => settingChanged();
volumeMeterMusic.Bindable.ValueChanged += _ => settingChanged();
2018-03-04 02:08:35 +08:00
muteButton.Current.ValueChanged += _ => settingChanged();
}
private void settingChanged()
{
Show();
schedulePopOut();
2016-10-13 22:52:49 +08:00
}
public bool Adjust(GlobalAction action)
{
switch (action)
{
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-17 00:46:54 +08:00
case GlobalAction.ToggleMute:
Show();
2018-03-04 02:08:35 +08:00
muteButton.Current.Value = !muteButton.Current;
2018-01-17 00:46:54 +08:00
return true;
}
return false;
}
2017-03-07 09:59:19 +08:00
private ScheduledDelegate popOutDelegate;
protected override void PopIn()
{
2017-02-25 20:12:39 +08:00
ClearTransforms();
this.FadeIn(100);
schedulePopOut();
}
protected override void PopOut()
{
this.FadeOut(100);
}
private void schedulePopOut()
{
popOutDelegate?.Cancel();
this.Delay(1000).Schedule(Hide, out popOutDelegate);
}
}
}