Merge branch 'master' into fetch-private-chat-history

This commit is contained in:
Dan Balasescu
2020-06-09 14:42:29 +09:00
committed by GitHub
24 changed files with 353 additions and 94 deletions

View File

@ -5,6 +5,6 @@
"version": "3.1.100" "version": "3.1.100"
}, },
"msbuild-sdks": { "msbuild-sdks": {
"Microsoft.Build.Traversal": "2.0.34" "Microsoft.Build.Traversal": "2.0.48"
} }
} }

View File

@ -1,11 +1,10 @@
// 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 System;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
@ -15,7 +14,6 @@ using osu.Framework.Allocation;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
@ -730,23 +728,17 @@ namespace osu.Game.Tests.Beatmaps.IO
await osu.Dependencies.Get<BeatmapManager>().Import(temp); await osu.Dependencies.Get<BeatmapManager>().Import(temp);
BeatmapSetInfo setToUpdate = manager.GetAllUsableBeatmapSets()[0]; BeatmapSetInfo setToUpdate = manager.GetAllUsableBeatmapSets()[0];
var beatmapInfo = setToUpdate.Beatmaps.First(b => b.RulesetID == 0);
Beatmap beatmapToUpdate = (Beatmap)manager.GetWorkingBeatmap(setToUpdate.Beatmaps.First(b => b.RulesetID == 0)).Beatmap; Beatmap beatmapToUpdate = (Beatmap)manager.GetWorkingBeatmap(setToUpdate.Beatmaps.First(b => b.RulesetID == 0)).Beatmap;
BeatmapSetFileInfo fileToUpdate = setToUpdate.Files.First(f => beatmapToUpdate.BeatmapInfo.Path.Contains(f.Filename)); BeatmapSetFileInfo fileToUpdate = setToUpdate.Files.First(f => beatmapToUpdate.BeatmapInfo.Path.Contains(f.Filename));
using (var stream = new MemoryStream()) string oldMd5Hash = beatmapToUpdate.BeatmapInfo.MD5Hash;
{
using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
{
beatmapToUpdate.HitObjects.Clear();
beatmapToUpdate.HitObjects.Add(new HitCircle { StartTime = 5000 });
new LegacyBeatmapEncoder(beatmapToUpdate).Encode(writer); beatmapToUpdate.HitObjects.Clear();
} beatmapToUpdate.HitObjects.Add(new HitCircle { StartTime = 5000 });
stream.Seek(0, SeekOrigin.Begin); manager.Save(beatmapInfo, beatmapToUpdate);
manager.UpdateFile(setToUpdate, fileToUpdate, stream);
}
// Check that the old file reference has been removed // Check that the old file reference has been removed
Assert.That(manager.QueryBeatmapSet(s => s.ID == setToUpdate.ID).Files.All(f => f.ID != fileToUpdate.ID)); Assert.That(manager.QueryBeatmapSet(s => s.ID == setToUpdate.ID).Files.All(f => f.ID != fileToUpdate.ID));
@ -755,6 +747,7 @@ namespace osu.Game.Tests.Beatmaps.IO
Beatmap updatedBeatmap = (Beatmap)manager.GetWorkingBeatmap(manager.QueryBeatmap(b => b.ID == beatmapToUpdate.BeatmapInfo.ID)).Beatmap; Beatmap updatedBeatmap = (Beatmap)manager.GetWorkingBeatmap(manager.QueryBeatmap(b => b.ID == beatmapToUpdate.BeatmapInfo.ID)).Beatmap;
Assert.That(updatedBeatmap.HitObjects.Count, Is.EqualTo(1)); Assert.That(updatedBeatmap.HitObjects.Count, Is.EqualTo(1));
Assert.That(updatedBeatmap.HitObjects[0].StartTime, Is.EqualTo(5000)); Assert.That(updatedBeatmap.HitObjects[0].StartTime, Is.EqualTo(5000));
Assert.That(updatedBeatmap.BeatmapInfo.MD5Hash, Is.Not.EqualTo(oldMd5Hash));
} }
finally finally
{ {

View File

@ -4,12 +4,18 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Platform;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.Multi; using osu.Game.Screens.Multi;
@ -23,6 +29,18 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
private TestPlaylist playlist; private TestPlaylist playlist;
private BeatmapManager manager;
private RulesetStore rulesets;
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, host, Beatmap.Default));
manager.Import(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapSet).Wait();
}
[Test] [Test]
public void TestNonEditableNonSelectable() public void TestNonEditableNonSelectable()
{ {
@ -182,6 +200,28 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("click delete button", () => InputManager.Click(MouseButton.Left)); AddStep("click delete button", () => InputManager.Click(MouseButton.Left));
} }
[Test]
public void TestDownloadButtonHiddenInitiallyWhenBeatmapExists()
{
createPlaylist(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo);
AddAssert("download button hidden", () => !playlist.ChildrenOfType<BeatmapDownloadTrackingComposite>().Single().IsPresent);
}
[Test]
public void TestDownloadButtonVisibleInitiallyWhenBeatmapDoesNotExist()
{
var byOnlineId = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;
byOnlineId.BeatmapSet.OnlineBeatmapSetID = 1337; // Some random ID that does not exist locally.
var byChecksum = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;
byChecksum.MD5Hash = "1337"; // Some random checksum that does not exist locally.
createPlaylist(byOnlineId, byChecksum);
AddAssert("download buttons shown", () => playlist.ChildrenOfType<BeatmapDownloadTrackingComposite>().All(d => d.IsPresent));
}
private void moveToItem(int index, Vector2? offset = null) private void moveToItem(int index, Vector2? offset = null)
=> AddStep($"move mouse to item {index}", () => InputManager.MoveMouseTo(playlist.ChildrenOfType<OsuRearrangeableListItem<PlaylistItem>>().ElementAt(index), offset)); => AddStep($"move mouse to item {index}", () => InputManager.MoveMouseTo(playlist.ChildrenOfType<OsuRearrangeableListItem<PlaylistItem>>().ElementAt(index), offset));
@ -235,6 +275,39 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddUntilStep("wait for items to load", () => playlist.ItemMap.Values.All(i => i.IsLoaded)); AddUntilStep("wait for items to load", () => playlist.ItemMap.Values.All(i => i.IsLoaded));
} }
private void createPlaylist(params BeatmapInfo[] beatmaps)
{
AddStep("create playlist", () =>
{
Child = playlist = new TestPlaylist(false, false)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(500, 300)
};
int index = 0;
foreach (var b in beatmaps)
{
playlist.Items.Add(new PlaylistItem
{
ID = index++,
Beatmap = { Value = b },
Ruleset = { Value = new OsuRuleset().RulesetInfo },
RequiredMods =
{
new OsuModHardRock(),
new OsuModDoubleTime(),
new OsuModAutoplay()
}
});
}
});
AddUntilStep("wait for items to load", () => playlist.ItemMap.Values.All(i => i.IsLoaded));
}
private class TestPlaylist : DrawableRoomPlaylist private class TestPlaylist : DrawableRoomPlaylist
{ {
public new IReadOnlyDictionary<PlaylistItem, RearrangeableListItem<PlaylistItem>> ItemMap => base.ItemMap; public new IReadOnlyDictionary<PlaylistItem, RearrangeableListItem<PlaylistItem>> ItemMap => base.ItemMap;

View File

@ -141,6 +141,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
} }
public readonly BindableList<Room> Rooms = new BindableList<Room>(); public readonly BindableList<Room> Rooms = new BindableList<Room>();
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
IBindableList<Room> IRoomManager.Rooms => Rooms; IBindableList<Room> IRoomManager.Rooms => Rooms;
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => Rooms.Add(room); public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => Rooms.Add(room);

