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