1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-11 14:37:18 +08:00
osu-lazer/osu.Game/Overlays/Changelog/Header/TextBadgePairListing.cs

73 lines
2.2 KiB
C#
Raw Normal View History

2018-07-16 23:50:22 +02: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;
2018-07-23 10:05:19 +02:00
using osu.Framework.Input.States;
2018-07-16 23:50:22 +02:00
namespace osu.Game.Overlays.Changelog.Header
{
public class TextBadgePairListing : TextBadgePair
{
2018-07-18 19:32:15 +02:00
private readonly ColourInfo badgeColour;
2018-07-16 23:50:22 +02:00
2018-07-18 01:35:06 +02:00
public TextBadgePairListing(ColourInfo badgeColour) : base(badgeColour, "Listing", false)
2018-07-16 23:50:22 +02:00
{
2018-07-18 19:32:15 +02:00
IsActivated = true;
2018-07-16 23:50:22 +02:00
this.badgeColour = badgeColour;
2018-07-18 19:32:15 +02:00
Text.Font = "Exo2.0-Bold";
Text.Anchor = Anchor.TopCentre;
Text.Origin = Anchor.TopCentre;
2018-07-17 15:01:53 +02:00
2018-07-18 15:17:20 +02: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-18 19:32:15 +02:00
LineBadge.RelativeSizeAxes = Axes.None;
2018-07-18 15:17:20 +02:00
2018-07-17 15:01:53 +02:00
// this doesn't work without the scheduler
// (because the text isn't yet fully drawn when it's loaded?)
2018-07-18 19:32:15 +02:00
Text.OnLoadComplete = d => Scheduler.Add(UpdateBadgeWidth);
2018-07-16 23:50:22 +02:00
}
public override void Activate()
{
if (IsActivated)
return;
2018-07-18 19:32:15 +02:00
IsActivated = true;
LineBadge.Uncollapse();
2018-07-18 19:32:15 +02:00
Text.Font = "Exo2.0-Bold";
2018-07-17 15:01:53 +02:00
SetTextColour(Color4.White, 100);
2018-07-16 23:50:22 +02:00
}
public override void Deactivate()
{
2018-07-18 19:32:15 +02:00
IsActivated = false;
LineBadge.Collapse();
Text.Font = "Exo2.0-Regular";
2018-07-17 15:01:53 +02:00
SetTextColour(badgeColour, 100);
2018-07-16 23:50:22 +02:00
}
protected override bool OnClick(InputState state)
{
Activate();
return base.OnClick(state);
}
protected override bool OnHover(InputState state)
{
LineBadge.Uncollapse();
2018-07-16 23:50:22 +02:00
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
2018-07-20 00:52:50 +02:00
if (!IsActivated)
LineBadge.Collapse();
2018-07-16 23:50:22 +02:00
base.OnHoverLost(state);
}
2018-07-18 15:17:20 +02:00
2018-07-18 19:32:15 +02:00
public void UpdateBadgeWidth() => LineBadge.ResizeWidthTo(Text.DrawWidth);
2018-07-16 23:50:22 +02:00
}
}