1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-05 09:32:54 +08:00

Merge branch 'ppy:master' into master

This commit is contained in:
Nostril 2022-03-12 05:25:09 -08:00 committed by GitHub
commit 690b27e441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 414 additions and 36 deletions

View File

@ -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;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
@ -37,7 +38,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
Child Child
.FadeTo(flash_opacity, EarlyActivationMilliseconds, Easing.OutQuint) .FadeTo(flash_opacity, EarlyActivationMilliseconds, Easing.OutQuint)
.Then() .Then()
.FadeOut(timingPoint.BeatLength - fade_length, Easing.OutSine); .FadeOut(Math.Max(fade_length, timingPoint.BeatLength - fade_length), Easing.OutSine);
} }
} }
} }

View File

@ -118,7 +118,7 @@ namespace osu.Game.Tests.Online
[Test] [Test]
public void TestBeatmapDownloadingFlow() public void TestBeatmapDownloadingFlow()
{ {
AddAssert("ensure beatmap unavailable", () => !beatmaps.IsAvailableLocally(testBeatmapSet)); AddUntilStep("ensure beatmap unavailable", () => !beatmaps.IsAvailableLocally(testBeatmapSet));
addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded); addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded);
AddStep("start downloading", () => beatmapDownloader.Download(testBeatmapSet)); AddStep("start downloading", () => beatmapDownloader.Download(testBeatmapSet));
@ -132,7 +132,7 @@ namespace osu.Game.Tests.Online
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true)); AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
AddUntilStep("wait for import", () => beatmaps.CurrentImport != null); AddUntilStep("wait for import", () => beatmaps.CurrentImport != null);
AddAssert("ensure beatmap available", () => beatmaps.IsAvailableLocally(testBeatmapSet)); AddUntilStep("ensure beatmap available", () => beatmaps.IsAvailableLocally(testBeatmapSet));
addAvailabilityCheckStep("state is locally available", BeatmapAvailability.LocallyAvailable); addAvailabilityCheckStep("state is locally available", BeatmapAvailability.LocallyAvailable);
} }

View File

@ -133,7 +133,7 @@ namespace osu.Game.Tests.Visual.Navigation
AddStep("confirm deletion", () => InputManager.Key(Key.Number1)); AddStep("confirm deletion", () => InputManager.Key(Key.Number1));
AddUntilStep("wait for dialog dismissed", () => Game.Dependencies.Get<DialogOverlay>().CurrentDialog == null); AddUntilStep("wait for dialog dismissed", () => Game.Dependencies.Get<DialogOverlay>().CurrentDialog == null);
AddAssert("ensure score is pending deletion", () => Game.Realm.Run(r => r.Find<ScoreInfo>(score.ID)?.DeletePending == true)); AddUntilStep("ensure score is pending deletion", () => Game.Realm.Run(r => r.Find<ScoreInfo>(score.ID)?.DeletePending == true));
AddUntilStep("wait for score panel removal", () => scorePanel.Parent == null); AddUntilStep("wait for score panel removal", () => scorePanel.Parent == null);
} }
@ -178,7 +178,7 @@ namespace osu.Game.Tests.Visual.Navigation
AddStep("confirm deletion", () => InputManager.Key(Key.Number1)); AddStep("confirm deletion", () => InputManager.Key(Key.Number1));
AddUntilStep("wait for dialog dismissed", () => Game.Dependencies.Get<DialogOverlay>().CurrentDialog == null); AddUntilStep("wait for dialog dismissed", () => Game.Dependencies.Get<DialogOverlay>().CurrentDialog == null);
AddAssert("ensure score is pending deletion", () => Game.Realm.Run(r => r.Find<ScoreInfo>(score.ID)?.DeletePending == true)); AddUntilStep("ensure score is pending deletion", () => Game.Realm.Run(r => r.Find<ScoreInfo>(score.ID)?.DeletePending == true));
AddUntilStep("wait for score panel removal", () => scorePanel.Parent == null); AddUntilStep("wait for score panel removal", () => scorePanel.Parent == null);
} }

