mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 16:13:57 +09:00
Merge branch 'master' into main-page-wiki
This commit is contained in:
@ -10,7 +10,6 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Containers.Markdown;
|
using osu.Framework.Graphics.Containers.Markdown;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics.Containers.Markdown;
|
using osu.Game.Graphics.Containers.Markdown;
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Wiki.Markdown;
|
using osu.Game.Overlays.Wiki.Markdown;
|
||||||
|
|
||||||
@ -23,9 +22,6 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
[Cached]
|
[Cached]
|
||||||
private readonly OverlayColourProvider overlayColour = new OverlayColourProvider(OverlayColourScheme.Orange);
|
private readonly OverlayColourProvider overlayColour = new OverlayColourProvider(OverlayColourScheme.Orange);
|
||||||
|
|
||||||
[Cached]
|
|
||||||
private readonly IAPIProvider api = new DummyAPIAccess();
|
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup() => Schedule(() =>
|
public void Setup() => Schedule(() =>
|
||||||
{
|
{
|
||||||
@ -55,16 +51,16 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
AddStep("set current path", () => markdownContainer.CurrentPath = "Article_styling_criteria/");
|
AddStep("set current path", () => markdownContainer.CurrentPath = "Article_styling_criteria/");
|
||||||
|
|
||||||
AddStep("set '/wiki/Main_Page''", () => markdownContainer.Text = "[wiki main page](/wiki/Main_Page)");
|
AddStep("set '/wiki/Main_Page''", () => markdownContainer.Text = "[wiki main page](/wiki/Main_Page)");
|
||||||
AddAssert("check url", () => markdownContainer.Link.Url == $"{api.WebsiteRootUrl}/wiki/Main_Page");
|
AddAssert("check url", () => markdownContainer.Link.Url == $"{API.WebsiteRootUrl}/wiki/Main_Page");
|
||||||
|
|
||||||
AddStep("set '../FAQ''", () => markdownContainer.Text = "[FAQ](../FAQ)");
|
AddStep("set '../FAQ''", () => markdownContainer.Text = "[FAQ](../FAQ)");
|
||||||
AddAssert("check url", () => markdownContainer.Link.Url == $"{api.WebsiteRootUrl}/wiki/FAQ");
|
AddAssert("check url", () => markdownContainer.Link.Url == $"{API.WebsiteRootUrl}/wiki/FAQ");
|
||||||
|
|
||||||
AddStep("set './Writing''", () => markdownContainer.Text = "[wiki writing guidline](./Writing)");
|
AddStep("set './Writing''", () => markdownContainer.Text = "[wiki writing guidline](./Writing)");
|
||||||
AddAssert("check url", () => markdownContainer.Link.Url == $"{api.WebsiteRootUrl}/wiki/Article_styling_criteria/Writing");
|
AddAssert("check url", () => markdownContainer.Link.Url == $"{API.WebsiteRootUrl}/wiki/Article_styling_criteria/Writing");
|
||||||
|
|
||||||
AddStep("set 'Formatting''", () => markdownContainer.Text = "[wiki formatting guidline](Formatting)");
|
AddStep("set 'Formatting''", () => markdownContainer.Text = "[wiki formatting guidline](Formatting)");
|
||||||
AddAssert("check url", () => markdownContainer.Link.Url == $"{api.WebsiteRootUrl}/wiki/Article_styling_criteria/Formatting");
|
AddAssert("check url", () => markdownContainer.Link.Url == $"{API.WebsiteRootUrl}/wiki/Article_styling_criteria/Formatting");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -106,6 +102,7 @@ needs_cleanup: true
|
|||||||
{
|
{
|
||||||
AddStep("Add absolute image", () =>
|
AddStep("Add absolute image", () =>
|
||||||
{
|
{
|
||||||
|
markdownContainer.DocumentUrl = "https://dev.ppy.sh";
|
||||||
markdownContainer.Text = "";
|
markdownContainer.Text = "";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -115,6 +112,7 @@ needs_cleanup: true
|
|||||||
{
|
{
|
||||||
AddStep("Add relative image", () =>
|
AddStep("Add relative image", () =>
|
||||||
{
|
{
|
||||||
|
markdownContainer.DocumentUrl = "https://dev.ppy.sh";
|
||||||
markdownContainer.CurrentPath = "Interface/";
|
markdownContainer.CurrentPath = "Interface/";
|
||||||
markdownContainer.Text = "";
|
markdownContainer.Text = "";
|
||||||
});
|
});
|
||||||
@ -125,6 +123,7 @@ needs_cleanup: true
|
|||||||
{
|
{
|
||||||
AddStep("Add paragraph with block image", () =>
|
AddStep("Add paragraph with block image", () =>
|
||||||
{
|
{
|
||||||
|
markdownContainer.DocumentUrl = "https://dev.ppy.sh";
|
||||||
markdownContainer.CurrentPath = "Interface/";
|
markdownContainer.CurrentPath = "Interface/";
|
||||||
markdownContainer.Text = @"Line before image
|
markdownContainer.Text = @"Line before image
|
||||||
|
|
||||||
@ -139,6 +138,7 @@ Line after image";
|
|||||||
{
|
{
|
||||||
AddStep("Add inline image", () =>
|
AddStep("Add inline image", () =>
|
||||||
{
|
{
|
||||||
|
markdownContainer.DocumentUrl = "https://dev.ppy.sh";
|
||||||
markdownContainer.Text = " osu!";
|
markdownContainer.Text = " osu!";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -147,6 +147,11 @@ Line after image";
|
|||||||
{
|
{
|
||||||
public LinkInline Link;
|
public LinkInline Link;
|
||||||
|
|
||||||
|
public new string DocumentUrl
|
||||||
|
{
|
||||||
|
set => base.DocumentUrl = value;
|
||||||
|
}
|
||||||
|
|
||||||
public override MarkdownTextFlowContainer CreateTextFlow() => new TestMarkdownTextFlowContainer
|
public override MarkdownTextFlowContainer CreateTextFlow() => new TestMarkdownTextFlowContainer
|
||||||
{
|
{
|
||||||
UrlAdded = link => Link = link,
|
UrlAdded = link => Link = link,
|
||||||
@ -162,6 +167,8 @@ Line after image";
|
|||||||
|
|
||||||
UrlAdded?.Invoke(linkInline);
|
UrlAdded?.Invoke(linkInline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void AddImage(LinkInline linkInline) => AddDrawable(new WikiMarkdownImage(linkInline));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,14 @@ namespace osu.Game.Graphics.Containers.Markdown
|
|||||||
LineSpacing = 21;
|
LineSpacing = 21;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
private void load(IAPIProvider api)
|
|
||||||
{
|
{
|
||||||
|
var api = parent.Get<IAPIProvider>();
|
||||||
|
|
||||||
|
// needs to be set before the base BDL call executes to avoid invalidating any already populated markdown content.
|
||||||
DocumentUrl = api.WebsiteRootUrl;
|
DocumentUrl = api.WebsiteRootUrl;
|
||||||
|
|
||||||
|
return base.CreateChildDependencies(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level)
|
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level)
|
||||||
|
@ -16,28 +16,29 @@ namespace osu.Game.Graphics.Containers.Markdown
|
|||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private OsuGame game { get; set; }
|
private OsuGame game { get; set; }
|
||||||
|
|
||||||
protected string Text;
|
private readonly string text;
|
||||||
protected string Title;
|
private readonly string title;
|
||||||
|
|
||||||
public OsuMarkdownLinkText(string text, LinkInline linkInline)
|
public OsuMarkdownLinkText(string text, LinkInline linkInline)
|
||||||
: base(text, linkInline)
|
: base(text, linkInline)
|
||||||
{
|
{
|
||||||
Text = text;
|
this.text = text;
|
||||||
Title = linkInline.Title;
|
title = linkInline.Title;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OverlayColourProvider colourProvider)
|
private void load()
|
||||||
{
|
{
|
||||||
var text = CreateSpriteText().With(t => t.Text = Text);
|
var textDrawable = CreateSpriteText().With(t => t.Text = text);
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
text,
|
textDrawable,
|
||||||
new OsuMarkdownLinkCompiler(new[] { text })
|
new OsuMarkdownLinkCompiler(new[] { textDrawable })
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Action = OnLinkPressed,
|
Action = OnLinkPressed,
|
||||||
TooltipText = Title ?? Url,
|
TooltipText = title ?? Url,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Online.API.Requests;
|
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
@ -20,26 +19,16 @@ namespace osu.Game.Overlays.News.Displays
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ArticleListing : CompositeDrawable
|
public class ArticleListing : CompositeDrawable
|
||||||
{
|
{
|
||||||
public Action<APINewsSidebar> SidebarMetadataUpdated;
|
private readonly Action fetchMorePosts;
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private IAPIProvider api { get; set; }
|
|
||||||
|
|
||||||
private FillFlowContainer content;
|
private FillFlowContainer content;
|
||||||
private ShowMoreButton showMore;
|
private ShowMoreButton showMore;
|
||||||
|
|
||||||
private GetNewsRequest request;
|
private CancellationTokenSource cancellationToken;
|
||||||
private Cursor lastCursor;
|
|
||||||
|
|
||||||
private readonly int? year;
|
public ArticleListing(Action fetchMorePosts)
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Instantiate a listing for the specified year.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="year">The year to load articles from. If null, will show the most recent articles.</param>
|
|
||||||
public ArticleListing(int? year = null)
|
|
||||||
{
|
{
|
||||||
this.year = year;
|
this.fetchMorePosts = fetchMorePosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -47,6 +36,7 @@ namespace osu.Game.Overlays.News.Displays
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
Padding = new MarginPadding
|
Padding = new MarginPadding
|
||||||
{
|
{
|
||||||
Vertical = 20,
|
Vertical = 20,
|
||||||
@ -75,53 +65,25 @@ namespace osu.Game.Overlays.News.Displays
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
Origin = Anchor.TopCentre,
|
Origin = Anchor.TopCentre,
|
||||||
Margin = new MarginPadding
|
Margin = new MarginPadding { Top = 15 },
|
||||||
{
|
Action = fetchMorePosts,
|
||||||
Top = 15
|
|
||||||
},
|
|
||||||
Action = performFetch,
|
|
||||||
Alpha = 0
|
Alpha = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
performFetch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performFetch()
|
public void AddPosts(IEnumerable<APINewsPost> posts, bool morePostsAvailable) => Schedule(() =>
|
||||||
{
|
LoadComponentsAsync(posts.Select(p => new NewsCard(p)).ToList(), loaded =>
|
||||||
request?.Cancel();
|
|
||||||
|
|
||||||
request = new GetNewsRequest(year, lastCursor);
|
|
||||||
request.Success += response => Schedule(() => onSuccess(response));
|
|
||||||
api.PerformAsync(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CancellationTokenSource cancellationToken;
|
|
||||||
|
|
||||||
private void onSuccess(GetNewsResponse response)
|
|
||||||
{
|
|
||||||
cancellationToken?.Cancel();
|
|
||||||
|
|
||||||
// only needs to be updated on the initial load, as the content won't change during pagination.
|
|
||||||
if (lastCursor == null)
|
|
||||||
SidebarMetadataUpdated?.Invoke(response.SidebarMetadata);
|
|
||||||
|
|
||||||
// store cursor for next pagination request.
|
|
||||||
lastCursor = response.Cursor;
|
|
||||||
|
|
||||||
LoadComponentsAsync(response.NewsPosts.Select(p => new NewsCard(p)).ToList(), loaded =>
|
|
||||||
{
|
{
|
||||||
content.AddRange(loaded);
|
content.AddRange(loaded);
|
||||||
|
|
||||||
showMore.IsLoading = false;
|
showMore.IsLoading = false;
|
||||||
showMore.Alpha = response.Cursor != null ? 1 : 0;
|
showMore.Alpha = morePostsAvailable ? 1 : 0;
|
||||||
}, (cancellationToken = new CancellationTokenSource()).Token);
|
}, (cancellationToken = new CancellationTokenSource()).Token)
|
||||||
}
|
);
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
request?.Cancel();
|
|
||||||
cancellationToken?.Cancel();
|
cancellationToken?.Cancel();
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ using System.Threading;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Overlays.News;
|
using osu.Game.Overlays.News;
|
||||||
using osu.Game.Overlays.News.Displays;
|
using osu.Game.Overlays.News.Displays;
|
||||||
using osu.Game.Overlays.News.Sidebar;
|
using osu.Game.Overlays.News.Sidebar;
|
||||||
@ -14,13 +15,21 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
public class NewsOverlay : OnlineOverlay<NewsHeader>
|
public class NewsOverlay : OnlineOverlay<NewsHeader>
|
||||||
{
|
{
|
||||||
private readonly Bindable<string> article = new Bindable<string>(null);
|
private readonly Bindable<string> article = new Bindable<string>();
|
||||||
|
|
||||||
private readonly Container sidebarContainer;
|
private readonly Container sidebarContainer;
|
||||||
private readonly NewsSidebar sidebar;
|
private readonly NewsSidebar sidebar;
|
||||||
|
|
||||||
private readonly Container content;
|
private readonly Container content;
|
||||||
|
|
||||||
|
private GetNewsRequest request;
|
||||||
|
|
||||||
|
private Cursor lastCursor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The year currently being displayed. If null, the main listing is being displayed.
|
||||||
|
/// </summary>
|
||||||
|
private int? displayedYear;
|
||||||
|
|
||||||
private CancellationTokenSource cancellationToken;
|
private CancellationTokenSource cancellationToken;
|
||||||
|
|
||||||
private bool displayUpdateRequired = true;
|
private bool displayUpdateRequired = true;
|
||||||
@ -65,7 +74,13 @@ namespace osu.Game.Overlays
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
// should not be run until first pop-in to avoid requesting data before user views.
|
// should not be run until first pop-in to avoid requesting data before user views.
|
||||||
article.BindValueChanged(onArticleChanged);
|
article.BindValueChanged(a =>
|
||||||
|
{
|
||||||
|
if (a.NewValue == null)
|
||||||
|
loadListing();
|
||||||
|
else
|
||||||
|
loadArticle(a.NewValue);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override NewsHeader CreateHeader() => new NewsHeader { ShowFrontPage = ShowFrontPage };
|
protected override NewsHeader CreateHeader() => new NewsHeader { ShowFrontPage = ShowFrontPage };
|
||||||
@ -95,7 +110,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public void ShowYear(int year)
|
public void ShowYear(int year)
|
||||||
{
|
{
|
||||||
loadFrontPage(year);
|
loadListing(year);
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +123,11 @@ namespace osu.Game.Overlays
|
|||||||
protected void LoadDisplay(Drawable display)
|
protected void LoadDisplay(Drawable display)
|
||||||
{
|
{
|
||||||
ScrollFlow.ScrollToStart();
|
ScrollFlow.ScrollToStart();
|
||||||
LoadComponentAsync(display, loaded => content.Child = loaded, (cancellationToken = new CancellationTokenSource()).Token);
|
LoadComponentAsync(display, loaded =>
|
||||||
|
{
|
||||||
|
content.Child = loaded;
|
||||||
|
Loading.Hide();
|
||||||
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
@ -118,48 +137,65 @@ namespace osu.Game.Overlays
|
|||||||
sidebarContainer.Y = Math.Clamp(ScrollFlow.Current - Header.DrawHeight, 0, Math.Max(ScrollFlow.ScrollContent.DrawHeight - DrawHeight - Header.DrawHeight, 0));
|
sidebarContainer.Y = Math.Clamp(ScrollFlow.Current - Header.DrawHeight, 0, Math.Max(ScrollFlow.ScrollContent.DrawHeight - DrawHeight - Header.DrawHeight, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onArticleChanged(ValueChangedEvent<string> article)
|
private void loadListing(int? year = null)
|
||||||
{
|
{
|
||||||
if (article.NewValue == null)
|
|
||||||
loadFrontPage();
|
|
||||||
else
|
|
||||||
loadArticle(article.NewValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadFrontPage(int? year = null)
|
|
||||||
{
|
|
||||||
beginLoading();
|
|
||||||
|
|
||||||
Header.SetFrontPage();
|
Header.SetFrontPage();
|
||||||
|
|
||||||
var page = new ArticleListing(year);
|
displayedYear = year;
|
||||||
page.SidebarMetadataUpdated += metadata => Schedule(() =>
|
lastCursor = null;
|
||||||
|
|
||||||
|
beginLoading(true);
|
||||||
|
|
||||||
|
request = new GetNewsRequest(displayedYear);
|
||||||
|
request.Success += response => Schedule(() =>
|
||||||
{
|
{
|
||||||
sidebar.Metadata.Value = metadata;
|
lastCursor = response.Cursor;
|
||||||
Loading.Hide();
|
sidebar.Metadata.Value = response.SidebarMetadata;
|
||||||
|
|
||||||
|
var listing = new ArticleListing(getMorePosts);
|
||||||
|
listing.AddPosts(response.NewsPosts, response.Cursor != null);
|
||||||
|
LoadDisplay(listing);
|
||||||
});
|
});
|
||||||
LoadDisplay(page);
|
|
||||||
|
API.PerformAsync(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getMorePosts()
|
||||||
|
{
|
||||||
|
beginLoading(false);
|
||||||
|
|
||||||
|
request = new GetNewsRequest(displayedYear, lastCursor);
|
||||||
|
request.Success += response => Schedule(() =>
|
||||||
|
{
|
||||||
|
lastCursor = response.Cursor;
|
||||||
|
if (content.Child is ArticleListing listing)
|
||||||
|
listing.AddPosts(response.NewsPosts, response.Cursor != null);
|
||||||
|
});
|
||||||
|
|
||||||
|
API.PerformAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadArticle(string article)
|
private void loadArticle(string article)
|
||||||
{
|
{
|
||||||
beginLoading();
|
// This is not yet implemented nor called from anywhere.
|
||||||
|
beginLoading(true);
|
||||||
|
|
||||||
Header.SetArticle(article);
|
Header.SetArticle(article);
|
||||||
|
|
||||||
// Temporary, should be handled by ArticleDisplay later
|
|
||||||
LoadDisplay(Empty());
|
LoadDisplay(Empty());
|
||||||
Loading.Hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void beginLoading()
|
private void beginLoading(bool showLoadingOverlay)
|
||||||
{
|
{
|
||||||
|
request?.Cancel();
|
||||||
cancellationToken?.Cancel();
|
cancellationToken?.Cancel();
|
||||||
Loading.Show();
|
|
||||||
|
if (showLoadingOverlay)
|
||||||
|
Loading.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
|
request?.Cancel();
|
||||||
cancellationToken?.Cancel();
|
cancellationToken?.Cancel();
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using Markdig.Extensions.Yaml;
|
using Markdig.Extensions.Yaml;
|
||||||
using Markdig.Syntax;
|
using Markdig.Syntax;
|
||||||
using Markdig.Syntax.Inlines;
|
using Markdig.Syntax.Inlines;
|
||||||
@ -14,7 +15,7 @@ namespace osu.Game.Overlays.Wiki.Markdown
|
|||||||
{
|
{
|
||||||
public string CurrentPath
|
public string CurrentPath
|
||||||
{
|
{
|
||||||
set => Schedule(() => DocumentUrl += $"wiki/{value}");
|
set => DocumentUrl = $"{DocumentUrl}wiki/{value}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level)
|
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level)
|
||||||
@ -22,21 +23,25 @@ namespace osu.Game.Overlays.Wiki.Markdown
|
|||||||
switch (markdownObject)
|
switch (markdownObject)
|
||||||
{
|
{
|
||||||
case YamlFrontMatterBlock yamlFrontMatterBlock:
|
case YamlFrontMatterBlock yamlFrontMatterBlock:
|
||||||
container.Add(CreateNotice(yamlFrontMatterBlock));
|
container.Add(new WikiNoticeContainer(yamlFrontMatterBlock));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case ParagraphBlock paragraphBlock:
|
||||||
base.AddMarkdownComponent(markdownObject, container, level);
|
// Check if paragraph only contains an image
|
||||||
|
if (paragraphBlock.Inline.Count() == 1 && paragraphBlock.Inline.FirstChild is LinkInline { IsImage: true } linkInline)
|
||||||
|
{
|
||||||
|
container.Add(new WikiMarkdownImageBlock(linkInline));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base.AddMarkdownComponent(markdownObject, container, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override MarkdownTextFlowContainer CreateTextFlow() => new WikiMarkdownTextFlowContainer();
|
public override MarkdownTextFlowContainer CreateTextFlow() => new WikiMarkdownTextFlowContainer();
|
||||||
|
|
||||||
protected override MarkdownParagraph CreateParagraph(ParagraphBlock paragraphBlock, int level) => new WikiMarkdownParagraph(paragraphBlock);
|
|
||||||
|
|
||||||
protected virtual FillFlowContainer CreateNotice(YamlFrontMatterBlock yamlFrontMatterBlock) => new WikiNoticeContainer(yamlFrontMatterBlock);
|
|
||||||
|
|
||||||
private class WikiMarkdownTextFlowContainer : OsuMarkdownTextFlowContainer
|
private class WikiMarkdownTextFlowContainer : OsuMarkdownTextFlowContainer
|
||||||
{
|
{
|
||||||
protected override void AddImage(LinkInline linkInline) => AddDrawable(new WikiMarkdownImage(linkInline));
|
protected override void AddImage(LinkInline linkInline) => AddDrawable(new WikiMarkdownImage(linkInline));
|
||||||
|
@ -2,37 +2,28 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using Markdig.Syntax.Inlines;
|
using Markdig.Syntax.Inlines;
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Containers.Markdown;
|
using osu.Framework.Graphics.Containers.Markdown;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Game.Online.API;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Wiki.Markdown
|
namespace osu.Game.Overlays.Wiki.Markdown
|
||||||
{
|
{
|
||||||
public class WikiMarkdownImage : MarkdownImage, IHasTooltip
|
public class WikiMarkdownImage : MarkdownImage, IHasTooltip
|
||||||
{
|
{
|
||||||
private readonly string url;
|
|
||||||
|
|
||||||
public string TooltipText { get; }
|
public string TooltipText { get; }
|
||||||
|
|
||||||
public WikiMarkdownImage(LinkInline linkInline)
|
public WikiMarkdownImage(LinkInline linkInline)
|
||||||
: base(linkInline.Url)
|
: base(linkInline.Url)
|
||||||
{
|
{
|
||||||
url = linkInline.Url;
|
|
||||||
TooltipText = linkInline.Title;
|
TooltipText = linkInline.Title;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
protected override ImageContainer CreateImageContainer(string url)
|
||||||
private void load(IAPIProvider api)
|
|
||||||
{
|
{
|
||||||
// The idea is replace "{api.WebsiteRootUrl}/wiki/{path-to-image}" to "{api.WebsiteRootUrl}/wiki/images/{path-to-image}"
|
// The idea is replace "https://website.url/wiki/{path-to-image}" to "https://website.url/wiki/images/{path-to-image}"
|
||||||
// "/wiki/images/*" is route to fetch wiki image from osu!web server (see: https://github.com/ppy/osu-web/blob/4205eb66a4da86bdee7835045e4bf28c35456e04/routes/web.php#L289)
|
// "/wiki/images/*" is route to fetch wiki image from osu!web server (see: https://github.com/ppy/osu-web/blob/4205eb66a4da86bdee7835045e4bf28c35456e04/routes/web.php#L289)
|
||||||
// Currently all image in dev server (https://dev.ppy.sh/wiki/image/*) is 404
|
url = url.Replace("/wiki/", "/wiki/images/");
|
||||||
// So for now just replace "{api.WebsiteRootUrl}/wiki/*" to "https://osu.ppy.sh/wiki/images/*" for simplicity
|
|
||||||
var imageUrl = url.Replace($"{api.WebsiteRootUrl}/wiki", "https://osu.ppy.sh/wiki/images");
|
|
||||||
|
|
||||||
InternalChild = new DelayedLoadWrapper(CreateImageContainer(imageUrl));
|
return base.CreateImageContainer(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
osu.Game/Overlays/Wiki/Markdown/WikiMarkdownImageBlock.cs
Normal file
49
osu.Game/Overlays/Wiki/Markdown/WikiMarkdownImageBlock.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// 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 Markdig.Syntax.Inlines;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Containers.Markdown;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Wiki.Markdown
|
||||||
|
{
|
||||||
|
public class WikiMarkdownImageBlock : FillFlowContainer
|
||||||
|
{
|
||||||
|
[Resolved]
|
||||||
|
private IMarkdownTextComponent parentTextComponent { get; set; }
|
||||||
|
|
||||||
|
private readonly LinkInline linkInline;
|
||||||
|
|
||||||
|
public WikiMarkdownImageBlock(LinkInline linkInline)
|
||||||
|
{
|
||||||
|
this.linkInline = linkInline;
|
||||||
|
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
Direction = FillDirection.Vertical;
|
||||||
|
Spacing = new Vector2(0, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new WikiMarkdownImage(linkInline)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
},
|
||||||
|
parentTextComponent.CreateSpriteText().With(t =>
|
||||||
|
{
|
||||||
|
t.Text = linkInline.Title;
|
||||||
|
t.Anchor = Anchor.TopCentre;
|
||||||
|
t.Origin = Anchor.TopCentre;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,40 +0,0 @@
|
|||||||
// 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.Linq;
|
|
||||||
using Markdig.Syntax;
|
|
||||||
using Markdig.Syntax.Inlines;
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers.Markdown;
|
|
||||||
using osuTK;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Wiki.Markdown
|
|
||||||
{
|
|
||||||
public class WikiMarkdownParagraph : MarkdownParagraph
|
|
||||||
{
|
|
||||||
private readonly ParagraphBlock paragraphBlock;
|
|
||||||
|
|
||||||
public WikiMarkdownParagraph(ParagraphBlock paragraphBlock)
|
|
||||||
: base(paragraphBlock)
|
|
||||||
{
|
|
||||||
this.paragraphBlock = paragraphBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
MarkdownTextFlowContainer textFlow;
|
|
||||||
InternalChild = textFlow = CreateTextFlow();
|
|
||||||
textFlow.AddInlineText(paragraphBlock.Inline);
|
|
||||||
|
|
||||||
// Check if paragraph only contains an image.
|
|
||||||
if (paragraphBlock.Inline.Count() == 1 && paragraphBlock.Inline.FirstChild is LinkInline { IsImage: true } linkInline)
|
|
||||||
{
|
|
||||||
textFlow.TextAnchor = Anchor.TopCentre;
|
|
||||||
textFlow.Spacing = new Vector2(0, 5);
|
|
||||||
textFlow.AddText($"\n{linkInline.Title}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -59,6 +59,10 @@ namespace osu.Game.Skinning.Editor
|
|||||||
// the selection quad is always upright, so use an AABB rect to make mutating the values easier.
|
// the selection quad is always upright, so use an AABB rect to make mutating the values easier.
|
||||||
var selectionRect = getSelectionQuad().AABBFloat;
|
var selectionRect = getSelectionQuad().AABBFloat;
|
||||||
|
|
||||||
|
// If the selection has no area we cannot scale it
|
||||||
|
if (selectionRect.Area == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
// copy to mutate, as we will need to compare to the original later on.
|
// copy to mutate, as we will need to compare to the original later on.
|
||||||
var adjustedRect = selectionRect;
|
var adjustedRect = selectionRect;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user