1
0
mirror of https://github.com/ppy/osu.git synced 2024-10-01 23:32:50 +08:00
osu-lazer/osu.Game/Overlays/Changelog/Header/TextBadgePair.cs

108 lines
3.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
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using System;
namespace osu.Game.Overlays.Changelog.Header
{
public class TextBadgePair : ClickableContainer
{
2018-07-17 21:01:53 +08:00
protected SpriteText text;
protected LineBadge lineBadge;
2018-07-18 07:35:06 +08:00
protected bool startCollapsed;
2018-07-17 05:50:22 +08:00
public Action OnActivation;
public Action OnDeactivation;
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
{
text.FadeColour(newColour, duration, easing);
}
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
{
lineBadge.FadeColour(newColour, duration, easing);
}
public void HideText(double duration = 0, Easing easing = Easing.InOutCubic)
{
lineBadge.IsCollapsed = true;
text.MoveToY(20, duration, easing)
.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-18 21:17:20 +08:00
lineBadge.IsCollapsed = false;
if (!string.IsNullOrEmpty(displayText)) text.Text = displayText;
2018-07-17 05:50:22 +08:00
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)
{
lineBadge.IsCollapsed = true;
text.MoveToY(20, duration, easing)
.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
// since using .finally/.oncomplete after first fadeout made the badge
// not hide sometimes in visual tests(because FinishTransforms()/CancelTransforms()
// didn't apply to transforms that come after the .finally), I'm using a scheduler here
Scheduler.AddDelayed(() =>
{
if (!string.IsNullOrEmpty(displayText)) text.Text = displayText;
2018-07-18 21:17:20 +08:00
lineBadge.IsCollapsed = false;
2018-07-17 21:01:53 +08:00
}, duration);
2018-07-17 05:50:22 +08:00
}
2018-07-18 07:35:06 +08:00
public TextBadgePair(ColourInfo badgeColour, string displayText = "Listing", bool startBadgeCollapsed = true)
2018-07-17 05:50:22 +08:00
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
text = new SpriteText
{
2018-07-17 21:01:53 +08:00
TextSize = 21, // web is 16, but here it looks too small?
2018-07-17 05:50:22 +08:00
Text = displayText,
2018-07-17 21:01:53 +08:00
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
2018-07-17 05:50:22 +08:00
Margin = new MarginPadding()
{
Top = 5,
Bottom = 15,
}
},
2018-07-18 07:35:06 +08:00
lineBadge = new LineBadge(startCollapsed)
2018-07-17 05:50:22 +08:00
{
2018-07-18 21:17:20 +08:00
Width = 1,
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()
{
lineBadge.IsCollapsed = true;
text.Font = "Exo2.0-Regular";
}
public virtual void Activate()
{
lineBadge.IsCollapsed = false;
text.Font = "Exo2.0-Bold";
}
}
}