1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 03:42:58 +08:00
osu-lazer/osu.Game/Overlays/Changelog/ChangelogStreams.cs

99 lines
3.5 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()
{
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)
{
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
{
if (SelectedRelease.UpdateStream.Id != streamBadge.ChangelogEntry.UpdateStream.Id)
2018-07-18 09:26:08 +08:00
streamBadge.Deactivate();
else
streamBadge.EnableDim();
2018-07-18 09:26:08 +08:00
}
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)
{
foreach (StreamBadge streamBadge in BadgesContainer.Children)
{
if (SelectedRelease == null)
2018-07-20 06:52:50 +08:00
streamBadge.Activate(true);
else if (streamBadge.ChangelogEntry.UpdateStream.Id == SelectedRelease.UpdateStream.Id)
streamBadge.DisableDim();
}
2018-07-18 09:26:08 +08:00
base.OnHoverLost(state);
}
2018-07-18 07:35:06 +08:00
}
}