Update arrow colour on hover

This commit is contained in:
Andrei Zavatski
2020-07-11 08:13:11 +03:00
parent 42d3288f17
commit b1b2e961bc
2 changed files with 70 additions and 73 deletions

View File

@ -26,22 +26,10 @@ namespace osu.Game.Tests.Visual.UserInterface
Spacing = new Vector2(0, 10), Spacing = new Vector2(0, 10),
Children = new Drawable[] Children = new Drawable[]
{ {
new TestButton new TestButton(),
{ new LoadRepliesButton(),
Action = () => { } new ShowRepliesButton(1),
},
new LoadRepliesButton
{
Action = () => { }
},
new ShowRepliesButton(1)
{
Action = () => { }
},
new ShowRepliesButton(2) new ShowRepliesButton(2)
{
Action = () => { }
}
} }
}; };
} }

View File

@ -1,100 +1,109 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK; using osuTK;
namespace osu.Game.Overlays.Comments.Buttons namespace osu.Game.Overlays.Comments.Buttons
{ {
public abstract class CommentRepliesButton : OsuHoverContainer public abstract class CommentRepliesButton : CompositeDrawable
{ {
protected override IEnumerable<Drawable> EffectTargets => new[] { background }; public Action Action { get; set; }
protected ChevronIcon Icon; [Resolved]
private OverlayColourProvider colourProvider { get; set; }
protected SpriteIcon Icon;
private Box background; private Box background;
public CommentRepliesButton() [BackgroundDependencyLoader]
private void load()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
} InternalChildren = new Drawable[]
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Add(new CircularContainer
{ {
AutoSizeAxes = Axes.Both, new CircularContainer
Masking = true,
Children = new Drawable[]
{ {
background = new Box AutoSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
{ {
RelativeSizeAxes = Axes.Both background = new Box
},
new Container
{
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding
{ {
Vertical = 5, RelativeSizeAxes = Axes.Both,
Horizontal = 10, Colour = colourProvider.Background2
}, },
Child = new FillFlowContainer new Container
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal, Margin = new MarginPadding
Spacing = new Vector2(15, 0),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{ {
new OsuSpriteText Vertical = 5,
Horizontal = 10,
},
Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(15, 0),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{ {
Anchor = Anchor.CentreLeft, new OsuSpriteText
Origin = Anchor.CentreLeft, {
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold), Anchor = Anchor.CentreLeft,
Text = GetText() Origin = Anchor.CentreLeft,
}, Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
Icon = new ChevronIcon Text = GetText()
{ },
Anchor = Anchor.CentreLeft, Icon = new SpriteIcon
Origin = Anchor.CentreLeft, {
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(7.5f),
Icon = FontAwesome.Solid.ChevronDown,
Colour = colourProvider.Foreground1
}
} }
} }
} }
} }
} },
}); new HoverClickSounds(),
};
IdleColour = colourProvider.Background2;
HoverColour = colourProvider.Background1;
} }
protected abstract string GetText(); protected abstract string GetText();
protected class ChevronIcon : SpriteIcon protected override bool OnHover(HoverEvent e)
{ {
public ChevronIcon() base.OnHover(e);
{ background.FadeColour(colourProvider.Background1, 200, Easing.OutQuint);
Anchor = Anchor.Centre; Icon.FadeColour(colourProvider.Light1, 200, Easing.OutQuint);
Origin = Anchor.Centre; return true;
Size = new Vector2(7.5f); }
Icon = FontAwesome.Solid.ChevronDown;
}
[BackgroundDependencyLoader] protected override void OnHoverLost(HoverLostEvent e)
private void load(OverlayColourProvider colourProvider) {
{ base.OnHoverLost(e);
Colour = colourProvider.Foreground1; background.FadeColour(colourProvider.Background2, 200, Easing.OutQuint);
} Icon.FadeColour(colourProvider.Foreground1, 200, Easing.OutQuint);
}
protected override bool OnClick(ClickEvent e)
{
Action?.Invoke();
return base.OnClick(e);
} }
} }
} }