Remove usage of TooltipIconButton completely

This commit is contained in:
Dean Herbert 2019-05-19 11:28:34 +09:00
parent dae315ec0a
commit 1c85fcbc81
2 changed files with 36 additions and 116 deletions

View File

@ -1,20 +1,22 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Changelog.Components;
using osuTK;
namespace osu.Game.Overlays.Changelog
@ -82,29 +84,19 @@ namespace osu.Game.Overlays.Changelog
});
}
TooltipIconButton left, right;
NavigationIconButton left, right;
fill.AddRange(new[]
{
left = new TooltipIconButton
left = new NavigationIconButton(Build.Versions?.Previous)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.ChevronLeft,
Size = new Vector2(24),
TooltipText = Build.Versions?.Previous?.DisplayVersion,
IsEnabled = Build.Versions?.Previous != null,
Action = () => { SelectBuild?.Invoke(Build.Versions.Previous); },
SelectBuild = b => SelectBuild(b)
},
right = new TooltipIconButton
right = new NavigationIconButton(Build.Versions?.Next)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.ChevronRight,
Size = new Vector2(24),
TooltipText = Build.Versions?.Next?.DisplayVersion,
IsEnabled = Build.Versions?.Next != null,
Action = () => { SelectBuild?.Invoke(Build.Versions.Next); },
SelectBuild = b => SelectBuild(b)
},
});
@ -114,5 +106,33 @@ namespace osu.Game.Overlays.Changelog
return fill;
}
}
private class NavigationIconButton : IconButton
{
public Action<APIChangelogBuild> SelectBuild;
public NavigationIconButton(APIChangelogBuild build)
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
if (build == null) return;
TooltipText = build.DisplayVersion;
Action = () =>
{
SelectBuild?.Invoke(build);
Enabled.Value = false;
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
HoverColour = colours.GreyVioletLight.Opacity(0.6f);
FlashColour = colours.GreyVioletLighter;
}
}
}
}

View File

@ -1,100 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osuTK;
namespace osu.Game.Overlays.Changelog.Components
{
/// <summary>
/// An icon with an action upon click that can be disabled.
/// </summary>
public class TooltipIconButton : Container, IHasTooltip
{
private readonly SpriteIcon icon;
private SampleChannel sampleHover;
private SampleChannel sampleClick;
/// <summary>
/// The action to fire upon click if <see cref="IsEnabled"/> is set to true.
/// </summary>
public Action Action;
private bool isEnabled;
/// <summary>
/// If set to true, upon click the <see cref="Action"/> will execute.
/// </summary>
public bool IsEnabled
{
get => isEnabled;
set
{
isEnabled = value;
icon.FadeTo(value ? 1 : 0.5f, 250);
}
}
public IconUsage Icon
{
get => icon.Icon;
set => icon.Icon = value;
}
public TooltipIconButton()
{
isEnabled = true;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
},
icon = new SpriteIcon
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.8f),
}
};
}
protected override bool OnClick(ClickEvent e)
{
if (isEnabled)
{
sampleClick?.Play();
Action?.Invoke();
}
return base.OnClick(e);
}
protected override bool OnHover(HoverEvent e)
{
if (isEnabled)
sampleHover?.Play();
return base.OnHover(e);
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleHover = audio.Sample.Get(@"UI/generic-hover-soft");
sampleClick = audio.Sample.Get(@"UI/generic-select-soft");
}
public string TooltipText { get; set; }
}
}