2021-05-10 13:47:00 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.News.Sidebar
|
|
|
|
|
{
|
|
|
|
|
public class MonthPanel : CompositeDrawable
|
|
|
|
|
{
|
2021-05-11 19:43:23 +08:00
|
|
|
|
private const int header_height = 15;
|
|
|
|
|
private const int animation_duration = 250;
|
|
|
|
|
|
2021-05-10 13:47:00 +08:00
|
|
|
|
public readonly BindableBool IsOpen = new BindableBool();
|
|
|
|
|
|
|
|
|
|
private readonly FillFlowContainer postsFlow;
|
|
|
|
|
|
2021-05-10 22:00:18 +08:00
|
|
|
|
public MonthPanel(List<APINewsPost> posts)
|
2021-05-10 13:47:00 +08:00
|
|
|
|
{
|
|
|
|
|
Width = 160;
|
2021-05-11 19:43:23 +08:00
|
|
|
|
Masking = true;
|
2021-05-10 13:47:00 +08:00
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 5),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-05-10 22:00:18 +08:00
|
|
|
|
new DropdownButton(posts[0].PublishedAt)
|
2021-05-10 13:47:00 +08:00
|
|
|
|
{
|
|
|
|
|
IsOpen = { BindTarget = IsOpen }
|
|
|
|
|
},
|
|
|
|
|
postsFlow = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 5),
|
|
|
|
|
Children = posts.Select(p => new PostButton(p)).ToArray()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
IsOpen.BindValueChanged(open =>
|
|
|
|
|
{
|
|
|
|
|
ClearTransforms();
|
|
|
|
|
|
|
|
|
|
if (open.NewValue)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2021-05-11 19:43:23 +08:00
|
|
|
|
postsFlow.FadeIn(animation_duration, Easing.OutQuint);
|
2021-05-10 13:47:00 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.None;
|
2021-05-11 19:43:23 +08:00
|
|
|
|
this.ResizeHeightTo(header_height, animation_duration, Easing.OutQuint);
|
2021-05-10 13:47:00 +08:00
|
|
|
|
|
2021-05-11 19:43:23 +08:00
|
|
|
|
postsFlow.FadeOut(animation_duration, Easing.OutQuint);
|
2021-05-10 13:47:00 +08:00
|
|
|
|
}
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
// First state change should be instant.
|
2021-05-11 19:43:23 +08:00
|
|
|
|
FinishTransforms(true);
|
2021-05-10 13:47:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 19:43:23 +08:00
|
|
|
|
private bool shouldUpdateAutosize = true;
|
|
|
|
|
|
|
|
|
|
// Workaround to allow the dropdown to be opened immediately since FinishTransforms doesn't work for AutosizeDuration.
|
|
|
|
|
protected override void UpdateAfterAutoSize()
|
2021-05-10 13:47:00 +08:00
|
|
|
|
{
|
2021-05-11 19:43:23 +08:00
|
|
|
|
base.UpdateAfterAutoSize();
|
|
|
|
|
|
|
|
|
|
if (shouldUpdateAutosize)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeDuration = animation_duration;
|
|
|
|
|
AutoSizeEasing = Easing.OutQuint;
|
2021-05-10 13:47:00 +08:00
|
|
|
|
|
2021-05-11 19:43:23 +08:00
|
|
|
|
shouldUpdateAutosize = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class DropdownButton : OsuClickableContainer
|
|
|
|
|
{
|
|
|
|
|
public readonly BindableBool IsOpen = new BindableBool();
|
2021-05-10 13:47:00 +08:00
|
|
|
|
|
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
|
|
2021-05-10 22:00:18 +08:00
|
|
|
|
public DropdownButton(DateTimeOffset date)
|
2021-05-10 13:47:00 +08:00
|
|
|
|
{
|
2021-05-11 19:43:23 +08:00
|
|
|
|
Size = new Vector2(160, header_height);
|
2021-05-10 13:47:00 +08:00
|
|
|
|
Action = IsOpen.Toggle;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
|
|
|
|
Text = date.ToString("MMM yyyy")
|
|
|
|
|
},
|
|
|
|
|
icon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Size = new Vector2(10),
|
|
|
|
|
Icon = FontAwesome.Solid.ChevronDown
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
IsOpen.BindValueChanged(open =>
|
|
|
|
|
{
|
|
|
|
|
icon.Scale = new Vector2(1, open.NewValue ? -1 : 1);
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class PostButton : OsuHoverContainer
|
|
|
|
|
{
|
|
|
|
|
protected override IEnumerable<Drawable> EffectTargets => new[] { text };
|
|
|
|
|
|
|
|
|
|
private readonly TextFlowContainer text;
|
|
|
|
|
|
|
|
|
|
public PostButton(APINewsPost post)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Child = text = new TextFlowContainer(t => t.Font = OsuFont.GetFont(size: 12))
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Text = post.Title
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
|
{
|
|
|
|
|
IdleColour = colourProvider.Light2;
|
|
|
|
|
HoverColour = colourProvider.Light1;
|
|
|
|
|
Action = () => { }; // TODO
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|