2018-07-18 07:35:06 +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;
|
2018-07-19 01:32:15 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-07-23 16:05:19 +08:00
|
|
|
|
using osu.Framework.Input.States;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-07-23 23:49:42 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
2018-07-20 01:07:24 +08:00
|
|
|
|
namespace osu.Game.Overlays.Changelog
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2018-07-18 09:26:08 +08:00
|
|
|
|
public class StreamBadge : ClickableContainer
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
private const float badge_height = 56.5f;
|
|
|
|
|
private const float badge_width = 100;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
private const float transition_duration = 100;
|
|
|
|
|
|
2018-07-23 01:51:31 +08:00
|
|
|
|
public delegate void SelectedHandler(StreamBadge source, EventArgs args);
|
|
|
|
|
|
|
|
|
|
public event SelectedHandler Selected;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
|
2018-07-19 01:32:15 +08:00
|
|
|
|
private bool isActivated;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
|
2018-07-23 23:49:42 +08:00
|
|
|
|
private readonly LineBadge lineBadge;
|
2018-07-24 05:15:14 +08:00
|
|
|
|
private SampleChannel sampleClick;
|
2018-07-19 01:32:15 +08:00
|
|
|
|
private SampleChannel sampleHover;
|
2018-07-24 05:15:14 +08:00
|
|
|
|
|
|
|
|
|
public readonly APIChangelog LatestBuild;
|
2018-07-21 04:16:16 +08:00
|
|
|
|
private readonly FillFlowContainer<SpriteText> text;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
|
2018-07-24 05:15:14 +08:00
|
|
|
|
public StreamBadge(APIChangelog latestBuild)
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
this.LatestBuild = latestBuild;
|
2018-07-19 01:32:15 +08:00
|
|
|
|
Height = badge_height;
|
2018-07-24 05:15:14 +08:00
|
|
|
|
base.Width = this.LatestBuild.IsFeatured ? badge_width * 2 : badge_width;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
Margin = new MarginPadding(5);
|
2018-07-19 01:32:15 +08:00
|
|
|
|
isActivated = true;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-07-21 04:16:16 +08:00
|
|
|
|
text = new FillFlowContainer<SpriteText>
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
Text = this.LatestBuild.UpdateStream.DisplayName,
|
2018-07-18 07:35:06 +08:00
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
TextSize = 16,
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
2018-07-18 09:26:08 +08:00
|
|
|
|
Top = 7,
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
Text = this.LatestBuild.DisplayVersion,
|
2018-07-18 07:35:06 +08:00
|
|
|
|
Font = @"Exo2.0-Light",
|
|
|
|
|
TextSize = 21,
|
|
|
|
|
},
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
Text = this.LatestBuild.Users > 0 ?
|
|
|
|
|
$"{this.LatestBuild.Users:N0} users online" :
|
2018-07-18 07:35:06 +08:00
|
|
|
|
null,
|
|
|
|
|
TextSize = 12,
|
|
|
|
|
Font = @"Exo2.0-Regular",
|
|
|
|
|
Colour = new Color4(203, 164, 218, 255),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-23 23:49:42 +08:00
|
|
|
|
lineBadge = new LineBadge(false)
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2018-07-24 05:15:14 +08:00
|
|
|
|
Colour = StreamColour.FromStreamName(this.LatestBuild.UpdateStream.Name),
|
2018-07-23 23:49:42 +08:00
|
|
|
|
UncollapsedSize = 4,
|
|
|
|
|
CollapsedSize = 2,
|
2018-07-18 07:35:06 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 23:49:42 +08:00
|
|
|
|
/// <param name="withoutFiringUpdates">In case we don't want to
|
|
|
|
|
/// fire the <see cref="Selected"/> event.</param>
|
2018-07-23 04:13:14 +08:00
|
|
|
|
public void Activate(bool withoutFiringUpdates = true)
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
isActivated = true;
|
2018-07-18 07:35:06 +08:00
|
|
|
|
this.FadeIn(transition_duration);
|
2018-07-23 23:49:42 +08:00
|
|
|
|
lineBadge.Uncollapse();
|
2018-07-23 04:31:24 +08:00
|
|
|
|
if (!withoutFiringUpdates)
|
|
|
|
|
Selected?.Invoke(this, EventArgs.Empty);
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Deactivate()
|
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
isActivated = false;
|
2018-07-21 04:13:10 +08:00
|
|
|
|
DisableDim();
|
2018-07-19 01:32:15 +08:00
|
|
|
|
if (!IsHovered)
|
|
|
|
|
{
|
|
|
|
|
this.FadeTo(0.5f, transition_duration);
|
2018-07-23 23:49:42 +08:00
|
|
|
|
lineBadge.Collapse(200);
|
2018-07-19 01:32:15 +08:00
|
|
|
|
}
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
2018-07-23 04:13:14 +08:00
|
|
|
|
Activate(false);
|
2018-07-24 05:15:14 +08:00
|
|
|
|
sampleClick?.Play();
|
2018-07-18 07:35:06 +08:00
|
|
|
|
return base.OnClick(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2018-07-21 04:13:10 +08:00
|
|
|
|
sampleHover?.Play();
|
|
|
|
|
DisableDim();
|
2018-07-18 07:35:06 +08:00
|
|
|
|
this.FadeIn(transition_duration);
|
2018-07-23 23:49:42 +08:00
|
|
|
|
lineBadge.Uncollapse();
|
2018-07-18 07:35:06 +08:00
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
2018-07-19 01:32:15 +08:00
|
|
|
|
if (!isActivated)
|
2018-07-18 07:35:06 +08:00
|
|
|
|
{
|
|
|
|
|
this.FadeTo(0.5f, transition_duration);
|
2018-07-23 23:49:42 +08:00
|
|
|
|
lineBadge.Collapse(200);
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
2018-07-21 04:13:10 +08:00
|
|
|
|
else
|
|
|
|
|
EnableDim();
|
2018-07-18 07:35:06 +08:00
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
2018-07-19 01:32:15 +08:00
|
|
|
|
|
2018-07-21 04:16:16 +08:00
|
|
|
|
public void EnableDim() => text.FadeTo(0.5f, transition_duration);
|
2018-07-21 04:13:10 +08:00
|
|
|
|
|
2018-07-21 04:16:16 +08:00
|
|
|
|
public void DisableDim() => text.FadeIn(transition_duration);
|
2018-07-21 04:13:10 +08:00
|
|
|
|
|
2018-07-19 01:32:15 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
sampleClick = audio.Sample.Get(@"UI/generic-select-soft");
|
2018-07-19 01:32:15 +08:00
|
|
|
|
sampleHover = audio.Sample.Get(@"UI/generic-hover-soft");
|
|
|
|
|
}
|
2018-07-18 07:35:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|