View File

@ -133,6 +133,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
remove { } remove { }
} }
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
public IBindableList<Room> Rooms { get; } = null; public IBindableList<Room> Rooms { get; } = null;
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)

View File

@ -5,7 +5,9 @@ using System;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Platform;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -29,14 +31,20 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Cached(typeof(IRoomManager))] [Cached(typeof(IRoomManager))]
private readonly TestRoomManager roomManager = new TestRoomManager(); private readonly TestRoomManager roomManager = new TestRoomManager();
[Resolved] private BeatmapManager manager;
private BeatmapManager beatmaps { get; set; } private RulesetStore rulesets;
[Resolved]
private RulesetStore rulesets { get; set; }
private TestMatchSubScreen match; private TestMatchSubScreen match;
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, host, Beatmap.Default));
manager.Import(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapSet).Wait();
}
[SetUp] [SetUp]
public void Setup() => Schedule(() => public void Setup() => Schedule(() =>
{ {
@ -75,10 +83,49 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddAssert("first playlist item selected", () => match.SelectedItem.Value == Room.Playlist[0]); AddAssert("first playlist item selected", () => match.SelectedItem.Value == Room.Playlist[0]);
} }
[Test]
public void TestBeatmapUpdatedOnReImport()
{
BeatmapSetInfo importedSet = null;
AddStep("import altered beatmap", () =>
{
var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo);
beatmap.BeatmapInfo.BaseDifficulty.CircleSize = 1;
importedSet = manager.Import(beatmap.BeatmapInfo.BeatmapSet).Result;
});
AddStep("load room", () =>
{
Room.Name.Value = "my awesome room";
Room.Host.Value = new User { Id = 2, Username = "peppy" };
Room.Playlist.Add(new PlaylistItem
{
Beatmap = { Value = importedSet.Beatmaps[0] },
Ruleset = { Value = new OsuRuleset().RulesetInfo }
});
});
AddStep("create room", () =>
{
InputManager.MoveMouseTo(match.ChildrenOfType<MatchSettingsOverlay.CreateRoomButton>().Single());
InputManager.Click(MouseButton.Left);
});
AddAssert("match has altered beatmap", () => match.Beatmap.Value.Beatmap.BeatmapInfo.BaseDifficulty.CircleSize == 1);
AddStep("re-import original beatmap", () => manager.Import(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapSet).Wait());
AddAssert("match has original beatmap", () => match.Beatmap.Value.Beatmap.BeatmapInfo.BaseDifficulty.CircleSize != 1);
}
private class TestMatchSubScreen : MatchSubScreen private class TestMatchSubScreen : MatchSubScreen
{ {
public new Bindable<PlaylistItem> SelectedItem => base.SelectedItem; public new Bindable<PlaylistItem> SelectedItem => base.SelectedItem;
public new Bindable<WorkingBeatmap> Beatmap => base.Beatmap;
public TestMatchSubScreen(Room room) public TestMatchSubScreen(Room room)
: base(room) : base(room)
{ {
@ -93,6 +140,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
remove => throw new NotImplementedException(); remove => throw new NotImplementedException();
} }
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
public IBindableList<Room> Rooms { get; } = new BindableList<Room>(); public IBindableList<Room> Rooms { get; } = new BindableList<Room>();
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)

View File

@ -79,6 +79,8 @@ namespace osu.Game.Beatmaps
beatmaps = (BeatmapStore)ModelStore; beatmaps = (BeatmapStore)ModelStore;
beatmaps.BeatmapHidden += b => beatmapHidden.Value = new WeakReference<BeatmapInfo>(b); beatmaps.BeatmapHidden += b => beatmapHidden.Value = new WeakReference<BeatmapInfo>(b);
beatmaps.BeatmapRestored += b => beatmapRestored.Value = new WeakReference<BeatmapInfo>(b); beatmaps.BeatmapRestored += b => beatmapRestored.Value = new WeakReference<BeatmapInfo>(b);
beatmaps.ItemRemoved += removeWorkingCache;
beatmaps.ItemUpdated += removeWorkingCache;
onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage); onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
} }
@ -203,12 +205,17 @@ namespace osu.Game.Beatmaps
stream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin);
UpdateFile(setInfo, setInfo.Files.Single(f => string.Equals(f.Filename, info.Path, StringComparison.OrdinalIgnoreCase)), stream); using (ContextFactory.GetForWrite())
{
var beatmapInfo = setInfo.Beatmaps.Single(b => b.ID == info.ID);
beatmapInfo.MD5Hash = stream.ComputeMD5Hash();
stream.Seek(0, SeekOrigin.Begin);
UpdateFile(setInfo, setInfo.Files.Single(f => string.Equals(f.Filename, info.Path, StringComparison.OrdinalIgnoreCase)), stream);
}
} }
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == info.ID); removeWorkingCache(info);
if (working != null)
workingCache.Remove(working);
} }
private readonly WeakList<WorkingBeatmap> workingCache = new WeakList<WorkingBeatmap>(); private readonly WeakList<WorkingBeatmap> workingCache = new WeakList<WorkingBeatmap>();
@ -410,6 +417,24 @@ namespace osu.Game.Beatmaps
return endTime - startTime; return endTime - startTime;
} }
private void removeWorkingCache(BeatmapSetInfo info)
{
if (info.Beatmaps == null) return;
foreach (var b in info.Beatmaps)
removeWorkingCache(b);
}
private void removeWorkingCache(BeatmapInfo info)
{
lock (workingCache)
{
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == info.ID);
if (working != null)
workingCache.Remove(working);
}
}
public void Dispose() public void Dispose()
{ {
onlineLookupQueue?.Dispose(); onlineLookupQueue?.Dispose();

View File

@ -42,7 +42,7 @@ namespace osu.Game.Beatmaps
} }
} }
private string getPathForFile(string filename) => BeatmapSetInfo.Files.FirstOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath; private string getPathForFile(string filename) => BeatmapSetInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
private TextureStore textureStore; private TextureStore textureStore;

