1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 19:22:55 +08:00
osu-lazer/osu.Game/Overlays/Changelog/ChangelogStreams.cs

96 lines
3.4 KiB
C#
Raw Normal View History

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;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2018-07-18 09:26:08 +08:00
using osu.Framework.Input;
2018-07-20 01:07:24 +08:00
using osu.Game.Online.API.Requests.Responses;
using System;
2018-07-18 07:35:06 +08:00
namespace osu.Game.Overlays.Changelog
{
public class ChangelogStreams : Container
{
2018-07-19 01:32:15 +08:00
private const float container_height = 106.5f;
2018-07-20 03:49:13 +08:00
private const float padding_y = 20;
private const float padding_x = 85;
2018-07-20 01:07:24 +08:00
public Action OnSelection;
2018-07-18 07:35:06 +08:00
2018-07-20 01:07:24 +08:00
public APIChangelog SelectedRelease;
2018-07-20 03:49:13 +08:00
// not using SelectedRelease as a Bindable and then using .OnValueChange instead of OnSelection
// because it doesn't "refresh" the selection if the same stream is chosen
2018-07-18 07:35:06 +08:00
2018-07-19 01:32:15 +08:00
public readonly FillFlowContainer<StreamBadge> BadgesContainer;
2018-07-18 09:26:08 +08:00
2018-07-18 07:35:06 +08:00
public ChangelogStreams()
{
2018-07-20 03:49:13 +08:00
// this should actually be resizeable (https://streamable.com/yw2ug)
// if not, with small width:height ratio it cuts off right-most content
2018-07-18 07:35:06 +08:00
RelativeSizeAxes = Axes.X;
2018-07-20 03:49:13 +08:00
AutoSizeAxes = Axes.Y;
2018-07-18 07:35:06 +08:00
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(32, 24, 35, 255),
},
2018-07-19 01:32:15 +08:00
BadgesContainer = new FillFlowContainer<StreamBadge>
2018-07-18 07:35:06 +08:00
{
2018-07-20 03:49:13 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding
2018-07-18 07:35:06 +08:00
{
2018-07-20 03:49:13 +08:00
Top = padding_y,
Bottom = padding_y,
Left = padding_x,
Right = padding_x,
2018-07-18 07:35:06 +08:00
},
},
};
2018-07-20 01:07:24 +08:00
// ok, so this is probably not the best.
2018-07-20 03:49:13 +08:00
// how else can this be done?
2018-07-20 01:07:24 +08:00
BadgesContainer.OnUpdate = d =>
2018-07-18 07:35:06 +08:00
{
2018-07-19 01:32:15 +08:00
foreach (StreamBadge streamBadge in BadgesContainer.Children)
2018-07-18 07:35:06 +08:00
{
streamBadge.OnActivation = () =>
{
2018-07-20 01:07:24 +08:00
SelectedRelease = streamBadge.ChangelogEntry;
2018-07-19 01:32:15 +08:00
foreach (StreamBadge item in BadgesContainer.Children)
2018-07-20 06:52:50 +08:00
if (item.ChangelogEntry.Id != streamBadge.ChangelogEntry.Id)
item.Deactivate();
2018-07-20 01:07:24 +08:00
OnSelection?.Invoke();
2018-07-18 07:35:06 +08:00
};
}
};
}
2018-07-18 09:26:08 +08:00
protected override bool OnHover(InputState state)
{
// is this nullreference-safe for badgesContainer?
2018-07-19 01:32:15 +08:00
foreach (StreamBadge streamBadge in BadgesContainer.Children)
2018-07-18 09:26:08 +08:00
{
2018-07-20 01:07:24 +08:00
if (SelectedRelease != null)
2018-07-18 09:26:08 +08:00
{
2018-07-20 01:07:24 +08:00
if (SelectedRelease.UpdateStream.Id != streamBadge.ChangelogEntry.Id)
2018-07-18 09:26:08 +08:00
streamBadge.Deactivate();
}
2018-07-20 06:52:50 +08:00
else
streamBadge.Deactivate();
2018-07-18 09:26:08 +08:00
}
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
2018-07-20 01:07:24 +08:00
if (SelectedRelease == null)
2018-07-20 06:52:50 +08:00
foreach (StreamBadge streamBadge in BadgesContainer.Children)
streamBadge.Activate(true);
2018-07-18 09:26:08 +08:00
base.OnHoverLost(state);
}
2018-07-18 07:35:06 +08:00
}
}