2019-05-12 23:36:05 +08:00
|
|
|
|
// 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.
|
2018-07-17 05:50:22 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2018-10-19 02:56:43 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-05-12 23:36:05 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-07-17 05:50:22 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Changelog.Header
|
|
|
|
|
{
|
|
|
|
|
public class TextBadgePairListing : TextBadgePair
|
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
private readonly ColourInfo badgeColour;
|
2018-07-17 05:50:22 +08:00
|
|
|
|
|
2019-05-12 23:36:05 +08:00
|
|
|
|
public TextBadgePairListing(ColourInfo badgeColour)
|
|
|
|
|
: base(badgeColour, "Listing", false)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
IsActivated = true;
|
2018-07-17 05:50:22 +08:00
|
|
|
|
this.badgeColour = badgeColour;
|
2018-07-19 01:32:15 +08:00
|
|
|
|
Text.Font = "Exo2.0-Bold";
|
|
|
|
|
Text.Anchor = Anchor.TopCentre;
|
|
|
|
|
Text.Origin = Anchor.TopCentre;
|
2018-07-17 21:01:53 +08:00
|
|
|
|
|
2018-07-18 21:17:20 +08:00
|
|
|
|
// I'm using this for constant badge width here, so that the whole
|
|
|
|
|
// thing doesn't jump left/right when listing's size changes
|
|
|
|
|
// due to different font weight (and thus width)
|
2018-07-19 01:32:15 +08:00
|
|
|
|
LineBadge.RelativeSizeAxes = Axes.None;
|
2018-07-18 21:17:20 +08:00
|
|
|
|
|
2018-07-17 21:01:53 +08:00
|
|
|
|
// this doesn't work without the scheduler
|
|
|
|
|
// (because the text isn't yet fully drawn when it's loaded?)
|
2019-05-12 23:36:05 +08:00
|
|
|
|
Text.OnLoadComplete += d => Scheduler.Add(UpdateBadgeWidth);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Activate()
|
|
|
|
|
{
|
2018-07-24 02:36:24 +08:00
|
|
|
|
if (IsActivated)
|
|
|
|
|
return;
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2018-07-19 01:32:15 +08:00
|
|
|
|
IsActivated = true;
|
2018-07-23 23:49:42 +08:00
|
|
|
|
LineBadge.Uncollapse();
|
2018-07-19 01:32:15 +08:00
|
|
|
|
Text.Font = "Exo2.0-Bold";
|
2018-07-17 21:01:53 +08:00
|
|
|
|
SetTextColour(Color4.White, 100);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Deactivate()
|
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
IsActivated = false;
|
2018-07-23 23:49:42 +08:00
|
|
|
|
LineBadge.Collapse();
|
2018-07-24 02:36:24 +08:00
|
|
|
|
Text.Font = "Exo2.0-Regular";
|
2018-07-17 21:01:53 +08:00
|
|
|
|
SetTextColour(badgeColour, 100);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 02:56:43 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Activate();
|
2018-10-19 02:56:43 +08:00
|
|
|
|
return base.OnClick(e);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 02:56:43 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
2018-07-23 23:49:42 +08:00
|
|
|
|
LineBadge.Uncollapse();
|
2018-10-19 02:56:43 +08:00
|
|
|
|
return base.OnHover(e);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 02:56:43 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
2018-07-20 06:52:50 +08:00
|
|
|
|
if (!IsActivated)
|
2018-07-23 23:49:42 +08:00
|
|
|
|
LineBadge.Collapse();
|
2018-10-19 02:56:43 +08:00
|
|
|
|
base.OnHoverLost(e);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
2018-07-18 21:17:20 +08:00
|
|
|
|
|
2018-07-19 01:32:15 +08:00
|
|
|
|
public void UpdateBadgeWidth() => LineBadge.ResizeWidthTo(Text.DrawWidth);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|