View File

@ -429,7 +429,6 @@ namespace osu.Game.Database
using (ContextFactory.GetForWrite()) using (ContextFactory.GetForWrite())
{ {
item.Hash = computeHash(item); item.Hash = computeHash(item);
ModelStore.Update(item); ModelStore.Update(item);
} }
} }

View File

@ -0,0 +1,23 @@
// 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 Newtonsoft.Json;
using osu.Game.Beatmaps;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
namespace osu.Game.Online.API
{
public class APIPlaylistBeatmap : APIBeatmap
{
[JsonProperty("checksum")]
public string Checksum { get; set; }
public override BeatmapInfo ToBeatmap(RulesetStore rulesets)
{
var b = base.ToBeatmap(rulesets);
b.MD5Hash = Checksum;
return b;
}
}
}

View File

@ -64,7 +64,7 @@ namespace osu.Game.Online.API.Requests.Responses
[JsonProperty(@"max_combo")] [JsonProperty(@"max_combo")]
private int? maxCombo { get; set; } private int? maxCombo { get; set; }
public BeatmapInfo ToBeatmap(RulesetStore rulesets) public virtual BeatmapInfo ToBeatmap(RulesetStore rulesets)
{ {
var set = BeatmapSet?.ToBeatmapSet(rulesets); var set = BeatmapSet?.ToBeatmapSet(rulesets);

View File

@ -7,7 +7,6 @@ using Newtonsoft.Json;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
@ -37,7 +36,7 @@ namespace osu.Game.Online.Multiplayer
public readonly BindableList<Mod> RequiredMods = new BindableList<Mod>(); public readonly BindableList<Mod> RequiredMods = new BindableList<Mod>();
[JsonProperty("beatmap")] [JsonProperty("beatmap")]
private APIBeatmap apiBeatmap { get; set; } private APIPlaylistBeatmap apiBeatmap { get; set; }
private APIMod[] allowedModsBacking; private APIMod[] allowedModsBacking;

View File

@ -41,9 +41,9 @@ namespace osu.Game.Screens.Menu
protected IBindable<bool> MenuMusic { get; private set; } protected IBindable<bool> MenuMusic { get; private set; }
private WorkingBeatmap introBeatmap; private WorkingBeatmap initialBeatmap;
protected Track Track { get; private set; } protected Track Track => initialBeatmap?.Track;
private readonly BindableDouble exitingVolumeFade = new BindableDouble(1); private readonly BindableDouble exitingVolumeFade = new BindableDouble(1);
@ -58,6 +58,11 @@ namespace osu.Game.Screens.Menu
[Resolved] [Resolved]
private AudioManager audio { get; set; } private AudioManager audio { get; set; }
/// <summary>
/// Whether the <see cref="Track"/> is provided by osu! resources, rather than a user beatmap.
/// </summary>
protected bool UsingThemedIntro { get; private set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game) private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game)
{ {
@ -71,29 +76,45 @@ namespace osu.Game.Screens.Menu
BeatmapSetInfo setInfo = null; BeatmapSetInfo setInfo = null;
// if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection.
if (!MenuMusic.Value) if (!MenuMusic.Value)
{ {
var sets = beatmaps.GetAllUsableBeatmapSets(IncludedDetails.Minimal); var sets = beatmaps.GetAllUsableBeatmapSets(IncludedDetails.Minimal);
if (sets.Count > 0) if (sets.Count > 0)
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
}
if (setInfo == null)
{
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapHash);
if (setInfo == null)
{ {
// we need to import the default menu background beatmap setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
setInfo = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).Result; initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
setInfo.Protected = true;
beatmaps.Update(setInfo);
} }
} }
introBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]); // we generally want a song to be playing on startup, so use the intro music even if a user has specified not to if no other track is available.
Track = introBeatmap.Track; if (setInfo == null)
{
if (!loadThemedIntro())
{
// if we detect that the theme track or beatmap is unavailable this is either first startup or things are in a bad state.
// this could happen if a user has nuked their files store. for now, reimport to repair this.
var import = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).Result;
import.Protected = true;
beatmaps.Update(import);
loadThemedIntro();
}
}
bool loadThemedIntro()
{
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapHash);
if (setInfo != null)
{
initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
UsingThemedIntro = !(Track is TrackVirtual);
}
return UsingThemedIntro;
}
} }
public override void OnResuming(IScreen last) public override void OnResuming(IScreen last)
@ -119,7 +140,7 @@ namespace osu.Game.Screens.Menu
public override void OnSuspending(IScreen next) public override void OnSuspending(IScreen next)
{ {
base.OnSuspending(next); base.OnSuspending(next);
Track = null; initialBeatmap = null;
} }
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack(); protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack();
@ -127,7 +148,7 @@ namespace osu.Game.Screens.Menu
protected void StartTrack() protected void StartTrack()
{ {
// Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Menu. // Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Menu.
if (MenuMusic.Value) if (UsingThemedIntro)
Track.Restart(); Track.Restart();
} }
@ -141,8 +162,7 @@ namespace osu.Game.Screens.Menu
if (!resuming) if (!resuming)
{ {
beatmap.Value = introBeatmap; beatmap.Value = initialBeatmap;
introBeatmap = null;
logo.MoveTo(new Vector2(0.5f)); logo.MoveTo(new Vector2(0.5f));
logo.ScaleTo(Vector2.One); logo.ScaleTo(Vector2.One);

View File

@ -46,7 +46,7 @@ namespace osu.Game.Screens.Menu
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
if (MenuVoice.Value && !MenuMusic.Value) if (MenuVoice.Value && !UsingThemedIntro)
welcome = audio.Samples.Get(@"welcome"); welcome = audio.Samples.Get(@"welcome");
} }
@ -61,7 +61,7 @@ namespace osu.Game.Screens.Menu
LoadComponentAsync(new TrianglesIntroSequence(logo, background) LoadComponentAsync(new TrianglesIntroSequence(logo, background)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Clock = new FramedClock(MenuMusic.Value ? Track : null), Clock = new FramedClock(UsingThemedIntro ? Track : null),
LoadMenu = LoadMenu LoadMenu = LoadMenu
}, t => }, t =>
{ {

View File

@ -188,7 +188,7 @@ namespace osu.Game.Screens.Multi
X = -18, X = -18,
Children = new Drawable[] Children = new Drawable[]
{ {
new PlaylistDownloadButton(item.Beatmap.Value.BeatmapSet) new PlaylistDownloadButton(item)
{ {
Size = new Vector2(50, 30) Size = new Vector2(50, 30)
}, },
@ -212,9 +212,15 @@ namespace osu.Game.Screens.Multi
private class PlaylistDownloadButton : BeatmapPanelDownloadButton private class PlaylistDownloadButton : BeatmapPanelDownloadButton
{ {
public PlaylistDownloadButton(BeatmapSetInfo beatmapSet) private readonly PlaylistItem playlistItem;
: base(beatmapSet)
[Resolved]
private BeatmapManager beatmapManager { get; set; }
public PlaylistDownloadButton(PlaylistItem playlistItem)
: base(playlistItem.Beatmap.Value.BeatmapSet)
{ {
this.playlistItem = playlistItem;
Alpha = 0; Alpha = 0;
} }
@ -223,11 +229,26 @@ namespace osu.Game.Screens.Multi
base.LoadComplete(); base.LoadComplete();
State.BindValueChanged(stateChanged, true); State.BindValueChanged(stateChanged, true);
FinishTransforms(true);
} }
private void stateChanged(ValueChangedEvent<DownloadState> state) private void stateChanged(ValueChangedEvent<DownloadState> state)
{ {
this.FadeTo(state.NewValue == DownloadState.LocallyAvailable ? 0 : 1, 500); switch (state.NewValue)
{
case DownloadState.LocallyAvailable:
// Perform a local query of the beatmap by beatmap checksum, and reset the state if not matching.
if (beatmapManager.QueryBeatmap(b => b.MD5Hash == playlistItem.Beatmap.Value.MD5Hash) == null)
State.Value = DownloadState.NotDownloaded;
else
this.FadeTo(0, 500);
break;
default:
this.FadeTo(1, 500);
break;
}
} }
} }

View File

@ -14,6 +14,11 @@ namespace osu.Game.Screens.Multi
/// </summary> /// </summary>
event Action RoomsUpdated; event Action RoomsUpdated;
/// <summary>
/// Whether an initial listing of rooms has been received.
/// </summary>
Bindable<bool> InitialRoomsReceived { get; }
/// <summary> /// <summary>
/// All the active <see cref="Room"/>s. /// All the active <see cref="Room"/>s.
/// </summary> /// </summary>

View File

@ -22,12 +22,16 @@ namespace osu.Game.Screens.Multi.Lounge
protected readonly FilterControl Filter; protected readonly FilterControl Filter;
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
private readonly Container content; private readonly Container content;
private readonly LoadingLayer loadingLayer; private readonly LoadingLayer loadingLayer;
[Resolved] [Resolved]
private Bindable<Room> selectedRoom { get; set; } private Bindable<Room> selectedRoom { get; set; }
private bool joiningRoom;
public LoungeSubScreen() public LoungeSubScreen()
{ {
SearchContainer searchContainer; SearchContainer searchContainer;
@ -73,6 +77,14 @@ namespace osu.Game.Screens.Multi.Lounge
}; };
} }
protected override void LoadComplete()
{
base.LoadComplete();
initialRoomsReceived.BindTo(RoomManager.InitialRoomsReceived);
initialRoomsReceived.BindValueChanged(onInitialRoomsReceivedChanged, true);
}
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();
@ -126,12 +138,29 @@ namespace osu.Game.Screens.Multi.Lounge
private void joinRequested(Room room) private void joinRequested(Room room)
{ {
loadingLayer.Show(); joiningRoom = true;
updateLoadingLayer();
RoomManager?.JoinRoom(room, r => RoomManager?.JoinRoom(room, r =>
{ {
Open(room); Open(room);
joiningRoom = false;
updateLoadingLayer();
}, _ =>
{
joiningRoom = false;
updateLoadingLayer();
});
}
private void onInitialRoomsReceivedChanged(ValueChangedEvent<bool> received) => updateLoadingLayer();
private void updateLoadingLayer()
{
if (joiningRoom || !initialRoomsReceived.Value)
loadingLayer.Show();
else
loadingLayer.Hide(); loadingLayer.Hide();
}, _ => loadingLayer.Hide());
} }
/// <summary> /// <summary>

