2019-12-14 01:59:40 +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;
|
2019-12-14 01:50:49 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2020-01-12 22:38:15 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-12-14 01:50:49 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.News
|
|
|
|
|
{
|
|
|
|
|
public class NewsArticleCover : Container
|
|
|
|
|
{
|
2020-01-12 22:38:15 +08:00
|
|
|
|
private const int hover_duration = 300;
|
|
|
|
|
|
|
|
|
|
private readonly Box gradient;
|
|
|
|
|
|
2019-12-14 01:50:49 +08:00
|
|
|
|
public NewsArticleCover(ArticleInfo info)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = 4;
|
|
|
|
|
|
|
|
|
|
NewsBackground bg;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = ColourInfo.GradientVertical(OsuColour.Gray(0.2f), OsuColour.Gray(0.1f))
|
|
|
|
|
},
|
2019-12-14 01:59:40 +08:00
|
|
|
|
new DelayedLoadWrapper(bg = new NewsBackground(info.CoverUrl)
|
2019-12-14 01:50:49 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
|
Alpha = 0
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2020-01-12 22:38:15 +08:00
|
|
|
|
gradient = new Box
|
2019-12-14 01:50:49 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-01-12 22:38:15 +08:00
|
|
|
|
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.1f), Color4.Black.Opacity(0.7f)),
|
|
|
|
|
Alpha = 0
|
2019-12-14 01:50:49 +08:00
|
|
|
|
},
|
|
|
|
|
new DateContainer(info.Time)
|
|
|
|
|
{
|
2019-12-14 01:59:40 +08:00
|
|
|
|
Margin = new MarginPadding
|
2019-12-14 01:50:49 +08:00
|
|
|
|
{
|
|
|
|
|
Right = 20,
|
|
|
|
|
Top = 20,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
2019-12-14 01:59:40 +08:00
|
|
|
|
Margin = new MarginPadding
|
2019-12-14 01:50:49 +08:00
|
|
|
|
{
|
|
|
|
|
Left = 25,
|
|
|
|
|
Bottom = 50,
|
|
|
|
|
},
|
2020-03-13 12:32:16 +08:00
|
|
|
|
Font = OsuFont.GetFont(Typeface.Torus, 24, FontWeight.Bold),
|
2019-12-14 01:50:49 +08:00
|
|
|
|
Text = info.Title,
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
2019-12-14 01:59:40 +08:00
|
|
|
|
Margin = new MarginPadding
|
2019-12-14 01:50:49 +08:00
|
|
|
|
{
|
|
|
|
|
Left = 25,
|
|
|
|
|
Bottom = 30,
|
|
|
|
|
},
|
2020-03-13 12:32:16 +08:00
|
|
|
|
Font = OsuFont.GetFont(Typeface.Torus, 16, FontWeight.Bold),
|
2019-12-14 01:50:49 +08:00
|
|
|
|
Text = "by " + info.Author
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bg.OnLoadComplete += d => d.FadeIn(250, Easing.In);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-12 22:38:15 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
|
|
|
|
gradient.FadeIn(hover_duration, Easing.OutQuint);
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
gradient.FadeOut(hover_duration, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-14 01:50:49 +08:00
|
|
|
|
[LongRunningLoad]
|
|
|
|
|
private class NewsBackground : Sprite
|
|
|
|
|
{
|
|
|
|
|
private readonly string url;
|
|
|
|
|
|
|
|
|
|
public NewsBackground(string coverUrl)
|
|
|
|
|
{
|
|
|
|
|
url = coverUrl ?? "Headers/news";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(LargeTextureStore store)
|
|
|
|
|
{
|
|
|
|
|
Texture = store.Get(url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class DateContainer : Container, IHasTooltip
|
|
|
|
|
{
|
|
|
|
|
private readonly DateTime date;
|
|
|
|
|
|
|
|
|
|
public DateContainer(DateTime date)
|
|
|
|
|
{
|
|
|
|
|
this.date = date;
|
|
|
|
|
|
|
|
|
|
Anchor = Anchor.TopRight;
|
|
|
|
|
Origin = Anchor.TopRight;
|
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = 4;
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.5f),
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2020-03-17 07:32:25 +08:00
|
|
|
|
Font = OsuFont.GetFont(Typeface.Torus, 12, FontWeight.Bold, false, false),
|
2019-12-14 18:40:59 +08:00
|
|
|
|
Text = date.ToString("d MMM yyy").ToUpper(),
|
2019-12-14 01:59:40 +08:00
|
|
|
|
Margin = new MarginPadding
|
2019-12-14 01:50:49 +08:00
|
|
|
|
{
|
|
|
|
|
Vertical = 4,
|
|
|
|
|
Horizontal = 8,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-14 18:40:59 +08:00
|
|
|
|
public string TooltipText => date.ToString("dddd dd MMMM yyyy hh:mm:ss UTCz").ToUpper();
|
2019-12-14 01:50:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// fake API data struct to use for now as a skeleton for data, as there is no API struct for news article info for now
|
2019-12-14 01:50:49 +08:00
|
|
|
|
public class ArticleInfo
|
|
|
|
|
{
|
|
|
|
|
public string Title { get; set; }
|
2019-12-14 01:59:40 +08:00
|
|
|
|
public string CoverUrl { get; set; }
|
2019-12-14 01:50:49 +08:00
|
|
|
|
public DateTime Time { get; set; }
|
|
|
|
|
public string Author { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|