2019-05-22 23:13:59 +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;
|
2019-05-22 23:13:59 +08:00
|
|
|
|
using System.Linq;
|
2019-05-19 01:09:08 +08:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2019-05-22 23:11:26 +08:00
|
|
|
|
using osu.Game.Users;
|
2019-05-19 01:09:08 +08:00
|
|
|
|
using osuTK.Graphics;
|
2019-06-08 02:59:56 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-09-20 02:08:14 +08:00
|
|
|
|
using System.Net;
|
2019-09-23 21:12:43 +08:00
|
|
|
|
using osuTK;
|
2020-02-21 22:22:46 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
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-31 12:53:55 +08:00
|
|
|
|
public const float HORIZONTAL_PADDING = 70;
|
|
|
|
|
|
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;
|
2019-05-31 12:53:55 +08:00
|
|
|
|
Padding = new MarginPadding { Horizontal = HORIZONTAL_PADDING };
|
2019-05-19 01:09:08 +08:00
|
|
|
|
|
|
|
|
|
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-06-08 02:59:56 +08:00
|
|
|
|
}
|
2019-05-17 16:47:28 +08:00
|
|
|
|
|
2019-06-08 02:59:56 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-21 22:11:29 +08:00
|
|
|
|
private void load(OsuColour colours, OverlayColourProvider colourProvider)
|
2019-06-08 02:59:56 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (var categoryEntries in Build.ChangelogEntries.GroupBy(b => b.Category).OrderBy(c => c.Key))
|
2019-05-19 01:09:08 +08:00
|
|
|
|
{
|
|
|
|
|
ChangelogEntries.Add(new OsuSpriteText
|
|
|
|
|
{
|
2019-05-22 23:13:59 +08:00
|
|
|
|
Text = categoryEntries.Key,
|
2020-02-21 22:11:29 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 18),
|
2019-05-19 01:09:08 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 35, Bottom = 15 },
|
|
|
|
|
});
|
|
|
|
|
|
2020-02-21 22:11:29 +08:00
|
|
|
|
var fontLarge = OsuFont.GetFont(size: 16);
|
|
|
|
|
var fontMedium = OsuFont.GetFont(size: 12);
|
2019-05-22 23:13:47 +08:00
|
|
|
|
|
2020-02-21 22:11:29 +08:00
|
|
|
|
foreach (var entry in categoryEntries)
|
2019-05-19 01:09:08 +08:00
|
|
|
|
{
|
2019-09-23 22:05:19 +08:00
|
|
|
|
var entryColour = entry.Major ? colours.YellowLight : Color4.White;
|
|
|
|
|
|
2019-09-23 21:12:43 +08:00
|
|
|
|
LinkFlowContainer title;
|
|
|
|
|
|
2020-02-21 22:11:29 +08:00
|
|
|
|
var titleContainer = new Container
|
2019-05-19 01:09:08 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2019-09-23 21:12:43 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2019-05-19 01:09:08 +08:00
|
|
|
|
Margin = new MarginPadding { Vertical = 5 },
|
2019-09-23 22:05:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2019-09-23 21:12:43 +08:00
|
|
|
|
{
|
2019-09-23 22:05:19 +08:00
|
|
|
|
new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
2020-02-21 22:11:29 +08:00
|
|
|
|
Size = new Vector2(10),
|
2020-12-26 03:08:57 +08:00
|
|
|
|
Icon = getIconForChangelogEntry(entry.Type),
|
2020-02-23 06:22:37 +08:00
|
|
|
|
Colour = entryColour.Opacity(0.5f),
|
2019-09-23 22:05:19 +08:00
|
|
|
|
Margin = new MarginPadding { Right = 5 },
|
|
|
|
|
},
|
|
|
|
|
title = new LinkFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Full,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-03-14 23:36:21 +08:00
|
|
|
|
TextAnchor = Anchor.BottomLeft,
|
2019-09-23 22:05:19 +08:00
|
|
|
|
}
|
2019-09-23 21:12:43 +08:00
|
|
|
|
}
|
2019-05-19 01:09:08 +08:00
|
|
|
|
};
|
2019-05-17 16:47:28 +08:00
|
|
|
|
|
2019-06-08 00:51:43 +08:00
|
|
|
|
title.AddText(entry.Title, t =>
|
|
|
|
|
{
|
|
|
|
|
t.Font = fontLarge;
|
2019-06-08 02:59:56 +08:00
|
|
|
|
t.Colour = entryColour;
|
2019-06-08 00:51:43 +08:00
|
|
|
|
});
|
2019-05-17 16:47:28 +08:00
|
|
|
|
|
2019-05-19 01:09:08 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(entry.Repository))
|
|
|
|
|
{
|
2019-06-08 00:51:43 +08:00
|
|
|
|
title.AddText(" (", t =>
|
|
|
|
|
{
|
|
|
|
|
t.Font = fontLarge;
|
2019-06-08 02:59:56 +08:00
|
|
|
|
t.Colour = entryColour;
|
2019-06-08 00:51:43 +08:00
|
|
|
|
});
|
2019-11-01 10:40:51 +08:00
|
|
|
|
title.AddLink($"{entry.Repository.Replace("ppy/", "")}#{entry.GithubPullRequestId}", entry.GithubUrl,
|
2019-06-08 00:51:43 +08:00
|
|
|
|
creationParameters: t =>
|
|
|
|
|
{
|
|
|
|
|
t.Font = fontLarge;
|
2019-06-08 02:59:56 +08:00
|
|
|
|
t.Colour = entryColour;
|
2019-06-08 00:51:43 +08:00
|
|
|
|
});
|
|
|
|
|
title.AddText(")", t =>
|
|
|
|
|
{
|
|
|
|
|
t.Font = fontLarge;
|
2019-06-08 02:59:56 +08:00
|
|
|
|
t.Colour = entryColour;
|
2019-06-08 00:51:43 +08:00
|
|
|
|
});
|
2019-05-19 01:09:08 +08:00
|
|
|
|
}
|
2019-05-17 16:15:51 +08:00
|
|
|
|
|
2020-02-23 06:22:37 +08:00
|
|
|
|
title.AddText("by ", t =>
|
2019-06-08 00:51:43 +08:00
|
|
|
|
{
|
2020-03-14 23:36:21 +08:00
|
|
|
|
t.Font = fontMedium;
|
2019-06-08 02:59:56 +08:00
|
|
|
|
t.Colour = entryColour;
|
2020-02-23 06:22:37 +08:00
|
|
|
|
t.Padding = new MarginPadding { Left = 10 };
|
2019-06-08 00:51:43 +08:00
|
|
|
|
});
|
2019-05-19 01:09:08 +08:00
|
|
|
|
|
2020-12-24 20:28:21 +08:00
|
|
|
|
if (entry.GithubUser != null)
|
2019-11-11 19:53:22 +08:00
|
|
|
|
{
|
2020-12-24 20:28:21 +08:00
|
|
|
|
if (entry.GithubUser.UserId != null)
|
2019-05-22 23:11:26 +08:00
|
|
|
|
{
|
2020-12-24 20:28:21 +08:00
|
|
|
|
title.AddUserLink(new User
|
|
|
|
|
{
|
|
|
|
|
Username = entry.GithubUser.OsuUsername,
|
|
|
|
|
Id = entry.GithubUser.UserId.Value
|
|
|
|
|
}, t =>
|
|
|
|
|
{
|
|
|
|
|
t.Font = fontMedium;
|
|
|
|
|
t.Colour = entryColour;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (entry.GithubUser.GithubUrl != null)
|
2019-06-08 00:51:43 +08:00
|
|
|
|
{
|
2020-12-24 20:28:21 +08:00
|
|
|
|
title.AddLink(entry.GithubUser.DisplayName, entry.GithubUser.GithubUrl, t =>
|
|
|
|
|
{
|
|
|
|
|
t.Font = fontMedium;
|
|
|
|
|
t.Colour = entryColour;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
2019-06-08 00:51:43 +08:00
|
|
|
|
{
|
2020-12-24 20:28:21 +08:00
|
|
|
|
title.AddText(entry.GithubUser.DisplayName, t =>
|
|
|
|
|
{
|
|
|
|
|
t.Font = fontMedium;
|
|
|
|
|
t.Colour = entryColour;
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-11-11 19:53:22 +08:00
|
|
|
|
}
|
2019-05-19 01:09:08 +08:00
|
|
|
|
|
2019-09-23 21:12:43 +08:00
|
|
|
|
ChangelogEntries.Add(titleContainer);
|
2019-05-19 01:09:08 +08:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(entry.MessageHtml))
|
|
|
|
|
{
|
2020-02-21 22:11:29 +08:00
|
|
|
|
var message = new TextFlowContainer
|
2019-05-19 01:09:08 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// todo: use markdown parsing once API returns markdown
|
2019-09-20 02:08:14 +08:00
|
|
|
|
message.AddText(WebUtility.HtmlDecode(Regex.Replace(entry.MessageHtml, @"<(.|\n)*?>", string.Empty)), t =>
|
2019-05-19 01:09:08 +08:00
|
|
|
|
{
|
2020-02-21 22:11:29 +08:00
|
|
|
|
t.Font = fontMedium;
|
|
|
|
|
t.Colour = colourProvider.Foreground1;
|
2019-05-19 01:09:08 +08:00
|
|
|
|
});
|
|
|
|
|
|
2019-05-22 23:13:47 +08:00
|
|
|
|
ChangelogEntries.Add(message);
|
2019-05-19 01:09:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-17 16:15:51 +08:00
|
|
|
|
}
|
2019-05-19 01:09:08 +08:00
|
|
|
|
|
2020-12-26 03:08:57 +08:00
|
|
|
|
private static IconUsage getIconForChangelogEntry(ChangelogEntryType entryType)
|
|
|
|
|
{
|
|
|
|
|
// compare: https://github.com/ppy/osu-web/blob/master/resources/assets/coffee/react/_components/changelog-entry.coffee#L8-L11
|
|
|
|
|
switch (entryType)
|
|
|
|
|
{
|
|
|
|
|
case ChangelogEntryType.Add:
|
|
|
|
|
return FontAwesome.Solid.Plus;
|
|
|
|
|
|
|
|
|
|
case ChangelogEntryType.Fix:
|
|
|
|
|
return FontAwesome.Solid.Check;
|
|
|
|
|
|
|
|
|
|
case ChangelogEntryType.Misc:
|
|
|
|
|
return FontAwesome.Regular.Circle;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(entryType), $"Unrecognised entry type {entryType}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|