osu/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs

115 lines
3.4 KiB
C#
Raw Normal View History

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