1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 02:03:20 +08:00

Merge branch 'master' into beatmap-refactor/beatmap-overlays

This commit is contained in:
Dean Herbert 2021-10-29 22:37:29 +09:00 committed by GitHub
commit 5311fe2d02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 82 additions and 45 deletions

View File

@ -52,7 +52,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2021.1029.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Transitive Dependencies"> <ItemGroup Label="Transitive Dependencies">
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. --> <!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics.Sprites;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -58,39 +59,34 @@ namespace osu.Game.Graphics.Containers
} }
public void AddLink(string text, string url, Action<SpriteText> creationParameters = null) => public void AddLink(string text, string url, Action<SpriteText> creationParameters = null) =>
createLink(AddText(text, creationParameters), new LinkDetails(LinkAction.External, url), url); createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.External, url), url);
public void AddLink(string text, Action action, string tooltipText = null, Action<SpriteText> creationParameters = null) public void AddLink(string text, Action action, string tooltipText = null, Action<SpriteText> creationParameters = null)
=> createLink(AddText(text, creationParameters), new LinkDetails(LinkAction.Custom, string.Empty), tooltipText, action); => createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.Custom, string.Empty), tooltipText, action);
public void AddLink(string text, LinkAction action, string argument, string tooltipText = null, Action<SpriteText> creationParameters = null) public void AddLink(string text, LinkAction action, string argument, string tooltipText = null, Action<SpriteText> creationParameters = null)
=> createLink(AddText(text, creationParameters), new LinkDetails(action, argument), tooltipText); => createLink(CreateChunkFor(text, true, CreateSpriteText, creationParameters), new LinkDetails(action, argument), tooltipText);
public void AddLink(LocalisableString text, LinkAction action, string argument, string tooltipText = null, Action<SpriteText> creationParameters = null) public void AddLink(LocalisableString text, LinkAction action, string argument, string tooltipText = null, Action<SpriteText> creationParameters = null)
{ {
var spriteText = new OsuSpriteText { Text = text }; var spriteText = new OsuSpriteText { Text = text };
AddText(spriteText, creationParameters); AddText(spriteText, creationParameters);
createLink(spriteText.Yield(), new LinkDetails(action, argument), tooltipText); RemoveInternal(spriteText); // TODO: temporary, will go away when TextParts support localisation properly.
createLink(new TextPartManual(spriteText.Yield()), new LinkDetails(action, argument), tooltipText);
} }
public void AddLink(IEnumerable<SpriteText> text, LinkAction action, string linkArgument, string tooltipText = null) public void AddLink(IEnumerable<SpriteText> text, LinkAction action, string linkArgument, string tooltipText = null)
{ {
foreach (var t in text) createLink(new TextPartManual(text), new LinkDetails(action, linkArgument), tooltipText);
AddArbitraryDrawable(t);
createLink(text, new LinkDetails(action, linkArgument), tooltipText);
} }
public void AddUserLink(User user, Action<SpriteText> creationParameters = null) public void AddUserLink(User user, Action<SpriteText> creationParameters = null)
=> createLink(AddText(user.Username, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile"); => createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile");
private void createLink(IEnumerable<Drawable> drawables, LinkDetails link, string tooltipText, Action action = null) private void createLink(ITextPart textPart, LinkDetails link, LocalisableString tooltipText, Action action = null)
{ {
var linkCompiler = CreateLinkCompiler(drawables.OfType<SpriteText>()); Action onClickAction = () =>
linkCompiler.RelativeSizeAxes = Axes.Both;
linkCompiler.TooltipText = tooltipText;
linkCompiler.Action = () =>
{ {
if (action != null) if (action != null)
action(); action();
@ -101,10 +97,41 @@ namespace osu.Game.Graphics.Containers
host.OpenUrlExternally(link.Argument); host.OpenUrlExternally(link.Argument);
}; };
AddInternal(linkCompiler); AddPart(new TextLink(textPart, tooltipText, onClickAction));
} }
protected virtual DrawableLinkCompiler CreateLinkCompiler(IEnumerable<SpriteText> parts) => new DrawableLinkCompiler(parts); private class TextLink : TextPart
{
private readonly ITextPart innerPart;
private readonly LocalisableString tooltipText;
private readonly Action action;
public TextLink(ITextPart innerPart, LocalisableString tooltipText, Action action)
{
this.innerPart = innerPart;
this.tooltipText = tooltipText;
this.action = action;
}
protected override IEnumerable<Drawable> CreateDrawablesFor(TextFlowContainer textFlowContainer)
{
var linkFlowContainer = (LinkFlowContainer)textFlowContainer;
innerPart.RecreateDrawablesFor(linkFlowContainer);
var drawables = innerPart.Drawables.ToList();
drawables.Add(linkFlowContainer.CreateLinkCompiler(innerPart).With(c =>
{
c.RelativeSizeAxes = Axes.Both;
c.TooltipText = tooltipText;
c.Action = action;
}));
return drawables;
}
}
protected virtual DrawableLinkCompiler CreateLinkCompiler(ITextPart textPart) => new DrawableLinkCompiler(textPart);
// We want the compilers to always be visible no matter where they are, so RelativeSizeAxes is used. // We want the compilers to always be visible no matter where they are, so RelativeSizeAxes is used.
// However due to https://github.com/ppy/osu-framework/issues/2073, it's possible for the compilers to be relative size in the flow's auto-size axes - an unsupported operation. // However due to https://github.com/ppy/osu-framework/issues/2073, it's possible for the compilers to be relative size in the flow's auto-size axes - an unsupported operation.

View File

@ -2,7 +2,7 @@
// 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 osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
@ -19,8 +19,8 @@ namespace osu.Game.Graphics.Containers
protected override SpriteText CreateSpriteText() => new OsuSpriteText(); protected override SpriteText CreateSpriteText() => new OsuSpriteText();
public void AddArbitraryDrawable(Drawable drawable) => AddInternal(drawable); public ITextPart AddArbitraryDrawable(Drawable drawable) => AddPart(new TextPartManual(drawable.Yield()));
public IEnumerable<Drawable> AddIcon(IconUsage icon, Action<SpriteText> creationParameters = null) => AddText(icon.Icon.ToString(), creationParameters); public ITextPart AddIcon(IconUsage icon, Action<SpriteText> creationParameters = null) => AddText(icon.Icon.ToString(), creationParameters);
} }
} }

