1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 07:22:55 +08:00

generalize the hover code

This commit is contained in:
Jorolf 2017-08-08 23:11:46 +02:00
parent 02a22e3f77
commit 1c2329f111
3 changed files with 50 additions and 21 deletions

View File

@ -0,0 +1,32 @@

using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Input;
namespace osu.Game.Graphics.Containers
{
public class OsuHoverContainer : OsuClickableContainer
{
private Color4 hoverColour;
protected override bool OnHover(InputState state)
{
this.FadeColour(hoverColour, 500, Easing.OutQuint);
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
this.FadeColour(Color4.White, 500, Easing.OutQuint);
base.OnHoverLost(state);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
hoverColour = colours.Yellow;
}
}
}

View File

@ -19,6 +19,7 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Users;
using System.Diagnostics;
using System.Globalization;
using System.Collections.Generic;
namespace osu.Game.Overlays.Profile
{
@ -509,34 +510,29 @@ namespace osu.Game.Overlays.Profile
public class LinkText : OsuSpriteText
{
public override bool HandleInput => Url != null;
private readonly OsuHoverContainer content;
public string Url;
public override bool HandleInput => content.Action != null;
private Color4 hoverColour;
protected override Container<Drawable> Content => content ?? (Container<Drawable>)this;
protected override bool OnHover(InputState state)
protected override IEnumerable<Drawable> FlowingChildren => Children;
public string Url
{
this.FadeColour(hoverColour, 500, Easing.OutQuint);
return base.OnHover(state);
set
{
if(value != null)
content.Action = () => Process.Start(value);
}
}
protected override void OnHoverLost(InputState state)
public LinkText()
{
this.FadeColour(Color4.White, 500, Easing.OutQuint);
base.OnHoverLost(state);
}
protected override bool OnClick(InputState state)
{
Process.Start(Url);
return true;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
hoverColour = colours.Yellow;
AddInternal(content = new OsuHoverContainer
{
AutoSizeAxes = Axes.Both,
});
}
}
}

View File

@ -92,6 +92,7 @@
<Compile Include="Graphics\UserInterface\MenuItemType.cs" />
<Compile Include="Graphics\UserInterface\OsuContextMenu.cs" />
<Compile Include="Graphics\UserInterface\OsuContextMenuItem.cs" />
<Compile Include="Graphics\Containers\OsuHoverContainer.cs" />
<Compile Include="IO\FileStore.cs" />
<Compile Include="IO\FileInfo.cs" />
<Compile Include="Online\API\Requests\GetUsersRequest.cs" />