View File

@ -433,7 +433,7 @@ namespace osu.Game.Screens.Multi.Match.Components
} }
} }
private class CreateRoomButton : TriangleButton public class CreateRoomButton : TriangleButton
{ {
public CreateRoomButton() public CreateRoomButton()
{ {

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -52,24 +53,14 @@ namespace osu.Game.Screens.Multi.Match.Components
private void updateSelectedItem(PlaylistItem item) private void updateSelectedItem(PlaylistItem item)
{ {
hasBeatmap = false; hasBeatmap = findBeatmap(expr => beatmaps.QueryBeatmap(expr));
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
if (beatmapId == null)
return;
hasBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId) != null;
} }
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet) private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet)
{ {
if (weakSet.NewValue.TryGetTarget(out var set)) if (weakSet.NewValue.TryGetTarget(out var set))
{ {
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID; if (findBeatmap(expr => set.Beatmaps.AsQueryable().FirstOrDefault(expr)))
if (beatmapId == null)
return;
if (set.Beatmaps.Any(b => b.OnlineBeatmapID == beatmapId))
Schedule(() => hasBeatmap = true); Schedule(() => hasBeatmap = true);
} }
} }
@ -78,15 +69,22 @@ namespace osu.Game.Screens.Multi.Match.Components
{ {
if (weakSet.NewValue.TryGetTarget(out var set)) if (weakSet.NewValue.TryGetTarget(out var set))
{ {
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID; if (findBeatmap(expr => set.Beatmaps.AsQueryable().FirstOrDefault(expr)))
if (beatmapId == null)
return;
if (set.Beatmaps.Any(b => b.OnlineBeatmapID == beatmapId))
Schedule(() => hasBeatmap = false); Schedule(() => hasBeatmap = false);
} }
} }
private bool findBeatmap(Func<Expression<Func<BeatmapInfo, bool>>, BeatmapInfo> expression)
{
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
string checksum = SelectedItem.Value?.Beatmap.Value?.MD5Hash;
if (beatmapId == null || checksum == null)
return false;
return expression(b => b.OnlineBeatmapID == beatmapId && b.MD5Hash == checksum) != null;
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();

View File

@ -207,6 +207,8 @@ namespace osu.Game.Screens.Multi.Match
Ruleset.Value = item.Ruleset.Value; Ruleset.Value = item.Ruleset.Value;
} }
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet) => Schedule(updateWorkingBeatmap);
private void updateWorkingBeatmap() private void updateWorkingBeatmap()
{ {
var beatmap = SelectedItem.Value?.Beatmap.Value; var beatmap = SelectedItem.Value?.Beatmap.Value;
@ -217,17 +219,6 @@ namespace osu.Game.Screens.Multi.Match
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap); Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
} }
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet)
{
Schedule(() =>
{
if (Beatmap.Value != beatmapManager.DefaultBeatmap)
return;
updateWorkingBeatmap();
});
}
private void onStart() private void onStart()
{ {
switch (type.Value) switch (type.Value)

View File

@ -25,6 +25,9 @@ namespace osu.Game.Screens.Multi
public event Action RoomsUpdated; public event Action RoomsUpdated;
private readonly BindableList<Room> rooms = new BindableList<Room>(); private readonly BindableList<Room> rooms = new BindableList<Room>();
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>();
public IBindableList<Room> Rooms => rooms; public IBindableList<Room> Rooms => rooms;
public double TimeBetweenListingPolls public double TimeBetweenListingPolls
@ -62,7 +65,11 @@ namespace osu.Game.Screens.Multi
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
listingPollingComponent = new ListingPollingComponent { RoomsReceived = onListingReceived }, listingPollingComponent = new ListingPollingComponent
{
InitialRoomsReceived = { BindTarget = InitialRoomsReceived },
RoomsReceived = onListingReceived
},
selectionPollingComponent = new SelectionPollingComponent { RoomReceived = onSelectedRoomReceived } selectionPollingComponent = new SelectionPollingComponent { RoomReceived = onSelectedRoomReceived }
}; };
} }
@ -262,6 +269,8 @@ namespace osu.Game.Screens.Multi
{ {
public Action<List<Room>> RoomsReceived; public Action<List<Room>> RoomsReceived;
public readonly Bindable<bool> InitialRoomsReceived = new Bindable<bool>();
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
@ -273,6 +282,8 @@ namespace osu.Game.Screens.Multi
{ {
currentFilter.BindValueChanged(_ => currentFilter.BindValueChanged(_ =>
{ {
InitialRoomsReceived.Value = false;
if (IsLoaded) if (IsLoaded)
PollImmediately(); PollImmediately();
}); });
@ -292,6 +303,7 @@ namespace osu.Game.Screens.Multi
pollReq.Success += result => pollReq.Success += result =>
{ {
InitialRoomsReceived.Value = true;
RoomsReceived?.Invoke(result); RoomsReceived?.Invoke(result);
tcs.SetResult(true); tcs.SetResult(true);
}; };

View File

@ -1,9 +1,11 @@
// 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 System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using osu.Framework.Extensions;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -43,10 +45,25 @@ namespace osu.Game.Tests.Beatmaps
private static Beatmap createTestBeatmap() private static Beatmap createTestBeatmap()
{ {
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(test_beatmap_data))) using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(test_beatmap_data)))
using (var reader = new LineBufferedReader(stream)) {
return Decoder.GetDecoder<Beatmap>(reader).Decode(reader); using (var reader = new LineBufferedReader(stream))
{
var b = Decoder.GetDecoder<Beatmap>(reader).Decode(reader);
b.BeatmapInfo.MD5Hash = test_beatmap_hash.Value.md5;
b.BeatmapInfo.Hash = test_beatmap_hash.Value.sha2;
return b;
}
}
} }
private static readonly Lazy<(string md5, string sha2)> test_beatmap_hash = new Lazy<(string md5, string sha2)>(() =>
{
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(test_beatmap_data)))
return (stream.ComputeMD5Hash(), stream.ComputeSHA2Hash());
});
private const string test_beatmap_data = @"osu file format v14 private const string test_beatmap_data = @"osu file format v14
[General] [General]