View File

@ -2,7 +2,7 @@
// 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.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osuTK.Graphics; using osuTK.Graphics;
@ -10,7 +10,7 @@ namespace osu.Game.Graphics
{ {
public class ErrorTextFlowContainer : OsuTextFlowContainer public class ErrorTextFlowContainer : OsuTextFlowContainer
{ {
private readonly List<Drawable> errorDrawables = new List<Drawable>(); private readonly List<ITextPart> errorTextParts = new List<ITextPart>();
public ErrorTextFlowContainer() public ErrorTextFlowContainer()
: base(cp => cp.Font = cp.Font.With(size: 12)) : base(cp => cp.Font = cp.Font.With(size: 12))
@ -19,7 +19,8 @@ namespace osu.Game.Graphics
public void ClearErrors() public void ClearErrors()
{ {
errorDrawables.ForEach(d => d.Expire()); foreach (var textPart in errorTextParts)
RemovePart(textPart);
} }
public void AddErrors(string[] errors) public void AddErrors(string[] errors)
@ -29,7 +30,7 @@ namespace osu.Game.Graphics
if (errors == null) return; if (errors == null) return;
foreach (string error in errors) foreach (string error in errors)
errorDrawables.AddRange(AddParagraph(error, cp => cp.Colour = Color4.Red)); errorTextParts.Add(AddParagraph(error, cp => cp.Colour = Color4.Red));
} }
} }
} }

View File

