2019-05-13 16:14:52 +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.
|
2018-07-20 01:07:24 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
2018-07-21 12:38:02 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-07-20 18:22:31 +08:00
|
|
|
|
using System;
|
2018-07-21 05:57:46 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-05-12 23:36:05 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Changelog
|
|
|
|
|
{
|
|
|
|
|
public class ChangelogContentGroup : FillFlowContainer
|
|
|
|
|
{
|
2018-07-20 23:24:21 +08:00
|
|
|
|
private readonly TooltipIconButton chevronPrevious, chevronNext;
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2019-05-13 16:24:33 +08:00
|
|
|
|
private readonly SortedDictionary<string, List<APIChangelogEntry>> categories =
|
|
|
|
|
new SortedDictionary<string, List<APIChangelogEntry>>();
|
2018-07-20 23:24:21 +08:00
|
|
|
|
|
2018-10-19 03:04:21 +08:00
|
|
|
|
public delegate void BuildSelectedEventHandler(APIChangelogBuild build, EventArgs args);
|
2018-07-23 02:14:58 +08:00
|
|
|
|
|
|
|
|
|
public event BuildSelectedEventHandler BuildSelected;
|
|
|
|
|
|
2018-07-21 08:58:53 +08:00
|
|
|
|
public readonly FillFlowContainer ChangelogEntries;
|
2018-07-21 05:57:46 +08:00
|
|
|
|
|
2018-10-19 03:04:21 +08:00
|
|
|
|
public ChangelogContentGroup(APIChangelogBuild build)
|
2018-07-20 01:07:24 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Direction = FillDirection.Vertical;
|
2018-07-22 11:28:43 +08:00
|
|
|
|
Padding = new MarginPadding { Horizontal = 70 };
|
2018-07-20 01:07:24 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
2018-07-25 00:47:05 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 20 },
|
2018-07-20 01:07:24 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-07-20 23:24:21 +08:00
|
|
|
|
chevronPrevious = new TooltipIconButton
|
2018-07-20 01:07:24 +08:00
|
|
|
|
{
|
2018-07-21 01:35:38 +08:00
|
|
|
|
IsEnabled = false,
|
2019-05-12 23:36:05 +08:00
|
|
|
|
Icon = FontAwesome.Solid.ChevronLeft,
|
2018-07-20 01:07:24 +08:00
|
|
|
|
Size = new Vector2(24),
|
2018-07-25 01:34:40 +08:00
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
OnBuildSelected(build.Versions.Previous);
|
|
|
|
|
chevronPrevious.IsEnabled = false;
|
|
|
|
|
},
|
2018-07-20 01:07:24 +08:00
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer<SpriteText>
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2018-07-25 00:47:05 +08:00
|
|
|
|
Margin = new MarginPadding { Horizontal = 40 },
|
2018-07-20 01:07:24 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = build.UpdateStream.DisplayName,
|
2019-05-12 23:46:22 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Medium, size: 28), // web: 24,
|
2018-07-20 01:07:24 +08:00
|
|
|
|
},
|
2018-07-20 21:48:20 +08:00
|
|
|
|
new SpriteText
|
2018-07-20 01:07:24 +08:00
|
|
|
|
{
|
|
|
|
|
Text = " ",
|
2019-05-12 23:46:22 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Medium, size: 28), // web: 24,
|
2018-07-20 01:07:24 +08:00
|
|
|
|
},
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = build.DisplayVersion,
|
2019-05-12 23:46:22 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Light, size: 28), // web: 24,
|
2018-07-20 03:49:13 +08:00
|
|
|
|
Colour = StreamColour.FromStreamName(build.UpdateStream.Name),
|
2018-07-20 01:07:24 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-20 23:24:21 +08:00
|
|
|
|
chevronNext = new TooltipIconButton
|
2018-07-20 01:07:24 +08:00
|
|
|
|
{
|
2018-07-21 01:35:38 +08:00
|
|
|
|
IsEnabled = false,
|
2019-05-12 23:36:05 +08:00
|
|
|
|
Icon = FontAwesome.Solid.ChevronRight,
|
2018-07-20 01:07:24 +08:00
|
|
|
|
Size = new Vector2(24),
|
2018-07-25 01:34:40 +08:00
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
OnBuildSelected(build.Versions.Next);
|
|
|
|
|
chevronNext.IsEnabled = false;
|
|
|
|
|
},
|
2018-07-20 01:07:24 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
// do we need .ToUniversalTime() here?
|
2018-07-20 03:49:13 +08:00
|
|
|
|
// also, this should be a temporary solution to weekdays in >localized< date strings
|
2018-07-21 09:19:30 +08:00
|
|
|
|
Text = build.CreatedAt.Date.ToLongDateString().Replace(build.CreatedAt.ToString("dddd") + ", ", ""),
|
2019-05-12 23:46:22 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Medium, size: 17), // web: 14,
|
2018-07-20 01:07:24 +08:00
|
|
|
|
Colour = OsuColour.FromHex(@"FD5"),
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2018-07-25 23:04:36 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 5 },
|
2018-07-20 01:07:24 +08:00
|
|
|
|
},
|
2018-07-21 08:58:53 +08:00
|
|
|
|
ChangelogEntries = new FillFlowContainer
|
2018-07-21 05:57:46 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2018-07-21 08:58:53 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2018-07-21 05:57:46 +08:00
|
|
|
|
},
|
2018-07-20 01:07:24 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-07-20 23:24:21 +08:00
|
|
|
|
|
2018-10-19 03:04:21 +08:00
|
|
|
|
public ChangelogContentGroup(APIChangelogBuild build, bool newDate)
|
2018-07-22 11:28:43 +08:00
|
|
|
|
{
|
2018-07-26 20:19:58 +08:00
|
|
|
|
OsuHoverContainer clickableBuildText;
|
2018-07-22 11:28:43 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Direction = FillDirection.Vertical;
|
|
|
|
|
Padding = new MarginPadding { Horizontal = 70 };
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
// do we need .ToUniversalTime() here?
|
|
|
|
|
// also, this should be a temporary solution to weekdays in >localized< date strings
|
|
|
|
|
Text = build.CreatedAt.Date.ToLongDateString().Replace(build.CreatedAt.ToString("dddd") + ", ", ""),
|
2019-05-12 23:46:22 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Light, size: 28), // web: 24,
|
2018-07-22 11:28:43 +08:00
|
|
|
|
Colour = OsuColour.FromHex(@"FD5"),
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2018-07-25 00:47:05 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 20 },
|
2018-07-22 11:28:43 +08:00
|
|
|
|
Alpha = newDate ? 1 : 0,
|
|
|
|
|
},
|
2018-07-26 20:19:58 +08:00
|
|
|
|
clickableBuildText = new OsuHoverContainer
|
2018-07-22 11:28:43 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2018-07-25 00:47:05 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 20 },
|
2018-07-26 20:19:58 +08:00
|
|
|
|
Action = () => OnBuildSelected(build),
|
|
|
|
|
Child = new FillFlowContainer
|
2018-07-22 11:28:43 +08:00
|
|
|
|
{
|
2018-07-26 20:19:58 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
2018-07-22 11:28:43 +08:00
|
|
|
|
{
|
2018-07-26 20:19:58 +08:00
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = build.UpdateStream.DisplayName,
|
2019-05-12 23:46:22 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Medium, size: 20), // web: 19,
|
2018-07-26 20:19:58 +08:00
|
|
|
|
},
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = build.DisplayVersion,
|
2019-05-12 23:46:22 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Light, size: 20), // web: 19,
|
2018-07-26 20:19:58 +08:00
|
|
|
|
Colour = StreamColour.FromStreamName(build.UpdateStream.Name),
|
|
|
|
|
},
|
2018-07-22 11:28:43 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ChangelogEntries = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
},
|
|
|
|
|
};
|
2018-07-25 03:42:25 +08:00
|
|
|
|
|
2018-08-22 19:49:08 +08:00
|
|
|
|
// we may not want double clicks,
|
2018-07-26 20:19:58 +08:00
|
|
|
|
// can be clicked again only after a delay
|
|
|
|
|
clickableBuildText.Action += () =>
|
2018-07-25 03:42:25 +08:00
|
|
|
|
{
|
2018-07-26 20:19:58 +08:00
|
|
|
|
clickableBuildText.Action = null;
|
|
|
|
|
clickableBuildText.FadeTo(0.5f, 500);
|
2019-05-12 23:36:05 +08:00
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
|
{
|
2018-07-26 20:19:58 +08:00
|
|
|
|
clickableBuildText.Action = () => OnBuildSelected(build);
|
|
|
|
|
clickableBuildText.FadeIn(500);
|
|
|
|
|
}, 2000);
|
2018-07-25 03:42:25 +08:00
|
|
|
|
};
|
2018-07-22 11:28:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-20 23:24:21 +08:00
|
|
|
|
public void UpdateChevronTooltips(string previousVersion, string nextVersion)
|
|
|
|
|
{
|
2018-07-21 00:23:25 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(previousVersion))
|
2018-07-21 01:35:38 +08:00
|
|
|
|
{
|
2018-07-20 23:24:21 +08:00
|
|
|
|
chevronPrevious.TooltipText = previousVersion;
|
2018-07-21 01:35:38 +08:00
|
|
|
|
chevronPrevious.IsEnabled = true;
|
|
|
|
|
}
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2018-07-21 00:23:25 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(nextVersion))
|
2018-07-21 01:35:38 +08:00
|
|
|
|
{
|
2018-07-20 23:24:21 +08:00
|
|
|
|
chevronNext.TooltipText = nextVersion;
|
2018-07-21 01:35:38 +08:00
|
|
|
|
chevronNext.IsEnabled = true;
|
|
|
|
|
}
|
2018-07-20 23:24:21 +08:00
|
|
|
|
}
|
2018-07-21 05:57:46 +08:00
|
|
|
|
|
2018-10-19 03:04:21 +08:00
|
|
|
|
protected virtual void OnBuildSelected(APIChangelogBuild build)
|
2018-07-23 02:14:58 +08:00
|
|
|
|
{
|
2018-07-24 03:38:14 +08:00
|
|
|
|
BuildSelected?.Invoke(build, EventArgs.Empty);
|
2018-07-23 02:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-13 16:24:33 +08:00
|
|
|
|
public void GenerateText(List<APIChangelogEntry> changelogEntries)
|
2018-07-21 05:57:46 +08:00
|
|
|
|
{
|
2018-07-21 12:38:02 +08:00
|
|
|
|
// sort entries by category
|
2019-05-13 16:24:33 +08:00
|
|
|
|
foreach (APIChangelogEntry entry in changelogEntries)
|
2018-07-21 12:38:02 +08:00
|
|
|
|
{
|
|
|
|
|
if (!categories.ContainsKey(entry.Category))
|
2019-05-13 16:24:33 +08:00
|
|
|
|
categories.Add(entry.Category, new List<APIChangelogEntry> { entry });
|
2018-07-21 12:38:02 +08:00
|
|
|
|
else
|
|
|
|
|
categories[entry.Category].Add(entry);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-13 16:24:33 +08:00
|
|
|
|
foreach (KeyValuePair<string, List<APIChangelogEntry>> category in categories)
|
2018-07-21 05:57:46 +08:00
|
|
|
|
{
|
2018-07-21 08:58:53 +08:00
|
|
|
|
ChangelogEntries.Add(new SpriteText
|
|
|
|
|
{
|
2018-07-21 12:38:02 +08:00
|
|
|
|
Text = category.Key,
|
2019-05-12 23:46:22 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 24), // web: 24,
|
2018-07-25 00:47:05 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 35, Bottom = 15 },
|
2018-07-21 08:58:53 +08:00
|
|
|
|
});
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2019-05-13 16:24:33 +08:00
|
|
|
|
foreach (APIChangelogEntry entry in category.Value)
|
2018-07-21 08:58:53 +08:00
|
|
|
|
{
|
2018-07-25 09:54:16 +08:00
|
|
|
|
LinkFlowContainer title = new LinkFlowContainer
|
2018-07-21 08:58:53 +08:00
|
|
|
|
{
|
2018-07-21 12:38:02 +08:00
|
|
|
|
Direction = FillDirection.Full,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2018-07-25 00:47:05 +08:00
|
|
|
|
Margin = new MarginPadding { Vertical = 5 },
|
2018-07-25 05:25:57 +08:00
|
|
|
|
};
|
2019-05-12 23:46:22 +08:00
|
|
|
|
|
2019-05-12 23:36:05 +08:00
|
|
|
|
title.AddIcon(FontAwesome.Solid.Check, t =>
|
2018-07-25 00:47:05 +08:00
|
|
|
|
{
|
2019-05-12 23:46:22 +08:00
|
|
|
|
t.Font = OsuFont.GetFont(size: 12);
|
2018-07-25 00:47:05 +08:00
|
|
|
|
t.Padding = new MarginPadding { Left = -17, Right = 5 };
|
2018-07-21 12:38:02 +08:00
|
|
|
|
});
|
2019-05-12 23:46:22 +08:00
|
|
|
|
|
|
|
|
|
title.AddText(entry.Title, t => { t.Font = OsuFont.GetFont(size: 18); });
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2018-07-21 12:38:02 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(entry.Repository))
|
|
|
|
|
{
|
2019-05-12 23:46:22 +08:00
|
|
|
|
title.AddText(" (", t => t.Font = OsuFont.GetFont(size: 18));
|
2018-07-25 09:54:16 +08:00
|
|
|
|
title.AddLink($"{entry.Repository.Replace("ppy/", "")}#{entry.GithubPullRequestId}",
|
|
|
|
|
entry.GithubUrl, Online.Chat.LinkAction.External, null,
|
2019-05-12 23:46:22 +08:00
|
|
|
|
null, t => { t.Font = OsuFont.GetFont(size: 18); });
|
|
|
|
|
title.AddText(")", t => t.Font = OsuFont.GetFont(size: 18));
|
2018-07-21 08:58:53 +08:00
|
|
|
|
}
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2019-05-12 23:46:22 +08:00
|
|
|
|
title.AddText(" by ", t => t.Font = OsuFont.GetFont(size: 14));
|
|
|
|
|
|
2018-07-25 09:54:16 +08:00
|
|
|
|
if (entry.GithubUser.GithubUrl != null)
|
|
|
|
|
title.AddLink(entry.GithubUser.DisplayName, entry.GithubUser.GithubUrl,
|
|
|
|
|
Online.Chat.LinkAction.External, null, null,
|
2019-05-12 23:46:22 +08:00
|
|
|
|
t => t.Font = OsuFont.GetFont(size: 14));
|
2018-07-25 09:54:16 +08:00
|
|
|
|
else
|
2019-05-12 23:46:22 +08:00
|
|
|
|
title.AddText(entry.GithubUser.DisplayName, t => t.Font = OsuFont.GetFont(size: 14)); //web: 12;
|
|
|
|
|
|
2018-07-25 05:25:57 +08:00
|
|
|
|
ChangelogEntries.Add(title);
|
2019-05-12 23:46:22 +08:00
|
|
|
|
|
2018-07-25 05:25:57 +08:00
|
|
|
|
TextFlowContainer messageContainer = new TextFlowContainer
|
2018-07-21 12:38:02 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-07-25 05:25:57 +08:00
|
|
|
|
};
|
2019-05-12 23:46:22 +08:00
|
|
|
|
|
2018-07-22 20:44:11 +08:00
|
|
|
|
messageContainer.AddText($"{entry.MessageHtml?.Replace("<p>", "").Replace("</p>", "")}\n", t =>
|
|
|
|
|
{
|
2019-05-12 23:46:22 +08:00
|
|
|
|
t.Font = OsuFont.GetFont(size: 14); // web: 12,
|
2018-07-22 20:44:11 +08:00
|
|
|
|
t.Colour = new Color4(235, 184, 254, 255);
|
|
|
|
|
});
|
2019-05-12 23:46:22 +08:00
|
|
|
|
|
2018-07-25 05:25:57 +08:00
|
|
|
|
ChangelogEntries.Add(messageContainer);
|
2018-07-21 12:38:02 +08:00
|
|
|
|
}
|
2018-07-21 05:57:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-20 01:07:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|