1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-20 07:23:20 +08:00
osu-lazer/osu.Game/Overlays/Changelog/Header/TextBadgePair.cs

144 lines
4.7 KiB
C#
Raw Normal View History

2018-07-17 05:50:22 +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
2018-07-19 01:32:15 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
2018-07-17 05:50:22 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
2018-07-23 16:05:19 +08:00
using osu.Framework.Input.States;
using osu.Game.Graphics.UserInterface;
2018-07-17 05:50:22 +08:00
using System;
namespace osu.Game.Overlays.Changelog.Header
{
2018-07-19 01:32:15 +08:00
public class TextBadgePair : Container
2018-07-17 05:50:22 +08:00
{
2018-07-19 01:32:15 +08:00
protected SpriteText Text;
protected LineBadge LineBadge;
public bool IsActivated { get; protected set; }
2018-07-17 05:50:22 +08:00
public delegate void ActivatedEventHandler(object source, EventArgs args);
public event ActivatedEventHandler Activated;
2018-07-19 01:32:15 +08:00
private SampleChannel sampleHover;
protected SampleChannel SampleActivate;
2018-07-18 09:26:08 +08:00
2018-07-19 01:32:15 +08:00
public TextBadgePair(ColourInfo badgeColour, string displayText = "Listing", bool startCollapsed = true)
2018-07-17 05:50:22 +08:00
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
2018-07-19 01:32:15 +08:00
Text = new SpriteText
2018-07-17 05:50:22 +08:00
{
2018-07-20 03:49:13 +08:00
TextSize = 21, // web: 16,
2018-07-17 05:50:22 +08:00
Text = displayText,
2018-07-19 01:32:15 +08:00
Margin = new MarginPadding
2018-07-17 05:50:22 +08:00
{
Top = 5,
Bottom = 15,
}
},
2018-07-19 01:32:15 +08:00
LineBadge = new LineBadge(startCollapsed)
2018-07-17 05:50:22 +08:00
{
CollapsedSize = 2,
UncollapsedSize = 10,
2018-07-17 05:50:22 +08:00
Colour = badgeColour,
Anchor = Anchor.BottomCentre,
2018-07-17 05:50:22 +08:00
}
};
}
2018-07-24 00:17:50 +08:00
/// <param name="duration">
/// The duration of popping in and popping out not combined.
/// Full change takes double this time.</param>
public void ChangeText(double duration = 0, string displayText = null, Easing easing = Easing.InOutCubic)
{
LineBadge.Collapse();
Text.MoveToY(20, duration, easing)
.FadeOut(duration, easing)
.Then()
.MoveToY(0, duration, easing)
.FadeIn(duration, easing);
// since using .finally/.oncomplete after first fadeout made the badge not hide
// sometimes in visual tests (https://streamable.com/0qssq), I'm using a scheduler here
Scheduler.AddDelayed(() =>
{
if (!string.IsNullOrEmpty(displayText)) Text.Text = displayText;
LineBadge.Uncollapse();
}, duration);
}
2018-07-17 05:50:22 +08:00
public virtual void Deactivate()
{
2018-07-19 01:32:15 +08:00
IsActivated = false;
LineBadge.Collapse();
2018-07-19 01:32:15 +08:00
Text.Font = "Exo2.0-Regular";
2018-07-17 05:50:22 +08:00
}
public virtual void Activate()
{
2018-07-19 01:32:15 +08:00
IsActivated = true;
LineBadge.Uncollapse();
2018-07-19 01:32:15 +08:00
Text.Font = "Exo2.0-Bold";
SampleActivate?.Play();
}
2018-07-24 00:17:50 +08:00
public void SetTextColour(ColourInfo newColour, double duration = 0, Easing easing = Easing.None)
{
Text.FadeColour(newColour, duration, easing);
}
public void SetBadgeColour(ColourInfo newColour, double duration = 0, Easing easing = Easing.None)
{
LineBadge.FadeColour(newColour, duration, easing);
}
public void HideText(double duration = 0, Easing easing = Easing.InOutCubic)
{
LineBadge.Collapse();
Text.MoveToY(20, duration, easing)
.FadeOut(duration, easing);
}
public void ShowText(double duration = 0, string displayText = null, Easing easing = Easing.InOutCubic)
{
LineBadge.Uncollapse();
if (!string.IsNullOrEmpty(displayText))
Text.Text = displayText;
Text.MoveToY(0, duration, easing)
.FadeIn(duration, easing);
}
2018-07-19 01:32:15 +08:00
protected override bool OnHover(InputState state)
{
2018-07-20 06:52:50 +08:00
if (!IsActivated)
sampleHover?.Play();
2018-07-19 01:32:15 +08:00
return base.OnHover(state);
}
protected override bool OnClick(InputState state)
{
OnActivated();
return base.OnClick(state);
}
protected virtual void OnActivated()
{
Activated?.Invoke(this, EventArgs.Empty);
}
2018-07-19 01:32:15 +08:00
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleHover = audio.Sample.Get(@"UI/generic-hover-soft");
SampleActivate = audio.Sample.Get(@"UI/generic-select-soft");
2018-07-17 05:50:22 +08:00
}
}
}