@ -5,6 +5,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
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.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -30,6 +32,11 @@ namespace osu.Game.Online.Chat
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new LinkHoverSounds(sampleSet, Parts); protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new LinkHoverSounds(sampleSet, Parts);
public DrawableLinkCompiler(ITextPart part)
: this(part.Drawables.OfType<SpriteText>())
{
}
public DrawableLinkCompiler(IEnumerable<Drawable> parts) public DrawableLinkCompiler(IEnumerable<Drawable> parts)
: base(HoverSampleSet.Submit) : base(HoverSampleSet.Submit)
{ {

View File

@ -2,7 +2,6 @@
// 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.Tasks; using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -37,7 +36,7 @@ namespace osu.Game.Overlays.AccountCreation
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
private ShakeContainer registerShake; private ShakeContainer registerShake;
private IEnumerable<Drawable> characterCheckText; private ITextPart characterCheckText;
private OsuTextBox[] textboxes; private OsuTextBox[] textboxes;
private LoadingLayer loadingLayer; private LoadingLayer loadingLayer;
@ -136,7 +135,7 @@ namespace osu.Game.Overlays.AccountCreation
characterCheckText = passwordDescription.AddText("8 characters long"); characterCheckText = passwordDescription.AddText("8 characters long");
passwordDescription.AddText(". Choose something long but also something you will remember, like a line from your favourite song."); passwordDescription.AddText(". Choose something long but also something you will remember, like a line from your favourite song.");
passwordTextBox.Current.ValueChanged += password => { characterCheckText.ForEach(s => s.Colour = password.NewValue.Length == 0 ? Color4.White : Interpolation.ValueAt(password.NewValue.Length, Color4.OrangeRed, Color4.YellowGreen, 0, 8, Easing.In)); }; passwordTextBox.Current.ValueChanged += password => { characterCheckText.Drawables.ForEach(s => s.Colour = password.NewValue.Length == 0 ? Color4.White : Interpolation.ValueAt(password.NewValue.Length, Color4.OrangeRed, Color4.YellowGreen, 0, 8, Easing.In)); };
} }
public override void OnEntering(IScreen last) public override void OnEntering(IScreen last)

View File

