From 0edc64a08c98c2fce9f475fd6a9baaa0c3c871cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sat, 4 Feb 2017 09:50:58 +0100 Subject: [PATCH 1/3] Re-use checkbox nub for option sliders and slightly re-structure. --- osu-framework | 2 +- .../Graphics/UserInterface/OsuCheckbox.cs | 104 ++------------ osu.Game/Graphics/UserInterface/OsuNub.cs | 113 +++++++++++++++ .../Graphics/UserInterface/OsuSliderBar.cs | 131 ++++++++++++++++++ osu.Game/Overlays/Options/OptionSlider.cs | 128 +---------------- osu.Game/osu.Game.csproj | 2 + 6 files changed, 260 insertions(+), 220 deletions(-) create mode 100644 osu.Game/Graphics/UserInterface/OsuNub.cs create mode 100644 osu.Game/Graphics/UserInterface/OsuSliderBar.cs diff --git a/osu-framework b/osu-framework index 542d2eb587..e39f0c4683 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 542d2eb5877f0be8995943d18c7b98931322654a +Subproject commit e39f0c468399f3f9bea8832fcfe12a0595b59cae diff --git a/osu.Game/Graphics/UserInterface/OsuCheckbox.cs b/osu.Game/Graphics/UserInterface/OsuCheckbox.cs index 0c3869e848..e0e973e8f0 100644 --- a/osu.Game/Graphics/UserInterface/OsuCheckbox.cs +++ b/osu.Game/Graphics/UserInterface/OsuCheckbox.cs @@ -66,7 +66,7 @@ namespace osu.Game.Graphics.UserInterface } } - private Light light; + private OsuNub nub; private SpriteText labelSpriteText; private AudioSample sampleChecked; private AudioSample sampleUnchecked; @@ -79,7 +79,7 @@ namespace osu.Game.Graphics.UserInterface Children = new Drawable[] { labelSpriteText = new OsuSpriteText(), - light = new Light + nub = new OsuNub { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, @@ -102,13 +102,15 @@ namespace osu.Game.Graphics.UserInterface protected override bool OnHover(InputState state) { - light.Glowing = true; + nub.Glowing = true; + nub.Expanded = true; return base.OnHover(state); } protected override void OnHoverLost(InputState state) { - light.Glowing = false; + nub.Glowing = false; + nub.Expanded = false; base.OnHoverLost(state); } @@ -125,7 +127,7 @@ namespace osu.Game.Graphics.UserInterface bindable.Value = true; sampleChecked?.Play(); - light.State = CheckBoxState.Checked; + nub.State = CheckBoxState.Checked; } protected override void OnUnchecked() @@ -134,97 +136,7 @@ namespace osu.Game.Graphics.UserInterface bindable.Value = false; sampleUnchecked?.Play(); - light.State = CheckBoxState.Unchecked; + nub.State = CheckBoxState.Unchecked; } - - private class Light : Container, IStateful - { - private Box fill; - - const float border_width = 3; - private Color4 glowingColour, idleColour; - - public Light() - { - Size = new Vector2(20, 12); - - Masking = true; - - CornerRadius = Height / 2; - Masking = true; - BorderColour = Color4.White; - BorderThickness = border_width; - - Children = new[] - { - fill = new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 0.01f, //todo: remove once we figure why containers aren't drawing at all times - }, - }; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - Colour = idleColour = colours.Pink; - glowingColour = colours.PinkLighter; - - EdgeEffect = new EdgeEffect - { - Colour = colours.PinkDarker, - Type = EdgeEffectType.Glow, - Radius = 10, - Roundness = 8, - }; - - FadeGlowTo(0); - } - - public bool Glowing - { - set - { - if (value) - { - ResizeTo(new Vector2(40, 12), 500, EasingTypes.OutQuint); - FadeColour(glowingColour, 500, EasingTypes.OutQuint); - FadeGlowTo(1, 500, EasingTypes.OutQuint); - } - else - { - ResizeTo(new Vector2(20, 12), 500, EasingTypes.OutQuint); - FadeGlowTo(0, 500); - FadeColour(idleColour, 500); - } - } - } - - private CheckBoxState state; - - public CheckBoxState State - { - get - { - return state; - } - set - { - state = value; - - switch (state) - { - case CheckBoxState.Checked: - fill.FadeIn(200, EasingTypes.OutQuint); - break; - case CheckBoxState.Unchecked: - fill.FadeTo(0.01f, 200, EasingTypes.OutQuint); //todo: remove once we figure why containers aren't drawing at all times - break; - } - } - } - } - } } diff --git a/osu.Game/Graphics/UserInterface/OsuNub.cs b/osu.Game/Graphics/UserInterface/OsuNub.cs new file mode 100644 index 0000000000..78d8a8ab81 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/OsuNub.cs @@ -0,0 +1,113 @@ +// Copyright (c) 2007-2016 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using osu.Framework.Graphics.UserInterface; + +namespace osu.Game.Graphics.UserInterface +{ + class OsuNub : Container, IStateful + { + public const float COLLAPSED_SIZE = 20; + public const float EXPANDED_SIZE = 40; + + private Box fill; + + const float border_width = 3; + private Color4 glowingColour, idleColour; + + public OsuNub() + { + Size = new Vector2(COLLAPSED_SIZE, 12); + + Masking = true; + + CornerRadius = Height / 2; + Masking = true; + BorderColour = Color4.White; + BorderThickness = border_width; + + Children = new[] + { + fill = new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.01f, //todo: remove once we figure why containers aren't drawing at all times + }, + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + Colour = idleColour = colours.Pink; + glowingColour = colours.PinkLighter; + + EdgeEffect = new EdgeEffect + { + Colour = colours.PinkDarker, + Type = EdgeEffectType.Glow, + Radius = 10, + Roundness = 8, + }; + + FadeGlowTo(0); + } + + public bool Glowing + { + set + { + if (value) + { + FadeColour(glowingColour, 500, EasingTypes.OutQuint); + FadeGlowTo(1, 500, EasingTypes.OutQuint); + } + else + { + FadeGlowTo(0, 500); + FadeColour(idleColour, 500); + } + } + } + + public bool Expanded + { + set + { + ResizeTo(new Vector2(value ? EXPANDED_SIZE : COLLAPSED_SIZE, 12), 500, EasingTypes.OutQuint); + } + } + + private CheckBoxState state; + + public CheckBoxState State + { + get + { + return state; + } + set + { + state = value; + + switch (state) + { + case CheckBoxState.Checked: + fill.FadeIn(200, EasingTypes.OutQuint); + break; + case CheckBoxState.Unchecked: + fill.FadeTo(0.01f, 200, EasingTypes.OutQuint); //todo: remove once we figure why containers aren't drawing at all times + break; + } + } + } + } +} diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs new file mode 100644 index 0000000000..989395359e --- /dev/null +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -0,0 +1,131 @@ +// Copyright (c) 2007-2016 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE + +using OpenTK; +using OpenTK.Input; +using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input; + +namespace osu.Game.Graphics.UserInterface +{ + public class OsuSliderBar : SliderBar where U : struct + { + private AudioSample sample; + private double lastSampleTime; + + private OsuNub nub; + private Box leftBox, rightBox; + + public OsuSliderBar() + { + Height = 12; + RangePadding = 20; + Children = new Drawable[] + { + leftBox = new Box + { + Height = 2, + Position = new Vector2(2, 0), + RelativeSizeAxes = Axes.None, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }, + rightBox = new Box + { + Height = 2, + Position = new Vector2(-2, 0), + RelativeSizeAxes = Axes.None, + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Alpha = 0.5f, + }, + nub = new OsuNub + { + Origin = Anchor.TopCentre, + State = CheckBoxState.Unchecked, + Expanded = true, + } + }; + } + + [BackgroundDependencyLoader] + private void load(AudioManager audio, OsuColour colours) + { + sample = audio.Sample.Get(@"Sliderbar/sliderbar"); + leftBox.Colour = colours.Pink; + rightBox.Colour = colours.Pink; + } + + private void playSample() + { + if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50) + return; + lastSampleTime = Clock.CurrentTime; + sample.Frequency.Value = 1 + NormalizedValue * 0.2f; + sample.Play(); + } + + protected override bool OnHover(InputState state) + { + nub.Glowing = true; + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + nub.Glowing = false; + base.OnHoverLost(state); + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (args.Key == Key.Left || args.Key == Key.Right) + playSample(); + return base.OnKeyDown(state, args); + } + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + nub.State = CheckBoxState.Checked; + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) + { + nub.State = CheckBoxState.Unchecked; + return base.OnMouseUp(state, args); + } + + protected override bool OnClick(InputState state) + { + playSample(); + return base.OnClick(state); + } + + protected override bool OnDrag(InputState state) + { + playSample(); + return base.OnDrag(state); + } + + protected override void Update() + { + base.Update(); + leftBox.Scale = new Vector2(MathHelper.Clamp( + nub.DrawPosition.X - nub.DrawWidth / 2, 0, DrawWidth), 1); + rightBox.Scale = new Vector2(MathHelper.Clamp( + DrawWidth - nub.DrawPosition.X - nub.DrawWidth / 2, 0, DrawWidth), 1); + } + + protected override void UpdateValue(float value) + { + nub.MoveToX(RangePadding + UsableWidth * value, 250, EasingTypes.OutQuint); + } + } +} diff --git a/osu.Game/Overlays/Options/OptionSlider.cs b/osu.Game/Overlays/Options/OptionSlider.cs index d48dd1d234..5ca5695ecc 100644 --- a/osu.Game/Overlays/Options/OptionSlider.cs +++ b/osu.Game/Overlays/Options/OptionSlider.cs @@ -1,24 +1,14 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using OpenTK; -using OpenTK.Input; -using OpenTK.Graphics; -using osu.Framework.Allocation; -using osu.Framework.Audio; -using osu.Framework.Audio.Sample; 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; -using osu.Framework.Input; -using osu.Game.Graphics; -using System.Linq; using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options { @@ -48,9 +38,12 @@ namespace osu.Game.Overlays.Options Direction = FlowDirection.VerticalOnly; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; + Padding = new MarginPadding { Right = 5 }; + Children = new Drawable[] { - text = new OsuSpriteText { + text = new OsuSpriteText + { Alpha = 0, }, slider = new OsuSliderBar @@ -60,116 +53,5 @@ namespace osu.Game.Overlays.Options } }; } - - private class OsuSliderBar : SliderBar where U : struct - { - private AudioSample sample; - private double lastSampleTime; - - private Container nub; - private Box leftBox, rightBox; - - private float innerWidth - { - get - { - return DrawWidth - Height; - } - } - - public OsuSliderBar() - { - Height = 20; - Padding = new MarginPadding { Left = Height / 2, Right = Height / 2 }; - Children = new Drawable[] - { - leftBox = new Box - { - Height = 2, - RelativeSizeAxes = Axes.None, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - }, - rightBox = new Box - { - Height = 2, - RelativeSizeAxes = Axes.None, - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - Alpha = 0.5f, - }, - nub = new Container - { - Width = Height, - Height = Height, - CornerRadius = Height / 2, - Origin = Anchor.TopCentre, - AutoSizeAxes = Axes.None, - RelativeSizeAxes = Axes.None, - Masking = true, - BorderThickness = 3, - Children = new[] - { - new Box - { - RelativeSizeAxes = Axes.Both - } - } - } - }; - } - - [BackgroundDependencyLoader] - private void load(AudioManager audio, OsuColour colours) - { - sample = audio.Sample.Get(@"Sliderbar/sliderbar"); - leftBox.Colour = colours.Pink; - rightBox.Colour = colours.Pink; - nub.BorderColour = colours.Pink; - (nub.Children.First() as Box).Colour = colours.Pink.Opacity(0); - } - - private void playSample() - { - if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50) - return; - lastSampleTime = Clock.CurrentTime; - sample.Frequency.Value = 1 + NormalizedValue * 0.2f; - sample.Play(); - } - - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - if (args.Key == Key.Left || args.Key == Key.Right) - playSample(); - return base.OnKeyDown(state, args); - } - - protected override bool OnClick(InputState state) - { - playSample(); - return base.OnClick(state); - } - - protected override bool OnDrag(InputState state) - { - playSample(); - return base.OnDrag(state); - } - - protected override void Update() - { - base.Update(); - leftBox.Scale = new Vector2(MathHelper.Clamp( - nub.DrawPosition.X - nub.DrawWidth / 2 + 2, 0, innerWidth), 1); - rightBox.Scale = new Vector2(MathHelper.Clamp( - innerWidth - nub.DrawPosition.X - nub.DrawWidth / 2 + 2, 0, innerWidth), 1); - } - - protected override void UpdateValue(float value) - { - nub.MoveToX(innerWidth * value); - } - } } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 3eeffa3206..0b8f65a12c 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -68,6 +68,8 @@ + + From f4dfc477f48c972f6f93dd24cfdd5d0f3cf14497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sat, 4 Feb 2017 10:04:01 +0100 Subject: [PATCH 2/3] Update framework. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index e39f0c4683..3eb6af1e53 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit e39f0c468399f3f9bea8832fcfe12a0595b59cae +Subproject commit 3eb6af1e532442da444fc5365ef2bace47549f52 From d6714324dfcbe92485ec9e4583ec260a2e1e51a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Sat, 4 Feb 2017 12:06:53 +0100 Subject: [PATCH 3/3] OsuNub -> Nub. --- osu.Game/Graphics/UserInterface/{OsuNub.cs => Nub.cs} | 4 ++-- osu.Game/Graphics/UserInterface/OsuCheckbox.cs | 4 ++-- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 4 ++-- osu.Game/osu.Game.csproj | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename osu.Game/Graphics/UserInterface/{OsuNub.cs => Nub.cs} (94%) diff --git a/osu.Game/Graphics/UserInterface/OsuNub.cs b/osu.Game/Graphics/UserInterface/Nub.cs similarity index 94% rename from osu.Game/Graphics/UserInterface/OsuNub.cs rename to osu.Game/Graphics/UserInterface/Nub.cs index 78d8a8ab81..cd59c13d12 100644 --- a/osu.Game/Graphics/UserInterface/OsuNub.cs +++ b/osu.Game/Graphics/UserInterface/Nub.cs @@ -13,7 +13,7 @@ using osu.Framework.Graphics.UserInterface; namespace osu.Game.Graphics.UserInterface { - class OsuNub : Container, IStateful + class Nub : Container, IStateful { public const float COLLAPSED_SIZE = 20; public const float EXPANDED_SIZE = 40; @@ -23,7 +23,7 @@ namespace osu.Game.Graphics.UserInterface const float border_width = 3; private Color4 glowingColour, idleColour; - public OsuNub() + public Nub() { Size = new Vector2(COLLAPSED_SIZE, 12); diff --git a/osu.Game/Graphics/UserInterface/OsuCheckbox.cs b/osu.Game/Graphics/UserInterface/OsuCheckbox.cs index e0e973e8f0..d48f860e74 100644 --- a/osu.Game/Graphics/UserInterface/OsuCheckbox.cs +++ b/osu.Game/Graphics/UserInterface/OsuCheckbox.cs @@ -66,7 +66,7 @@ namespace osu.Game.Graphics.UserInterface } } - private OsuNub nub; + private Nub nub; private SpriteText labelSpriteText; private AudioSample sampleChecked; private AudioSample sampleUnchecked; @@ -79,7 +79,7 @@ namespace osu.Game.Graphics.UserInterface Children = new Drawable[] { labelSpriteText = new OsuSpriteText(), - nub = new OsuNub + nub = new Nub { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 989395359e..968f70364c 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -19,7 +19,7 @@ namespace osu.Game.Graphics.UserInterface private AudioSample sample; private double lastSampleTime; - private OsuNub nub; + private Nub nub; private Box leftBox, rightBox; public OsuSliderBar() @@ -45,7 +45,7 @@ namespace osu.Game.Graphics.UserInterface Origin = Anchor.CentreRight, Alpha = 0.5f, }, - nub = new OsuNub + nub = new Nub { Origin = Anchor.TopCentre, State = CheckBoxState.Unchecked, diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 0b8f65a12c..5f7c171cfe 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -68,7 +68,7 @@ - +