2020-08-07 16:33:02 +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.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-08-09 10:16:08 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2020-08-09 10:28:43 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-08-07 16:33:02 +08:00
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Game.Overlays.News;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Dashboard.Home.News
|
|
|
|
|
{
|
2020-08-12 16:24:26 +08:00
|
|
|
|
public class FeaturedNewsItemPanel : HomePanel
|
2020-08-07 16:33:02 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly APINewsPost post;
|
|
|
|
|
|
2020-08-12 16:24:26 +08:00
|
|
|
|
public FeaturedNewsItemPanel(APINewsPost post)
|
2020-08-07 16:33:02 +08:00
|
|
|
|
{
|
|
|
|
|
this.post = post;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-08-09 10:28:43 +08:00
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2020-08-07 16:33:02 +08:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new ClickableNewsBackground(post),
|
2020-08-09 10:28:43 +08:00
|
|
|
|
new GridContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize)
|
|
|
|
|
},
|
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, size: 60),
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, size: 20),
|
|
|
|
|
new Dimension()
|
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Date(post.PublishedAt),
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Vertical = 10 },
|
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Width = 1,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Colour = colourProvider.Light1
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Margin = new MarginPadding { Top = 5, Bottom = 10 },
|
|
|
|
|
Padding = new MarginPadding { Right = 10 },
|
|
|
|
|
Spacing = new Vector2(0, 10),
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new NewsTitleLink(post),
|
|
|
|
|
new TextFlowContainer(f =>
|
|
|
|
|
{
|
|
|
|
|
f.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular);
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Text = post.Preview
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 16:33:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class ClickableNewsBackground : OsuHoverContainer
|
|
|
|
|
{
|
|
|
|
|
private readonly APINewsPost post;
|
|
|
|
|
|
|
|
|
|
public ClickableNewsBackground(APINewsPost post)
|
|
|
|
|
{
|
|
|
|
|
this.post = post;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = 130;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(GameHost host)
|
|
|
|
|
{
|
|
|
|
|
NewsPostBackground bg;
|
|
|
|
|
|
|
|
|
|
Child = new DelayedLoadWrapper(bg = new NewsPostBackground(post.FirstImage)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Alpha = 0
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bg.OnLoadComplete += d => d.FadeIn(250, Easing.In);
|
|
|
|
|
|
|
|
|
|
TooltipText = "view in browser";
|
|
|
|
|
Action = () => host.OpenUrlExternally("https://osu.ppy.sh/home/news/" + post.Slug);
|
|
|
|
|
|
|
|
|
|
HoverColour = Color4.White;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-09 10:16:08 +08:00
|
|
|
|
|
2021-08-29 00:09:37 +08:00
|
|
|
|
private class Date : CompositeDrawable, IHasCustomTooltip<DateTimeOffset>
|
2020-08-09 10:16:08 +08:00
|
|
|
|
{
|
2021-09-01 01:06:34 +08:00
|
|
|
|
private readonly DateTimeOffset date;
|
2020-08-07 16:33:02 +08:00
|
|
|
|
|
2020-08-09 10:16:08 +08:00
|
|
|
|
public Date(DateTimeOffset date)
|
2020-08-07 16:33:02 +08:00
|
|
|
|
{
|
2021-09-01 01:06:34 +08:00
|
|
|
|
this.date = date;
|
2020-08-09 10:16:08 +08:00
|
|
|
|
}
|
2020-08-07 16:33:02 +08:00
|
|
|
|
|
2020-08-09 10:16:08 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Anchor = Anchor.TopRight;
|
|
|
|
|
Origin = Anchor.TopRight;
|
|
|
|
|
Margin = new MarginPadding { Top = 10 };
|
|
|
|
|
InternalChild = new FillFlowContainer
|
2020-08-07 16:33:02 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold), // using Bold since there is no 800 weight alternative
|
|
|
|
|
Colour = colourProvider.Light1,
|
2021-09-01 01:06:34 +08:00
|
|
|
|
Text = $"{date:dd}"
|
2020-08-07 16:33:02 +08:00
|
|
|
|
},
|
|
|
|
|
new TextFlowContainer(f =>
|
|
|
|
|
{
|
|
|
|
|
f.Font = OsuFont.GetFont(size: 11, weight: FontWeight.Regular);
|
|
|
|
|
f.Colour = colourProvider.Light1;
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2021-09-01 01:06:34 +08:00
|
|
|
|
Text = $"{date:MMM yyyy}"
|
2020-08-07 16:33:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-09-01 01:06:34 +08:00
|
|
|
|
|
|
|
|
|
ITooltip<DateTimeOffset> IHasCustomTooltip<DateTimeOffset>.GetCustomTooltip() => new DateTooltip();
|
|
|
|
|
|
|
|
|
|
DateTimeOffset IHasCustomTooltip<DateTimeOffset>.TooltipContent => date;
|
2020-08-07 16:33:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|