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