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

105 lines
3.8 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.Configuration;
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-18 07:35:06 +08:00
using osu.Game.Graphics;
using osu.Game.Overlays.Changelog.Streams;
namespace osu.Game.Overlays.Changelog
{
public class ChangelogStreams : Container
{
2018-07-19 01:32:15 +08:00
private const float container_height = 106.5f;
private const float container_margin_y = 20;
private const float container_margin_x = 85;
2018-07-18 07:35:06 +08:00
public Bindable<ReleaseStreamInfo> SelectedRelease = new Bindable<ReleaseStreamInfo>();
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-19 01:32:15 +08:00
Height = container_height;
2018-07-18 07:35:06 +08:00
RelativeSizeAxes = Axes.X;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Size = new OpenTK.Vector2(1),
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
{
Direction = FillDirection.Horizontal,
RelativeSizeAxes = Axes.Both,
2018-07-19 01:32:15 +08:00
Margin = new MarginPadding
2018-07-18 07:35:06 +08:00
{
2018-07-19 01:32:15 +08:00
Top = container_margin_y,
Bottom = container_margin_y,
Left = container_margin_x,
Right = container_margin_x,
2018-07-18 07:35:06 +08:00
},
Children = new[]
{
2018-07-19 01:32:15 +08:00
new StreamBadge(StreamColour.STABLE, "Stable", "20180626.1", 16370, true),
new StreamBadge(StreamColour.BETA, "Beta", "20180626", 186),
new StreamBadge(StreamColour.LAZER, "Lazer", "2018.713.1"),
2018-07-18 07:35:06 +08:00
},
},
};
2018-07-19 01:32:15 +08:00
BadgesContainer.OnLoadComplete = 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-19 01:32:15 +08:00
SelectedRelease.Value = new ReleaseStreamInfo
2018-07-18 07:35:06 +08:00
{
DisplayVersion = streamBadge.DisplayVersion,
IsFeatured = streamBadge.IsFeatured,
Name = streamBadge.Name,
Users = streamBadge.Users,
};
2018-07-19 01:32:15 +08:00
foreach (StreamBadge item in BadgesContainer.Children)
2018-07-18 07:35:06 +08:00
{
if (item.Name != streamBadge.Name) item.Deactivate();
}
};
}
};
}
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
{
if (SelectedRelease.Value != null)
{
if (SelectedRelease.Value.Name != streamBadge.Name)
{
streamBadge.Deactivate();
}
}
else streamBadge.Deactivate();
}
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
if (SelectedRelease.Value == null)
{
2018-07-19 01:32:15 +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
}
}