1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Merge branch 'localisable-filter-items' into update-framework

This commit is contained in:
Dean Herbert 2022-05-21 15:17:51 +09:00
commit 982856a8b2
36 changed files with 57 additions and 46 deletions

View File

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

View File

@ -507,7 +507,7 @@ namespace osu.Game.Tests.Database
using (var stream = storage.GetStream(firstFile.File.GetStoragePath()))
originalLength = stream.Length;
using (var stream = storage.GetStream(firstFile.File.GetStoragePath(), FileAccess.Write, FileMode.Create))
using (var stream = storage.CreateFileSafely(firstFile.File.GetStoragePath()))
stream.WriteByte(0);
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);

View File

@ -1,7 +1,6 @@
// 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.IO;
using System.Linq;
using System.Runtime.InteropServices;
using NUnit.Framework;
@ -25,7 +24,7 @@ namespace osu.Game.Tests.Visual.Navigation
if (isDisposing)
return;
using (var outStream = LocalStorage.GetStream(DatabaseContextFactory.DATABASE_NAME, FileAccess.Write, FileMode.Create))
using (var outStream = LocalStorage.CreateFileSafely(DatabaseContextFactory.DATABASE_NAME))
using (var stream = TestResources.OpenResource(DatabaseContextFactory.DATABASE_NAME))
stream.CopyTo(outStream);
}

View File

@ -55,7 +55,7 @@ namespace osu.Game.Tests.Visual.Settings
.OfType<ISettingsItem>()
.OfType<IFilterable>()
.Where(f => !(f is IHasFilterableChildren))
.All(f => f.FilterTerms.Any(t => t.Contains("scaling")))
.All(f => f.FilterTerms.Any(t => t.ToString().Contains("scaling")))
));
AddAssert("ensure section is current", () => settings.CurrentSection.Value is GraphicsSection);

View File

@ -89,7 +89,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddAssert("results filtered correctly",
() => playlistOverlay.ChildrenOfType<PlaylistItem>()
.Where(item => item.MatchingFilter)
.All(item => item.FilterTerms.Any(term => term.Contains("10"))));
.All(item => item.FilterTerms.Any(term => term.ToString().Contains("10"))));
}
}
}

View File

