Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drag bar on chat overlay to better signal resize-ability #25567

Merged
merged 8 commits into from
Nov 27, 2023
80 changes: 76 additions & 4 deletions osu.Game/Overlays/Chat/ChatOverlayTopBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
Expand All @@ -19,14 +18,16 @@
{
public partial class ChatOverlayTopBar : Container
{
private Box background = null!;

Check failure on line 21 in osu.Game/Overlays/Chat/ChatOverlayTopBar.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Field 'background' is assigned but its value is never used in osu.Game\Overlays\Chat\ChatOverlayTopBar.cs on line 21

private Color4 backgroundColour;

Check failure on line 23 in osu.Game/Overlays/Chat/ChatOverlayTopBar.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Field 'backgroundColour' is assigned but its value is never used in osu.Game\Overlays\Chat\ChatOverlayTopBar.cs on line 23

public Drawable DragBar = null!;

[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, TextureStore textures)
{
Children = new Drawable[]

Check failure on line 30 in osu.Game/Overlays/Chat/ChatOverlayTopBar.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Redundant explicit array type specification in osu.Game\Overlays\Chat\ChatOverlayTopBar.cs on line 30
{
background = new Box
{
Expand All @@ -50,7 +51,7 @@
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = textures.Get("Icons/Hexacons/messaging"),
Size = new Vector2(18),
Size = new Vector2(24),
},
// Placeholder text
new OsuSpriteText
Expand All @@ -64,19 +65,90 @@
},
},
},
DragBar = new DragArea
{
Alpha = 0,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = colourProvider.Background4,
}
};
}

protected override bool OnHover(HoverEvent e)
{
background.FadeColour(backgroundColour.Lighten(0.1f), 300, Easing.OutQuint);
DragBar.FadeIn(100);
return base.OnHover(e);
}

protected override void OnHoverLost(HoverLostEvent e)
{
background.FadeColour(backgroundColour, 300, Easing.OutQuint);
DragBar.FadeOut(100);
base.OnHoverLost(e);
}

private partial class DragArea : CompositeDrawable
{
private readonly Circle circle;

public DragArea()
{
AutoSizeAxes = Axes.Both;

InternalChildren = new Drawable[]
{
circle = new Circle
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(150, 7),
Margin = new MarginPadding(12),
}
};
}

protected override bool OnHover(HoverEvent e)
{
updateScale();
return base.OnHover(e);
}

protected override void OnHoverLost(HoverLostEvent e)
{
updateScale();
base.OnHoverLost(e);
}

private bool dragging;

protected override bool OnMouseDown(MouseDownEvent e)
{
dragging = true;
updateScale();
return base.OnMouseDown(e);
}

protected override void OnMouseUp(MouseUpEvent e)
{
dragging = false;
updateScale();
base.OnMouseUp(e);
}

private void updateScale()
{
if (dragging || IsHovered)
circle.FadeIn(100);
else
circle.FadeTo(0.6f, 100);

if (dragging)
circle.ScaleTo(1f, 400, Easing.OutQuint);
else if (IsHovered)
circle.ScaleTo(1.05f, 400, Easing.OutElasticHalf);
else
circle.ScaleTo(1f, 500, Easing.OutQuint);
}
}
}
}
8 changes: 6 additions & 2 deletions osu.Game/Overlays/ChatOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,14 @@ public void OnReleased(KeyBindingReleaseEvent<PlatformAction> e)
{
}

protected override bool OnDragStart(DragStartEvent e)
protected override bool OnMouseDown(MouseDownEvent e)
{
isDraggingTopBar = topBar.IsHovered;
isDraggingTopBar = topBar.DragBar.IsHovered;
return base.OnMouseDown(e);
}

protected override bool OnDragStart(DragStartEvent e)
{
if (!isDraggingTopBar)
return base.OnDragStart(e);

Expand Down