2017-02-07 12:59:30 +08:00
|
|
|
|
// 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;
|
2016-10-26 17:45:48 +08:00
|
|
|
|
using osu.Framework;
|
2016-10-12 22:36:42 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2016-10-07 02:05:26 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input;
|
2016-10-26 17:45:48 +08:00
|
|
|
|
using osu.Framework.Threading;
|
2016-10-13 01:45:42 +08:00
|
|
|
|
using OpenTK;
|
2016-11-15 00:22:20 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-11-23 19:26:46 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Allocation;
|
2016-10-07 02:05:26 +08:00
|
|
|
|
|
2016-10-26 17:45:48 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface.Volume
|
2016-10-07 02:05:26 +08:00
|
|
|
|
{
|
2016-10-26 17:45:48 +08:00
|
|
|
|
internal class VolumeControl : OverlayContainer
|
2016-10-07 02:05:26 +08:00
|
|
|
|
{
|
2016-10-26 17:45:48 +08:00
|
|
|
|
private VolumeMeter volumeMeterMaster;
|
|
|
|
|
|
2017-02-09 11:46:53 +08:00
|
|
|
|
protected override bool HideOnEscape => false;
|
|
|
|
|
|
2016-10-26 17:45:48 +08:00
|
|
|
|
private void volumeChanged(object sender, EventArgs e)
|
2016-10-13 03:17:53 +08:00
|
|
|
|
{
|
2016-10-26 17:45:48 +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;
|
2016-10-26 17:45:48 +08:00
|
|
|
|
Anchor = Anchor.BottomRight;
|
|
|
|
|
Origin = Anchor.BottomRight;
|
2016-11-13 01:34:36 +08:00
|
|
|
|
|
2016-11-23 15:12:21 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-11-13 01:34:36 +08:00
|
|
|
|
{
|
2016-11-23 15:12:21 +08:00
|
|
|
|
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 16:50:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 01:34:36 +08:00
|
|
|
|
protected override void LoadComplete()
|
2016-10-07 02:05:26 +08:00
|
|
|
|
{
|
2016-11-13 01:34:36 +08:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2016-11-29 17:35:40 +08:00
|
|
|
|
volumeMeterMaster.Bindable.ValueChanged += volumeChanged;
|
|
|
|
|
volumeMeterEffect.Bindable.ValueChanged += volumeChanged;
|
|
|
|
|
volumeMeterMusic.Bindable.ValueChanged += volumeChanged;
|
2016-10-07 02:05:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 14:22:14 +08:00
|
|
|
|
public void Adjust(InputState state)
|
2016-10-07 02:05:26 +08:00
|
|
|
|
{
|
2017-02-05 16:40:12 +08:00
|
|
|
|
if (State == Visibility.Hidden)
|
2016-11-15 14:22:14 +08:00
|
|
|
|
{
|
|
|
|
|
Show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-26 17:45:48 +08:00
|
|
|
|
|
2016-11-06 15:25:21 +08:00
|
|
|
|
volumeMeterMaster.TriggerWheel(state);
|
2016-10-07 02:05:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 19:26:46 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
2016-11-29 17:35:40 +08:00
|
|
|
|
volumeMeterMaster.Bindable.Weld(audio.Volume);
|
|
|
|
|
volumeMeterEffect.Bindable.Weld(audio.VolumeSample);
|
|
|
|
|
volumeMeterMusic.Bindable.Weld(audio.VolumeTrack);
|
2016-11-23 19:26:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 17:45:48 +08:00
|
|
|
|
ScheduledDelegate popOutDelegate;
|
|
|
|
|
|
2016-11-23 15:12:21 +08:00
|
|
|
|
private VolumeMeter volumeMeterEffect;
|
|
|
|
|
private VolumeMeter volumeMeterMusic;
|
|
|
|
|
|
2016-10-26 17:45:48 +08:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
ClearTransformations();
|
|
|
|
|
FadeIn(100);
|
|
|
|
|
|
|
|
|
|
schedulePopOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
FadeOut(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void schedulePopOut()
|
2016-10-07 02:05:26 +08:00
|
|
|
|
{
|
2016-10-26 17:45:48 +08:00
|
|
|
|
popOutDelegate?.Cancel();
|
|
|
|
|
Delay(1000);
|
|
|
|
|
popOutDelegate = Schedule(Hide);
|
2016-10-07 02:05:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|