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 OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Changelog.Header
|
|
|
|
|
{
|
|
|
|
|
public class TextBadgePairListing : TextBadgePair
|
|
|
|
|
{
|
|
|
|
|
private ColourInfo badgeColour;
|
|
|
|
|
|
2018-07-18 07:35:06 +08:00
|
|
|
|
public TextBadgePairListing(ColourInfo badgeColour) : base(badgeColour, "Listing", false)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
this.badgeColour = badgeColour;
|
|
|
|
|
text.Font = "Exo2.0-Bold";
|
2018-07-17 21:01:53 +08:00
|
|
|
|
text.Anchor = Anchor.TopCentre;
|
|
|
|
|
text.Origin = Anchor.TopCentre;
|
|
|
|
|
|
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)
|
|
|
|
|
lineBadge.RelativeSizeAxes = Axes.None;
|
|
|
|
|
|
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?)
|
|
|
|
|
text.OnLoadComplete = d => Scheduler.Add(UpdateBadgeWidth);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Activate()
|
|
|
|
|
{
|
|
|
|
|
lineBadge.IsCollapsed = false;
|
|
|
|
|
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
|
|
|
|
OnActivation?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Deactivate()
|
|
|
|
|
{
|
|
|
|
|
lineBadge.IsCollapsed = true;
|
2018-07-17 21:01:53 +08:00
|
|
|
|
text.Font = "Exo2.0-Regular"; // commented out since it makes bad resize-jumping
|
|
|
|
|
SetTextColour(badgeColour, 100);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
OnDeactivation?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
|
|
|
|
Activate();
|
|
|
|
|
return base.OnClick(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
lineBadge.ResizeHeightTo(lineBadge.UncollapsedHeight, lineBadge.TransitionDuration);
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (lineBadge.IsCollapsed) lineBadge.ResizeHeightTo(1, lineBadge.TransitionDuration);
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
2018-07-18 21:17:20 +08:00
|
|
|
|
|
|
|
|
|
public void UpdateBadgeWidth() => lineBadge.ResizeWidthTo(text.DrawWidth);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|