2018-07-20 01:07:24 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
2018-07-21 01:35:38 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-07-21 01:35:38 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-07-21 01:35:38 +08:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using System;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2018-07-21 01:35:38 +08:00
|
|
|
|
// not inheriting osuclickablecontainer/osuhovercontainer
|
|
|
|
|
// because click/hover sounds cannot be disabled, and they make
|
|
|
|
|
// double sounds when reappearing under the cursor
|
|
|
|
|
public class TooltipIconButton : ClickableContainer, IHasTooltip
|
2018-07-20 01:07:24 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly SpriteIcon icon;
|
2018-07-21 01:35:38 +08:00
|
|
|
|
private SampleChannel sampleClick;
|
|
|
|
|
private SampleChannel sampleHover;
|
|
|
|
|
public Action Action;
|
|
|
|
|
|
|
|
|
|
private bool isEnabled;
|
|
|
|
|
public bool IsEnabled
|
|
|
|
|
{
|
|
|
|
|
get { return isEnabled; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
isEnabled = value;
|
|
|
|
|
icon.Alpha = value ? 1 : 0.5f;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-20 01:07:24 +08:00
|
|
|
|
|
|
|
|
|
public FontAwesome Icon
|
|
|
|
|
{
|
|
|
|
|
get { return icon.Icon; }
|
|
|
|
|
set { icon.Icon = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TooltipIconButton()
|
|
|
|
|
{
|
2018-07-21 01:35:38 +08:00
|
|
|
|
isEnabled = true;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
Children = new Drawable[]
|
2018-07-20 06:52:50 +08:00
|
|
|
|
{
|
|
|
|
|
new Box
|
2018-07-20 01:07:24 +08:00
|
|
|
|
{
|
2018-07-20 06:52:50 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
|
|
|
|
icon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(18),
|
2018-07-21 01:35:38 +08:00
|
|
|
|
Alpha = 0.5f,
|
2018-07-20 06:52:50 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-07-20 01:07:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-21 01:35:38 +08:00
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (isEnabled)
|
|
|
|
|
{
|
|
|
|
|
Action?.Invoke();
|
|
|
|
|
sampleClick?.Play();
|
|
|
|
|
}
|
|
|
|
|
return base.OnClick(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (isEnabled)
|
|
|
|
|
sampleHover?.Play();
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
|
|
|
|
sampleClick = audio.Sample.Get(@"UI/generic-select-soft");
|
|
|
|
|
sampleHover = audio.Sample.Get(@"UI/generic-hover-soft");
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-20 01:07:24 +08:00
|
|
|
|
public string TooltipText { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|