Improvements to TooltipIconButton

Disable sounds when disabled; Remove default tooltip texts
This commit is contained in:
HoutarouOreki 2018-07-20 19:35:38 +02:00
parent b049ffa11d
commit 835a813715
2 changed files with 58 additions and 4 deletions

View File

@ -2,16 +2,38 @@
// 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; using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers; using osu.Framework.Input;
using System;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
public class TooltipIconButton : OsuClickableContainer, IHasTooltip // 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
{ {
private readonly SpriteIcon icon; private readonly SpriteIcon icon;
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;
}
}
public FontAwesome Icon public FontAwesome Icon
{ {
@ -21,6 +43,7 @@ namespace osu.Game.Graphics.UserInterface
public TooltipIconButton() public TooltipIconButton()
{ {
isEnabled = true;
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -33,10 +56,35 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.Centre, Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Size = new Vector2(18), Size = new Vector2(18),
Alpha = 0.5f,
} }
}; };
} }
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");
}
public string TooltipText { get; set; } public string TooltipText { get; set; }
} }
} }

View File

@ -44,9 +44,9 @@ namespace osu.Game.Overlays.Changelog
{ {
chevronPrevious = new TooltipIconButton chevronPrevious = new TooltipIconButton
{ {
IsEnabled = false,
Icon = FontAwesome.fa_chevron_left, Icon = FontAwesome.fa_chevron_left,
Size = new Vector2(24), Size = new Vector2(24),
TooltipText = "Previous",
Action = () => PreviousRequested(), Action = () => PreviousRequested(),
}, },
new FillFlowContainer<SpriteText> new FillFlowContainer<SpriteText>
@ -81,9 +81,9 @@ namespace osu.Game.Overlays.Changelog
}, },
chevronNext = new TooltipIconButton chevronNext = new TooltipIconButton
{ {
IsEnabled = false,
Icon = FontAwesome.fa_chevron_right, Icon = FontAwesome.fa_chevron_right,
Size = new Vector2(24), Size = new Vector2(24),
TooltipText = "Next",
Action = () => NextRequested(), Action = () => NextRequested(),
}, },
} }
@ -109,9 +109,15 @@ namespace osu.Game.Overlays.Changelog
public void UpdateChevronTooltips(string previousVersion, string nextVersion) public void UpdateChevronTooltips(string previousVersion, string nextVersion)
{ {
if (!string.IsNullOrEmpty(previousVersion)) if (!string.IsNullOrEmpty(previousVersion))
{
chevronPrevious.TooltipText = previousVersion; chevronPrevious.TooltipText = previousVersion;
chevronPrevious.IsEnabled = true;
}
if (!string.IsNullOrEmpty(nextVersion)) if (!string.IsNullOrEmpty(nextVersion))
{
chevronNext.TooltipText = nextVersion; chevronNext.TooltipText = nextVersion;
chevronNext.IsEnabled = true;
}
} }
//public ChangelogContentGroup() { } // for listing //public ChangelogContentGroup() { } // for listing
} }