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:
parent
02a22e3f77
commit
1c2329f111
32
osu.Game/Graphics/Containers/OsuHoverContainer.cs
Normal file
32
osu.Game/Graphics/Containers/OsuHoverContainer.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile
|
namespace osu.Game.Overlays.Profile
|
||||||
{
|
{
|
||||||
@ -509,34 +510,29 @@ namespace osu.Game.Overlays.Profile
|
|||||||
|
|
||||||
public class LinkText : OsuSpriteText
|
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);
|
set
|
||||||
return base.OnHover(state);
|
{
|
||||||
|
if(value != null)
|
||||||
|
content.Action = () => Process.Start(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(InputState state)
|
public LinkText()
|
||||||
{
|
{
|
||||||
this.FadeColour(Color4.White, 500, Easing.OutQuint);
|
AddInternal(content = new OsuHoverContainer
|
||||||
base.OnHoverLost(state);
|
{
|
||||||
}
|
AutoSizeAxes = Axes.Both,
|
||||||
|
});
|
||||||
protected override bool OnClick(InputState state)
|
|
||||||
{
|
|
||||||
Process.Start(Url);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuColour colours)
|
|
||||||
{
|
|
||||||
hoverColour = colours.Yellow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@
|
|||||||
<Compile Include="Graphics\UserInterface\MenuItemType.cs" />
|
<Compile Include="Graphics\UserInterface\MenuItemType.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuContextMenu.cs" />
|
<Compile Include="Graphics\UserInterface\OsuContextMenu.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuContextMenuItem.cs" />
|
<Compile Include="Graphics\UserInterface\OsuContextMenuItem.cs" />
|
||||||
|
<Compile Include="Graphics\Containers\OsuHoverContainer.cs" />
|
||||||
<Compile Include="IO\FileStore.cs" />
|
<Compile Include="IO\FileStore.cs" />
|
||||||
<Compile Include="IO\FileInfo.cs" />
|
<Compile Include="IO\FileInfo.cs" />
|
||||||
<Compile Include="Online\API\Requests\GetUsersRequest.cs" />
|
<Compile Include="Online\API\Requests\GetUsersRequest.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user