2018-07-23 01:51:31 +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-23 16:05:19 +08:00
|
|
|
|
using osu.Framework.Input.States;
|
2018-07-23 01:51:31 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Changelog
|
|
|
|
|
{
|
|
|
|
|
public class ChangelogBadges : Container
|
|
|
|
|
{
|
|
|
|
|
private const float container_height = 106.5f;
|
|
|
|
|
private const float padding_y = 20;
|
|
|
|
|
private const float padding_x = 85;
|
|
|
|
|
|
2018-07-24 03:38:14 +08:00
|
|
|
|
public delegate void SelectionHandler(APIChangelog releaseStream, EventArgs args);
|
2018-07-23 01:51:31 +08:00
|
|
|
|
|
|
|
|
|
public event SelectionHandler Selected;
|
|
|
|
|
|
|
|
|
|
private readonly FillFlowContainer<StreamBadge> badgesContainer;
|
2018-07-23 04:13:14 +08:00
|
|
|
|
private long selectedStreamId = -1;
|
2018-07-23 01:51:31 +08:00
|
|
|
|
|
|
|
|
|
public ChangelogBadges()
|
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Populate(List<APIChangelog> latestBuilds)
|
|
|
|
|
{
|
|
|
|
|
foreach (APIChangelog updateStream in latestBuilds)
|
|
|
|
|
{
|
|
|
|
|
var streamBadge = new StreamBadge(updateStream);
|
2018-07-23 04:13:14 +08:00
|
|
|
|
streamBadge.Selected += onBadgeSelected;
|
2018-07-23 01:51:31 +08:00
|
|
|
|
badgesContainer.Add(streamBadge);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SelectNone()
|
|
|
|
|
{
|
2018-07-23 04:13:14 +08:00
|
|
|
|
selectedStreamId = -1;
|
|
|
|
|
if (badgesContainer != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (StreamBadge streamBadge in badgesContainer)
|
|
|
|
|
{
|
|
|
|
|
if (!IsHovered)
|
|
|
|
|
streamBadge.Activate();
|
|
|
|
|
else
|
|
|
|
|
streamBadge.Deactivate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-23 01:51:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SelectUpdateStream(string updateStream)
|
|
|
|
|
{
|
|
|
|
|
foreach (StreamBadge streamBadge in badgesContainer)
|
2018-07-23 04:13:14 +08:00
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
if (streamBadge.LatestBuild.UpdateStream.Name == updateStream)
|
2018-07-23 01:51:31 +08:00
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
selectedStreamId = streamBadge.LatestBuild.UpdateStream.Id;
|
2018-07-23 01:51:31 +08:00
|
|
|
|
streamBadge.Activate();
|
|
|
|
|
}
|
2018-07-23 04:13:14 +08:00
|
|
|
|
else
|
|
|
|
|
streamBadge.Deactivate();
|
|
|
|
|
}
|
2018-07-23 01:51:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 04:13:14 +08:00
|
|
|
|
private void onBadgeSelected(StreamBadge source, EventArgs args)
|
2018-07-23 01:51:31 +08:00
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
selectedStreamId = source.LatestBuild.UpdateStream.Id;
|
2018-07-23 01:51:31 +08:00
|
|
|
|
OnSelected(source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void OnSelected(StreamBadge source)
|
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
Selected?.Invoke(source.LatestBuild, EventArgs.Empty);
|
2018-07-23 01:51:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 04:13:14 +08:00
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
|
|
|
|
{
|
|
|
|
|
if (selectedStreamId < 0)
|
|
|
|
|
{
|
2018-07-24 05:15:14 +08:00
|
|
|
|
if (selectedStreamId != streamBadge.LatestBuild.UpdateStream.Id)
|
2018-07-23 04:13:14 +08:00
|
|
|
|
streamBadge.Deactivate();
|
|
|
|
|
else
|
|
|
|
|
streamBadge.EnableDim();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
streamBadge.Deactivate();
|
|
|
|
|
}
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
2018-07-23 01:51:31 +08:00
|
|
|
|
|
2018-07-23 04:13:14 +08:00
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
|
|
|
|
{
|
|
|
|
|
if (selectedStreamId < 0)
|
2018-07-23 04:31:24 +08:00
|
|
|
|
streamBadge.Activate();
|
2018-07-24 05:15:14 +08:00
|
|
|
|
else if (streamBadge.LatestBuild.UpdateStream.Id == selectedStreamId)
|
2018-07-23 04:13:14 +08:00
|
|
|
|
streamBadge.DisableDim();
|
|
|
|
|
}
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
2018-07-23 01:51:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|