2019-05-13 16:14:52 +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-23 01:51:31 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-10-19 02:56:43 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-07-23 01:51:31 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using System.Collections.Generic;
|
2019-05-17 10:43:36 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-05-12 23:36:05 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-07-23 01:51:31 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Changelog
|
|
|
|
|
{
|
2019-05-15 16:55:26 +08:00
|
|
|
|
public class BadgeDisplay : CompositeDrawable
|
2018-07-23 01:51:31 +08:00
|
|
|
|
{
|
2018-07-25 23:04:36 +08:00
|
|
|
|
private const float vertical_padding = 20;
|
|
|
|
|
private const float horizontal_padding = 85;
|
2018-07-23 01:51:31 +08:00
|
|
|
|
|
2019-05-17 10:43:36 +08:00
|
|
|
|
public readonly Bindable<APIUpdateStream> Current = new Bindable<APIUpdateStream>();
|
2018-07-23 01:51:31 +08:00
|
|
|
|
|
|
|
|
|
private readonly FillFlowContainer<StreamBadge> badgesContainer;
|
|
|
|
|
|
2019-05-15 16:55:26 +08:00
|
|
|
|
public BadgeDisplay()
|
2018-07-23 01:51:31 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2019-05-15 16:55:26 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-07-23 01:51:31 +08:00
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = new Color4(32, 24, 35, 255),
|
|
|
|
|
},
|
|
|
|
|
badgesContainer = new FillFlowContainer<StreamBadge>
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2018-07-25 23:04:36 +08:00
|
|
|
|
Padding = new MarginPadding { Vertical = vertical_padding, Horizontal = horizontal_padding },
|
2018-07-23 01:51:31 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
2019-05-17 10:43:36 +08:00
|
|
|
|
|
|
|
|
|
Current.ValueChanged += e =>
|
|
|
|
|
{
|
|
|
|
|
foreach (StreamBadge streamBadge in badgesContainer)
|
|
|
|
|
{
|
|
|
|
|
if (!IsHovered || e.NewValue.Id == streamBadge.Stream.Id)
|
|
|
|
|
streamBadge.Activate();
|
|
|
|
|
else
|
|
|
|
|
streamBadge.Deactivate();
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-07-23 01:51:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-13 16:24:33 +08:00
|
|
|
|
public void Populate(List<APIUpdateStream> streams)
|
2018-07-23 01:51:31 +08:00
|
|
|
|
{
|
2019-05-17 10:43:36 +08:00
|
|
|
|
Current.Value = null;
|
2019-05-15 17:08:19 +08:00
|
|
|
|
|
2019-05-13 16:24:33 +08:00
|
|
|
|
foreach (APIUpdateStream updateStream in streams)
|
2018-07-23 01:51:31 +08:00
|
|
|
|
{
|
|
|
|
|
var streamBadge = new StreamBadge(updateStream);
|
2019-05-17 10:43:36 +08:00
|
|
|
|
streamBadge.Selected += () => Current.Value = updateStream;
|
2018-07-23 01:51:31 +08:00
|
|
|
|
badgesContainer.Add(streamBadge);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 02:56:43 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-07-23 04:13:14 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
2019-05-17 10:43:36 +08:00
|
|
|
|
streamBadge.EnableDim();
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2018-10-19 02:56:43 +08:00
|
|
|
|
return base.OnHover(e);
|
2018-07-23 04:13:14 +08:00
|
|
|
|
}
|
2018-07-23 01:51:31 +08:00
|
|
|
|
|
2018-10-19 02:56:43 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-07-23 04:13:14 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
2019-05-17 10:43:36 +08:00
|
|
|
|
streamBadge.DisableDim();
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2018-10-19 02:56:43 +08:00
|
|
|
|
base.OnHoverLost(e);
|
2018-07-23 04:13:14 +08:00
|
|
|
|
}
|
2018-07-23 01:51:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|