mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 18:32:56 +08:00
ClickableText changes colour on hover
This commit is contained in:
parent
e1a24f55cf
commit
6e6e43e8df
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
@ -20,9 +21,13 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
private bool isEnabled;
|
private bool isEnabled;
|
||||||
private bool isMuted;
|
private bool isMuted;
|
||||||
|
|
||||||
private SampleChannel sampleHover;
|
private SampleChannel sampleHover;
|
||||||
private SampleChannel sampleClick;
|
private SampleChannel sampleClick;
|
||||||
|
|
||||||
|
protected Color4 HoverColour;
|
||||||
|
protected Color4 IdleColour;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An action that can be set to execute after click.
|
/// An action that can be set to execute after click.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -78,10 +83,19 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
protected override bool OnHover(InputState state)
|
protected override bool OnHover(InputState state)
|
||||||
{
|
{
|
||||||
if (isEnabled && !IsHoverMuted)
|
if (isEnabled && !IsHoverMuted)
|
||||||
|
{
|
||||||
|
this.FadeColour(HoverColour, 500, Easing.OutQuint);
|
||||||
sampleHover?.Play();
|
sampleHover?.Play();
|
||||||
|
}
|
||||||
return base.OnHover(state);
|
return base.OnHover(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(InputState state)
|
||||||
|
{
|
||||||
|
this.FadeColour(IdleColour, 500, Easing.OutQuint);
|
||||||
|
base.OnHoverLost(state);
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnClick(InputState state)
|
protected override bool OnClick(InputState state)
|
||||||
{
|
{
|
||||||
if (isEnabled)
|
if (isEnabled)
|
||||||
@ -93,13 +107,20 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
return base.OnClick(state);
|
return base.OnClick(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
IdleColour = Colour;
|
||||||
|
base.LoadComplete();
|
||||||
|
}
|
||||||
|
|
||||||
public string TooltipText { get; set; }
|
public string TooltipText { get; set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(AudioManager audio)
|
private void load(AudioManager audio, OsuColour colours)
|
||||||
{
|
{
|
||||||
sampleClick = audio.Sample.Get(@"UI/generic-select-soft");
|
sampleClick = audio.Sample.Get(@"UI/generic-select-soft");
|
||||||
sampleHover = audio.Sample.Get(@"UI/generic-hover-soft");
|
sampleHover = audio.Sample.Get(@"UI/generic-hover-soft");
|
||||||
|
HoverColour = colours.Yellow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user