Skip to content

Commit

Permalink
implement color picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Flutterish committed Mar 1, 2021
1 parent b4696b0 commit 874f06f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Hitokori/Objects/Drawables/Hitokori/StandardOrbital.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions Hitokori/Objects/Drawables/Trails/CircularConnector.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 );

Expand Down
4 changes: 4 additions & 0 deletions Hitokori/Objects/Drawables/Trails/Trail.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 );
}
Expand Down
65 changes: 61 additions & 4 deletions Hitokori/UI/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,46 @@ protected override void Update () {
private class HueNotch : CompositeDrawable {
Drawable ring;
public Action<float> OnHueChange;
BindableInt interactionCount = new();

Box box;
public IBindable<float> 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;
}

Expand All @@ -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 );
Expand All @@ -266,13 +296,34 @@ private class SVNotch : Circle {
public IBindable<float> HueProgress { get; init; }
public IBindable<float> SaturationProgress { get; init; }
public IBindable<float> 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 () {
Expand All @@ -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<float> OnSaturationChange;
public Action<float> OnValueChange;
protected override void OnDrag ( DragEvent e ) {
Expand Down
2 changes: 1 addition & 1 deletion Hitokori/osu.Game.Rulesets.Hitokori.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ppy.osu.Game" Version="2021.220.0" />
<PackageReference Include="ppy.osu.Game" Version="2021.226.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 2 additions & 4 deletions Tests/TestSceneOsuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit 874f06f

Please sign in to comment.