1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 15:33:21 +08:00

Change volume in VolumeMeter

This commit is contained in:
TocoToucan 2016-10-10 17:19:05 +03:00
parent 89d7de31ee
commit f3c1c60ab7
2 changed files with 37 additions and 53 deletions

View File

@ -2,7 +2,6 @@
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Graphics.Transformations;
using OpenTK; using OpenTK;
namespace osu.Game namespace osu.Game
@ -10,10 +9,6 @@ namespace osu.Game
internal class VolumeControl : Container internal class VolumeControl : Container
{ {
private FlowContainer volumeMetersContainer; private FlowContainer volumeMetersContainer;
private VolumeMeter VolumeMeterGlobal;
private VolumeMeter VolumeMeterSample;
private VolumeMeter VolumeMeterTrack;
public BindableDouble VolumeGlobal { get; set; } public BindableDouble VolumeGlobal { get; set; }
public BindableDouble VolumeSample { get; set; } public BindableDouble VolumeSample { get; set; }
public BindableDouble VolumeTrack { get; set; } public BindableDouble VolumeTrack { get; set; }
@ -28,75 +23,35 @@ namespace osu.Game
base.Load(); base.Load();
Children = new Drawable[] Children = new Drawable[]
{ {
volumeMetersContainer = new FlowContainer() { volumeMetersContainer = new FlowContainer
{
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight, Origin = Anchor.BottomRight,
Position = new Vector2(10, 30), Position = new Vector2(10, 30),
Alpha = 0, Alpha = 0,
Padding = new Vector2(15,0), Padding = new Vector2(15, 0),
Children = new Drawable[] Children = new Drawable[]
{ {
VolumeMeterGlobal = new VolumeMeter("Master"), new VolumeMeter("Master", VolumeGlobal),
VolumeMeterSample= new VolumeMeter("Effects"), new VolumeMeter("Effects", VolumeSample),
VolumeMeterTrack= new VolumeMeter("Music") new VolumeMeter("Music", VolumeTrack)
} }
} }
}; };
updateFill();
} }
protected override bool OnWheelDown(InputState state) protected override bool OnWheelDown(InputState state)
{ {
appear(); appear();
if (VolumeMeterSample.Contains(state.Mouse.Position))
{
VolumeSample.Value -= 0.05f;
}
else if (VolumeMeterTrack.Contains(state.Mouse.Position))
{
VolumeTrack.Value -= 0.05f;
}
else
{
VolumeGlobal.Value -= 0.05f;
}
updateFill();
return base.OnWheelDown(state); return base.OnWheelDown(state);
} }
protected override bool OnWheelUp(InputState state) protected override bool OnWheelUp(InputState state)
{ {
appear(); appear();
if (VolumeMeterSample.Contains(state.Mouse.Position))
{
VolumeSample.Value += 0.05f;
}
else if (VolumeMeterTrack.Contains(state.Mouse.Position))
{
VolumeTrack.Value += 0.05f;
}
else
{
VolumeGlobal.Value += 0.05f;
}
updateFill();
return base.OnWheelUp(state); return base.OnWheelUp(state);
} }
private void updateFill()
{
VolumeMeterGlobal.MeterFill.ScaleTo(new Vector2(1, (float)VolumeGlobal.Value), 300, EasingTypes.OutQuint);
VolumeMeterSample.MeterFill.ScaleTo(new Vector2(1, (float)VolumeSample.Value), 300, EasingTypes.OutQuint);
VolumeMeterTrack.MeterFill.ScaleTo(new Vector2(1, (float)VolumeTrack.Value), 300, EasingTypes.OutQuint);
}
private void appear() private void appear()
{ {
volumeMetersContainer.ClearTransformations(); volumeMetersContainer.ClearTransformations();

View File

@ -1,7 +1,10 @@
using osu.Framework.Graphics; using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables; using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
@ -10,8 +13,12 @@ namespace osu.Game
internal class VolumeMeter : Container internal class VolumeMeter : Container
{ {
public Box MeterFill { get; set; } public Box MeterFill { get; set; }
public VolumeMeter(string meterName)
public BindableDouble Volume { get; set; }
public VolumeMeter(string meterName, BindableDouble volume)
{ {
Volume = volume;
Size = new Vector2(40, 180); Size = new Vector2(40, 180);
Children = new Drawable[] Children = new Drawable[]
{ {
@ -45,5 +52,27 @@ namespace osu.Game
new SpriteText {Text = meterName, Anchor = Anchor.BottomCentre,Origin = Anchor.BottomCentre,Position = new Vector2(0,-20)} new SpriteText {Text = meterName, Anchor = Anchor.BottomCentre,Origin = Anchor.BottomCentre,Position = new Vector2(0,-20)}
}; };
} }
public override void Load()
{
base.Load();
updateFill();
}
protected override bool OnWheelUp(InputState state)
{
Volume.Value += 0.05f;
updateFill();
return base.OnWheelUp(state);
}
protected override bool OnWheelDown(InputState state)
{
Volume.Value -= 0.05f;
updateFill();
return base.OnWheelDown(state);
}
private void updateFill() => MeterFill.ScaleTo(new Vector2(1, (float)Volume.Value), 300, EasingTypes.OutQuint);
} }
} }