2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-07-21 10:38:28 +08:00
|
|
|
|
using osu.Framework.Input.States;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.MathUtils;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Volume
|
|
|
|
|
{
|
2018-06-27 17:43:29 +08:00
|
|
|
|
public class VolumeMeter : Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
private CircularProgress volumeCircle;
|
2018-06-13 18:18:11 +08:00
|
|
|
|
private CircularProgress volumeCircleGlow;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public BindableDouble Bindable { get; } = new BindableDouble { MinValue = 0, MaxValue = 1 };
|
|
|
|
|
private readonly float circleSize;
|
|
|
|
|
private readonly Color4 meterColour;
|
|
|
|
|
private readonly string name;
|
|
|
|
|
|
|
|
|
|
private OsuSpriteText text;
|
|
|
|
|
private BufferedContainer maxGlow;
|
|
|
|
|
|
|
|
|
|
public VolumeMeter(string name, float circleSize, Color4 meterColour)
|
|
|
|
|
{
|
|
|
|
|
this.circleSize = circleSize;
|
|
|
|
|
this.meterColour = meterColour;
|
|
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
2018-06-13 18:18:11 +08:00
|
|
|
|
Color4 backgroundColour = colours.Gray1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
CircularProgress bgProgress;
|
|
|
|
|
|
2018-06-13 18:18:11 +08:00
|
|
|
|
const float progress_start_radius = 0.75f;
|
|
|
|
|
const float progress_size = 0.03f;
|
|
|
|
|
const float progress_end_radius = progress_start_radius + progress_size;
|
|
|
|
|
|
|
|
|
|
const float blur_amount = 5;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-13 18:18:11 +08:00
|
|
|
|
new Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-13 18:18:11 +08:00
|
|
|
|
Size = new Vector2(circleSize),
|
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-13 18:18:11 +08:00
|
|
|
|
new BufferedContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-13 18:18:11 +08:00
|
|
|
|
Alpha = 0.9f,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-06-13 18:18:11 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Circle
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = backgroundColour,
|
|
|
|
|
},
|
|
|
|
|
new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Masking = true,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Size = new Vector2(progress_end_radius),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
bgProgress = new CircularProgress
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Rotation = 180,
|
|
|
|
|
Colour = backgroundColour,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Name = "Progress under covers for smoothing",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Rotation = 180,
|
|
|
|
|
Child = volumeCircle = new CircularProgress
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Circle
|
|
|
|
|
{
|
|
|
|
|
Name = "Inner Cover",
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = backgroundColour,
|
|
|
|
|
Size = new Vector2(progress_start_radius),
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "Progress overlay for glow",
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Size = new Vector2(progress_start_radius + progress_size / 1.5f),
|
|
|
|
|
Rotation = 180,
|
|
|
|
|
Padding = new MarginPadding(-Blur.KernelSize(blur_amount)),
|
|
|
|
|
Child = (volumeCircleGlow = new CircularProgress
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
InnerRadius = progress_size * 0.8f,
|
|
|
|
|
}).WithEffect(new GlowEffect
|
|
|
|
|
{
|
|
|
|
|
Colour = meterColour,
|
|
|
|
|
BlurSigma = new Vector2(blur_amount),
|
|
|
|
|
Strength = 5,
|
|
|
|
|
PadExtent = true
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
maxGlow = (text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Font = "Venera",
|
|
|
|
|
TextSize = 0.16f * circleSize
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}).WithEffect(new GlowEffect
|
|
|
|
|
{
|
2018-06-13 18:18:11 +08:00
|
|
|
|
Colour = Color4.Transparent,
|
|
|
|
|
PadExtent = true,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(120, 20),
|
|
|
|
|
CornerRadius = 10,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Margin = new MarginPadding { Left = circleSize + 10 },
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-13 18:18:11 +08:00
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0.9f,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = backgroundColour,
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Font = "Exo2.0-Bold",
|
|
|
|
|
Text = name
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-06-13 18:18:11 +08:00
|
|
|
|
};
|
|
|
|
|
Bindable.ValueChanged += newVolume =>
|
|
|
|
|
{
|
|
|
|
|
this.TransformTo("DisplayVolume",
|
|
|
|
|
newVolume,
|
|
|
|
|
400,
|
|
|
|
|
Easing.OutQuint);
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
bgProgress.Current.Value = 0.75f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
Bindable.TriggerChange();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double displayVolume;
|
|
|
|
|
|
|
|
|
|
protected double DisplayVolume
|
|
|
|
|
{
|
|
|
|
|
get => displayVolume;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
displayVolume = value;
|
|
|
|
|
|
|
|
|
|
if (displayVolume > 0.99f)
|
|
|
|
|
{
|
|
|
|
|
text.Text = "MAX";
|
|
|
|
|
maxGlow.EffectColour = meterColour.Opacity(2f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
maxGlow.EffectColour = Color4.Transparent;
|
|
|
|
|
text.Text = Math.Round(displayVolume * 100).ToString(CultureInfo.CurrentCulture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volumeCircle.Current.Value = displayVolume * 0.75f;
|
2018-06-13 18:18:11 +08:00
|
|
|
|
volumeCircleGlow.Current.Value = displayVolume * 0.75f;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double Volume
|
|
|
|
|
{
|
|
|
|
|
get => Bindable;
|
|
|
|
|
private set => Bindable.Value = value;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 17:15:03 +08:00
|
|
|
|
private const float adjust_step = 0.05f;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-27 17:43:29 +08:00
|
|
|
|
public void Increase(double amount = 1, bool isPrecise = false) => adjust(amount, isPrecise);
|
|
|
|
|
public void Decrease(double amount = 1, bool isPrecise = false) => adjust(-amount, isPrecise);
|
2018-06-08 17:15:03 +08:00
|
|
|
|
|
2018-06-27 17:43:29 +08:00
|
|
|
|
// because volume precision is set to 0.01, this local is required to keep track of more precise adjustments and only apply when possible.
|
|
|
|
|
private double adjustAccumulator;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-27 17:43:29 +08:00
|
|
|
|
private void adjust(double delta, bool isPrecise)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-27 17:43:29 +08:00
|
|
|
|
adjustAccumulator += delta * adjust_step * (isPrecise ? 0.1 : 1);
|
|
|
|
|
if (Math.Abs(adjustAccumulator) < Bindable.Precision)
|
|
|
|
|
return;
|
|
|
|
|
Volume += adjustAccumulator;
|
|
|
|
|
adjustAccumulator = 0;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 15:46:27 +08:00
|
|
|
|
protected override bool OnScroll(InputState state)
|
|
|
|
|
{
|
2018-06-27 17:43:29 +08:00
|
|
|
|
adjust(state.Mouse.ScrollDelta.Y, state.Mouse.HasPreciseScroll);
|
2018-06-13 15:46:27 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 00:13:35 +08:00
|
|
|
|
private const float transition_length = 500;
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
this.ScaleTo(1.04f, transition_length, Easing.OutExpo);
|
2018-06-13 15:46:48 +08:00
|
|
|
|
return false;
|
2018-06-07 00:13:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
this.ScaleTo(1f, transition_length, Easing.OutExpo);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|