View File

@ -0,0 +1,90 @@
// 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.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
using osu.Game.Overlays.Chat.Listing;
using osuTK;
namespace osu.Game.Tests.Visual.Online
{
[TestFixture]
public class TestSceneChannelListing : OsuTestScene
{
[Cached]
private readonly OverlayColourProvider overlayColours = new OverlayColourProvider(OverlayColourScheme.Pink);
private SearchTextBox search;
private ChannelListing listing;
[SetUp]
public void SetUp()
{
Schedule(() =>
{
Children = new Drawable[]
{
search = new SearchTextBox
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Width = 300,
Margin = new MarginPadding { Top = 100 },
},
listing = new ChannelListing
{
Size = new Vector2(800, 400),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
};
listing.Show();
search.Current.ValueChanged += term => listing.SearchTerm = term.NewValue;
});
}
[SetUpSteps]
public void SetUpSteps()
{
AddStep("Add Join/Leave callbacks", () =>
{
listing.OnRequestJoin += channel => channel.Joined.Value = true;
listing.OnRequestLeave += channel => channel.Joined.Value = false;
});
}
[Test]
public void TestAddRandomChannels()
{
AddStep("Add Random Channels", () =>
{
listing.UpdateAvailableChannels(createRandomChannels(20));
});
}
private Channel createRandomChannel()
{
int id = RNG.Next(0, 10000);
return new Channel
{
Name = $"#channel-{id}",
Topic = RNG.Next(4) < 3 ? $"We talk about the number {id} here" : null,
Type = ChannelType.Public,
Id = id,
};
}
private List<Channel> createRandomChannels(int num)
=> Enumerable.Range(0, num)
.Select(_ => createRandomChannel())
.ToList();
}
}

View File

@ -0,0 +1,79 @@
// 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.
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
using osu.Game.Online.Chat;
namespace osu.Game.Overlays.Chat.Listing
{
public class ChannelListing : VisibilityContainer
{
public event Action<Channel>? OnRequestJoin;
public event Action<Channel>? OnRequestLeave;
public string SearchTerm
{
get => flow.SearchTerm;
set => flow.SearchTerm = value;
}
private SearchContainer<ChannelListingItem> flow = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4,
},
new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarAnchor = Anchor.TopRight,
Child = flow = new SearchContainer<ChannelListingItem>
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding
{
Vertical = 13,
Horizontal = 15,
},
},
},
};
}
public void UpdateAvailableChannels(IEnumerable<Channel> newChannels)
{
flow.ChildrenEnumerable = newChannels.Where(c => c.Type == ChannelType.Public)
.Select(c => new ChannelListingItem(c));
foreach (var item in flow.Children)
{
item.OnRequestJoin += channel => OnRequestJoin?.Invoke(channel);
item.OnRequestLeave += channel => OnRequestLeave?.Invoke(channel);
}
}
protected override void PopIn() => this.FadeIn();
protected override void PopOut() => this.FadeOut();
}
}

View File

