1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:12:57 +08:00

Move mute button to master volume circle

This commit is contained in:
Dean Herbert 2024-08-08 12:56:03 +09:00
parent 8d8975121f
commit d84d0310e0
No known key found for this signature in database
4 changed files with 93 additions and 42 deletions

View File

@ -0,0 +1,54 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osuTK.Graphics;
namespace osu.Game.Overlays.Volume
{
public partial class MasterVolumeMeter : VolumeMeter
{
private MuteButton muteButton = null!;
public Bindable<bool> IsMuted { get; } = new Bindable<bool>();
private readonly BindableDouble muteAdjustment = new BindableDouble();
[Resolved]
private VolumeOverlay volumeOverlay { get; set; } = null!;
public MasterVolumeMeter(string name, float circleSize, Color4 meterColour)
: base(name, circleSize, meterColour)
{
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
IsMuted.BindValueChanged(muted =>
{
if (muted.NewValue)
audio.AddAdjustment(AdjustableProperty.Volume, muteAdjustment);
else
audio.RemoveAdjustment(AdjustableProperty.Volume, muteAdjustment);
});
Add(muteButton = new MuteButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
Blending = BlendingParameters.Additive,
X = CircleSize / 2,
Y = CircleSize * 0.23f,
Current = { BindTarget = IsMuted }
});
muteButton.Current.ValueChanged += _ => volumeOverlay.Show();
}
public void ToggleMute() => muteButton.Current.Value = !muteButton.Current.Value;
}
}

View File

@ -35,16 +35,16 @@ namespace osu.Game.Overlays.Volume
private Color4 hoveredColour, unhoveredColour;
private const float width = 100;
public const float HEIGHT = 35;
public MuteButton()
{
const float width = 30;
const float height = 30;
Content.BorderThickness = 3;
Content.CornerRadius = HEIGHT / 2;
Content.CornerRadius = height / 2;
Content.CornerExponent = 2;
Size = new Vector2(width, HEIGHT);
Size = new Vector2(width, height);
Action = () => Current.Value = !Current.Value;
}
@ -52,7 +52,7 @@ namespace osu.Game.Overlays.Volume
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
hoveredColour = colours.YellowDark;
hoveredColour = colours.PinkLight;
Content.BorderColour = unhoveredColour = colours.Gray1;
BackgroundColour = colours.Gray1;

View File

@ -35,8 +35,12 @@ namespace osu.Game.Overlays.Volume
private CircularProgress volumeCircle;
private CircularProgress volumeCircleGlow;
protected static readonly Vector2 LABEL_SIZE = new Vector2(120, 20);
public BindableDouble Bindable { get; } = new BindableDouble { MinValue = 0, MaxValue = 1, Precision = 0.01 };
private readonly float circleSize;
protected readonly float CircleSize;
private readonly Color4 meterColour;
private readonly string name;
@ -73,7 +77,7 @@ namespace osu.Game.Overlays.Volume
public VolumeMeter(string name, float circleSize, Color4 meterColour)
{
this.circleSize = circleSize;
CircleSize = circleSize;
this.meterColour = meterColour;
this.name = name;
@ -101,7 +105,7 @@ namespace osu.Game.Overlays.Volume
{
new Container
{
Size = new Vector2(circleSize),
Size = new Vector2(CircleSize),
Children = new Drawable[]
{
new BufferedContainer
@ -199,7 +203,7 @@ namespace osu.Game.Overlays.Volume
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Numeric.With(size: 0.16f * circleSize)
Font = OsuFont.Numeric.With(size: 0.16f * CircleSize)
}).WithEffect(new GlowEffect
{
Colour = Color4.Transparent,
@ -209,10 +213,10 @@ namespace osu.Game.Overlays.Volume
},
new Container
{
Size = new Vector2(120, 20),
Size = LABEL_SIZE,
CornerRadius = 10,
Masking = true,
Margin = new MarginPadding { Left = circleSize + 10 },
Margin = new MarginPadding { Left = CircleSize + 10 },
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Children = new Drawable[]

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
@ -20,21 +21,19 @@ using osuTK.Graphics;
namespace osu.Game.Overlays
{
[Cached]
public partial class VolumeOverlay : VisibilityContainer
{
public Bindable<bool> IsMuted { get; } = new Bindable<bool>();
private const float offset = 10;
private VolumeMeter volumeMeterMaster = null!;
private VolumeMeter volumeMeterEffect = null!;
private VolumeMeter volumeMeterMusic = null!;
private MuteButton muteButton = null!;
private SelectionCycleFillFlowContainer<VolumeMeter> volumeMeters = null!;
private readonly BindableDouble muteAdjustment = new BindableDouble();
public Bindable<bool> IsMuted { get; } = new Bindable<bool>();
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours)
{
@ -49,14 +48,7 @@ namespace osu.Game.Overlays
Width = 300,
Colour = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.75f), Color4.Black.Opacity(0))
},
muteButton = new MuteButton
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Margin = new MarginPadding(10),
Current = { BindTarget = IsMuted }
},
volumeMeters = new SelectionCycleFillFlowContainer<VolumeMeter>
new FillFlowContainer
{
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
@ -64,26 +56,29 @@ namespace osu.Game.Overlays
Origin = Anchor.CentreLeft,
Spacing = new Vector2(0, offset),
Margin = new MarginPadding { Left = offset },
Children = new[]
Children = new Drawable[]
{
volumeMeterEffect = new VolumeMeter("EFFECTS", 125, colours.BlueDarker),
volumeMeterMaster = new VolumeMeter("MASTER", 150, colours.PinkDarker),
volumeMeterMusic = new VolumeMeter("MUSIC", 125, colours.BlueDarker),
}
}
volumeMeters = new SelectionCycleFillFlowContainer<VolumeMeter>
{
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Spacing = new Vector2(0, offset),
Children = new[]
{
volumeMeterEffect = new VolumeMeter("EFFECTS", 125, colours.BlueDarker),
volumeMeterMaster = new MasterVolumeMeter("MASTER", 150, colours.PinkDarker) { IsMuted = { BindTarget = IsMuted }, },
volumeMeterMusic = new VolumeMeter("MUSIC", 125, colours.BlueDarker),
}
},
},
},
});
volumeMeterMaster.Bindable.BindTo(audio.Volume);
volumeMeterEffect.Bindable.BindTo(audio.VolumeSample);
volumeMeterMusic.Bindable.BindTo(audio.VolumeTrack);
IsMuted.BindValueChanged(muted =>
{
if (muted.NewValue)
audio.AddAdjustment(AdjustableProperty.Volume, muteAdjustment);
else
audio.RemoveAdjustment(AdjustableProperty.Volume, muteAdjustment);
});
}
protected override void LoadComplete()
@ -92,8 +87,6 @@ namespace osu.Game.Overlays
foreach (var volumeMeter in volumeMeters)
volumeMeter.Bindable.ValueChanged += _ => Show();
muteButton.Current.ValueChanged += _ => Show();
}
public bool Adjust(GlobalAction action, float amount = 1, bool isPrecise = false)
@ -130,7 +123,7 @@ namespace osu.Game.Overlays
case GlobalAction.ToggleMute:
Show();
muteButton.Current.Value = !muteButton.Current.Value;
volumeMeters.OfType<MasterVolumeMeter>().First().ToggleMute();
return true;
}