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