View File

@ -20,13 +20,13 @@
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="Dapper" Version="2.0.35" /> <PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="DiffPlex" Version="1.6.3" /> <PackageReference Include="DiffPlex" Version="1.6.3" />
<PackageReference Include="Humanizer" Version="2.8.11" /> <PackageReference Include="Humanizer" Version="2.8.26" />
<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="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2020.601.0" /> <PackageReference Include="ppy.osu.Framework" Version="2020.601.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.602.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2020.602.0" />
<PackageReference Include="Sentry" Version="2.1.1" /> <PackageReference Include="Sentry" Version="2.1.3" />
<PackageReference Include="SharpCompress" Version="0.25.1" /> <PackageReference Include="SharpCompress" Version="0.25.1" />
<PackageReference Include="NUnit" Version="3.12.0" /> <PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" /> <PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />

View File

@ -76,7 +76,7 @@
<!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. --> <!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. -->
<ItemGroup Label="Transitive Dependencies"> <ItemGroup Label="Transitive Dependencies">
<PackageReference Include="DiffPlex" Version="1.6.3" /> <PackageReference Include="DiffPlex" Version="1.6.3" />
<PackageReference Include="Humanizer" Version="2.8.11" /> <PackageReference Include="Humanizer" Version="2.8.26" />
<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="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />