From 874f06fe9564034a3a03b70fcc1458aa89d09ab0 Mon Sep 17 00:00:00 2001 From: Flutterish Date: Mon, 1 Mar 2021 19:15:12 +0100 Subject: [PATCH] implement color picker --- .../Drawables/Hitokori/StandardOrbital.cs | 4 ++ .../Drawables/Trails/CircularConnector.cs | 4 ++ Hitokori/Objects/Drawables/Trails/Trail.cs | 4 ++ Hitokori/UI/ColorPicker.cs | 65 +++++++++++++++++-- Hitokori/osu.Game.Rulesets.Hitokori.csproj | 2 +- Tests/TestSceneOsuGame.cs | 6 +- 6 files changed, 76 insertions(+), 9 deletions(-) diff --git a/Hitokori/Objects/Drawables/Hitokori/StandardOrbital.cs b/Hitokori/Objects/Drawables/Hitokori/StandardOrbital.cs index d9bcab4..677aa5d 100644 --- a/Hitokori/Objects/Drawables/Hitokori/StandardOrbital.cs +++ b/Hitokori/Objects/Drawables/Hitokori/StandardOrbital.cs @@ -1,5 +1,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Shapes; using osu.Game.Rulesets.Hitokori.Objects.Base; using osu.Game.Rulesets.Hitokori.UI; @@ -34,6 +35,9 @@ public StandardOrbital ( IHasTilePosition parent, Radius radius, Colour4 colour } } + protected override bool ComputeIsMaskedAway ( RectangleF maskingBounds ) + => false; + public override void MakeImportant () { circle.ScaleTo( 1.1f, 100 ); circle.FadeTo( 1, 100 ); diff --git a/Hitokori/Objects/Drawables/Trails/CircularConnector.cs b/Hitokori/Objects/Drawables/Trails/CircularConnector.cs index 4f2f46a..4398bf5 100644 --- a/Hitokori/Objects/Drawables/Trails/CircularConnector.cs +++ b/Hitokori/Objects/Drawables/Trails/CircularConnector.cs @@ -1,6 +1,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.UserInterface; using osu.Game.Rulesets.Hitokori.Objects.Base; using osu.Game.Rulesets.Hitokori.Settings; @@ -45,6 +46,9 @@ public CircularConnector () { AutoSizeAxes = Axes.None; } + protected override bool ComputeIsMaskedAway ( RectangleF maskingBounds ) + => false; + protected override void render () { var radius = TrailRadius + Around.DistanceTo( From ); diff --git a/Hitokori/Objects/Drawables/Trails/Trail.cs b/Hitokori/Objects/Drawables/Trails/Trail.cs index 1691e7d..a7d9755 100644 --- a/Hitokori/Objects/Drawables/Trails/Trail.cs +++ b/Hitokori/Objects/Drawables/Trails/Trail.cs @@ -1,6 +1,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Lines; +using osu.Framework.Graphics.Primitives; using osu.Game.Rulesets.Hitokori.Objects.Base; using osu.Game.Rulesets.Hitokori.Utils; using osuTK; @@ -34,6 +35,9 @@ public Trail () { Line.Size = new Vector2( 400 ); } + protected override bool ComputeIsMaskedAway ( RectangleF maskingBounds ) + => false; + public void AddVertice ( Vector2 position ) { vertices.Add( position ); } diff --git a/Hitokori/UI/ColorPicker.cs b/Hitokori/UI/ColorPicker.cs index 0dcf0b3..a9b0e76 100644 --- a/Hitokori/UI/ColorPicker.cs +++ b/Hitokori/UI/ColorPicker.cs @@ -220,21 +220,46 @@ protected override void Update () { private class HueNotch : CompositeDrawable { Drawable ring; public Action OnHueChange; + BindableInt interactionCount = new(); + Box box; public IBindable HueBindable { get; init; } public HueNotch ( Drawable ring ) { - InternalChild = new Box { RelativeSizeAxes = Axes.Both, AlwaysPresent = true }; Masking = true; - BorderThickness = 2; + BorderThickness = 3; BorderColour = Color4.Black; Size = new osuTK.Vector2( 12, delta + 12 ); CornerRadius = 5; BypassAutoSizeAxes = Axes.Both; this.ring = ring; + AddRangeInternal( new Drawable[] { + box = new Box { RelativeSizeAxes = Axes.Both, AlwaysPresent = true }, + new HoverClickSounds() + } ); + + interactionCount.ValueChanged += v => { + if ( v.NewValue > 0 ) { + this.ScaleTo( 1.2f, 100 ); + } + else { + this.ScaleTo( 1, 100 ); + } + }; + } + + protected override bool OnHover ( HoverEvent e ) { + interactionCount.Value++; + return base.OnHover( e ); + } + + protected override void OnHoverLost ( HoverLostEvent e ) { + interactionCount.Value--; + base.OnHoverLost( e ); } protected override bool OnDragStart ( DragStartEvent e ) { + interactionCount.Value++; return true; } @@ -244,12 +269,17 @@ protected override void OnDrag ( DragEvent e ) { OnHueChange?.Invoke( (float)angle ); } + protected override void OnDragEnd ( DragEndEvent e ) { + interactionCount.Value--; + base.OnDragEnd( e ); + } + protected override void LoadComplete () { base.LoadComplete(); HueBindable.BindValueChanged( v => { var c = TextureGeneration.FromHSV( v.NewValue, 1, 1 ); - InternalChild.Colour = new Colour4( c.R, c.G, c.B, 255 ); + box.Colour = new Colour4( c.R, c.G, c.B, 255 ); Position = new osuTK.Vector2( MathF.Cos( v.NewValue * MathF.PI / 180 ), -MathF.Sin( v.NewValue * MathF.PI / 180 ) ) * ( MathF.Sqrt( 2 ) * size / 2 + delta / 2 ); Rotation = 90 - v.NewValue; }, true ); @@ -266,13 +296,34 @@ private class SVNotch : Circle { public IBindable HueProgress { get; init; } public IBindable SaturationProgress { get; init; } public IBindable ValueProgress { get; init; } + BindableInt interactionCount = new(); public SVNotch () { Size = new osuTK.Vector2( 15 ); Origin = Anchor.Centre; RelativePositionAxes = Axes.Both; - BorderThickness = 2; + BorderThickness = 3; BorderColour = Color4.Black; + Add( new HoverClickSounds() ); + + interactionCount.ValueChanged += v => { + if ( v.NewValue > 0 ) { + this.ScaleTo( 1.2f, 100 ); + } + else { + this.ScaleTo( 1, 100 ); + } + }; + } + + protected override bool OnHover ( HoverEvent e ) { + interactionCount.Value++; + return base.OnHover( e ); + } + + protected override void OnHoverLost ( HoverLostEvent e ) { + interactionCount.Value--; + base.OnHoverLost( e ); } protected override void LoadComplete () { @@ -293,9 +344,15 @@ private void updateColor () { } protected override bool OnDragStart ( DragStartEvent e ) { + interactionCount.Value++; return true; } + protected override void OnDragEnd ( DragEndEvent e ) { + interactionCount.Value--; + base.OnDragEnd( e ); + } + public Action OnSaturationChange; public Action OnValueChange; protected override void OnDrag ( DragEvent e ) { diff --git a/Hitokori/osu.Game.Rulesets.Hitokori.csproj b/Hitokori/osu.Game.Rulesets.Hitokori.csproj index 2baabb0..88e67d3 100644 --- a/Hitokori/osu.Game.Rulesets.Hitokori.csproj +++ b/Hitokori/osu.Game.Rulesets.Hitokori.csproj @@ -6,7 +6,7 @@ - + diff --git a/Tests/TestSceneOsuGame.cs b/Tests/TestSceneOsuGame.cs index bdeadf4..744e53f 100644 --- a/Tests/TestSceneOsuGame.cs +++ b/Tests/TestSceneOsuGame.cs @@ -15,10 +15,8 @@ private void load ( GameHost host, OsuGameBase gameBase ) { OsuGame game = new OsuGame(); game.SetHost( host ); - Children = new Drawable[] - { - new Box - { + Children = new Drawable[] { + new Box { RelativeSizeAxes = Axes.Both, Colour = Color4.Black, },