1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 07:22:54 +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.Containers;
using osu.Framework.Input;
using osu.Framework.Graphics.Transformations;
using OpenTK;
namespace osu.Game
@ -10,10 +9,6 @@ namespace osu.Game
internal class VolumeControl : Container
{
private FlowContainer volumeMetersContainer;
private VolumeMeter VolumeMeterGlobal;
private VolumeMeter VolumeMeterSample;
private VolumeMeter VolumeMeterTrack;
public BindableDouble VolumeGlobal { get; set; }
public BindableDouble VolumeSample { get; set; }
public BindableDouble VolumeTrack { get; set; }
@ -28,75 +23,35 @@ namespace osu.Game
base.Load();
Children = new Drawable[]
{
volumeMetersContainer = new FlowContainer() {
volumeMetersContainer = new FlowContainer
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Position = new Vector2(10, 30),
Alpha = 0,
Padding = new Vector2(15,0),
Padding = new Vector2(15, 0),
Children = new Drawable[]
{
VolumeMeterGlobal = new VolumeMeter("Master"),
VolumeMeterSample= new VolumeMeter("Effects"),
VolumeMeterTrack= new VolumeMeter("Music")
new VolumeMeter("Master", VolumeGlobal),
new VolumeMeter("Effects", VolumeSample),
new VolumeMeter("Music", VolumeTrack)
}
}
};
updateFill();
}
protected override bool OnWheelDown(InputState state)
{
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);
}
protected override bool OnWheelUp(InputState state)
{
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);
}
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()
{
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.Drawables;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using OpenTK;
using OpenTK.Graphics;
@ -10,8 +13,12 @@ namespace osu.Game
internal class VolumeMeter : Container
{
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);
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)}
};
}
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);
}
}