From c642f6c34f3cef27d924318891d464212d7dbb2e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 7 Dec 2016 15:39:21 -0500 Subject: [PATCH] Add sliderbar L+F --- osu.Game/Overlays/Options/SliderOption.cs | 135 +++++++++++++++------- 1 file changed, 91 insertions(+), 44 deletions(-) diff --git a/osu.Game/Overlays/Options/SliderOption.cs b/osu.Game/Overlays/Options/SliderOption.cs index d00eeebe35..cbb6fc4148 100644 --- a/osu.Game/Overlays/Options/SliderOption.cs +++ b/osu.Game/Overlays/Options/SliderOption.cs @@ -1,53 +1,100 @@ -using System; +using System; +using OpenTK; using OpenTK.Graphics; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; using osu.Framework.Graphics.UserInterface; -namespace osu.Game.Overlays.Options -{ - public class SliderOption : FlowContainer where T : struct, - IComparable, IFormattable, IConvertible, IComparable, IEquatable - { - private SliderBar slider; - private SpriteText text; - - public string LabelText - { - get { return text.Text; } - set - { - text.Text = value; - text.Alpha = string.IsNullOrEmpty(value) ? 0 : 1; - } - } - - public BindableNumber Bindable - { - get { return slider.Bindable; } - set { slider.Bindable = value; } - } - - public SliderOption() - { - Direction = FlowDirection.VerticalOnly; - RelativeSizeAxes = Axes.X; - AutoSizeAxes = Axes.Y; - Children = new Drawable[] - { - text = new SpriteText { Alpha = 0 }, - slider = new SliderBar - { - Margin = new MarginPadding { Top = 5 }, - Height = 10, - RelativeSizeAxes = Axes.X, - Color = Color4.White, - SelectionColor = new Color4(255, 102, 170, 255), - } - }; - } - } +namespace osu.Game.Overlays.Options +{ + public class SliderOption : FlowContainer where T : struct, + IComparable, IFormattable, IConvertible, IComparable, IEquatable + { + private SliderBar slider; + private SpriteText text; + + public string LabelText + { + get { return text.Text; } + set + { + text.Text = value; + text.Alpha = string.IsNullOrEmpty(value) ? 0 : 1; + } + } + + public BindableNumber Bindable + { + get { return slider.Bindable; } + set { slider.Bindable = value; } + } + + public SliderOption() + { + Direction = FlowDirection.VerticalOnly; + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + Children = new Drawable[] + { + text = new SpriteText { Alpha = 0 }, + slider = new OsuSliderBar + { + Margin = new MarginPadding { Top = 5 }, + RelativeSizeAxes = Axes.X, + } + }; + } + + private class OsuSliderBar : SliderBar where U : struct, + IComparable, IFormattable, IConvertible, IComparable, IEquatable + { + private Container nub; + + public OsuSliderBar() + { + Height = 22; + Color = Color4.White; + SelectionColor = new Color4(255, 102, 170, 255); + Add(nub = new Container + { + Width = Height, + Height = Height, + CornerRadius = Height / 2, + Origin = Anchor.TopCentre, + AutoSizeAxes = Axes.None, + RelativeSizeAxes = Axes.None, + RelativePositionAxes = Axes.X, + Masking = true, + BorderColour = new Color4(255, 102, 170, 255), + BorderThickness = 2, + Children = new[] + { + new Box { Colour = Color4.Transparent, RelativeSizeAxes = Axes.Both } + } + }); + Box.Height = SelectionBox.Height = 2; + Box.RelativePositionAxes = Axes.None; + Box.RelativeSizeAxes = SelectionBox.RelativeSizeAxes = Axes.None; + Box.Position = SelectionBox.Position = new Vector2(0, Height / 2 - 1); + Box.Colour = new Color4(255, 102, 170, 100); + } + + protected override void UpdateAmount(float amt) + { + nub.MoveToX(amt, 300, EasingTypes.OutQuint); + SelectionBox.ScaleTo( + new Vector2(DrawWidth * amt - Height / 2 + 1, 1), + 300, EasingTypes.OutQuint); + Box.MoveToX(DrawWidth * amt + Height / 2 - 1, + 300, EasingTypes.OutQuint); + Box.ScaleTo( + new Vector2(DrawWidth * (1 - amt) - Height / 2 + 1, 1), + 300, EasingTypes.OutQuint); + } + } + } } \ No newline at end of file