mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 11:42:56 +08:00
basic volume meter and testcase
This commit is contained in:
parent
3db75cd2fc
commit
46dfb761c5
29
osu.Game.Tests/Visual/TestCaseVolumeControl.cs
Normal file
29
osu.Game.Tests/Visual/TestCaseVolumeControl.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Overlays.Volume;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public class TestCaseVolumeControl : TestCase
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(VolumeMeter), typeof(MuteButton) };
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio, OsuColour colours)
|
||||
{
|
||||
VolumeMeter meter;
|
||||
Add(meter = new VolumeMeter("MASTER", 125, colours.PinkDarker));
|
||||
Add(new MuteButton
|
||||
{
|
||||
Margin = new MarginPadding { Top = 200 }
|
||||
});
|
||||
|
||||
meter.Bindable.BindTo(audio.Volume);
|
||||
}
|
||||
}
|
||||
}
|
@ -162,6 +162,7 @@
|
||||
<Compile Include="Visual\TestCaseUserPanel.cs" />
|
||||
<Compile Include="Visual\TestCaseUserProfile.cs" />
|
||||
<Compile Include="Visual\TestCaseUserRanks.cs" />
|
||||
<Compile Include="Visual\TestCaseVolumeControl.cs" />
|
||||
<Compile Include="Visual\TestCaseWaveform.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
58
osu.Game/Overlays/Volume/MuteButton.cs
Normal file
58
osu.Game/Overlays/Volume/MuteButton.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Volume
|
||||
{
|
||||
public class MuteButton : Container, IHasCurrentValue<bool>
|
||||
{
|
||||
public Bindable<bool> Current { get; } = new Bindable<bool>();
|
||||
|
||||
private Color4 hoveredColour, unhoveredColour;
|
||||
|
||||
public MuteButton()
|
||||
{
|
||||
Masking = true;
|
||||
BorderThickness = 3;
|
||||
CornerRadius = 20;
|
||||
Size = new Vector2(100, 40);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
hoveredColour = colours.YellowDark;
|
||||
BorderColour = unhoveredColour = colours.Gray1.Opacity(0.9f);
|
||||
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.Gray1,
|
||||
Alpha = 0.9f,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
this.TransformTo<MuteButton, SRGBColour>("BorderColour", hoveredColour, 500, Easing.OutQuint);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
this.TransformTo<MuteButton, SRGBColour>("BorderColour", unhoveredColour, 500, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
193
osu.Game/Overlays/Volume/VolumeMeter.cs
Normal file
193
osu.Game/Overlays/Volume/VolumeMeter.cs
Normal file
@ -0,0 +1,193 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Transforms;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Input.Bindings;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Volume
|
||||
{
|
||||
public class VolumeMeter : Container, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
private CircularProgress volumeCircle;
|
||||
public BindableDouble Bindable { get; } = new BindableDouble();
|
||||
private readonly float circleSize;
|
||||
private readonly Color4 meterColour;
|
||||
private readonly string name;
|
||||
|
||||
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)
|
||||
{
|
||||
Add(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[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.Gray1,
|
||||
Alpha = 0.9f,
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Font = "Exo2.0-Bold",
|
||||
Text = name
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
OsuSpriteText text, maxText;
|
||||
CircularProgress bgProgress;
|
||||
BufferedContainer maxGlow;
|
||||
|
||||
Add(new CircularContainer
|
||||
{
|
||||
Masking = true,
|
||||
Size = new Vector2(circleSize),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.Gray1,
|
||||
Alpha = 0.9f,
|
||||
},
|
||||
bgProgress = new CircularProgress
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
InnerRadius = 0.05f,
|
||||
Rotation = 180,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Colour = colours.Gray2,
|
||||
Size = new Vector2(0.8f)
|
||||
},
|
||||
(volumeCircle = new CircularProgress
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
InnerRadius = 0.05f,
|
||||
Rotation = 180,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(0.8f)
|
||||
}).WithEffect(new GlowEffect
|
||||
{
|
||||
Colour = meterColour,
|
||||
Strength = 2
|
||||
}),
|
||||
maxGlow = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Font = "Venera",
|
||||
Text = "MAX",
|
||||
TextSize = 0.16f * circleSize
|
||||
}.WithEffect(new GlowEffect
|
||||
{
|
||||
Colour = meterColour,
|
||||
PadExtent = true,
|
||||
Strength = 2,
|
||||
}),
|
||||
text = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Font = "Venera",
|
||||
TextSize = 0.16f * circleSize
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Bindable.ValueChanged += newVolume => this.TransformTo("circleBindable", newVolume * 0.75, 250, Easing.OutQuint);
|
||||
volumeCircle.Current.ValueChanged += newVolume =>
|
||||
{
|
||||
if (newVolume > 0.745)
|
||||
{
|
||||
text.Alpha = 0;
|
||||
maxGlow.Alpha = 1; //show "MAX"
|
||||
}
|
||||
else
|
||||
{
|
||||
text.Text = Math.Round(newVolume / 0.0075).ToString(CultureInfo.CurrentCulture);
|
||||
text.Alpha = 1;
|
||||
maxGlow.Alpha = 0;
|
||||
}
|
||||
};
|
||||
|
||||
bgProgress.Current.Value = 0.75f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is needed because <see cref="TransformCustom{TValue,T}"/> doesn't support <see cref="Bindable{T}"/>
|
||||
/// </summary>
|
||||
private double circleBindable
|
||||
{
|
||||
get => volumeCircle.Current;
|
||||
set => volumeCircle.Current.Value = value;
|
||||
}
|
||||
|
||||
public double Volume
|
||||
{
|
||||
get => Bindable;
|
||||
private set => Bindable.Value = value;
|
||||
}
|
||||
|
||||
public void Increase()
|
||||
{
|
||||
Volume += 0.05f;
|
||||
}
|
||||
|
||||
public void Decrease()
|
||||
{
|
||||
Volume -= 0.05f;
|
||||
}
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
if (!IsHovered) return false;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.DecreaseVolume:
|
||||
Decrease();
|
||||
return true;
|
||||
case GlobalAction.IncreaseVolume:
|
||||
Increase();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool OnReleased(GlobalAction action) => false;
|
||||
}
|
||||
}
|
@ -330,6 +330,8 @@
|
||||
<Compile Include="Overlays\Profile\Sections\Ranks\ScoreModsContainer.cs" />
|
||||
<Compile Include="Overlays\Settings\Sections\Gameplay\ScrollingSettings.cs" />
|
||||
<Compile Include="Overlays\Settings\Sections\Maintenance\DeleteAllBeatmapsDialog.cs" />
|
||||
<Compile Include="Overlays\Volume\MuteButton.cs" />
|
||||
<Compile Include="Overlays\Volume\VolumeMeter.cs" />
|
||||
<Compile Include="Rulesets\Configuration\IRulesetConfigManager.cs" />
|
||||
<Compile Include="Rulesets\Configuration\RulesetConfigManager.cs" />
|
||||
<Compile Include="Rulesets\Mods\IApplicableFailOverride.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user