2021-05-10 05:47:00 +00: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.
|
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-05-10 05:47:00 +00:00
|
|
|
|
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;
|
2021-05-11 19:34:01 +00:00
|
|
|
|
using System.Diagnostics;
|
2021-07-30 12:35:07 +00:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2021-05-17 08:20:31 +00:00
|
|
|
|
using osu.Framework.Platform;
|
2021-05-10 05:47:00 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.News.Sidebar
|
|
|
|
|
{
|
2021-05-17 07:02:21 +00:00
|
|
|
|
public class MonthSection : CompositeDrawable
|
2021-05-10 05:47:00 +00:00
|
|
|
|
{
|
2022-01-19 22:12:35 +00:00
|
|
|
|
public int Year { get; private set; }
|
|
|
|
|
public int Month { get; private set; }
|
|
|
|
|
public readonly BindableBool Expanded = new BindableBool();
|
|
|
|
|
|
2021-05-11 11:43:23 +00:00
|
|
|
|
private const int animation_duration = 250;
|
2021-07-30 12:35:07 +00:00
|
|
|
|
private Sample sampleOpen;
|
|
|
|
|
private Sample sampleClose;
|
2021-05-11 11:43:23 +00:00
|
|
|
|
|
2021-05-17 07:02:21 +00:00
|
|
|
|
public MonthSection(int month, int year, IEnumerable<APINewsPost> posts)
|
2021-05-10 05:47:00 +00:00
|
|
|
|
{
|
2021-05-11 19:34:01 +00:00
|
|
|
|
Debug.Assert(posts.All(p => p.PublishedAt.Month == month && p.PublishedAt.Year == year));
|
|
|
|
|
|
2022-01-19 22:12:35 +00:00
|
|
|
|
Year = year;
|
|
|
|
|
Month = month;
|
|
|
|
|
|
2021-05-11 13:51:59 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2021-05-12 17:50:20 +00:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2021-05-11 11:43:23 +00:00
|
|
|
|
Masking = true;
|
2021-05-19 06:48:31 +00:00
|
|
|
|
|
2021-05-10 05:47:00 +00:00
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-05-11 19:34:01 +00:00
|
|
|
|
new DropdownHeader(month, year)
|
2021-05-10 05:47:00 +00:00
|
|
|
|
{
|
2021-05-19 06:48:31 +00:00
|
|
|
|
Expanded = { BindTarget = Expanded }
|
2021-05-10 05:47:00 +00:00
|
|
|
|
},
|
2021-05-12 17:50:20 +00:00
|
|
|
|
new PostsContainer
|
2021-05-10 05:47:00 +00:00
|
|
|
|
{
|
2021-05-19 06:48:31 +00:00
|
|
|
|
Expanded = { BindTarget = Expanded },
|
2021-05-10 05:47:00 +00:00
|
|
|
|
Children = posts.Select(p => new PostButton(p)).ToArray()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-07-30 12:35:07 +00:00
|
|
|
|
|
|
|
|
|
Expanded.ValueChanged += expanded =>
|
|
|
|
|
{
|
|
|
|
|
if (expanded.NewValue)
|
|
|
|
|
sampleOpen?.Play();
|
|
|
|
|
else
|
|
|
|
|
sampleClose?.Play();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
|
|
|
|
sampleOpen = audio.Samples.Get(@"UI/dropdown-open");
|
|
|
|
|
sampleClose = audio.Samples.Get(@"UI/dropdown-close");
|
2021-05-10 05:47:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 13:42:18 +00:00
|
|
|
|
private class DropdownHeader : OsuClickableContainer
|
2021-05-11 11:43:23 +00:00
|
|
|
|
{
|
2021-05-19 06:48:31 +00:00
|
|
|
|
public readonly BindableBool Expanded = new BindableBool();
|
2021-05-10 05:47:00 +00:00
|
|
|
|
|
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
|
|
2021-05-11 19:34:01 +00:00
|
|
|
|
public DropdownHeader(int month, int year)
|
2021-05-10 05:47:00 +00:00
|
|
|
|
{
|
2021-05-11 19:34:01 +00:00
|
|
|
|
var date = new DateTime(year, month, 1);
|
|
|
|
|
|
2021-05-11 13:42:18 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2021-05-12 17:50:20 +00:00
|
|
|
|
Height = 15;
|
2021-05-19 06:48:31 +00:00
|
|
|
|
Action = Expanded.Toggle;
|
2021-05-10 05:47:00 +00:00
|
|
|
|
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();
|
|
|
|
|
|
2021-05-19 06:48:31 +00:00
|
|
|
|
Expanded.BindValueChanged(open =>
|
2021-05-10 05:47:00 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
2021-05-17 08:20:31 +00:00
|
|
|
|
private readonly APINewsPost post;
|
2021-05-10 05:47:00 +00:00
|
|
|
|
|
|
|
|
|
public PostButton(APINewsPost post)
|
|
|
|
|
{
|
2021-05-17 08:20:31 +00:00
|
|
|
|
this.post = post;
|
|
|
|
|
|
2021-05-10 05:47:00 +00:00
|
|
|
|
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]
|
2021-05-19 06:45:24 +00:00
|
|
|
|
private void load(OverlayColourProvider overlayColours, GameHost host)
|
2021-05-10 05:47:00 +00:00
|
|
|
|
{
|
2021-05-19 06:45:24 +00:00
|
|
|
|
IdleColour = overlayColours.Light2;
|
|
|
|
|
HoverColour = overlayColours.Light1;
|
2021-05-17 08:20:31 +00:00
|
|
|
|
|
|
|
|
|
TooltipText = "view in browser";
|
|
|
|
|
Action = () => host.OpenUrlExternally("https://osu.ppy.sh/home/news/" + post.Slug);
|
2021-05-10 05:47:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-12 17:50:20 +00:00
|
|
|
|
|
|
|
|
|
private class PostsContainer : Container
|
|
|
|
|
{
|
2021-05-19 06:48:31 +00:00
|
|
|
|
public readonly BindableBool Expanded = new BindableBool();
|
2021-05-12 17:50:20 +00:00
|
|
|
|
|
2021-05-19 06:45:24 +00:00
|
|
|
|
protected override Container<Drawable> Content { get; }
|
2021-05-12 17:50:20 +00:00
|
|
|
|
|
|
|
|
|
public PostsContainer()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2021-05-18 19:30:36 +00:00
|
|
|
|
AutoSizeDuration = animation_duration;
|
|
|
|
|
AutoSizeEasing = Easing.Out;
|
2021-05-19 06:45:24 +00:00
|
|
|
|
InternalChild = Content = new FillFlowContainer
|
2021-05-12 17:50:20 +00:00
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding { Top = 5 },
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2021-05-18 19:30:36 +00:00
|
|
|
|
Spacing = new Vector2(0, 5),
|
|
|
|
|
Alpha = 0
|
2021-05-12 17:50:20 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2021-05-19 06:48:31 +00:00
|
|
|
|
Expanded.BindValueChanged(updateState, true);
|
2021-05-12 17:50:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 06:48:31 +00:00
|
|
|
|
private void updateState(ValueChangedEvent<bool> expanded)
|
2021-05-17 16:53:09 +00:00
|
|
|
|
{
|
|
|
|
|
ClearTransforms(true);
|
|
|
|
|
|
2021-05-19 06:48:31 +00:00
|
|
|
|
if (expanded.NewValue)
|
2021-05-17 16:53:09 +00:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2021-05-19 06:45:24 +00:00
|
|
|
|
Content.FadeIn(animation_duration, Easing.OutQuint);
|
2021-05-17 16:53:09 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.None;
|
|
|
|
|
this.ResizeHeightTo(0, animation_duration, Easing.OutQuint);
|
|
|
|
|
|
2021-05-19 06:45:24 +00:00
|
|
|
|
Content.FadeOut(animation_duration, Easing.OutQuint);
|
2021-05-17 16:53:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-12 17:50:20 +00:00
|
|
|
|
}
|
2021-05-10 05:47:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|