@ -28,7 +28,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
// ReSharper disable once AccessToDisposedClosure
var storage = host.Storage.GetStorageForDirectory(Path.Combine("tournaments", "default"));
using (var stream = storage.GetStream("bracket.json", FileAccess.Write, FileMode.Create))
using (var stream = storage.CreateFileSafely("bracket.json"))
using (var writer = new StreamWriter(stream))
{
writer.Write(@"{

View File

@ -15,7 +15,7 @@ namespace osu.Game.Tournament.Tests.Screens
[BackgroundDependencyLoader]
private void load(Storage storage)
{
using (var stream = storage.GetStream("drawings.txt", FileAccess.Write))
using (var stream = storage.CreateFileSafely("drawings.txt"))
using (var writer = new StreamWriter(stream))
{
writer.WriteLine("KR : South Korea : KOR");

View File

@ -45,7 +45,7 @@ namespace osu.Game.Tournament.Models
public void SaveChanges()
{
using (var stream = configStorage.GetStream(config_path, FileAccess.Write, FileMode.Create))
using (var stream = configStorage.CreateFileSafely(config_path))
using (var sw = new StreamWriter(stream))
{
sw.Write(JsonConvert.SerializeObject(this,

View File

@ -205,7 +205,7 @@ namespace osu.Game.Tournament.Screens.Drawings
try
{
// Write to drawings_results
using (Stream stream = storage.GetStream(results_filename, FileAccess.Write, FileMode.Create))
using (Stream stream = storage.CreateFileSafely(results_filename))
using (StreamWriter sw = new StreamWriter(stream))
{
sw.Write(text);

View File

@ -321,7 +321,7 @@ namespace osu.Game.Tournament
Converters = new JsonConverter[] { new JsonPointConverter() }
});
using (var stream = storage.GetStream(BRACKET_FILENAME, FileAccess.Write, FileMode.Create))
using (var stream = storage.CreateFileSafely(BRACKET_FILENAME))
using (var sw = new StreamWriter(stream))
sw.Write(serialisedLadder);
}

View File

@ -37,7 +37,7 @@ namespace osu.Game.Database
{
string filename = $"{item.GetDisplayString().GetValidArchiveContentFilename()}{FileExtension}";
using (var stream = exportStorage.GetStream(filename, FileAccess.Write, FileMode.Create))
using (var stream = exportStorage.CreateFileSafely(filename))
ExportModelTo(item, stream);
exportStorage.PresentFileExternally(filename);

View File

@ -242,7 +242,7 @@ namespace osu.Game.Database
storage.Delete(Filename);
using (var inputStream = storage.GetStream(recoveryFilename))
using (var outputStream = storage.GetStream(Filename, FileAccess.Write, FileMode.Create))
using (var outputStream = storage.CreateFileSafely(Filename))
inputStream.CopyTo(outputStream);
storage.Delete(recoveryFilename);

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
@ -118,7 +117,7 @@ namespace osu.Game.Graphics
if (filename == null) return;
using (var stream = storage.GetStream(filename, FileAccess.Write))
using (var stream = storage.CreateFileSafely(filename))
{
switch (screenshotFormat.Value)
{

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Graphics.Backgrounds;
namespace osu.Game.Graphics.UserInterface
@ -27,7 +28,7 @@ namespace osu.Game.Graphics.UserInterface
});
}
public virtual IEnumerable<string> FilterTerms => new[] { Text.ToString() };
public virtual IEnumerable<LocalisableString> FilterTerms => new[] { Text };
public bool MatchingFilter
{

View File

@ -6,6 +6,7 @@ using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
@ -39,7 +40,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
private void updateCornerRadius() => Content.CornerRadius = DrawHeight / 2;
public virtual IEnumerable<string> FilterTerms => new[] { Text.ToString() };
public virtual IEnumerable<LocalisableString> FilterTerms => new[] { Text };
public bool MatchingFilter
{

View File

@ -67,9 +67,13 @@ namespace osu.Game.IO
public override IEnumerable<string> GetFiles(string path, string pattern = "*") =>
ToLocalRelative(UnderlyingStorage.GetFiles(MutatePath(path), pattern));
public override Stream CreateFileSafely(string path) => UnderlyingStorage.CreateFileSafely(path);
public override Stream GetStream(string path, FileAccess access = FileAccess.Read, FileMode mode = FileMode.OpenOrCreate) =>
UnderlyingStorage.GetStream(MutatePath(path), access, mode);
public override void Move(string from, string to) => UnderlyingStorage.Move(from, to);
public override bool OpenFileExternally(string filename) => UnderlyingStorage.OpenFileExternally(MutatePath(filename));
public override bool PresentFileExternally(string filename) => UnderlyingStorage.PresentFileExternally(MutatePath(filename));

View File

@ -243,7 +243,7 @@ namespace osu.Game
{
if (source != null)
{
using (var destination = Storage.GetStream(Path.Combine(backup_folder, $"collection.{migration}.db"), FileAccess.Write, FileMode.CreateNew))
using (var destination = Storage.CreateFileSafely(Path.Combine(backup_folder, $"collection.{migration}.db")))
source.CopyTo(destination);
}
}

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
@ -28,7 +29,7 @@ namespace osu.Game.Overlays.Chat.Listing
public readonly Channel Channel;
public bool FilteringActive { get; set; }
public IEnumerable<string> FilterTerms => new[] { Channel.Name, Channel.Topic ?? string.Empty };
public IEnumerable<LocalisableString> FilterTerms => new LocalisableString[] { Channel.Name, Channel.Topic ?? string.Empty };
public bool MatchingFilter { set => this.FadeTo(value ? 1f : 0f, 100); }
private Box hoverBox = null!;

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
@ -36,7 +37,7 @@ namespace osu.Game.Overlays.Chat.Selection
private Color4 topicColour;
private Color4 hoverColour;
public IEnumerable<string> FilterTerms => new[] { Channel.Name, Channel.Topic ?? string.Empty };
public IEnumerable<LocalisableString> FilterTerms => new LocalisableString[] { Channel.Name, Channel.Topic ?? string.Empty };
public bool MatchingFilter
{

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
@ -18,7 +19,7 @@ namespace osu.Game.Overlays.Chat.Selection
public readonly FillFlowContainer<ChannelListItem> ChannelFlow;
public IEnumerable<IFilterable> FilterableChildren => ChannelFlow.Children;
public IEnumerable<string> FilterTerms => Array.Empty<string>();
public IEnumerable<LocalisableString> FilterTerms => Array.Empty<LocalisableString>();
public bool MatchingFilter
{

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -113,7 +114,7 @@ namespace osu.Game.Overlays.Music
}
}
public IEnumerable<string> FilterTerms => Model.PerformRead(m => m.Metadata.GetSearchableTerms());
public IEnumerable<LocalisableString> FilterTerms => Model.PerformRead(m => m.Metadata.GetSearchableTerms()).Select(s => (LocalisableString)s).ToArray();
private bool matchingFilter = true;

View File

@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
{
protected override LocalisableString Header => AudioSettingsStrings.OffsetHeader;
public override IEnumerable<string> FilterTerms => base.FilterTerms.Concat(new[] { "universal", "uo", "timing" });
public override IEnumerable<LocalisableString> FilterTerms => base.FilterTerms.Concat(new LocalisableString[] { "universal", "uo", "timing" });
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)

View File

@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Settings.Sections
Icon = FontAwesome.Solid.VolumeUp
};
public override IEnumerable<string> FilterTerms => base.FilterTerms.Concat(new[] { "sound" });
public override IEnumerable<LocalisableString> FilterTerms => base.FilterTerms.Concat(new LocalisableString[] { "sound" });
public AudioSection()
{

View File

@ -14,7 +14,7 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay
{
protected override LocalisableString Header => GameplaySettingsStrings.ModsHeader;
public override IEnumerable<string> FilterTerms => base.FilterTerms.Concat(new[] { "mod" });
public override IEnumerable<LocalisableString> FilterTerms => base.FilterTerms.Concat(new LocalisableString[] { "mod" });
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)

View File

@ -15,6 +15,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
@ -67,7 +68,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
private Bindable<bool> isDefault { get; } = new BindableBool(true);
public IEnumerable<string> FilterTerms => bindings.Select(b => keyCombinationProvider.GetReadableString(b.KeyCombination)).Prepend(text.Text.ToString());
public IEnumerable<LocalisableString> FilterTerms => bindings.Select(b => (LocalisableString)keyCombinationProvider.GetReadableString(b.KeyCombination)).Prepend(text.Text);
public KeyBindingRow(object action, List<RealmKeyBinding> bindings)
{

View File

@ -6,6 +6,7 @@ using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Database;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets;
@ -74,6 +75,6 @@ namespace osu.Game.Overlays.Settings.Sections.Input
}
// Empty FilterTerms so that the ResetButton is visible only when the whole subsection is visible.
public override IEnumerable<string> FilterTerms => Enumerable.Empty<string>();
public override IEnumerable<LocalisableString> FilterTerms => Enumerable.Empty<LocalisableString>();
}
}

View File

@ -20,13 +20,12 @@ namespace osu.Game.Overlays.Settings
public LocalisableString TooltipText { get; set; }
public override IEnumerable<string> FilterTerms
public override IEnumerable<LocalisableString> FilterTerms
{
get
{
if (TooltipText != default)
// TODO: this won't work as intended once the tooltip text is translated.
return base.FilterTerms.Append(TooltipText.ToString());
return base.FilterTerms.Append(TooltipText);
return base.FilterTerms;
}

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Settings
@ -25,7 +26,7 @@ namespace osu.Game.Overlays.Settings
set => Control.ItemSource = value;
}
public override IEnumerable<string> FilterTerms => base.FilterTerms.Concat(Control.Items.Select(i => i.ToString()));
public override IEnumerable<LocalisableString> FilterTerms => base.FilterTerms.Concat(Control.Items.Select(i => (LocalisableString)i.ToString()));
protected sealed override Drawable CreateControl() => CreateDropdown();

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -98,13 +99,13 @@ namespace osu.Game.Overlays.Settings
set => controlWithCurrent.Current = value;
}
public virtual IEnumerable<string> FilterTerms
public virtual IEnumerable<LocalisableString> FilterTerms
{
get
{
var keywords = new List<string>(Keywords ?? Array.Empty<string>())
var keywords = new List<LocalisableString>(Keywords?.Select(k => (LocalisableString)k) ?? Array.Empty<LocalisableString>())
{
LabelText.ToString()
LabelText
};
if (HasClassicDefault)

View File

@ -32,7 +32,7 @@ namespace osu.Game.Overlays.Settings
public abstract LocalisableString Header { get; }
public IEnumerable<IFilterable> FilterableChildren => Children.OfType<IFilterable>();
public virtual IEnumerable<string> FilterTerms => new[] { Header.ToString() };
public virtual IEnumerable<LocalisableString> FilterTerms => new[] { Header };
public const int ITEM_SPACING = 14;

View File

@ -25,11 +25,7 @@ namespace osu.Game.Overlays.Settings
public IEnumerable<IFilterable> FilterableChildren => Children.OfType<IFilterable>();
// FilterTerms should contains both original string and localised string for user to search.
// Since LocalisableString is unable to get original string at this time (2021-08-14),
// only call .ToString() to use localised one.
// TODO: Update here when FilterTerms accept LocalisableString.
public virtual IEnumerable<string> FilterTerms => new[] { Header.ToString() };
public virtual IEnumerable<LocalisableString> FilterTerms => new[] { Header };
public bool MatchingFilter
{

View File

@ -80,7 +80,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
matchingFilter &= criteria.Ruleset == null || r.Room.PlaylistItemStats.Value?.RulesetIDs.Any(id => id == criteria.Ruleset.OnlineID) != false;
if (!string.IsNullOrEmpty(criteria.SearchString))
matchingFilter &= r.FilterTerms.Any(term => term.Contains(criteria.SearchString, StringComparison.InvariantCultureIgnoreCase));
{
// Room name isn't translatable, so ToString() is used here for simplicity.
matchingFilter &= r.FilterTerms.Any(term => term.ToString().Contains(criteria.SearchString, StringComparison.InvariantCultureIgnoreCase));
}
r.MatchingFilter = matchingFilter;
}

View File

@ -14,6 +14,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
@ -101,7 +102,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
public bool FilteringActive { get; set; }
public IEnumerable<string> FilterTerms => new[] { Room.Name.Value };
public IEnumerable<LocalisableString> FilterTerms => new LocalisableString[] { Room.Name.Value };
private bool matchingFilter = true;

View File

@ -65,7 +65,7 @@ namespace osu.Game.Stores
{
data.Seek(0, SeekOrigin.Begin);
using (var output = Storage.GetStream(file.GetStoragePath(), FileAccess.Write))
using (var output = Storage.CreateFileSafely(file.GetStoragePath()))
data.CopyTo(output);
data.Seek(0, SeekOrigin.Begin);

View File

@ -35,7 +35,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Realm" Version="10.11.2" />
<PackageReference Include="ppy.osu.Framework" Version="2022.511.0" />
<PackageReference Include="ppy.osu.Framework" Version="2022.520.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.513.0" />
<PackageReference Include="Sentry" Version="3.17.1" />
<PackageReference Include="SharpCompress" Version="0.31.0" />

View File

@ -61,7 +61,7 @@
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2022.511.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2022.520.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.513.0" />
</ItemGroup>
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net6.0) -->
@ -84,7 +84,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="5.0.14" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ppy.osu.Framework" Version="2022.511.0" />
<PackageReference Include="ppy.osu.Framework" Version="2022.520.0" />
<PackageReference Include="SharpCompress" Version="0.31.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />