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 osu.Framework;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Graphics.Transformations; using OpenTK;
using osu.Framework;
namespace osu.Game namespace osu.Game
{ {
internal class VolumeControl : Container internal class VolumeControl : Container
{ {
private Box meterFill; private FlowContainer volumeMetersContainer;
private Container meterContainer; private VolumeMeter volumeMeterMaster;
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; }
@ -25,84 +20,63 @@ namespace osu.Game
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
} }
private void volumeChanged(object sender, System.EventArgs e)
{
appear();
}
public override void Load(BaseGame game) public override void Load(BaseGame game)
{ {
base.Load(game); base.Load(game);
VolumeGlobal.ValueChanged += volumeChanged;
VolumeSample.ValueChanged += volumeChanged;
VolumeTrack.ValueChanged += volumeChanged;
Children = new Drawable[] Children = new Drawable[]
{ {
meterContainer = new Container { volumeMetersContainer = new FlowContainer
{
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight, Origin = Anchor.BottomRight,
Position = new Vector2(10, 10), Position = new Vector2(10, 30),
Size = new Vector2(40, 180), Spacing = new Vector2(15,0),
Alpha = 0, Alpha = 0,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box volumeMeterMaster = new VolumeMeter("Master", VolumeGlobal),
{ new VolumeMeter("Effects", VolumeSample),
Colour = Color4.Black, new VolumeMeter("Music", VolumeTrack)
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
},
}
}
} }
} }
}; };
}
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) protected override bool OnWheelDown(InputState state)
{ {
appear(); volumeMeterMaster.TriggerWheelDown(state);
return true;
VolumeGlobal.Value -= 0.05f;
updateFill();
return base.OnWheelDown(state);
} }
protected override bool OnWheelUp(InputState state) protected override bool OnWheelUp(InputState state)
{ {
appear(); volumeMeterMaster.TriggerWheelUp(state);
return true;
VolumeGlobal.Value += 0.05f;
updateFill();
return base.OnWheelUp(state);
}
private void updateFill()
{
meterFill.ScaleTo(new Vector2(1, (float)VolumeGlobal.Value), 300, EasingTypes.OutQuint);
} }
private void appear() private void appear()
{ {
meterContainer.ClearTransformations(); volumeMetersContainer.ClearTransformations();
meterContainer.FadeIn(100); volumeMetersContainer.FadeIn(100);
meterContainer.Delay(1000); volumeMetersContainer.Delay(1000);
meterContainer.FadeOut(100); 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\IO\OszArchiveReader.cs" />
<Compile Include="Beatmaps\BaseDifficulty.cs" /> <Compile Include="Beatmaps\BaseDifficulty.cs" />
<Compile Include="Beatmaps\Events\EventType.cs" /> <Compile Include="Beatmaps\Events\EventType.cs" />
<Compile Include="VolumeMeter.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj"> <ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">