mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 15:12:57 +08:00
99 lines
3.5 KiB
C#
99 lines
3.5 KiB
C#
// 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;
|
|
using osu.Framework.Input;
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
using System;
|
|
|
|
namespace osu.Game.Overlays.Changelog
|
|
{
|
|
public class ChangelogStreams : Container
|
|
{
|
|
private const float container_height = 106.5f;
|
|
private const float padding_y = 20;
|
|
private const float padding_x = 85;
|
|
public Action OnSelection;
|
|
|
|
public APIChangelog SelectedRelease;
|
|
// 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
|
|
|
|
public readonly FillFlowContainer<StreamBadge> BadgesContainer;
|
|
|
|
public ChangelogStreams()
|
|
{
|
|
RelativeSizeAxes = Axes.X;
|
|
AutoSizeAxes = Axes.Y;
|
|
Children = new Drawable[]
|
|
{
|
|
new Box
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Colour = new Color4(32, 24, 35, 255),
|
|
},
|
|
BadgesContainer = new FillFlowContainer<StreamBadge>
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Padding = new MarginPadding
|
|
{
|
|
Top = padding_y,
|
|
Bottom = padding_y,
|
|
Left = padding_x,
|
|
Right = padding_x,
|
|
},
|
|
},
|
|
};
|
|
// ok, so this is probably not the best.
|
|
// how else can this be done?
|
|
BadgesContainer.OnUpdate = d =>
|
|
{
|
|
foreach (StreamBadge streamBadge in BadgesContainer.Children)
|
|
{
|
|
streamBadge.OnActivation = () =>
|
|
{
|
|
SelectedRelease = streamBadge.ChangelogEntry;
|
|
foreach (StreamBadge item in BadgesContainer.Children)
|
|
if (item.ChangelogEntry.Id != streamBadge.ChangelogEntry.Id)
|
|
item.Deactivate();
|
|
OnSelection?.Invoke();
|
|
};
|
|
}
|
|
};
|
|
}
|
|
|
|
protected override bool OnHover(InputState state)
|
|
{
|
|
foreach (StreamBadge streamBadge in BadgesContainer.Children)
|
|
{
|
|
if (SelectedRelease != null)
|
|
{
|
|
if (SelectedRelease.UpdateStream.Id != streamBadge.ChangelogEntry.UpdateStream.Id)
|
|
streamBadge.Deactivate();
|
|
else
|
|
streamBadge.EnableDim();
|
|
}
|
|
else
|
|
streamBadge.Deactivate();
|
|
}
|
|
return base.OnHover(state);
|
|
}
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
{
|
|
foreach (StreamBadge streamBadge in BadgesContainer.Children)
|
|
{
|
|
if (SelectedRelease == null)
|
|
streamBadge.Activate(true);
|
|
else if (streamBadge.ChangelogEntry.UpdateStream.Id == SelectedRelease.UpdateStream.Id)
|
|
streamBadge.DisableDim();
|
|
}
|
|
base.OnHoverLost(state);
|
|
}
|
|
}
|
|
}
|