2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
2017-05-16 21:49:38 +08:00
|
|
|
|
using System;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2017-02-04 16:50:58 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-10-04 00:44:23 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-02-04 16:50:58 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-12-26 14:14:19 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-10-04 00:44:23 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-04 16:50:58 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2023-02-03 00:24:45 +08:00
|
|
|
|
public partial class RoundedSliderBar<T> : OsuSliderBar<T>
|
2019-10-23 13:04:06 +08:00
|
|
|
|
where T : struct, IEquatable<T>, IComparable<T>, IConvertible
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
2023-02-03 19:19:09 +08:00
|
|
|
|
protected readonly Nub Nub;
|
2022-06-30 18:54:08 +08:00
|
|
|
|
protected readonly Box LeftBox;
|
|
|
|
|
protected readonly Box RightBox;
|
2019-12-26 14:14:19 +08:00
|
|
|
|
private readonly Container nubContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-11-03 16:44:54 +08:00
|
|
|
|
private readonly HoverClickSounds hoverClickSounds;
|
|
|
|
|
|
2017-05-30 15:40:35 +08:00
|
|
|
|
private Color4 accentColour;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2017-05-30 15:40:35 +08:00
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => accentColour;
|
2017-05-30 15:40:35 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
2022-06-30 18:54:08 +08:00
|
|
|
|
LeftBox.Colour = value;
|
2021-10-04 00:44:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Colour4 backgroundColour;
|
|
|
|
|
|
|
|
|
|
public Color4 BackgroundColour
|
|
|
|
|
{
|
|
|
|
|
get => backgroundColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
backgroundColour = value;
|
2022-06-30 18:54:08 +08:00
|
|
|
|
RightBox.Colour = value;
|
2017-05-30 15:40:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-02-03 00:24:45 +08:00
|
|
|
|
public RoundedSliderBar()
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
2023-02-03 19:19:09 +08:00
|
|
|
|
Height = Nub.HEIGHT;
|
2023-07-14 13:24:53 +08:00
|
|
|
|
RangePadding = Nub.DEFAULT_EXPANDED_SIZE / 2;
|
2017-02-04 16:50:58 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-10-04 00:44:23 +08:00
|
|
|
|
new Container
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
2021-10-04 00:44:23 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-02-04 16:50:58 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2021-10-04 00:44:23 +08:00
|
|
|
|
Padding = new MarginPadding { Horizontal = 2 },
|
|
|
|
|
Child = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 5f,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2022-06-30 18:54:08 +08:00
|
|
|
|
LeftBox = new Box
|
2021-10-04 00:44:23 +08:00
|
|
|
|
{
|
|
|
|
|
Height = 5,
|
|
|
|
|
EdgeSmoothness = new Vector2(0, 0.5f),
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
2022-06-30 18:54:08 +08:00
|
|
|
|
RightBox = new Box
|
2021-10-04 00:44:23 +08:00
|
|
|
|
{
|
|
|
|
|
Height = 5,
|
|
|
|
|
EdgeSmoothness = new Vector2(0, 0.5f),
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-02-04 16:50:58 +08:00
|
|
|
|
},
|
2019-12-26 14:14:19 +08:00
|
|
|
|
nubContainer = new Container
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
2019-12-26 14:14:19 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-02-03 19:19:09 +08:00
|
|
|
|
Child = Nub = new Nub
|
2019-12-26 14:14:19 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
RelativePositionAxes = Axes.X,
|
2021-10-04 00:44:23 +08:00
|
|
|
|
Current = { Value = true }
|
2019-12-26 14:14:19 +08:00
|
|
|
|
},
|
2017-11-26 01:41:18 +08:00
|
|
|
|
},
|
2022-11-03 16:44:54 +08:00
|
|
|
|
hoverClickSounds = new HoverClickSounds()
|
2017-02-04 16:50:58 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-04 00:44:23 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2023-01-26 19:58:58 +08:00
|
|
|
|
private void load(OverlayColourProvider? colourProvider, OsuColour colours)
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
2021-10-04 00:44:23 +08:00
|
|
|
|
AccentColour = colourProvider?.Highlight1 ?? colours.Pink;
|
2022-07-01 13:35:47 +08:00
|
|
|
|
BackgroundColour = colourProvider?.Background5 ?? colours.PinkDarker.Darken(1);
|
2017-02-04 16:50:58 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-26 14:14:19 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
nubContainer.Padding = new MarginPadding { Horizontal = RangePadding };
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-17 16:03:53 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2022-11-04 17:58:20 +08:00
|
|
|
|
|
|
|
|
|
Current.BindDisabledChanged(disabled =>
|
|
|
|
|
{
|
|
|
|
|
Alpha = disabled ? 0.3f : 1;
|
|
|
|
|
hoverClickSounds.Enabled.Value = !disabled;
|
|
|
|
|
}, true);
|
2019-01-17 16:03:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
2022-11-07 01:19:13 +08:00
|
|
|
|
updateGlow();
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnHover(e);
|
2017-02-04 16:50:58 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
2021-10-15 10:51:08 +08:00
|
|
|
|
updateGlow();
|
2018-10-02 11:02:47 +08:00
|
|
|
|
base.OnHoverLost(e);
|
2017-02-04 16:50:58 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-30 03:39:59 +08:00
|
|
|
|
protected override bool ShouldHandleAsRelativeDrag(MouseDownEvent e)
|
2023-01-26 22:01:27 +08:00
|
|
|
|
=> Nub.ReceivePositionalInputAt(e.ScreenSpaceMouseDownPosition);
|
2022-06-30 03:39:59 +08:00
|
|
|
|
|
2021-10-15 10:51:08 +08:00
|
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
|
|
|
|
{
|
|
|
|
|
updateGlow();
|
|
|
|
|
base.OnDragEnd(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateGlow()
|
|
|
|
|
{
|
2023-01-26 22:01:27 +08:00
|
|
|
|
Nub.Glowing = !Current.Disabled && (IsHovered || IsDragged);
|
2021-10-15 10:51:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 19:55:26 +08:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2017-02-04 16:50:58 +08:00
|
|
|
|
{
|
2017-02-04 19:55:26 +08:00
|
|
|
|
base.UpdateAfterChildren();
|
2023-01-26 22:01:27 +08:00
|
|
|
|
LeftBox.Scale = new Vector2(Math.Clamp(RangePadding + Nub.DrawPosition.X - Nub.DrawWidth / 2, 0, Math.Max(0, DrawWidth)), 1);
|
|
|
|
|
RightBox.Scale = new Vector2(Math.Clamp(DrawWidth - Nub.DrawPosition.X - RangePadding - Nub.DrawWidth / 2, 0, Math.Max(0, DrawWidth)), 1);
|
2017-02-04 16:50:58 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-04 16:50:58 +08:00
|
|
|
|
protected override void UpdateValue(float value)
|
|
|
|
|
{
|
2023-01-26 22:01:27 +08:00
|
|
|
|
Nub.MoveToX(value, 250, Easing.OutQuint);
|
2017-02-04 16:50:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|