@ -2,7 +2,6 @@
// 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 osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -166,12 +165,12 @@ namespace osu.Game.Overlays.Changelog
{ {
} }
protected override DrawableLinkCompiler CreateLinkCompiler(IEnumerable<SpriteText> parts) => new SupporterPromoLinkCompiler(parts); protected override DrawableLinkCompiler CreateLinkCompiler(ITextPart textPart) => new SupporterPromoLinkCompiler(textPart);
private class SupporterPromoLinkCompiler : DrawableLinkCompiler private class SupporterPromoLinkCompiler : DrawableLinkCompiler
{ {
public SupporterPromoLinkCompiler(IEnumerable<Drawable> parts) public SupporterPromoLinkCompiler(ITextPart part)
: base(parts) : base(part)
{ {
} }

View File

@ -3,12 +3,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
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.Framework.Graphics.Sprites;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -25,7 +23,7 @@ namespace osu.Game.Overlays.Music
public Action<BeatmapSetInfo> RequestSelection; public Action<BeatmapSetInfo> RequestSelection;
private TextFlowContainer text; private TextFlowContainer text;
private IEnumerable<Drawable> titleSprites; private ITextPart titlePart;
private ILocalisedBindableString title; private ILocalisedBindableString title;
private ILocalisedBindableString artist; private ILocalisedBindableString artist;
@ -63,11 +61,16 @@ namespace osu.Game.Overlays.Music
if (set.OldValue?.Equals(Model) != true && set.NewValue?.Equals(Model) != true) if (set.OldValue?.Equals(Model) != true && set.NewValue?.Equals(Model) != true)
return; return;
foreach (Drawable s in titleSprites) updateSelectionState(false);
s.FadeColour(set.NewValue.Equals(Model) ? selectedColour : Color4.White, FADE_DURATION);
}, true); }, true);
} }
private void updateSelectionState(bool instant)
{
foreach (Drawable s in titlePart.Drawables)
s.FadeColour(SelectedSet.Value?.Equals(Model) == true ? selectedColour : Color4.White, instant ? 0 : FADE_DURATION);
}
protected override Drawable CreateContent() => text = new OsuTextFlowContainer protected override Drawable CreateContent() => text = new OsuTextFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -79,7 +82,8 @@ namespace osu.Game.Overlays.Music
text.Clear(); text.Clear();
// space after the title to put a space between the title and artist // space after the title to put a space between the title and artist
titleSprites = text.AddText(title.Value + @" ", sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular)).OfType<SpriteText>(); titlePart = text.AddText(title.Value + @" ", sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular));
updateSelectionState(true);
text.AddText(artist.Value, sprite => text.AddText(artist.Value, sprite =>
{ {

View File

@ -37,7 +37,7 @@ namespace osu.Game.Screens.Menu
private readonly Bindable<User> currentUser = new Bindable<User>(); private readonly Bindable<User> currentUser = new Bindable<User>();
private FillFlowContainer fill; private FillFlowContainer fill;
private readonly List<Drawable> expendableText = new List<Drawable>(); private readonly List<ITextPart> expendableText = new List<ITextPart>();
public Disclaimer(OsuScreen nextScreen = null) public Disclaimer(OsuScreen nextScreen = null)
{ {
@ -97,7 +97,7 @@ namespace osu.Game.Screens.Menu
textFlow.AddText("this is osu!", t => t.Font = t.Font.With(Typeface.Torus, 30, FontWeight.Regular)); textFlow.AddText("this is osu!", t => t.Font = t.Font.With(Typeface.Torus, 30, FontWeight.Regular));
expendableText.AddRange(textFlow.AddText("lazer", t => expendableText.Add(textFlow.AddText("lazer", t =>
{ {
t.Font = t.Font.With(Typeface.Torus, 30, FontWeight.Regular); t.Font = t.Font.With(Typeface.Torus, 30, FontWeight.Regular);
t.Colour = colours.PinkLight; t.Colour = colours.PinkLight;
@ -114,7 +114,7 @@ namespace osu.Game.Screens.Menu
t.Font = t.Font.With(Typeface.Torus, 20, FontWeight.SemiBold); t.Font = t.Font.With(Typeface.Torus, 20, FontWeight.SemiBold);
t.Colour = colours.Pink; t.Colour = colours.Pink;
}); });
expendableText.AddRange(textFlow.AddText(" coming to osu!", formatRegular)); expendableText.Add(textFlow.AddText(" coming to osu!", formatRegular));
textFlow.AddText(".", formatRegular); textFlow.AddText(".", formatRegular);
textFlow.NewParagraph(); textFlow.NewParagraph();
@ -152,7 +152,7 @@ namespace osu.Game.Screens.Menu
t.Font = t.Font.With(size: 20); t.Font = t.Font.With(size: 20);
t.Origin = Anchor.Centre; t.Origin = Anchor.Centre;
t.Colour = colours.Pink; t.Colour = colours.Pink;
}).First(); }).Drawables.First();
if (IsLoaded) if (IsLoaded)
animateHeart(); animateHeart();
@ -193,7 +193,7 @@ namespace osu.Game.Screens.Menu
using (BeginDelayedSequence(520 + 160)) using (BeginDelayedSequence(520 + 160))
{ {
fill.MoveToOffset(new Vector2(0, 15), 160, Easing.OutQuart); fill.MoveToOffset(new Vector2(0, 15), 160, Easing.OutQuart);
Schedule(() => expendableText.ForEach(t => Schedule(() => expendableText.SelectMany(t => t.Drawables).ForEach(t =>
{ {
t.FadeOut(100); t.FadeOut(100);
t.ScaleTo(new Vector2(0, 1), 100, Easing.OutQuart); t.ScaleTo(new Vector2(0, 1), 100, Easing.OutQuart);

View File

@ -36,7 +36,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Realm" Version="10.6.0" /> <PackageReference Include="Realm" Version="10.6.0" />
<PackageReference Include="ppy.osu.Framework" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Framework" Version="2021.1029.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" />
<PackageReference Include="Sentry" Version="3.9.4" /> <PackageReference Include="Sentry" Version="3.9.4" />
<PackageReference Include="SharpCompress" Version="0.29.0" /> <PackageReference Include="SharpCompress" Version="0.29.0" />

View File

@ -70,7 +70,7 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2021.1029.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" />
</ItemGroup> </ItemGroup>
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) --> <!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
@ -93,7 +93,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ppy.osu.Framework" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Framework" Version="2021.1029.0" />
<PackageReference Include="SharpCompress" Version="0.28.3" /> <PackageReference Include="SharpCompress" Version="0.28.3" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />