1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs

115 lines
3.4 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-12-06 17:56:20 +08:00
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Threading;
using OpenTK;
using osu.Framework.Graphics.Primitives;
2016-11-23 19:26:46 +08:00
using osu.Framework.Audio;
using osu.Framework.Allocation;
namespace osu.Game.Graphics.UserInterface.Volume
{
internal class VolumeControl : OverlayContainer
{
private VolumeMeter volumeMeterMaster;
protected override bool HideOnEscape => false;
private void volumeChanged(object sender, EventArgs e)
2016-10-13 03:17:53 +08:00
{
Show();
schedulePopOut();
2016-10-13 03:17:53 +08:00
}
2016-10-22 16:50:42 +08:00
public VolumeControl()
{
AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomRight;
Origin = Anchor.BottomRight;
Children = new Drawable[]
{
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding { Left = 10, Right = 10, Top = 30, Bottom = 30 },
2017-03-02 02:33:01 +08:00
Spacing = new Vector2(15, 0),
Children = new Drawable[]
{
volumeMeterMaster = new VolumeMeter("Master"),
volumeMeterEffect = new VolumeMeter("Effects"),
volumeMeterMusic = new VolumeMeter("Music")
}
}
};
2016-10-22 16:50:42 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2016-11-29 17:35:40 +08:00
volumeMeterMaster.Bindable.ValueChanged += volumeChanged;
volumeMeterEffect.Bindable.ValueChanged += volumeChanged;
volumeMeterMusic.Bindable.ValueChanged += volumeChanged;
}
2016-10-13 22:52:49 +08:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
2016-11-29 17:35:40 +08:00
volumeMeterMaster.Bindable.ValueChanged -= volumeChanged;
volumeMeterEffect.Bindable.ValueChanged -= volumeChanged;
volumeMeterMusic.Bindable.ValueChanged -= volumeChanged;
2016-10-13 22:52:49 +08:00
}
public void Adjust(InputState state)
{
if (State == Visibility.Hidden)
{
Show();
return;
}
volumeMeterMaster.TriggerWheel(state);
}
2016-11-23 19:26:46 +08:00
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
2017-02-27 11:24:50 +08:00
volumeMeterMaster.Bindable.BindTo(audio.Volume);
volumeMeterEffect.Bindable.BindTo(audio.VolumeSample);
volumeMeterMusic.Bindable.BindTo(audio.VolumeTrack);
2016-11-23 19:26:46 +08:00
}
ScheduledDelegate popOutDelegate;
private VolumeMeter volumeMeterEffect;
private VolumeMeter volumeMeterMusic;
protected override void PopIn()
{
2017-02-25 20:12:39 +08:00
ClearTransforms();
FadeIn(100);
schedulePopOut();
}
protected override void PopOut()
{
FadeOut(100);
}
private void schedulePopOut()
{
popOutDelegate?.Cancel();
Delay(1000);
popOutDelegate = Schedule(Hide);
}
}
}