@ -0,0 +1,173 @@
// 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.
#nullable enable
using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
using osuTK;
namespace osu.Game.Overlays.Chat.Listing
{
public class ChannelListingItem : OsuClickableContainer, IFilterable
{
public event Action<Channel>? OnRequestJoin;
public event Action<Channel>? OnRequestLeave;
public bool FilteringActive { get; set; }
public IEnumerable<string> FilterTerms => new[] { channel.Name, channel.Topic ?? string.Empty };
public bool MatchingFilter { set => this.FadeTo(value ? 1f : 0f, 100); }
private readonly Channel channel;
private Box hoverBox = null!;
private SpriteIcon checkbox = null!;
private OsuSpriteText channelText = null!;
private OsuSpriteText topicText = null!;
private IBindable<bool> channelJoined = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
private const float text_size = 18;
private const float icon_size = 14;
private const float vertical_margin = 1.5f;
public ChannelListingItem(Channel channel)
{
this.channel = channel;
}
[BackgroundDependencyLoader]
private void load()
{
Masking = true;
CornerRadius = 5;
RelativeSizeAxes = Axes.X;
Height = 20 + (vertical_margin * 2);
Children = new Drawable[]
{
hoverBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background3,
Margin = new MarginPadding { Vertical = vertical_margin },
Alpha = 0f,
},
new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 40),
new Dimension(GridSizeMode.Absolute, 200),
new Dimension(GridSizeMode.Absolute, 400),
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
},
Content = new[]
{
new Drawable[]
{
checkbox = new SpriteIcon
{
Alpha = 0,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.Check,
Size = new Vector2(icon_size),
},
channelText = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = channel.Name,
Font = OsuFont.Torus.With(size: text_size, weight: FontWeight.SemiBold),
Margin = new MarginPadding { Bottom = 2 },
},
topicText = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = channel.Topic,
Font = OsuFont.Torus.With(size: text_size),
Margin = new MarginPadding { Bottom = 2 },
},
new SpriteIcon
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Icon = FontAwesome.Solid.User,
Size = new Vector2(icon_size),
Margin = new MarginPadding { Right = 5 },
Colour = colourProvider.Light3,
},
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "0",
Font = OsuFont.Torus.With(size: text_size),
Margin = new MarginPadding { Bottom = 2 },
Colour = colourProvider.Light3,
},
},
},
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
channelJoined = channel.Joined.GetBoundCopy();
channelJoined.BindValueChanged(change =>
{
const double duration = 500;
if (change.NewValue)
{
checkbox.FadeIn(duration, Easing.OutQuint);
checkbox.ScaleTo(1f, duration, Easing.OutElastic);
channelText.Colour = Colour4.White;
topicText.Colour = Colour4.White;
}
else
{
checkbox.FadeOut(duration, Easing.OutQuint);
checkbox.ScaleTo(0.8f, duration, Easing.OutQuint);
channelText.Colour = colourProvider.Light3;
topicText.Colour = colourProvider.Content2;
}
}, true);
Action = () => (channelJoined.Value ? OnRequestLeave : OnRequestJoin)?.Invoke(channel);
}
protected override bool OnHover(HoverEvent e)
{
hoverBox.Show();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
hoverBox.FadeOut(300, Easing.OutQuint);
base.OnHoverLost(e);
}
}
}

View File

