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-19 01:32:15 +08:00
|
|
|
|
using osu.Framework.Input;
|
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 Action OnActivation;
|
|
|
|
|
public Action OnDeactivation;
|
2018-07-19 01:32:15 +08:00
|
|
|
|
private SampleChannel sampleHover;
|
|
|
|
|
protected SampleChannel SampleActivate;
|
2018-07-18 09:26:08 +08:00
|
|
|
|
|
2018-07-17 21:01:53 +08:00
|
|
|
|
public void SetTextColour(ColourInfo newColour, double duration = 0, Easing easing = Easing.None)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
Text.FadeColour(newColour, duration, easing);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-17 21:01:53 +08:00
|
|
|
|
public void SetBadgeColour(ColourInfo newColour, double duration = 0, Easing easing = Easing.None)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
LineBadge.FadeColour(newColour, duration, easing);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HideText(double duration = 0, Easing easing = Easing.InOutCubic)
|
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
LineBadge.IsCollapsed = true;
|
|
|
|
|
Text.MoveToY(20, duration, easing)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
.FadeOut(duration, easing);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-17 21:01:53 +08:00
|
|
|
|
public void ShowText(double duration = 0, string displayText = null, Easing easing = Easing.InOutCubic)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
LineBadge.IsCollapsed = false;
|
|
|
|
|
if (!string.IsNullOrEmpty(displayText)) Text.Text = displayText;
|
|
|
|
|
Text.MoveToY(0, duration, easing)
|
2018-07-18 21:17:20 +08:00
|
|
|
|
.FadeIn(duration, easing);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-17 21:01:53 +08:00
|
|
|
|
/// <param name="duration">
|
|
|
|
|
/// The duration of popping in and popping out not combined.
|
|
|
|
|
/// Full change takes double this time.</param>
|
2018-07-17 05:50:22 +08:00
|
|
|
|
public void ChangeText(double duration = 0, string displayText = null, Easing easing = Easing.InOutCubic)
|
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
LineBadge.IsCollapsed = true;
|
|
|
|
|
Text.MoveToY(20, duration, easing)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
.FadeOut(duration, easing)
|
2018-07-17 21:01:53 +08:00
|
|
|
|
.Then()
|
|
|
|
|
.MoveToY(0, duration, easing)
|
2018-07-18 21:17:20 +08:00
|
|
|
|
.FadeIn(duration, easing);
|
2018-07-17 21:01:53 +08:00
|
|
|
|
|
2018-07-20 03:49:13 +08:00
|
|
|
|
// 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
|
2018-07-17 21:01:53 +08:00
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(displayText)) Text.Text = displayText;
|
|
|
|
|
LineBadge.IsCollapsed = false;
|
2018-07-17 21:01:53 +08:00
|
|
|
|
}, duration);
|
2018-07-17 05:50:22 +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
|
|
|
|
{
|
|
|
|
|
Colour = badgeColour,
|
2018-07-18 21:17:20 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Deactivate()
|
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
IsActivated = false;
|
|
|
|
|
LineBadge.IsCollapsed = true;
|
|
|
|
|
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.IsCollapsed = false;
|
|
|
|
|
Text.Font = "Exo2.0-Bold";
|
|
|
|
|
SampleActivate?.Play();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (!IsActivated) sampleHover?.Play();
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|