1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 13:12:56 +08:00
osu-lazer/osu.Game/Overlays/Dashboard/Home/News/HomeNewsPanel.cs
2020-08-07 12:59:45 +03:00

159 lines
5.3 KiB
C#

// 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;
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
{
public class HomeNewsPanel : HomePanel
{
private readonly APINewsPost post;
public HomeNewsPanel(APINewsPost post)
{
this.post = post;
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new ClickableNewsBackground(post),
new Footer(post)
}
}
};
}
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;
}
}
private class Footer : HomeNewsPanelFooter
{
protected override float BarPading => 10;
public Footer(APINewsPost post)
: base(post)
{
}
protected override NewsPostDrawableDate CreateDate(DateTimeOffset date) => new Date(date);
protected override Drawable CreateContent(APINewsPost post) => new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = 5, Bottom = 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
}
}
};
private class Date : NewsPostDrawableDate
{
public Date(DateTimeOffset date)
: base(date)
{
Margin = new MarginPadding { Top = 10 };
}
protected override Drawable CreateDate(DateTimeOffset date, OverlayColourProvider colourProvider) => new FillFlowContainer
{
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,
Text = $"{date: dd}"
},
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,
Text = $"{date:MMM yyyy}"
}
}
};
}
}
}
}