@ -162,7 +162,9 @@ namespace osu.Game.Overlays
Expanded.BindValueChanged(v => Expanded.BindValueChanged(v =>
{ {
content.ClearTransforms(); // clearing transforms can break autosizing, see: https://github.com/ppy/osu-framework/issues/5064
if (v.NewValue != v.OldValue)
content.ClearTransforms();
if (v.NewValue) if (v.NewValue)
content.AutoSizeAxes = Axes.Y; content.AutoSizeAxes = Axes.Y;

View File

@ -73,6 +73,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
SelectionHandler = CreateSelectionHandler(); SelectionHandler = CreateSelectionHandler();
SelectionHandler.DeselectAll = deselectAll; SelectionHandler.DeselectAll = deselectAll;
SelectionHandler.SelectedItems.BindTo(SelectedItems);
AddRangeInternal(new[] AddRangeInternal(new[]
{ {

View File

@ -29,11 +29,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
// bring in updates from selection changes // bring in updates from selection changes
EditorBeatmap.HitObjectUpdated += _ => Scheduler.AddOnce(UpdateTernaryStates); EditorBeatmap.HitObjectUpdated += _ => Scheduler.AddOnce(UpdateTernaryStates);
SelectedItems.BindTo(EditorBeatmap.SelectedHitObjects); SelectedItems.CollectionChanged += (sender, args) => Scheduler.AddOnce(UpdateTernaryStates);
SelectedItems.CollectionChanged += (sender, args) =>
{
Scheduler.AddOnce(UpdateTernaryStates);
};
} }
protected override void DeleteItems(IEnumerable<HitObject> items) => EditorBeatmap.RemoveRange(items); protected override void DeleteItems(IEnumerable<HitObject> items) => EditorBeatmap.RemoveRange(items);

View File

@ -10,6 +10,7 @@ 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.Logging; using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
@ -171,11 +172,25 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
private void onMatchStarted() => Scheduler.Add(() => private void onMatchStarted() => Scheduler.Add(() =>
{ {
if (!this.IsCurrentScreen())
return;
loadingDisplay.Hide(); loadingDisplay.Hide();
base.StartGameplay(); base.StartGameplay();
}); });
private void onResultsReady() => resultsReady.SetResult(true); private void onResultsReady()
{
// Schedule is required to ensure that `TaskCompletionSource.SetResult` is not called more than once.
// A scenario where this can occur is if this instance is not immediately disposed (ie. async disposal queue).
Schedule(() =>
{
if (!this.IsCurrentScreen())
return;
resultsReady.SetResult(true);
});
}
protected override async Task PrepareScoreForResultsAsync(Score score) protected override async Task PrepareScoreForResultsAsync(Score score)
{ {

View File

@ -1,6 +1,8 @@
// 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.
#nullable enable
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -23,8 +25,6 @@ using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics; using osu.Game.Screens.Ranking.Statistics;
using osuTK; using osuTK;
#nullable enable
namespace osu.Game.Screens.Play.PlayerSettings namespace osu.Game.Screens.Play.PlayerSettings
{ {
public class BeatmapOffsetControl : CompositeDrawable public class BeatmapOffsetControl : CompositeDrawable
@ -122,7 +122,19 @@ namespace osu.Game.Screens.Play.PlayerSettings
beatmapOffsetSubscription = realm.SubscribeToPropertyChanged( beatmapOffsetSubscription = realm.SubscribeToPropertyChanged(
r => r.Find<BeatmapInfo>(beatmap.Value.BeatmapInfo.ID)?.UserSettings, r => r.Find<BeatmapInfo>(beatmap.Value.BeatmapInfo.ID)?.UserSettings,
settings => settings.Offset, settings => settings.Offset,
val => Current.Value = val); val =>
{
// At the point we reach here, it's not guaranteed that all realm writes have taken place (there may be some in-flight).
// We are only aware of writes that originated from our own flow, so if we do see one that's active we can avoid handling the feedback value arriving.
if (realmWriteTask == null)
Current.Value = val;
if (realmWriteTask?.IsCompleted == true)
{
// we can also mark any in-flight write that is managed locally as "seen" and start handling any incoming changes again.
realmWriteTask = null;
}
});
Current.BindValueChanged(currentChanged); Current.BindValueChanged(currentChanged);
} }
@ -158,10 +170,12 @@ namespace osu.Game.Screens.Play.PlayerSettings
if (settings == null) // only the case for tests. if (settings == null) // only the case for tests.
return; return;
if (settings.Offset == Current.Value) double val = Current.Value;
if (settings.Offset == val)
return; return;
settings.Offset = Current.Value; settings.Offset = val;
}); });
} }
} }

View File

