1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 01:17:27 +08:00
osu-lazer/osu.Game/Overlays/Volume/MuteButton.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3.4 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System;
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-02-28 23:14:52 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2018-02-28 23:14:52 +08:00
using osu.Framework.Graphics.UserInterface;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-02-28 23:14:52 +08:00
using osu.Game.Graphics;
2019-05-13 06:24:34 +08:00
using osu.Game.Graphics.UserInterface;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
2018-02-28 23:14:52 +08:00
namespace osu.Game.Overlays.Volume
{
2019-05-13 06:24:34 +08:00
public partial class MuteButton : OsuButton, IHasCurrentValue<bool>
2018-02-28 23:14:52 +08:00
{
private readonly Bindable<bool> current = new Bindable<bool>();
public Bindable<bool> Current
{
get => current;
set
{
ArgumentNullException.ThrowIfNull(value);
current.UnbindBindings();
current.BindTo(value);
}
}
2018-04-13 17:19:50 +08:00
private ColourInfo hoveredBorderColour;
private ColourInfo unhoveredBorderColour;
private CompositeDrawable border = null!;
2019-05-13 06:24:34 +08:00
2018-02-28 23:14:52 +08:00
public MuteButton()
{
const float width = 30;
const float height = 30;
Size = new Vector2(width, height);
Content.CornerRadius = height / 2;
2019-11-22 18:49:20 +08:00
Content.CornerExponent = 2;
2019-05-13 06:24:34 +08:00
Action = () => Current.Value = !Current.Value;
2018-02-28 23:14:52 +08:00
}
2018-04-13 17:19:50 +08:00
2018-02-28 23:14:52 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2019-05-13 06:24:34 +08:00
BackgroundColour = colours.Gray1;
hoveredBorderColour = colours.PinkLight;
unhoveredBorderColour = colours.Gray1;
2018-04-13 17:19:50 +08:00
2018-03-04 02:08:35 +08:00
SpriteIcon icon;
2019-05-13 06:24:34 +08:00
2018-02-28 23:14:52 +08:00
AddRange(new Drawable[]
{
2018-03-04 02:08:35 +08:00
icon = new SpriteIcon
{
2019-05-13 00:30:43 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
border = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = 3,
BorderColour = unhoveredBorderColour,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
}
2018-03-04 02:08:35 +08:00
}
2018-02-28 23:14:52 +08:00
});
2018-04-13 17:19:50 +08:00
2019-08-23 16:42:40 +08:00
Current.BindValueChanged(muted =>
2018-03-04 02:08:35 +08:00
{
2019-05-13 00:30:43 +08:00
icon.Icon = muted.NewValue ? FontAwesome.Solid.VolumeMute : FontAwesome.Solid.VolumeUp;
2024-08-09 18:29:23 +08:00
icon.Size = new Vector2(muted.NewValue ? 12 : 16);
2019-08-23 12:36:21 +08:00
icon.Margin = new MarginPadding { Right = muted.NewValue ? 2 : 0 };
2019-08-23 16:42:40 +08:00
}, true);
2018-02-28 23:14:52 +08:00
}
2018-04-13 17:19:50 +08:00
2018-10-02 11:02:47 +08:00
protected override bool OnHover(HoverEvent e)
2018-02-28 23:14:52 +08:00
{
border.TransformTo(nameof(BorderColour), hoveredBorderColour, 500, Easing.OutQuint);
2018-06-22 12:31:32 +08:00
return false;
2018-02-28 23:14:52 +08:00
}
2018-04-13 17:19:50 +08:00
2018-10-02 11:02:47 +08:00
protected override void OnHoverLost(HoverLostEvent e)
2018-02-28 23:14:52 +08:00
{
border.TransformTo(nameof(BorderColour), unhoveredBorderColour, 500, Easing.OutQuint);
2018-03-04 02:08:35 +08:00
}
protected override bool OnMouseDown(MouseDownEvent e)
{
base.OnMouseDown(e);
// Block mouse down to avoid dismissing overlays sitting behind the mute button
return true;
}
2018-02-28 23:14:52 +08:00
}
}