1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 16:47:24 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/NormalSliderBar.cs

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

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