Merge pull request #57 from UselessToucan/VolumeControl

VolumeControl: add controls for Effects and Music
This commit is contained in:
Dean Herbert 2016-10-14 15:50:45 +09:00 committed by GitHub
commit c3b745bfef
3 changed files with 120 additions and 61 deletions

View File

@ -1,21 +1,16 @@
using System;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Input;
using osu.Framework.Graphics.Transformations;
using osu.Framework;
using OpenTK;
namespace osu.Game
{
internal class VolumeControl : Container
{
private Box meterFill;
private Container meterContainer;
private FlowContainer volumeMetersContainer;
private VolumeMeter volumeMeterMaster;
public BindableDouble VolumeGlobal { get; set; }
public BindableDouble VolumeSample { get; set; }
public BindableDouble VolumeTrack { get; set; }
@ -25,84 +20,63 @@ namespace osu.Game
RelativeSizeAxes = Axes.Both;
}
private void volumeChanged(object sender, System.EventArgs e)
{
appear();
}
public override void Load(BaseGame game)
{
base.Load(game);
VolumeGlobal.ValueChanged += volumeChanged;
VolumeSample.ValueChanged += volumeChanged;
VolumeTrack.ValueChanged += volumeChanged;
Children = new Drawable[]
{
meterContainer = new Container {
volumeMetersContainer = new FlowContainer
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Position = new Vector2(10, 10),
Size = new Vector2(40, 180),
Position = new Vector2(10, 30),
Spacing = new Vector2(15,0),
Alpha = 0,
Children = new Drawable[]
{
new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.5f, 0.9f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
new Box
{
Colour = Color4.DarkGray,
RelativeSizeAxes = Axes.Both,
},
meterFill = new Box
{
Colour = Color4.White,
RelativeSizeAxes = Axes.Both,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre
},
}
}
volumeMeterMaster = new VolumeMeter("Master", VolumeGlobal),
new VolumeMeter("Effects", VolumeSample),
new VolumeMeter("Music", VolumeTrack)
}
}
};
}
updateFill();
protected override void Dispose(bool isDisposing)
{
VolumeGlobal.ValueChanged -= volumeChanged;
VolumeSample.ValueChanged -= volumeChanged;
VolumeTrack.ValueChanged -= volumeChanged;
base.Dispose(isDisposing);
}
protected override bool OnWheelDown(InputState state)
{
appear();
VolumeGlobal.Value -= 0.05f;
updateFill();
return base.OnWheelDown(state);
volumeMeterMaster.TriggerWheelDown(state);
return true;
}
protected override bool OnWheelUp(InputState state)
{
appear();
VolumeGlobal.Value += 0.05f;
updateFill();
return base.OnWheelUp(state);
}
private void updateFill()
{
meterFill.ScaleTo(new Vector2(1, (float)VolumeGlobal.Value), 300, EasingTypes.OutQuint);
volumeMeterMaster.TriggerWheelUp(state);
return true;
}
private void appear()
{
meterContainer.ClearTransformations();
meterContainer.FadeIn(100);
meterContainer.Delay(1000);
meterContainer.FadeOut(100);
volumeMetersContainer.ClearTransformations();
volumeMetersContainer.FadeIn(100);
volumeMetersContainer.Delay(1000);
volumeMetersContainer.FadeOut(100);
}
}
}

84
osu.Game/VolumeMeter.cs Normal file
View File

@ -0,0 +1,84 @@
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;
namespace osu.Game
{
internal class VolumeMeter : Container
{
private Box meterFill;
private BindableDouble volume;
public VolumeMeter(string meterName, BindableDouble volume)
{
this.volume = volume;
Size = new Vector2(40, 180);
Children = new Drawable[]
{
new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both
},
new Container
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.5f, 0.9f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
new Box
{
Colour = Color4.DarkGray,
RelativeSizeAxes = Axes.Both
},
meterFill = new Box
{
Colour = Color4.White,
RelativeSizeAxes = Axes.Both,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre
}
}
},
new SpriteText
{
Text = meterName,
Anchor = Anchor.BottomCentre,
Origin = Anchor.TopCentre
}
};
}
public double Volume
{
get { return volume.Value; }
private set
{
volume.Value = value;
updateFill();
}
}
protected override bool OnWheelUp(InputState state)
{
Volume += 0.05f;
return true;
}
protected override bool OnWheelDown(InputState state)
{
Volume -= 0.05f;
return true;
}
private void updateFill() => meterFill.ScaleTo(new Vector2(1, (float)Volume), 300, EasingTypes.OutQuint);
}
}

View File

@ -171,6 +171,7 @@
<Compile Include="Beatmaps\IO\OszArchiveReader.cs" />
<Compile Include="Beatmaps\BaseDifficulty.cs" />
<Compile Include="Beatmaps\Events\EventType.cs" />
<Compile Include="VolumeMeter.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">