1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-22 22:32:54 +08:00
osu-lazer/osu.Game/Overlays/Changelog/ChangelogContentGroup.cs

278 lines
12 KiB
C#
Raw Normal View History

2018-07-20 01:07:24 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
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;
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;
using System;
using System.Collections.Generic;
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;
private readonly SortedDictionary<string, List<ChangelogEntry>> categories =
new SortedDictionary<string, List<ChangelogEntry>>();
2018-07-20 23:24:21 +08:00
public delegate void BuildSelectedEventHandler(APIChangelog build, EventArgs args);
2018-07-23 02:14:58 +08:00
public event BuildSelectedEventHandler BuildSelected;
public readonly FillFlowContainer ChangelogEntries;
2018-07-20 01:07:24 +08:00
public ChangelogContentGroup(APIChangelog build)
{
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[]
{
// build version, arrows
new FillFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
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
{
IsEnabled = false,
2018-07-20 01:07:24 +08:00
Icon = FontAwesome.fa_chevron_left,
Size = new Vector2(24),
Action = () =>
{
OnBuildSelected(build.Versions.Previous);
chevronPrevious.IsEnabled = false;
},
2018-07-20 01:07:24 +08:00
},
new FillFlowContainer<SpriteText>
{
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Horizontal = 40 },
2018-07-20 01:07:24 +08:00
Children = new[]
{
new SpriteText
{
Text = build.UpdateStream.DisplayName,
TextSize = 28, // web: 24,
Font = @"Exo2.0-Medium",
},
new SpriteText
2018-07-20 01:07:24 +08:00
{
Text = " ",
TextSize = 28,
},
new SpriteText
{
Text = build.DisplayVersion,
TextSize = 28, // web: 24,
2018-07-20 03:49:13 +08:00
Font = @"Exo2.0-Light",
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
{
IsEnabled = false,
2018-07-20 01:07:24 +08:00
Icon = FontAwesome.fa_chevron_right,
Size = new Vector2(24),
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
Text = build.CreatedAt.Date.ToLongDateString().Replace(build.CreatedAt.ToString("dddd") + ", ", ""),
2018-07-20 01:07:24 +08:00
TextSize = 17, // web: 14,
Colour = OsuColour.FromHex(@"FD5"),
Font = @"Exo2.0-Medium",
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
},
ChangelogEntries = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
},
2018-07-20 01:07:24 +08:00
};
}
2018-07-20 23:24:21 +08:00
2018-07-26 19:43:47 +08:00
public ChangelogContentGroup(APIChangelog build, bool newDate)
2018-07-22 11:28:43 +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") + ", ", ""),
TextSize = 28, // web: 24,
Colour = OsuColour.FromHex(@"FD5"),
Font = @"Exo2.0-Light",
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Margin = new MarginPadding { Top = 20 },
2018-07-22 11:28:43 +08:00
Alpha = newDate ? 1 : 0,
},
clickableBuildText = new OsuHoverContainer
2018-07-22 11:28:43 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Top = 20 },
Action = () => OnBuildSelected(build),
Child = new FillFlowContainer
2018-07-22 11:28:43 +08:00
{
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
2018-07-22 11:28:43 +08:00
{
new SpriteText
{
Text = build.UpdateStream.DisplayName,
TextSize = 20, // web: 18,
Font = @"Exo2.0-Medium",
},
new SpriteText
{
Text = build.DisplayVersion,
TextSize = 20, // web: 18,
Font = @"Exo2.0-Light",
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,
},
};
// we may not want double clicks to make it double the work
// can be clicked again only after a delay
clickableBuildText.Action += () =>
{
clickableBuildText.Action = null;
clickableBuildText.FadeTo(0.5f, 500);
Scheduler.AddDelayed(() => {
clickableBuildText.Action = () => OnBuildSelected(build);
clickableBuildText.FadeIn(500);
}, 2000);
};
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-20 23:24:21 +08:00
chevronPrevious.TooltipText = previousVersion;
chevronPrevious.IsEnabled = true;
}
2018-07-21 00:23:25 +08:00
if (!string.IsNullOrEmpty(nextVersion))
{
2018-07-20 23:24:21 +08:00
chevronNext.TooltipText = nextVersion;
chevronNext.IsEnabled = true;
}
2018-07-20 23:24:21 +08:00
}
protected virtual void OnBuildSelected(APIChangelog build)
2018-07-23 02:14:58 +08:00
{
BuildSelected?.Invoke(build, EventArgs.Empty);
2018-07-23 02:14:58 +08:00
}
public void GenerateText(List<ChangelogEntry> changelogEntries)
{
// sort entries by category
foreach (ChangelogEntry entry in changelogEntries)
{
if (!categories.ContainsKey(entry.Category))
categories.Add(entry.Category, new List<ChangelogEntry> { entry });
else
categories[entry.Category].Add(entry);
}
foreach (KeyValuePair<string, List<ChangelogEntry>> category in categories)
{
ChangelogEntries.Add(new SpriteText
{
Text = category.Key,
TextSize = 24, // web: 18,
Font = @"Exo2.0-Bold",
Margin = new MarginPadding { Top = 35, Bottom = 15 },
});
foreach (ChangelogEntry entry in category.Value)
{
2018-07-25 09:54:16 +08:00
LinkFlowContainer title = new LinkFlowContainer
{
Direction = FillDirection.Full,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Vertical = 5 },
};
title.AddIcon(FontAwesome.fa_check, t =>
{
t.TextSize = 12;
t.Padding = new MarginPadding { Left = -17, Right = 5 };
});
title.AddText(entry.Title, t => { t.TextSize = 18; });
if (!string.IsNullOrEmpty(entry.Repository))
{
title.AddText(" (", t => t.TextSize = 18);
2018-07-25 09:54:16 +08:00
title.AddLink($"{entry.Repository.Replace("ppy/", "")}#{entry.GithubPullRequestId}",
entry.GithubUrl, Online.Chat.LinkAction.External, null,
null, t => { t.TextSize = 18; });
title.AddText(")", t => t.TextSize = 18);
}
2018-07-25 09:54:16 +08:00
title.AddText(" by ", t => t.TextSize = 14);
if (entry.GithubUser.GithubUrl != null)
title.AddLink(entry.GithubUser.DisplayName, entry.GithubUser.GithubUrl,
Online.Chat.LinkAction.External, null, null,
t => t.TextSize = 14);
else
title.AddText(entry.GithubUser.DisplayName, t => t.TextSize = 14); //web: 12;
ChangelogEntries.Add(title);
TextFlowContainer messageContainer = new TextFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
};
messageContainer.AddText($"{entry.MessageHtml?.Replace("<p>", "").Replace("</p>", "")}\n", t =>
{
t.TextSize = 14; // web: 12,
t.Colour = new Color4(235, 184, 254, 255);
});
ChangelogEntries.Add(messageContainer);
}
}
}
2018-07-20 01:07:24 +08:00
}
}