1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 07:27:25 +08:00

Delete ClickableText class, use OsuHoverContainer instead

This commit is contained in:
HoutarouOreki 2018-07-26 14:19:58 +02:00
parent a2959e9171
commit 0f263e2cca
3 changed files with 29 additions and 177 deletions

View File

@ -1,30 +0,0 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using System;
using System.Collections.Generic;
namespace osu.Game.Tests.Visual
{
public class TestCaseClickableText : OsuTestCase
{
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(ClickableText), typeof(FillFlowContainer) };
private readonly ClickableText text;
public TestCaseClickableText() => Child = new FillFlowContainer
{
Children = new[]
{
new ClickableText { Text = "Default", },
new ClickableText { IsEnabled = false, Text = "Disabled", },
new ClickableText { Text = "Without sounds", IsMuted = true, },
new ClickableText { Text = "Without click sounds", IsClickMuted = true, },
new ClickableText { Text = "Without hover sounds", IsHoverMuted = true, },
text = new ClickableText { Text = "Disables after click (Action)", Action = () => text.IsEnabled = false },
new ClickableText { Text = "Has tooltip", TooltipText = "Yep", },
}
};
}
}

View File

@ -1,127 +0,0 @@
// 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.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input.States;
using osu.Game.Graphics.Sprites;
using System;
namespace osu.Game.Graphics.UserInterface
{
// created a new class instead of using a Link in
// some kind of textflowcontainer because they aren't
// capable of having delegates/actions on click
// and (probably) can't be disabled
public class ClickableText : OsuSpriteText, IHasTooltip
{
private bool isEnabled;
private bool isMuted;
private SampleChannel sampleHover;
private SampleChannel sampleClick;
protected Color4 HoverColour;
protected Color4 IdleColour;
/// <summary>
/// An action that can be set to execute after click.
/// </summary>
public Action Action;
/// <summary>
/// If set to true, a sound will be played on click.
/// </summary>
public bool IsClickMuted;
/// <summary>
/// If set to true, a sound will be played on hover.
/// </summary>
public bool IsHoverMuted;
/// <summary>
/// If disabled, no sounds will be played and <see cref="Action"/> wont execute.
/// True by default.
/// </summary>
public bool IsEnabled
{
get { return isEnabled; }
set
{
isEnabled = value;
this.FadeTo(value ? 1 : 0.5f, 250);
}
}
/// <summary>
/// Whether to play sounds on hover and click. Automatically sets
/// <see cref="IsClickMuted"/> and <see cref="IsHoverMuted"/> to the same value.>
/// </summary>
public bool IsMuted {
get { return isMuted; }
set
{
IsHoverMuted = value;
IsClickMuted = value;
isMuted = value;
}
}
/// <summary>
/// A text with sounds on hover and click,
/// an action that can be set to execute on click,
/// and a tooltip.
/// </summary>
public ClickableText() => isEnabled = true;
public override bool HandleMouseInput => true;
protected override bool OnHover(InputState state)
{
if (isEnabled)
{
this.FadeColour(HoverColour, 500, Easing.OutQuint);
if (!IsHoverMuted)
sampleHover?.Play();
}
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)
{
if (isEnabled)
{
if (!IsClickMuted)
sampleClick?.Play();
Action?.Invoke();
}
return base.OnClick(state);
}
protected override void LoadComplete()
{
IdleColour = Colour;
base.LoadComplete();
}
public string TooltipText { get; set; }
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours)
{
sampleClick = audio.Sample.Get(@"UI/generic-select-soft");
sampleHover = audio.Sample.Get(@"UI/generic-hover-soft");
HoverColour = colours.Yellow;
}
}
}

View File

@ -118,7 +118,7 @@ namespace osu.Game.Overlays.Changelog
public ChangelogContentGroup(APIChangelog build, bool newDate)
{
ClickableText clickableText;
OsuHoverContainer clickableBuildText;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Direction = FillDirection.Vertical;
@ -138,29 +138,33 @@ namespace osu.Game.Overlays.Changelog
Margin = new MarginPadding { Top = 20 },
Alpha = newDate ? 1 : 0,
},
new FillFlowContainer
clickableBuildText = new OsuHoverContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Top = 20 },
Spacing = new Vector2(5),
Children = new Drawable[]
Action = () => OnBuildSelected(build),
Child = new FillFlowContainer
{
new SpriteText
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
Text = build.UpdateStream.DisplayName,
TextSize = 20, // web: 18,
Font = @"Exo2.0-Medium",
},
clickableText = new ClickableText
{
Text = build.DisplayVersion,
TextSize = 20, // web: 18,
Font = @"Exo2.0-Light",
Colour = StreamColour.FromStreamName(build.UpdateStream.Name),
Action = () => OnBuildSelected(build),
new SpriteText
{
Text = build.UpdateStream.DisplayName,
TextSize = 20, // web: 18,
Font = @"Exo2.0-Medium",
},
new SpriteText
{
Text = build.DisplayVersion,
TextSize = 20, // web: 18,
Font = @"Exo2.0-Light",
Colour = StreamColour.FromStreamName(build.UpdateStream.Name),
},
},
}
},
@ -173,10 +177,15 @@ namespace osu.Game.Overlays.Changelog
};
// we may not want double clicks to make it double the work
clickableText.Action += () =>
// can be clicked again only after a delay
clickableBuildText.Action += () =>
{
clickableText.IsEnabled = false;
Scheduler.AddDelayed(() => clickableText.IsEnabled = true, 2000);
clickableBuildText.Action = null;
clickableBuildText.FadeTo(0.5f, 500);
Scheduler.AddDelayed(() => {
clickableBuildText.Action = () => OnBuildSelected(build);
clickableBuildText.FadeIn(500);
}, 2000);
};
}