@ -152,7 +152,6 @@ namespace osu.Game.Screens.Select
public OsuSpriteText VersionLabel { get; private set; } public OsuSpriteText VersionLabel { get; private set; }
public OsuSpriteText TitleLabel { get; private set; } public OsuSpriteText TitleLabel { get; private set; }
public OsuSpriteText ArtistLabel { get; private set; } public OsuSpriteText ArtistLabel { get; private set; }
public BeatmapSetOnlineStatusPill StatusPill { get; private set; }
public FillFlowContainer MapperContainer { get; private set; } public FillFlowContainer MapperContainer { get; private set; }
private Container difficultyColourBar; private Container difficultyColourBar;
@ -169,6 +168,12 @@ namespace osu.Game.Screens.Select
[Resolved] [Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; } private IBindable<IReadOnlyList<Mod>> mods { get; set; }
[Resolved]
private BeatmapDifficultyCache difficultyCache { get; set; }
[Resolved]
private OsuColour colours { get; set; }
private ModSettingChangeTracker settingChangeTracker; private ModSettingChangeTracker settingChangeTracker;
public WedgeInfoText(WorkingBeatmap working, RulesetInfo userRuleset) public WedgeInfoText(WorkingBeatmap working, RulesetInfo userRuleset)
@ -181,7 +186,7 @@ namespace osu.Game.Screens.Select
private IBindable<StarDifficulty?> starDifficulty; private IBindable<StarDifficulty?> starDifficulty;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, LocalisationManager localisation, BeatmapDifficultyCache difficultyCache) private void load(LocalisationManager localisation)
{ {
var beatmapInfo = working.BeatmapInfo; var beatmapInfo = working.BeatmapInfo;
var metadata = beatmapInfo.Metadata; var metadata = beatmapInfo.Metadata;
@ -255,7 +260,7 @@ namespace osu.Game.Screens.Select
Shear = -wedged_container_shear, Shear = -wedged_container_shear,
Alpha = 0f, Alpha = 0f,
}, },
StatusPill = new BeatmapSetOnlineStatusPill new BeatmapSetOnlineStatusPill
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
@ -264,6 +269,7 @@ namespace osu.Game.Screens.Select
TextSize = 11, TextSize = 11,
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 }, TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Status = beatmapInfo.Status, Status = beatmapInfo.Status,
Alpha = string.IsNullOrEmpty(beatmapInfo.DifficultyName) ? 0 : 1
} }
} }
}, },
@ -311,22 +317,6 @@ namespace osu.Game.Screens.Select
titleBinding.BindValueChanged(_ => setMetadata(metadata.Source)); titleBinding.BindValueChanged(_ => setMetadata(metadata.Source));
artistBinding.BindValueChanged(_ => setMetadata(metadata.Source), true); artistBinding.BindValueChanged(_ => setMetadata(metadata.Source), true);
starRatingDisplay.DisplayedStars.BindValueChanged(s =>
{
difficultyColourBar.Colour = colours.ForStarDifficulty(s.NewValue);
}, true);
starDifficulty = difficultyCache.GetBindableDifficulty(beatmapInfo, (cancellationSource = new CancellationTokenSource()).Token);
starDifficulty.BindValueChanged(s =>
{
starRatingDisplay.FadeIn(transition_duration);
starRatingDisplay.Current.Value = s.NewValue ?? default;
});
// no difficulty means it can't have a status to show
if (string.IsNullOrEmpty(beatmapInfo.DifficultyName))
StatusPill.Hide();
addInfoLabels(); addInfoLabels();
} }
@ -334,6 +324,23 @@ namespace osu.Game.Screens.Select
{ {
base.LoadComplete(); base.LoadComplete();
starRatingDisplay.DisplayedStars.BindValueChanged(s =>
{
difficultyColourBar.Colour = colours.ForStarDifficulty(s.NewValue);
}, true);
starDifficulty = difficultyCache.GetBindableDifficulty(working.BeatmapInfo, (cancellationSource = new CancellationTokenSource()).Token);
starDifficulty.BindValueChanged(s =>
{
starRatingDisplay.Current.Value = s.NewValue ?? default;
// Don't roll the counter on initial display (but still allow it to roll on applying mods etc.)
if (!starRatingDisplay.IsPresent)
starRatingDisplay.FinishTransforms(true);
starRatingDisplay.FadeIn(transition_duration);
});
mods.BindValueChanged(m => mods.BindValueChanged(m =>
{ {
settingChangeTracker?.Dispose(); settingChangeTracker?.Dispose();