2019-05-19 01:09:08 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-05-17 16:15:51 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-05-17 16:15:51 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2019-05-19 01:09:08 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osuTK.Graphics;
|
2019-05-17 16:15:51 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Changelog
|
|
|
|
|
{
|
2019-05-19 01:09:08 +08:00
|
|
|
|
public class ChangelogBuild : FillFlowContainer
|
2019-05-17 16:15:51 +08:00
|
|
|
|
{
|
2019-05-19 01:09:08 +08:00
|
|
|
|
public Action<APIChangelogBuild> SelectBuild;
|
2019-05-17 16:15:51 +08:00
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
protected readonly APIChangelogBuild Build;
|
|
|
|
|
|
|
|
|
|
public readonly FillFlowContainer ChangelogEntries;
|
2019-05-17 16:15:51 +08:00
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
public ChangelogBuild(APIChangelogBuild build)
|
2019-05-17 16:15:51 +08:00
|
|
|
|
{
|
2019-05-19 01:09:08 +08:00
|
|
|
|
Build = build;
|
2019-05-17 16:47:28 +08:00
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Direction = FillDirection.Vertical;
|
|
|
|
|
Padding = new MarginPadding { Horizontal = 70 };
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
2019-05-17 16:47:28 +08:00
|
|
|
|
{
|
2019-05-19 01:09:08 +08:00
|
|
|
|
CreateHeader(),
|
|
|
|
|
ChangelogEntries = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
},
|
2019-05-17 16:47:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
var categories = new SortedDictionary<string, List<APIChangelogEntry>>();
|
|
|
|
|
|
|
|
|
|
// sort entries by category
|
|
|
|
|
foreach (APIChangelogEntry entry in build.ChangelogEntries)
|
|
|
|
|
{
|
|
|
|
|
if (!categories.ContainsKey(entry.Category))
|
|
|
|
|
categories.Add(entry.Category, new List<APIChangelogEntry> { entry });
|
|
|
|
|
else
|
|
|
|
|
categories[entry.Category].Add(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, List<APIChangelogEntry>> category in categories)
|
|
|
|
|
{
|
|
|
|
|
ChangelogEntries.Add(new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = category.Key,
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 24),
|
|
|
|
|
Margin = new MarginPadding { Top = 35, Bottom = 15 },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
foreach (APIChangelogEntry entry in category.Value)
|
|
|
|
|
{
|
|
|
|
|
LinkFlowContainer title = new LinkFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Full,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Margin = new MarginPadding { Vertical = 5 },
|
|
|
|
|
};
|
2019-05-17 16:47:28 +08:00
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
title.AddIcon(FontAwesome.Solid.Check, t =>
|
|
|
|
|
{
|
|
|
|
|
t.Font = OsuFont.GetFont(size: 12);
|
|
|
|
|
t.Padding = new MarginPadding { Left = -17, Right = 5 };
|
|
|
|
|
});
|
2019-05-17 16:47:28 +08:00
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
title.AddText(entry.Title, t => { t.Font = OsuFont.GetFont(size: 18); });
|
2019-05-17 16:47:28 +08:00
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(entry.Repository))
|
|
|
|
|
{
|
|
|
|
|
title.AddText(" (", t => t.Font = OsuFont.GetFont(size: 18));
|
|
|
|
|
title.AddLink($"{entry.Repository.Replace("ppy/", "")}#{entry.GithubPullRequestId}",
|
|
|
|
|
entry.GithubUrl, Online.Chat.LinkAction.External, null,
|
|
|
|
|
null, t => { t.Font = OsuFont.GetFont(size: 18); });
|
|
|
|
|
title.AddText(")", t => t.Font = OsuFont.GetFont(size: 18));
|
|
|
|
|
}
|
2019-05-17 16:15:51 +08:00
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
title.AddText(" by ", t => t.Font = OsuFont.GetFont(size: 14));
|
|
|
|
|
|
|
|
|
|
if (entry.GithubUser.GithubUrl != null)
|
|
|
|
|
title.AddLink(entry.GithubUser.DisplayName, entry.GithubUser.GithubUrl,
|
|
|
|
|
Online.Chat.LinkAction.External, null, null,
|
|
|
|
|
t => t.Font = OsuFont.GetFont(size: 14));
|
|
|
|
|
else
|
|
|
|
|
title.AddText(entry.GithubUser.DisplayName, t => t.Font = OsuFont.GetFont(size: 12));
|
|
|
|
|
|
|
|
|
|
ChangelogEntries.Add(title);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(entry.MessageHtml))
|
|
|
|
|
{
|
|
|
|
|
TextFlowContainer messageContainer = new TextFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// todo: use markdown parsing once API returns markdown
|
|
|
|
|
messageContainer.AddText(Regex.Replace(entry.MessageHtml, @"<(.|\n)*?>", string.Empty), t =>
|
|
|
|
|
{
|
|
|
|
|
t.Font = OsuFont.GetFont(size: 12);
|
|
|
|
|
t.Colour = new Color4(235, 184, 254, 255);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ChangelogEntries.Add(messageContainer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-17 16:15:51 +08:00
|
|
|
|
}
|
2019-05-19 01:09:08 +08:00
|
|
|
|
|
|
|
|
|
protected virtual FillFlowContainer CreateHeader() => new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Margin = new MarginPadding { Top = 20 },
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuHoverContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Action = () => SelectBuild?.Invoke(Build),
|
|
|
|
|
Child = new FillFlowContainer<SpriteText>
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Margin = new MarginPadding { Horizontal = 40 },
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = Build.UpdateStream.DisplayName,
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Medium, size: 19),
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = " ",
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Medium, size: 19),
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = Build.DisplayVersion,
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Light, size: 19),
|
|
|
|
|
Colour = Build.UpdateStream.Colour,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-05-17 16:15:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|