1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 23:52:57 +08:00

Merge branch 'master' into fix-hr-cs-mania-adjustment

This commit is contained in:
Bartłomiej Dach 2023-10-13 14:08:05 +02:00
commit c762241268
No known key found for this signature in database
52 changed files with 1739 additions and 427 deletions

View File

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.8" /> <PackageReference Include="BenchmarkDotNet" Version="0.13.9" />
<PackageReference Include="nunit" Version="3.13.3" /> <PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,48 @@
// 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;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Input.Bindings;
using osu.Framework.Testing;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko;
using osu.Game.Tests.Visual;
using osuTK.Input;
namespace osu.Game.Tests.Input
{
[HeadlessTest]
public partial class RealmKeyBindingTest : OsuTestScene
{
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
[Test]
public void TestUnmapGlobalAction()
{
var keyBinding = new RealmKeyBinding(GlobalAction.ToggleReplaySettings, KeyCombination.FromKey(Key.Z));
AddAssert("action is integer", () => keyBinding.Action, () => Is.EqualTo((int)GlobalAction.ToggleReplaySettings));
AddAssert("action unmaps correctly", () => keyBinding.GetAction(rulesets), () => Is.EqualTo(GlobalAction.ToggleReplaySettings));
}
[TestCase(typeof(OsuRuleset), OsuAction.Smoke, null)]
[TestCase(typeof(TaikoRuleset), TaikoAction.LeftCentre, null)]
[TestCase(typeof(CatchRuleset), CatchAction.MoveRight, null)]
[TestCase(typeof(ManiaRuleset), ManiaAction.Key7, 7)]
public void TestUnmapRulesetActions(Type rulesetType, object action, int? variant)
{
string rulesetName = ((Ruleset)Activator.CreateInstance(rulesetType)!).ShortName;
var keyBinding = new RealmKeyBinding(action, KeyCombination.FromKey(Key.Z), rulesetName, variant);
AddAssert("action is integer", () => keyBinding.Action, () => Is.EqualTo((int)action));
AddAssert("action unmaps correctly", () => keyBinding.GetAction(rulesets), () => Is.EqualTo(action));
}
}
}

View File

@ -72,12 +72,12 @@ namespace osu.Game.Tests.Visual.Gameplay
} }
[Test] [Test]
public void TestStoryboardExitDuringOutroStillExits() public void TestStoryboardExitDuringOutroProgressesToResults()
{ {
CreateTest(); CreateTest();
AddUntilStep("completion set by processor", () => Player.ScoreProcessor.HasCompleted.Value); AddUntilStep("completion set by processor", () => Player.ScoreProcessor.HasCompleted.Value);
AddStep("exit via pause", () => Player.ExitViaPause()); AddStep("exit via pause", () => Player.ExitViaPause());
AddAssert("player exited", () => !Player.IsCurrentScreen() && Player.GetChildScreen() == null); AddUntilStep("reached results screen", () => Stack.CurrentScreen is ResultsScreen);
} }
[TestCase(false)] [TestCase(false)]
@ -171,7 +171,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("disable storyboard", () => LocalConfig.SetValue(OsuSetting.ShowStoryboard, false)); AddStep("disable storyboard", () => LocalConfig.SetValue(OsuSetting.ShowStoryboard, false));
AddUntilStep("completion set by processor", () => Player.ScoreProcessor.HasCompleted.Value); AddUntilStep("completion set by processor", () => Player.ScoreProcessor.HasCompleted.Value);
AddStep("exit via pause", () => Player.ExitViaPause()); AddStep("exit via pause", () => Player.ExitViaPause());
AddAssert("player exited", () => Stack.CurrentScreen == null); AddUntilStep("reached results screen", () => Stack.CurrentScreen is ResultsScreen);
} }
[Test] [Test]

View File

@ -215,6 +215,24 @@ namespace osu.Game.Tests.Visual.Navigation
AddAssert("retry count is 1", () => player.RestartCount == 1); AddAssert("retry count is 1", () => player.RestartCount == 1);
} }
[Test]
public void TestRetryImmediatelyAfterCompletion()
{
var getOriginalPlayer = playToCompletion();
AddStep("attempt to retry", () => getOriginalPlayer().ChildrenOfType<HotkeyRetryOverlay>().First().Action());
AddUntilStep("wait for player", () => Game.ScreenStack.CurrentScreen != getOriginalPlayer() && Game.ScreenStack.CurrentScreen is Player);
}
[Test]
public void TestExitImmediatelyAfterCompletion()
{
var player = playToCompletion();
AddStep("attempt to exit", () => player().ChildrenOfType<HotkeyExitOverlay>().First().Action());
AddUntilStep("wait for results", () => Game.ScreenStack.CurrentScreen is ResultsScreen);
}
[Test] [Test]
public void TestRetryFromResults() public void TestRetryFromResults()
{ {
@ -778,6 +796,13 @@ namespace osu.Game.Tests.Visual.Navigation
} }
private Func<Player> playToResults() private Func<Player> playToResults()
{
var player = playToCompletion();
AddUntilStep("wait for results", () => (Game.ScreenStack.CurrentScreen as ResultsScreen)?.IsLoaded == true);
return player;
}
private Func<Player> playToCompletion()
{ {
Player player = null; Player player = null;
@ -803,7 +828,8 @@ namespace osu.Game.Tests.Visual.Navigation
AddUntilStep("wait for track playing", () => beatmap().Track.IsRunning); AddUntilStep("wait for track playing", () => beatmap().Track.IsRunning);
AddStep("seek to near end", () => player.ChildrenOfType<GameplayClockContainer>().First().Seek(beatmap().Beatmap.HitObjects[^1].StartTime - 1000)); AddStep("seek to near end", () => player.ChildrenOfType<GameplayClockContainer>().First().Seek(beatmap().Beatmap.HitObjects[^1].StartTime - 1000));
AddUntilStep("wait for pass", () => (Game.ScreenStack.CurrentScreen as ResultsScreen)?.IsLoaded == true); AddUntilStep("wait for complete", () => player.GameplayState.HasPassed);
return () => player; return () => player;
} }

View File

@ -0,0 +1,63 @@
// 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;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings.Sections.Input;
using osu.Game.Rulesets.Osu;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Settings
{
public partial class TestSceneKeyBindingConflictPopover : OsuTestScene
{
[Cached]
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
[Test]
public void TestAppearance()
{
ButtonWithConflictPopover button = null!;
AddStep("create content", () =>
{
Child = new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Child = button = new ButtonWithConflictPopover
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Open popover",
Width = 300
}
};
});
AddStep("show popover", () => button.TriggerClick());
}
private partial class ButtonWithConflictPopover : RoundedButton, IHasPopover
{
[BackgroundDependencyLoader]
private void load()
{
Action = this.ShowPopover;
}
public Popover GetPopover() => new KeyBindingConflictPopover(
new KeyBindingRow.KeyBindingConflictInfo(
new KeyBindingRow.ConflictingKeyBinding(Guid.NewGuid(), OsuAction.LeftButton, KeyCombination.FromKey(Key.X), new KeyCombination(InputKey.None)),
new KeyBindingRow.ConflictingKeyBinding(Guid.NewGuid(), OsuAction.RightButton, KeyCombination.FromKey(Key.Z), KeyCombination.FromKey(Key.X))
)
);
}
}
}

View File

@ -10,8 +10,11 @@ using osu.Framework.Testing;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections.Input; using osu.Game.Overlays.Settings.Sections.Input;
using osu.Game.Rulesets.Taiko;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Tests.Visual.Settings namespace osu.Game.Tests.Visual.Settings
@ -207,7 +210,7 @@ namespace osu.Game.Tests.Visual.Settings
AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType<RevertToDefaultButton<bool>>().First().Alpha == 0); AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType<RevertToDefaultButton<bool>>().First().Alpha == 0);
AddAssert("binding cleared", AddAssert("binding cleared",
() => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0))); () => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.Value.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0)));
} }
[Test] [Test]
@ -237,7 +240,7 @@ namespace osu.Game.Tests.Visual.Settings
AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType<RevertToDefaultButton<bool>>().First().Alpha == 0); AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType<RevertToDefaultButton<bool>>().First().Alpha == 0);
AddAssert("binding cleared", AddAssert("binding cleared",
() => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0))); () => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.Value.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0)));
} }
[Test] [Test]
@ -288,6 +291,106 @@ namespace osu.Game.Tests.Visual.Settings
AddUntilStep("all reset section bindings buttons shown", () => panel.ChildrenOfType<ResetButton>().All(button => button.Alpha == 1)); AddUntilStep("all reset section bindings buttons shown", () => panel.ChildrenOfType<ResetButton>().All(button => button.Alpha == 1));
} }
[Test]
public void TestBindingConflictResolvedByRollback()
{
AddStep("reset taiko section to default", () =>
{
var section = panel.ChildrenOfType<VariantBindingsSubsection>().First(section => new TaikoRuleset().RulesetInfo.Equals(section.Ruleset));
section.ChildrenOfType<ResetButton>().Single().TriggerClick();
});
AddStep("move mouse to centre", () => InputManager.MoveMouseTo(panel.ScreenSpaceDrawQuad.Centre));
AddUntilStep("wait for collapsed", () => panel.ChildrenOfType<SettingsSidebar>().Single().Expanded.Value, () => Is.False);
scrollToAndStartBinding("Left (rim)");
AddStep("attempt to bind M1 to two keys", () => InputManager.Click(MouseButton.Left));
KeyBindingConflictPopover popover = null;
AddUntilStep("wait for popover", () => popover = panel.ChildrenOfType<KeyBindingConflictPopover>().SingleOrDefault(), () => Is.Not.Null);
AddStep("click first button", () => popover.ChildrenOfType<RoundedButton>().First().TriggerClick());
checkBinding("Left (centre)", "M1");
checkBinding("Left (rim)", "M2");
}
[Test]
public void TestBindingConflictResolvedByOverwrite()
{
AddStep("reset taiko section to default", () =>
{
var section = panel.ChildrenOfType<VariantBindingsSubsection>().First(section => new TaikoRuleset().RulesetInfo.Equals(section.Ruleset));
section.ChildrenOfType<ResetButton>().Single().TriggerClick();
});
AddStep("move mouse to centre", () => InputManager.MoveMouseTo(panel.ScreenSpaceDrawQuad.Centre));
AddUntilStep("wait for collapsed", () => panel.ChildrenOfType<SettingsSidebar>().Single().Expanded.Value, () => Is.False);
scrollToAndStartBinding("Left (rim)");
AddStep("attempt to bind M1 to two keys", () => InputManager.Click(MouseButton.Left));
KeyBindingConflictPopover popover = null;
AddUntilStep("wait for popover", () => popover = panel.ChildrenOfType<KeyBindingConflictPopover>().SingleOrDefault(), () => Is.Not.Null);
AddStep("click second button", () => popover.ChildrenOfType<RoundedButton>().ElementAt(1).TriggerClick());
checkBinding("Left (centre)", string.Empty);
checkBinding("Left (rim)", "M1");
}
[Test]
public void TestBindingConflictCausedByResetToDefaultOfSingleRow()
{
AddStep("reset taiko section to default", () =>
{
var section = panel.ChildrenOfType<VariantBindingsSubsection>().First(section => new TaikoRuleset().RulesetInfo.Equals(section.Ruleset));
section.ChildrenOfType<ResetButton>().Single().TriggerClick();
});
AddStep("move mouse to centre", () => InputManager.MoveMouseTo(panel.ScreenSpaceDrawQuad.Centre));
AddUntilStep("wait for collapsed", () => panel.ChildrenOfType<SettingsSidebar>().Single().Expanded.Value, () => Is.False);
scrollToAndStartBinding("Left (centre)");
AddStep("clear binding", () =>
{
var row = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text.ToString() == "Left (centre)"));
row.ChildrenOfType<KeyBindingRow.ClearButton>().Single().TriggerClick();
});
scrollToAndStartBinding("Left (rim)");
AddStep("bind M1", () => InputManager.Click(MouseButton.Left));
AddStep("reset Left (centre) to default", () =>
{
var row = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text.ToString() == "Left (centre)"));
row.ChildrenOfType<RevertToDefaultButton<bool>>().Single().TriggerClick();
});
KeyBindingConflictPopover popover = null;
AddUntilStep("wait for popover", () => popover = panel.ChildrenOfType<KeyBindingConflictPopover>().SingleOrDefault(), () => Is.Not.Null);
AddStep("click second button", () => popover.ChildrenOfType<RoundedButton>().ElementAt(1).TriggerClick());
checkBinding("Left (centre)", "M1");
checkBinding("Left (rim)", string.Empty);
}
[Test]
public void TestResettingEntireSectionDoesNotCauseBindingConflicts()
{
AddStep("reset taiko section to default", () =>
{
var section = panel.ChildrenOfType<VariantBindingsSubsection>().First(section => new TaikoRuleset().RulesetInfo.Equals(section.Ruleset));
section.ChildrenOfType<ResetButton>().Single().TriggerClick();
});
AddStep("move mouse to centre", () => InputManager.MoveMouseTo(panel.ScreenSpaceDrawQuad.Centre));
AddUntilStep("wait for collapsed", () => panel.ChildrenOfType<SettingsSidebar>().Single().Expanded.Value, () => Is.False);
scrollToAndStartBinding("Left (centre)");
AddStep("clear binding", () =>
{
var row = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text.ToString() == "Left (centre)"));
row.ChildrenOfType<KeyBindingRow.ClearButton>().Single().TriggerClick();
});
scrollToAndStartBinding("Left (rim)");
AddStep("bind M1", () => InputManager.Click(MouseButton.Left));
AddStep("reset taiko section to default", () =>
{
var section = panel.ChildrenOfType<VariantBindingsSubsection>().First(section => new TaikoRuleset().RulesetInfo.Equals(section.Ruleset));
section.ChildrenOfType<ResetButton>().Single().TriggerClick();
});
AddWaitStep("wait a bit", 3);
AddUntilStep("conflict popover not shown", () => panel.ChildrenOfType<KeyBindingConflictPopover>().SingleOrDefault(), () => Is.Null);
}
private void checkBinding(string name, string keyName) private void checkBinding(string name, string keyName)
{ {
AddAssert($"Check {name} is bound to {keyName}", () => AddAssert($"Check {name} is bound to {keyName}", () =>

View File

@ -0,0 +1,60 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Testing;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings.Sections.Input;
namespace osu.Game.Tests.Visual.Settings
{
public partial class TestSceneKeyBindingRow : OsuTestScene
{
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
[Test]
public void TestChangesAfterConstruction()
{
KeyBindingRow row = null!;
AddStep("create row", () => Child = new Container
{
Width = 500,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Child = row = new KeyBindingRow(GlobalAction.Back)
{
Defaults = new[]
{
new KeyCombination(InputKey.Escape),
new KeyCombination(InputKey.ExtraMouseButton1)
}
}
});
AddStep("change key bindings", () =>
{
row.KeyBindings.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.Escape)));
row.KeyBindings.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.ExtraMouseButton1)));
});
AddUntilStep("revert to default button not shown", () => row.ChildrenOfType<RevertToDefaultButton<bool>>().Single().Alpha, () => Is.Zero);
AddStep("change key bindings", () =>
{
row.KeyBindings.Clear();
row.KeyBindings.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.X)));
row.KeyBindings.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.Z)));
row.KeyBindings.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.I)));
});
AddUntilStep("revert to default button not shown", () => row.ChildrenOfType<RevertToDefaultButton<bool>>().Single().Alpha, () => Is.Not.Zero);
}
}
}

View File

@ -2,16 +2,19 @@
// 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 NUnit.Framework; using NUnit.Framework;
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.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch; using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania; using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko; using osu.Game.Rulesets.Taiko;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
@ -34,6 +37,49 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test] [Test]
public void TestMania() => createSwitchTestFor(new ManiaRuleset()); public void TestMania() => createSwitchTestFor(new ManiaRuleset());
[Test]
public void TestShowRateAdjusts()
{
AddStep("create mod icons", () =>
{
Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Full,
ChildrenEnumerable = Ruleset.Value.CreateInstance().CreateAllMods()
.OfType<ModRateAdjust>()
.SelectMany(m =>
{
List<TestModSwitchTiny> icons = new List<TestModSwitchTiny> { new TestModSwitchTiny(m) };
for (double i = m.SpeedChange.MinValue; i < m.SpeedChange.MaxValue; i += m.SpeedChange.Precision * 10)
{
m = (ModRateAdjust)m.DeepClone();
m.SpeedChange.Value = i;
icons.Add(new TestModSwitchTiny(m, true));
}
return icons;
}),
};
});
AddStep("adjust rates", () =>
{
foreach (var icon in this.ChildrenOfType<TestModSwitchTiny>())
{
if (icon.Mod is ModRateAdjust rateAdjust)
{
rateAdjust.SpeedChange.Value = RNG.NextDouble() > 0.9
? rateAdjust.SpeedChange.Default
: RNG.NextDouble(rateAdjust.SpeedChange.MinValue, rateAdjust.SpeedChange.MaxValue);
}
}
});
AddToggleStep("toggle active", active => this.ChildrenOfType<TestModSwitchTiny>().ForEach(s => s.Active.Value = active));
}
private void createSwitchTestFor(Ruleset ruleset) private void createSwitchTestFor(Ruleset ruleset)
{ {
AddStep("no colour scheme", () => Child = createContent(ruleset, null)); AddStep("no colour scheme", () => Child = createContent(ruleset, null));
@ -43,7 +89,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep($"{scheme} colour scheme", () => Child = createContent(ruleset, scheme)); AddStep($"{scheme} colour scheme", () => Child = createContent(ruleset, scheme));
} }
AddToggleStep("toggle active", active => this.ChildrenOfType<ModSwitchTiny>().ForEach(s => s.Active.Value = active)); AddToggleStep("toggle active", active => this.ChildrenOfType<TestModSwitchTiny>().ForEach(s => s.Active.Value = active));
} }
private static Drawable createContent(Ruleset ruleset, OverlayColourScheme? colourScheme) private static Drawable createContent(Ruleset ruleset, OverlayColourScheme? colourScheme)
@ -62,7 +108,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full, Direction = FillDirection.Full,
Spacing = new Vector2(5), Spacing = new Vector2(5),
ChildrenEnumerable = group.Select(mod => new ModSwitchTiny(mod)) ChildrenEnumerable = group.Select(mod => new TestModSwitchTiny(mod))
}) })
}; };
@ -81,5 +127,15 @@ namespace osu.Game.Tests.Visual.UserInterface
return switchFlow; return switchFlow;
} }
private partial class TestModSwitchTiny : ModSwitchTiny
{
public new IMod Mod => base.Mod;
public TestModSwitchTiny(IMod mod, bool showExtendedInformation = false)
: base(mod, showExtendedInformation)
{
}
}
} }
} }

View File

@ -5,11 +5,13 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Extensions;
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;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Database;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -31,6 +33,8 @@ namespace osu.Game.Tests.Visual.UserInterface
public double TimeToCompleteProgress { get; set; } = 2000; public double TimeToCompleteProgress { get; set; } = 2000;
private readonly UserLookupCache userLookupCache = new TestUserLookupCache();
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>
{ {
@ -60,6 +64,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep(@"simple #2", sendAmazingNotification); AddStep(@"simple #2", sendAmazingNotification);
AddStep(@"progress #1", sendUploadProgress); AddStep(@"progress #1", sendUploadProgress);
AddStep(@"progress #2", sendDownloadProgress); AddStep(@"progress #2", sendDownloadProgress);
AddStep(@"User notification", sendUserNotification);
checkProgressingCount(2); checkProgressingCount(2);
@ -537,6 +542,16 @@ namespace osu.Game.Tests.Visual.UserInterface
progressingNotifications.Add(n); progressingNotifications.Add(n);
} }
private void sendUserNotification()
{
var user = userLookupCache.GetUserAsync(0).GetResultSafely();
if (user == null) return;
var n = new UserAvatarNotification(user, $"{user.Username} invited you to a multiplayer match!");
notificationOverlay.Post(n);
}
private void sendUploadProgress() private void sendUploadProgress()
{ {
var n = new ProgressNotification var n = new ProgressNotification

View File

@ -82,7 +82,7 @@ namespace osu.Game.Tournament.Screens.Editors
new TourneyButton new TourneyButton
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
BackgroundColour = colours.Pink3, BackgroundColour = colours.DangerousButtonColour,
Text = "Clear all", Text = "Clear all",
Action = () => Action = () =>
{ {

View File

@ -397,5 +397,7 @@ namespace osu.Game.Graphics
public Color4 SpotlightColour => Green2; public Color4 SpotlightColour => Green2;
public Color4 FeaturedArtistColour => Blue2; public Color4 FeaturedArtistColour => Blue2;
public Color4 DangerousButtonColour => Pink3;
} }
} }

View File

@ -11,7 +11,7 @@ namespace osu.Game.Graphics.UserInterface
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
BackgroundColour = colours.PinkDark; BackgroundColour = colours.DangerousButtonColour;
} }
} }
} }

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 System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Input; using osu.Framework.Input;
@ -13,6 +14,8 @@ namespace osu.Game.Input.Bindings
{ {
public partial class GlobalActionContainer : DatabasedKeyBindingContainer<GlobalAction>, IHandleGlobalKeyboardInput, IKeyBindingHandler<GlobalAction> public partial class GlobalActionContainer : DatabasedKeyBindingContainer<GlobalAction>, IHandleGlobalKeyboardInput, IKeyBindingHandler<GlobalAction>
{ {
protected override bool Prioritised => true;
private readonly IKeyBindingHandler<GlobalAction>? handler; private readonly IKeyBindingHandler<GlobalAction>? handler;
public GlobalActionContainer(OsuGameBase? game) public GlobalActionContainer(OsuGameBase? game)
@ -22,22 +25,62 @@ namespace osu.Game.Input.Bindings
handler = h; handler = h;
} }
protected override bool Prioritised => true; /// <summary>
/// All default key bindings across all categories, ordered with highest priority first.
// IMPORTANT: Take care when changing order of the items in the enumerable. /// </summary>
// It is used to decide the order of precedence, with the earlier items having higher precedence. /// <remarks>
public override IEnumerable<IKeyBinding> DefaultKeyBindings => GlobalKeyBindings /// IMPORTANT: Take care when changing order of the items in the enumerable.
.Concat(EditorKeyBindings) /// It is used to decide the order of precedence, with the earlier items having higher precedence.
.Concat(InGameKeyBindings) /// </remarks>
.Concat(ReplayKeyBindings) public override IEnumerable<IKeyBinding> DefaultKeyBindings => globalKeyBindings
.Concat(SongSelectKeyBindings) .Concat(editorKeyBindings)
.Concat(AudioControlKeyBindings) .Concat(inGameKeyBindings)
.Concat(replayKeyBindings)
.Concat(songSelectKeyBindings)
.Concat(audioControlKeyBindings)
// Overlay bindings may conflict with more local cases like the editor so they are checked last. // Overlay bindings may conflict with more local cases like the editor so they are checked last.
// It has generally been agreed on that local screens like the editor should have priority, // It has generally been agreed on that local screens like the editor should have priority,
// based on such usages potentially requiring a lot more key bindings that may be "shared" with global ones. // based on such usages potentially requiring a lot more key bindings that may be "shared" with global ones.
.Concat(OverlayKeyBindings); .Concat(overlayKeyBindings);
public IEnumerable<KeyBinding> GlobalKeyBindings => new[] public static IEnumerable<KeyBinding> GetDefaultBindingsFor(GlobalActionCategory category)
{
switch (category)
{
case GlobalActionCategory.General:
return globalKeyBindings;
case GlobalActionCategory.Editor:
return editorKeyBindings;
case GlobalActionCategory.InGame:
return inGameKeyBindings;
case GlobalActionCategory.Replay:
return replayKeyBindings;
case GlobalActionCategory.SongSelect:
return songSelectKeyBindings;
case GlobalActionCategory.AudioControl:
return audioControlKeyBindings;
case GlobalActionCategory.Overlays:
return overlayKeyBindings;
default:
throw new ArgumentOutOfRangeException(nameof(category), category, $"Unexpected {nameof(GlobalActionCategory)}");
}
}
public static IEnumerable<GlobalAction> GetGlobalActionsFor(GlobalActionCategory category)
=> GetDefaultBindingsFor(category).Select(binding => binding.Action).Cast<GlobalAction>().Distinct();
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e) => handler?.OnPressed(e) == true;
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) => handler?.OnReleased(e);
private static IEnumerable<KeyBinding> globalKeyBindings => new[]
{ {
new KeyBinding(InputKey.Up, GlobalAction.SelectPrevious), new KeyBinding(InputKey.Up, GlobalAction.SelectPrevious),
new KeyBinding(InputKey.Down, GlobalAction.SelectNext), new KeyBinding(InputKey.Down, GlobalAction.SelectNext),
@ -67,7 +110,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.F12, GlobalAction.TakeScreenshot), new KeyBinding(InputKey.F12, GlobalAction.TakeScreenshot),
}; };
public IEnumerable<KeyBinding> OverlayKeyBindings => new[] private static IEnumerable<KeyBinding> overlayKeyBindings => new[]
{ {
new KeyBinding(InputKey.F8, GlobalAction.ToggleChat), new KeyBinding(InputKey.F8, GlobalAction.ToggleChat),
new KeyBinding(InputKey.F6, GlobalAction.ToggleNowPlaying), new KeyBinding(InputKey.F6, GlobalAction.ToggleNowPlaying),
@ -77,7 +120,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(new[] { InputKey.Control, InputKey.N }, GlobalAction.ToggleNotifications), new KeyBinding(new[] { InputKey.Control, InputKey.N }, GlobalAction.ToggleNotifications),
}; };
public IEnumerable<KeyBinding> EditorKeyBindings => new[] private static IEnumerable<KeyBinding> editorKeyBindings => new[]
{ {
new KeyBinding(new[] { InputKey.F1 }, GlobalAction.EditorComposeMode), new KeyBinding(new[] { InputKey.F1 }, GlobalAction.EditorComposeMode),
new KeyBinding(new[] { InputKey.F2 }, GlobalAction.EditorDesignMode), new KeyBinding(new[] { InputKey.F2 }, GlobalAction.EditorDesignMode),
@ -101,7 +144,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(new[] { InputKey.Control, InputKey.R }, GlobalAction.EditorToggleRotateControl), new KeyBinding(new[] { InputKey.Control, InputKey.R }, GlobalAction.EditorToggleRotateControl),
}; };
public IEnumerable<KeyBinding> InGameKeyBindings => new[] private static IEnumerable<KeyBinding> inGameKeyBindings => new[]
{ {
new KeyBinding(InputKey.Space, GlobalAction.SkipCutscene), new KeyBinding(InputKey.Space, GlobalAction.SkipCutscene),
new KeyBinding(InputKey.ExtraMouseButton2, GlobalAction.SkipCutscene), new KeyBinding(InputKey.ExtraMouseButton2, GlobalAction.SkipCutscene),
@ -118,7 +161,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.F2, GlobalAction.ExportReplay), new KeyBinding(InputKey.F2, GlobalAction.ExportReplay),
}; };
public IEnumerable<KeyBinding> ReplayKeyBindings => new[] private static IEnumerable<KeyBinding> replayKeyBindings => new[]
{ {
new KeyBinding(InputKey.Space, GlobalAction.TogglePauseReplay), new KeyBinding(InputKey.Space, GlobalAction.TogglePauseReplay),
new KeyBinding(InputKey.MouseMiddle, GlobalAction.TogglePauseReplay), new KeyBinding(InputKey.MouseMiddle, GlobalAction.TogglePauseReplay),
@ -127,7 +170,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(new[] { InputKey.Control, InputKey.H }, GlobalAction.ToggleReplaySettings), new KeyBinding(new[] { InputKey.Control, InputKey.H }, GlobalAction.ToggleReplaySettings),
}; };
public IEnumerable<KeyBinding> SongSelectKeyBindings => new[] private static IEnumerable<KeyBinding> songSelectKeyBindings => new[]
{ {
new KeyBinding(InputKey.F1, GlobalAction.ToggleModSelection), new KeyBinding(InputKey.F1, GlobalAction.ToggleModSelection),
new KeyBinding(InputKey.F2, GlobalAction.SelectNextRandom), new KeyBinding(InputKey.F2, GlobalAction.SelectNextRandom),
@ -136,7 +179,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.BackSpace, GlobalAction.DeselectAllMods), new KeyBinding(InputKey.BackSpace, GlobalAction.DeselectAllMods),
}; };
public IEnumerable<KeyBinding> AudioControlKeyBindings => new[] private static IEnumerable<KeyBinding> audioControlKeyBindings => new[]
{ {
new KeyBinding(new[] { InputKey.Alt, InputKey.Up }, GlobalAction.IncreaseVolume), new KeyBinding(new[] { InputKey.Alt, InputKey.Up }, GlobalAction.IncreaseVolume),
new KeyBinding(new[] { InputKey.Alt, InputKey.Down }, GlobalAction.DecreaseVolume), new KeyBinding(new[] { InputKey.Alt, InputKey.Down }, GlobalAction.DecreaseVolume),
@ -153,10 +196,6 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.PlayPause, GlobalAction.MusicPlay), new KeyBinding(InputKey.PlayPause, GlobalAction.MusicPlay),
new KeyBinding(InputKey.F3, GlobalAction.MusicPlay) new KeyBinding(InputKey.F3, GlobalAction.MusicPlay)
}; };
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e) => handler?.OnPressed(e) == true;
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) => handler?.OnReleased(e);
} }
public enum GlobalAction public enum GlobalAction
@ -365,4 +404,15 @@ namespace osu.Game.Input.Bindings
[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorToggleRotateControl))] [LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorToggleRotateControl))]
EditorToggleRotateControl, EditorToggleRotateControl,
} }
public enum GlobalActionCategory
{
General,
Editor,
InGame,
Replay,
SongSelect,
AudioControl,
Overlays
}
} }

View File

@ -2,9 +2,11 @@
// 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.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Rulesets;
using Realms; using Realms;
namespace osu.Game.Input.Bindings namespace osu.Game.Input.Bindings
@ -26,6 +28,13 @@ namespace osu.Game.Input.Bindings
set => KeyCombinationString = value.ToString(); set => KeyCombinationString = value.ToString();
} }
/// <summary>
/// The resultant action which is triggered by this binding.
/// </summary>
/// <remarks>
/// This implementation always returns an integer.
/// If wanting to get the actual enum-typed value, use <see cref="GetAction"/>.
/// </remarks>
[Ignored] [Ignored]
public object Action public object Action
{ {
@ -53,5 +62,20 @@ namespace osu.Game.Input.Bindings
private RealmKeyBinding() private RealmKeyBinding()
{ {
} }
public object GetAction(RulesetStore rulesets)
{
if (string.IsNullOrEmpty(RulesetName))
return (GlobalAction)ActionInt;
var ruleset = rulesets.GetRuleset(RulesetName);
var actionType = ruleset!.CreateInstance()
.GetDefaultKeyBindings(Variant ?? 0)
.First() // let's just assume nobody does something stupid like mix multiple types...
.Action
.GetType();
return Enum.ToObject(actionType, ActionInt);
}
} }
} }

View File

@ -19,6 +19,11 @@ namespace osu.Game.Localisation
/// </summary> /// </summary>
public static LocalisableString ViewBeatmap => new TranslatableString(getKey(@"view_beatmap"), @"View beatmap"); public static LocalisableString ViewBeatmap => new TranslatableString(getKey(@"view_beatmap"), @"View beatmap");
/// <summary>
/// "Invite player"
/// </summary>
public static LocalisableString InvitePlayer => new TranslatableString(getKey(@"invite_player"), @"Invite player");
private static string getKey(string key) => $@"{prefix}:{key}"; private static string getKey(string key) => $@"{prefix}:{key}";
} }
} }

View File

@ -64,6 +64,26 @@ namespace osu.Game.Localisation
/// </summary> /// </summary>
public static LocalisableString KeyBindingPanelDescription => new TranslatableString(getKey(@"key_binding_panel_description"), @"Customise your keys!"); public static LocalisableString KeyBindingPanelDescription => new TranslatableString(getKey(@"key_binding_panel_description"), @"Customise your keys!");
/// <summary>
/// "The binding you&#39;ve selected conflicts with another existing binding."
/// </summary>
public static LocalisableString KeyBindingConflictDetected => new TranslatableString(getKey(@"key_binding_conflict_detected"), @"The binding you've selected conflicts with another existing binding.");
/// <summary>
/// "Keep existing"
/// </summary>
public static LocalisableString KeepExistingBinding => new TranslatableString(getKey(@"keep_existing_binding"), @"Keep existing");
/// <summary>
/// "Apply new"
/// </summary>
public static LocalisableString ApplyNewBinding => new TranslatableString(getKey(@"apply_new_binding"), @"Apply new");
/// <summary>
/// "(none)"
/// </summary>
public static LocalisableString ActionHasNoKeyBinding => new TranslatableString(getKey(@"action_has_no_key_binding"), @"(none)");
private static string getKey(string key) => $"{prefix}:{key}"; private static string getKey(string key) => $"{prefix}:{key}";
} }
} }

View File

@ -93,6 +93,11 @@ Please try changing your audio device to a working setting.");
/// </summary> /// </summary>
public static LocalisableString YourNameWasMentioned(string username) => new TranslatableString(getKey(@"your_name_was_mentioned"), @"Your name was mentioned in chat by '{0}'. Click to find out why!", username); public static LocalisableString YourNameWasMentioned(string username) => new TranslatableString(getKey(@"your_name_was_mentioned"), @"Your name was mentioned in chat by '{0}'. Click to find out why!", username);
/// <summary>
/// "{0} invited you to the multiplayer match &quot;{1}&quot;! Click to join."
/// </summary>
public static LocalisableString InvitedYouToTheMultiplayer(string username, string roomName) => new TranslatableString(getKey(@"invited_you_to_the_multiplayer"), @"{0} invited you to the multiplayer match ""{1}""! Click to join.", username, roomName);
/// <summary> /// <summary>
/// "You do not have the beatmap for this replay." /// "You do not have the beatmap for this replay."
/// </summary> /// </summary>

View File

@ -14,6 +14,16 @@ namespace osu.Game.Localisation
/// </summary> /// </summary>
public static LocalisableString SupporterOnlyDurationNotice => new TranslatableString(getKey(@"supporter_only_duration_notice"), @"Playlist durations longer than 2 weeks require an active osu!supporter tag."); public static LocalisableString SupporterOnlyDurationNotice => new TranslatableString(getKey(@"supporter_only_duration_notice"), @"Playlist durations longer than 2 weeks require an active osu!supporter tag.");
/// <summary>
/// "Can&#39;t invite this user as you have blocked them or they have blocked you."
/// </summary>
public static LocalisableString InviteFailedUserBlocked => new TranslatableString(getKey(@"cant_invite_this_user_as"), @"Can't invite this user as you have blocked them or they have blocked you.");
/// <summary>
/// "Can&#39;t invite this user as they have opted out of non-friend communications."
/// </summary>
public static LocalisableString InviteFailedUserOptOut => new TranslatableString(getKey(@"cant_invite_this_user_as1"), @"Can't invite this user as they have opted out of non-friend communications.");
private static string getKey(string key) => $@"{prefix}:{key}"; private static string getKey(string key) => $@"{prefix}:{key}";
} }
} }

View File

@ -42,6 +42,14 @@ namespace osu.Game.Online.Multiplayer
/// <param name="user">The user.</param> /// <param name="user">The user.</param>
Task UserKicked(MultiplayerRoomUser user); Task UserKicked(MultiplayerRoomUser user);
/// <summary>
/// Signals that the local user has been invited into a multiplayer room.
/// </summary>
/// <param name="invitedBy">Id of user that invited the player.</param>
/// <param name="roomID">Id of the room the user got invited to.</param>
/// <param name="password">Password to join the room.</param>
Task Invited(int invitedBy, long roomID, string password);
/// <summary> /// <summary>
/// Signal that the host of the room has changed. /// Signal that the host of the room has changed.
/// </summary> /// </summary>

View File

@ -99,5 +99,13 @@ namespace osu.Game.Online.Multiplayer
/// </summary> /// </summary>
/// <param name="playlistItemId">The item to remove.</param> /// <param name="playlistItemId">The item to remove.</param>
Task RemovePlaylistItem(long playlistItemId); Task RemovePlaylistItem(long playlistItemId);
/// <summary>
/// Invites a player to the current room.
/// </summary>
/// <param name="userId">The user to invite.</param>
/// <exception cref="UserBlockedException">The user has blocked or has been blocked by the invited user.</exception>
/// <exception cref="UserBlocksPMsException">The invited user does not accept private messages.</exception>
Task InvitePlayer(int userId);
} }
} }

View File

@ -23,6 +23,7 @@ using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Utils; using osu.Game.Utils;
using osu.Game.Localisation;
namespace osu.Game.Online.Multiplayer namespace osu.Game.Online.Multiplayer
{ {
@ -30,6 +31,8 @@ namespace osu.Game.Online.Multiplayer
{ {
public Action<Notification>? PostNotification { protected get; set; } public Action<Notification>? PostNotification { protected get; set; }
public Action<Room, string>? PresentMatch { protected get; set; }
/// <summary> /// <summary>
/// Invoked when any change occurs to the multiplayer room. /// Invoked when any change occurs to the multiplayer room.
/// </summary> /// </summary>
@ -260,6 +263,8 @@ namespace osu.Game.Online.Multiplayer
protected abstract Task LeaveRoomInternal(); protected abstract Task LeaveRoomInternal();
public abstract Task InvitePlayer(int userId);
/// <summary> /// <summary>
/// Change the current <see cref="MultiplayerRoom"/> settings. /// Change the current <see cref="MultiplayerRoom"/> settings.
/// </summary> /// </summary>
@ -440,6 +445,38 @@ namespace osu.Game.Online.Multiplayer
return handleUserLeft(user, UserKicked); return handleUserLeft(user, UserKicked);
} }
async Task IMultiplayerClient.Invited(int invitedBy, long roomID, string password)
{
APIUser? apiUser = await userLookupCache.GetUserAsync(invitedBy).ConfigureAwait(false);
Room? apiRoom = await getRoomAsync(roomID).ConfigureAwait(false);
if (apiUser == null || apiRoom == null) return;
PostNotification?.Invoke(
new UserAvatarNotification(apiUser, NotificationsStrings.InvitedYouToTheMultiplayer(apiUser.Username, apiRoom.Name.Value))
{
Activated = () =>
{
PresentMatch?.Invoke(apiRoom, password);
return true;
}
}
);
Task<Room?> getRoomAsync(long id)
{
TaskCompletionSource<Room?> taskCompletionSource = new TaskCompletionSource<Room?>();
var request = new GetRoomRequest(id);
request.Success += room => taskCompletionSource.TrySetResult(room);
request.Failure += _ => taskCompletionSource.TrySetResult(null);
API.Queue(request);
return taskCompletionSource.Task;
}
}
private void addUserToAPIRoom(MultiplayerRoomUser user) private void addUserToAPIRoom(MultiplayerRoomUser user)
{ {
Debug.Assert(APIRoom != null); Debug.Assert(APIRoom != null);

View File

@ -12,6 +12,8 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Overlays.Notifications;
using osu.Game.Localisation;
namespace osu.Game.Online.Multiplayer namespace osu.Game.Online.Multiplayer
{ {
@ -50,6 +52,7 @@ namespace osu.Game.Online.Multiplayer
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserJoined), ((IMultiplayerClient)this).UserJoined); connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserJoined), ((IMultiplayerClient)this).UserJoined);
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserLeft), ((IMultiplayerClient)this).UserLeft); connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserLeft), ((IMultiplayerClient)this).UserLeft);
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserKicked), ((IMultiplayerClient)this).UserKicked); connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserKicked), ((IMultiplayerClient)this).UserKicked);
connection.On<int, long, string>(nameof(IMultiplayerClient.Invited), ((IMultiplayerClient)this).Invited);
connection.On<int>(nameof(IMultiplayerClient.HostChanged), ((IMultiplayerClient)this).HostChanged); connection.On<int>(nameof(IMultiplayerClient.HostChanged), ((IMultiplayerClient)this).HostChanged);
connection.On<MultiplayerRoomSettings>(nameof(IMultiplayerClient.SettingsChanged), ((IMultiplayerClient)this).SettingsChanged); connection.On<MultiplayerRoomSettings>(nameof(IMultiplayerClient.SettingsChanged), ((IMultiplayerClient)this).SettingsChanged);
connection.On<int, MultiplayerUserState>(nameof(IMultiplayerClient.UserStateChanged), ((IMultiplayerClient)this).UserStateChanged); connection.On<int, MultiplayerUserState>(nameof(IMultiplayerClient.UserStateChanged), ((IMultiplayerClient)this).UserStateChanged);
@ -106,6 +109,32 @@ namespace osu.Game.Online.Multiplayer
return connection.InvokeAsync(nameof(IMultiplayerServer.LeaveRoom)); return connection.InvokeAsync(nameof(IMultiplayerServer.LeaveRoom));
} }
public override async Task InvitePlayer(int userId)
{
if (!IsConnected.Value)
return;
Debug.Assert(connection != null);
try
{
await connection.InvokeAsync(nameof(IMultiplayerServer.InvitePlayer), userId).ConfigureAwait(false);
}
catch (HubException exception)
{
switch (exception.GetHubExceptionMessage())
{
case UserBlockedException.MESSAGE:
PostNotification?.Invoke(new SimpleErrorNotification { Text = OnlinePlayStrings.InviteFailedUserBlocked });
break;
case UserBlocksPMsException.MESSAGE:
PostNotification?.Invoke(new SimpleErrorNotification { Text = OnlinePlayStrings.InviteFailedUserOptOut });
break;
}
}
}
public override Task TransferHost(int userId) public override Task TransferHost(int userId)
{ {
if (!IsConnected.Value) if (!IsConnected.Value)

View File

@ -0,0 +1,25 @@
// 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;
using System.Runtime.Serialization;
using Microsoft.AspNetCore.SignalR;
namespace osu.Game.Online.Multiplayer
{
[Serializable]
public class UserBlockedException : HubException
{
public const string MESSAGE = @"Cannot perform action due to user being blocked.";
public UserBlockedException()
: base(MESSAGE)
{
}
protected UserBlockedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

View File

@ -0,0 +1,25 @@
// 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;
using System.Runtime.Serialization;
using Microsoft.AspNetCore.SignalR;
namespace osu.Game.Online.Multiplayer
{
[Serializable]
public class UserBlocksPMsException : HubException
{
public const string MESSAGE = "Cannot perform action because user has disabled non-friend communications.";
public UserBlocksPMsException()
: base(MESSAGE)
{
}
protected UserBlocksPMsException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

View File

@ -46,6 +46,7 @@ using osu.Game.IO;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Rooms;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing; using osu.Game.Overlays.BeatmapListing;
using osu.Game.Overlays.Music; using osu.Game.Overlays.Music;
@ -58,6 +59,7 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osu.Game.Screens.OnlinePlay.Multiplayer;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
using osu.Game.Screens.Select; using osu.Game.Screens.Select;
@ -643,6 +645,24 @@ namespace osu.Game
}); });
} }
/// <summary>
/// Join a multiplayer match immediately.
/// </summary>
/// <param name="room">The room to join.</param>
/// <param name="password">The password to join the room, if any is given.</param>
public void PresentMultiplayerMatch(Room room, string password)
{
PerformFromScreen(screen =>
{
if (!(screen is Multiplayer multiplayer))
screen.Push(multiplayer = new Multiplayer());
multiplayer.Join(room, password);
});
// TODO: We should really be able to use `validScreens: new[] { typeof(Multiplayer) }` here
// but `PerformFromScreen` doesn't understand nested stacks.
}
/// <summary> /// <summary>
/// Present a score's replay immediately. /// Present a score's replay immediately.
/// The user should have already requested this interactively. /// The user should have already requested this interactively.
@ -853,6 +873,7 @@ namespace osu.Game
ScoreManager.PresentImport = items => PresentScore(items.First().Value); ScoreManager.PresentImport = items => PresentScore(items.First().Value);
MultiplayerClient.PostNotification = n => Notifications.Post(n); MultiplayerClient.PostNotification = n => Notifications.Post(n);
MultiplayerClient.PresentMatch = PresentMultiplayerMatch;
// make config aware of how to lookup skins for on-screen display purposes. // make config aware of how to lookup skins for on-screen display purposes.
// if this becomes a more common thing, tracked settings should be reconsidered to allow local DI. // if this becomes a more common thing, tracked settings should be reconsidered to allow local DI.

View File

@ -119,7 +119,7 @@ namespace osu.Game.Overlays.Dashboard
{ {
users.GetUserAsync(userId).ContinueWith(task => users.GetUserAsync(userId).ContinueWith(task =>
{ {
var user = task.GetResultSafely(); APIUser user = task.GetResultSafely();
if (user == null) if (user == null)
return; return;
@ -130,6 +130,9 @@ namespace osu.Game.Overlays.Dashboard
if (!playingUsers.Contains(user.Id)) if (!playingUsers.Contains(user.Id))
return; return;
// TODO: remove this once online state is being updated more correctly.
user.IsOnline = true;
userFlow.Add(createUserPanel(user)); userFlow.Add(createUserPanel(user));
}); });
}); });

View File

@ -65,7 +65,7 @@ namespace osu.Game.Overlays.FirstRunSetup
{ {
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
BackgroundColour = colours.Pink3, BackgroundColour = colours.DangerousButtonColour,
Text = FirstRunSetupOverlayStrings.ClassicDefaults, Text = FirstRunSetupOverlayStrings.ClassicDefaults,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Action = applyClassic Action = applyClassic

View File

@ -113,7 +113,8 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Children = new[] Children = new[]
{ {
new NotificationSection(AccountsStrings.NotificationsTitle, new[] { typeof(SimpleNotification) }), // The main section adds as a catch-all for notifications which don't group into other sections.
new NotificationSection(AccountsStrings.NotificationsTitle),
new NotificationSection(NotificationsStrings.RunningTasks, new[] { typeof(ProgressNotification) }), new NotificationSection(NotificationsStrings.RunningTasks, new[] { typeof(ProgressNotification) }),
} }
} }
@ -205,7 +206,8 @@ namespace osu.Game.Overlays
var ourType = notification.GetType(); var ourType = notification.GetType();
int depth = notification.DisplayOnTop ? -runningDepth : runningDepth; int depth = notification.DisplayOnTop ? -runningDepth : runningDepth;
var section = sections.Children.First(s => s.AcceptedNotificationTypes.Any(accept => accept.IsAssignableFrom(ourType))); var section = sections.Children.FirstOrDefault(s => s.AcceptedNotificationTypes?.Any(accept => accept.IsAssignableFrom(ourType)) == true)
?? sections.First();
section.Add(notification, depth); section.Add(notification, depth);

View File

@ -53,6 +53,8 @@ namespace osu.Game.Overlays.Notifications
public virtual string PopInSampleName => "UI/notification-default"; public virtual string PopInSampleName => "UI/notification-default";
public virtual string PopOutSampleName => "UI/overlay-pop-out"; public virtual string PopOutSampleName => "UI/overlay-pop-out";
protected const float CORNER_RADIUS = 6;
protected NotificationLight Light; protected NotificationLight Light;
protected Container IconContent; protected Container IconContent;
@ -128,7 +130,7 @@ namespace osu.Game.Overlays.Notifications
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
}.WithChild(MainContent = new Container }.WithChild(MainContent = new Container
{ {
CornerRadius = 6, CornerRadius = CORNER_RADIUS,
Masking = true, Masking = true,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
@ -473,10 +475,9 @@ namespace osu.Game.Overlays.Notifications
base.Colour = value; base.Colour = value;
pulsateLayer.EdgeEffect = new EdgeEffectParameters pulsateLayer.EdgeEffect = new EdgeEffectParameters
{ {
Colour = ((Color4)value).Opacity(0.5f), //todo: avoid cast Colour = ((Color4)value).Opacity(0.18f),
Type = EdgeEffectType.Glow, Type = EdgeEffectType.Glow,
Radius = 12, Radius = 14,
Roundness = 12,
}; };
} }
} }

View File

@ -37,13 +37,17 @@ namespace osu.Game.Overlays.Notifications
notifications.Insert((int)position, notification); notifications.Insert((int)position, notification);
} }
public IEnumerable<Type> AcceptedNotificationTypes { get; } /// <summary>
/// Enumerable of notification types accepted in this section.
/// If <see langword="null"/>, the section accepts any and all notifications.
/// </summary>
public IEnumerable<Type>? AcceptedNotificationTypes { get; }
private readonly LocalisableString titleText; private readonly LocalisableString titleText;
public NotificationSection(LocalisableString title, IEnumerable<Type> acceptedNotificationTypes) public NotificationSection(LocalisableString title, IEnumerable<Type>? acceptedNotificationTypes = null)
{ {
AcceptedNotificationTypes = acceptedNotificationTypes.ToArray(); AcceptedNotificationTypes = acceptedNotificationTypes?.ToArray();
titleText = title; titleText = title;
} }

View File

@ -0,0 +1,74 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Users.Drawables;
namespace osu.Game.Overlays.Notifications
{
public partial class UserAvatarNotification : Notification
{
private LocalisableString text;
public override LocalisableString Text
{
get => text;
set
{
text = value;
if (textDrawable != null)
textDrawable.Text = text;
}
}
private TextFlowContainer? textDrawable;
private readonly APIUser user;
public UserAvatarNotification(APIUser user, LocalisableString text)
{
this.user = user;
Text = text;
}
protected override IconUsage CloseButtonIcon => FontAwesome.Solid.Times;
[BackgroundDependencyLoader]
private void load(OsuColour colours, OverlayColourProvider colourProvider)
{
Light.Colour = colours.Orange2;
Content.Add(textDrawable = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 14, weight: FontWeight.Medium))
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Text = text
});
IconContent.Masking = true;
IconContent.CornerRadius = CORNER_RADIUS;
IconContent.AddRange(new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
},
});
LoadComponentAsync(new DrawableAvatar(user)
{
FillMode = FillMode.Fill,
}, IconContent.Add);
}
}
}

View File

@ -14,7 +14,7 @@ namespace osu.Game.Overlays.Settings
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
BackgroundColour = colours.Pink3; BackgroundColour = colours.DangerousButtonColour;
} }
} }
} }

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 osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation; using osu.Framework.Localisation;
@ -18,92 +19,19 @@ namespace osu.Game.Overlays.Settings.Sections.Input
public override LocalisableString Header => InputSettingsStrings.GlobalKeyBindingHeader; public override LocalisableString Header => InputSettingsStrings.GlobalKeyBindingHeader;
public GlobalKeyBindingsSection(GlobalActionContainer manager) [BackgroundDependencyLoader]
private void load()
{ {
Add(new DefaultBindingsSubsection(manager)); AddRange(new[]
Add(new OverlayBindingsSubsection(manager));
Add(new AudioControlKeyBindingsSubsection(manager));
Add(new SongSelectKeyBindingSubsection(manager));
Add(new InGameKeyBindingsSubsection(manager));
Add(new ReplayKeyBindingsSubsection(manager));
Add(new EditorKeyBindingsSubsection(manager));
}
private partial class DefaultBindingsSubsection : KeyBindingsSubsection
{ {
protected override LocalisableString Header => string.Empty; new GlobalKeyBindingsSubsection(string.Empty, GlobalActionCategory.General),
new GlobalKeyBindingsSubsection(InputSettingsStrings.OverlaysSection, GlobalActionCategory.Overlays),
public DefaultBindingsSubsection(GlobalActionContainer manager) new GlobalKeyBindingsSubsection(InputSettingsStrings.AudioSection, GlobalActionCategory.AudioControl),
: base(null) new GlobalKeyBindingsSubsection(InputSettingsStrings.SongSelectSection, GlobalActionCategory.SongSelect),
{ new GlobalKeyBindingsSubsection(InputSettingsStrings.InGameSection, GlobalActionCategory.InGame),
Defaults = manager.GlobalKeyBindings; new GlobalKeyBindingsSubsection(InputSettingsStrings.ReplaySection, GlobalActionCategory.Replay),
} new GlobalKeyBindingsSubsection(InputSettingsStrings.EditorSection, GlobalActionCategory.Editor),
} });
private partial class OverlayBindingsSubsection : KeyBindingsSubsection
{
protected override LocalisableString Header => InputSettingsStrings.OverlaysSection;
public OverlayBindingsSubsection(GlobalActionContainer manager)
: base(null)
{
Defaults = manager.OverlayKeyBindings;
}
}
private partial class SongSelectKeyBindingSubsection : KeyBindingsSubsection
{
protected override LocalisableString Header => InputSettingsStrings.SongSelectSection;
public SongSelectKeyBindingSubsection(GlobalActionContainer manager)
: base(null)
{
Defaults = manager.SongSelectKeyBindings;
}
}
private partial class InGameKeyBindingsSubsection : KeyBindingsSubsection
{
protected override LocalisableString Header => InputSettingsStrings.InGameSection;
public InGameKeyBindingsSubsection(GlobalActionContainer manager)
: base(null)
{
Defaults = manager.InGameKeyBindings;
}
}
private partial class ReplayKeyBindingsSubsection : KeyBindingsSubsection
{
protected override LocalisableString Header => InputSettingsStrings.ReplaySection;
public ReplayKeyBindingsSubsection(GlobalActionContainer manager)
: base(null)
{
Defaults = manager.ReplayKeyBindings;
}
}
private partial class AudioControlKeyBindingsSubsection : KeyBindingsSubsection
{
protected override LocalisableString Header => InputSettingsStrings.AudioSection;
public AudioControlKeyBindingsSubsection(GlobalActionContainer manager)
: base(null)
{
Defaults = manager.AudioControlKeyBindings;
}
}
private partial class EditorKeyBindingsSubsection : KeyBindingsSubsection
{
protected override LocalisableString Header => InputSettingsStrings.EditorSection;
public EditorKeyBindingsSubsection(GlobalActionContainer manager)
: base(null)
{
Defaults = manager.EditorKeyBindings;
}
} }
} }
} }

View File

@ -0,0 +1,36 @@
// 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 osu.Framework.Localisation;
using osu.Game.Database;
using osu.Game.Input.Bindings;
using Realms;
namespace osu.Game.Overlays.Settings.Sections.Input
{
public partial class GlobalKeyBindingsSubsection : KeyBindingsSubsection
{
protected override LocalisableString Header { get; }
private readonly GlobalActionCategory category;
public GlobalKeyBindingsSubsection(LocalisableString header, GlobalActionCategory category)
{
Header = header;
this.category = category;
Defaults = GlobalActionContainer.GetDefaultBindingsFor(category);
}
protected override IEnumerable<RealmKeyBinding> GetKeyBindings(Realm realm)
{
var bindings = realm.All<RealmKeyBinding>()
.Where(b => b.RulesetName == null && b.Variant == null)
.Detach();
var actionsInSection = GlobalActionContainer.GetGlobalActionsFor(category).Cast<int>().ToHashSet();
return bindings.Where(kb => actionsInSection.Contains(kb.ActionInt));
}
}
}

View File

@ -0,0 +1,299 @@
// 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;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
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.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osuTK;
namespace osu.Game.Overlays.Settings.Sections.Input
{
public partial class KeyBindingConflictPopover : OsuPopover
{
public Action? BindingConflictResolved { get; init; }
private ConflictingKeyBindingPreview newPreview = null!;
private ConflictingKeyBindingPreview existingPreview = null!;
private HoverableRoundedButton keepExistingButton = null!;
private HoverableRoundedButton applyNewButton = null!;
[Resolved]
private RealmAccess realm { get; set; } = null!;
[Resolved]
private OsuColour colours { get; set; } = null!;
private readonly KeyBindingRow.KeyBindingConflictInfo conflictInfo;
public KeyBindingConflictPopover(KeyBindingRow.KeyBindingConflictInfo conflictInfo)
{
this.conflictInfo = conflictInfo;
}
[BackgroundDependencyLoader]
private void load()
{
Child = new FillFlowContainer
{
Width = 250,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Children = new Drawable[]
{
new OsuTextFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Text = InputSettingsStrings.KeyBindingConflictDetected,
Margin = new MarginPadding { Bottom = 10 }
},
existingPreview = new ConflictingKeyBindingPreview(
conflictInfo.Existing.Action,
conflictInfo.Existing.CombinationWhenChosen,
conflictInfo.Existing.CombinationWhenNotChosen),
newPreview = new ConflictingKeyBindingPreview(
conflictInfo.New.Action,
conflictInfo.New.CombinationWhenChosen,
conflictInfo.New.CombinationWhenNotChosen),
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = 10 },
Children = new[]
{
keepExistingButton = new HoverableRoundedButton
{
Text = InputSettingsStrings.KeepExistingBinding,
RelativeSizeAxes = Axes.X,
Width = 0.48f,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Action = Hide
},
applyNewButton = new HoverableRoundedButton
{
Text = InputSettingsStrings.ApplyNewBinding,
BackgroundColour = colours.DangerousButtonColour,
RelativeSizeAxes = Axes.X,
Width = 0.48f,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Action = applyNew
}
}
}
}
};
}
private void applyNew()
{
// only "apply new" needs to cause actual realm changes, since the flow in `KeyBindingsSubsection` does not actually make db changes
// if it detects a binding conflict.
// the temporary visual changes will be reverted by calling `Hide()` / `BindingConflictResolved`.
realm.Write(r =>
{
var existingBinding = r.Find<RealmKeyBinding>(conflictInfo.Existing.ID);
existingBinding!.KeyCombinationString = conflictInfo.Existing.CombinationWhenNotChosen.ToString();
var newBinding = r.Find<RealmKeyBinding>(conflictInfo.New.ID);
newBinding!.KeyCombinationString = conflictInfo.Existing.CombinationWhenChosen.ToString();
});
Hide();
}
protected override void PopOut()
{
base.PopOut();
// workaround for `VisibilityContainer.PopOut()` being called in `LoadAsyncComplete()`
if (IsLoaded)
BindingConflictResolved?.Invoke();
}
protected override void LoadComplete()
{
base.LoadComplete();
keepExistingButton.IsHoveredBindable.BindValueChanged(_ => updatePreviews());
applyNewButton.IsHoveredBindable.BindValueChanged(_ => updatePreviews());
updatePreviews();
}
private void updatePreviews()
{
if (!keepExistingButton.IsHovered && !applyNewButton.IsHovered)
{
existingPreview.IsChosen.Value = newPreview.IsChosen.Value = null;
return;
}
existingPreview.IsChosen.Value = keepExistingButton.IsHovered;
newPreview.IsChosen.Value = applyNewButton.IsHovered;
}
private partial class ConflictingKeyBindingPreview : CompositeDrawable
{
private readonly object action;
private readonly KeyCombination combinationWhenChosen;
private readonly KeyCombination combinationWhenNotChosen;
private OsuSpriteText newBindingText = null!;
public Bindable<bool?> IsChosen { get; } = new Bindable<bool?>();
[Resolved]
private ReadableKeyCombinationProvider keyCombinationProvider { get; set; } = null!;
[Resolved]
private OsuColour colours { get; set; } = null!;
public ConflictingKeyBindingPreview(object action, KeyCombination combinationWhenChosen, KeyCombination combinationWhenNotChosen)
{
this.action = action;
this.combinationWhenChosen = combinationWhenChosen;
this.combinationWhenNotChosen = combinationWhenNotChosen;
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
CornerRadius = 5,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5
},
new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
new Drawable[]
{
new OsuSpriteText
{
Text = action.GetLocalisableDescription(),
Margin = new MarginPadding(7.5f),
},
new Container
{
AutoSizeAxes = Axes.Both,
CornerRadius = 5,
Masking = true,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
X = -5,
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background6
},
Empty().With(d => d.Width = 80), // poor man's min-width
newBindingText = new OsuSpriteText
{
Font = OsuFont.Numeric.With(size: 10),
Margin = new MarginPadding(5),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
}
}
},
}
}
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
IsChosen.BindValueChanged(_ => updateState(), true);
}
private void updateState()
{
LocalisableString keyCombinationText;
switch (IsChosen.Value)
{
case true:
keyCombinationText = keyCombinationProvider.GetReadableString(combinationWhenChosen);
newBindingText.Colour = colours.Green1;
break;
case false:
keyCombinationText = keyCombinationProvider.GetReadableString(combinationWhenNotChosen);
newBindingText.Colour = colours.Red1;
break;
case null:
keyCombinationText = keyCombinationProvider.GetReadableString(combinationWhenChosen);
newBindingText.Colour = Colour4.White;
break;
}
if (LocalisableString.IsNullOrEmpty(keyCombinationText))
keyCombinationText = InputSettingsStrings.ActionHasNoKeyBinding;
newBindingText.Text = keyCombinationText;
}
}
private partial class HoverableRoundedButton : RoundedButton
{
public BindableBool IsHoveredBindable { get; set; } = new BindableBool();
protected override bool OnHover(HoverEvent e)
{
IsHoveredBindable.Value = IsHovered;
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
IsHoveredBindable.Value = IsHovered;
base.OnHoverLost(e);
}
}
}
}

View File

@ -3,7 +3,6 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Input.Bindings;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -14,9 +13,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
protected override Drawable CreateHeader() => new SettingsHeader(InputSettingsStrings.KeyBindingPanelHeader, InputSettingsStrings.KeyBindingPanelDescription); protected override Drawable CreateHeader() => new SettingsHeader(InputSettingsStrings.KeyBindingPanelHeader, InputSettingsStrings.KeyBindingPanelDescription);
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(RulesetStore rulesets, GlobalActionContainer global) private void load(RulesetStore rulesets)
{ {
AddSection(new GlobalKeyBindingsSection(global)); AddSection(new GlobalKeyBindingsSection());
foreach (var ruleset in rulesets.AvailableRulesets) foreach (var ruleset in rulesets.AvailableRulesets)
AddSection(new RulesetBindingsSection(ruleset)); AddSection(new RulesetBindingsSection(ruleset));

View File

@ -9,7 +9,6 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
@ -19,15 +18,13 @@ using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Input;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets;
using osuTK; using osuTK;
using osuTK.Graphics;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Overlays.Settings.Sections.Input namespace osu.Game.Overlays.Settings.Sections.Input
@ -37,13 +34,22 @@ namespace osu.Game.Overlays.Settings.Sections.Input
/// <summary> /// <summary>
/// Invoked when the binding of this row is updated with a change being written. /// Invoked when the binding of this row is updated with a change being written.
/// </summary> /// </summary>
public Action<KeyBindingRow>? BindingUpdated { get; init; } public KeyBindingUpdated? BindingUpdated { get; set; }
public delegate void KeyBindingUpdated(KeyBindingRow sender, KeyBindingUpdatedEventArgs args);
public Func<List<RealmKeyBinding>> GetAllSectionBindings { get; set; } = null!;
/// <summary> /// <summary>
/// Whether left and right mouse button clicks should be included in the edited bindings. /// Whether left and right mouse button clicks should be included in the edited bindings.
/// </summary> /// </summary>
public bool AllowMainMouseButtons { get; init; } public bool AllowMainMouseButtons { get; init; }
/// <summary>
/// The bindings to display in this row.
/// </summary>
public BindableList<RealmKeyBinding> KeyBindings { get; } = new BindableList<RealmKeyBinding>();
/// <summary> /// <summary>
/// The default key bindings for this row. /// The default key bindings for this row.
/// </summary> /// </summary>
@ -65,20 +71,22 @@ namespace osu.Game.Overlays.Settings.Sections.Input
public bool FilteringActive { get; set; } public bool FilteringActive { get; set; }
public IEnumerable<LocalisableString> FilterTerms => bindings.Select(b => (LocalisableString)keyCombinationProvider.GetReadableString(b.KeyCombination)).Prepend(text.Text); public IEnumerable<LocalisableString> FilterTerms => KeyBindings.Select(b => (LocalisableString)keyCombinationProvider.GetReadableString(b.KeyCombination)).Prepend(text.Text);
#endregion #endregion
private readonly object action; public readonly object Action;
private readonly IEnumerable<RealmKeyBinding> bindings;
private Bindable<bool> isDefault { get; } = new BindableBool(true); private Bindable<bool> isDefault { get; } = new BindableBool(true);
[Resolved] [Resolved]
private ReadableKeyCombinationProvider keyCombinationProvider { get; set; } = null!; private RealmAccess realm { get; set; } = null!;
[Resolved] [Resolved]
private RealmAccess realm { get; set; } = null!; private RulesetStore rulesets { get; set; } = null!;
[Resolved]
private ReadableKeyCombinationProvider keyCombinationProvider { get; set; } = null!;
private Container content = null!; private Container content = null!;
@ -101,11 +109,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
/// Creates a new <see cref="KeyBindingRow"/>. /// Creates a new <see cref="KeyBindingRow"/>.
/// </summary> /// </summary>
/// <param name="action">The action that this row contains bindings for.</param> /// <param name="action">The action that this row contains bindings for.</param>
/// <param name="bindings">The keybindings to display in this row.</param> public KeyBindingRow(object action)
public KeyBindingRow(object action, List<RealmKeyBinding> bindings)
{ {
this.action = action; Action = action;
this.bindings = bindings;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -161,7 +167,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
}, },
text = new OsuSpriteText text = new OsuSpriteText
{ {
Text = action.GetLocalisableDescription(), Text = Action.GetLocalisableDescription(),
Margin = new MarginPadding(1.5f * padding), Margin = new MarginPadding(1.5f * padding),
}, },
buttons = new FillFlowContainer<KeyButton> buttons = new FillFlowContainer<KeyButton>
@ -191,10 +197,11 @@ namespace osu.Game.Overlays.Settings.Sections.Input
} }
}; };
foreach (var b in bindings) KeyBindings.BindCollectionChanged((_, _) =>
buttons.Add(new KeyButton(b)); {
Scheduler.AddOnce(updateButtons);
updateIsDefaultValue(); updateIsDefaultValue();
}, true);
} }
public void RestoreDefaults() public void RestoreDefaults()
@ -206,7 +213,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
var button = buttons[i++]; var button = buttons[i++];
button.UpdateKeyCombination(d); button.UpdateKeyCombination(d);
updateStoreFromButton(button); tryPersistKeyBinding(button.KeyBinding.Value, advanceToNextBinding: false);
} }
isDefault.Value = true; isDefault.Value = true;
@ -226,8 +233,6 @@ namespace osu.Game.Overlays.Settings.Sections.Input
base.OnHoverLost(e); base.OnHoverLost(e);
} }
private bool isModifier(Key k) => k < Key.F1;
protected override bool OnClick(ClickEvent e) => true; protected override bool OnClick(ClickEvent e) => true;
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
@ -300,6 +305,8 @@ namespace osu.Game.Overlays.Settings.Sections.Input
if (!isModifier(e.Key)) finalise(); if (!isModifier(e.Key)) finalise();
return true; return true;
bool isModifier(Key k) => k < Key.F1;
} }
protected override void OnKeyUp(KeyUpEvent e) protected override void OnKeyUp(KeyUpEvent e)
@ -409,6 +416,18 @@ namespace osu.Game.Overlays.Settings.Sections.Input
finalise(); finalise();
} }
private void updateButtons()
{
if (buttons.Count > KeyBindings.Count)
buttons.RemoveRange(buttons.Skip(KeyBindings.Count).ToArray(), true);
while (buttons.Count < KeyBindings.Count)
buttons.Add(new KeyButton());
foreach (var (button, binding) in buttons.Zip(KeyBindings))
button.KeyBinding.Value = binding;
}
private void clear() private void clear()
{ {
if (bindTarget == null) if (bindTarget == null)
@ -418,21 +437,19 @@ namespace osu.Game.Overlays.Settings.Sections.Input
finalise(false); finalise(false);
} }
private void finalise(bool hasChanged = true) private void finalise(bool advanceToNextBinding = true)
{ {
if (bindTarget != null) if (bindTarget != null)
{ {
updateStoreFromButton(bindTarget);
updateIsDefaultValue(); updateIsDefaultValue();
bindTarget.IsBinding = false; bindTarget.IsBinding = false;
var bindingToPersist = bindTarget.KeyBinding.Value;
Schedule(() => Schedule(() =>
{ {
// schedule to ensure we don't instantly get focus back on next OnMouseClick (see AcceptFocus impl.) // schedule to ensure we don't instantly get focus back on next OnMouseClick (see AcceptFocus impl.)
bindTarget = null; bindTarget = null;
if (hasChanged) tryPersistKeyBinding(bindingToPersist, advanceToNextBinding);
BindingUpdated?.Invoke(this);
}); });
} }
@ -461,6 +478,28 @@ namespace osu.Game.Overlays.Settings.Sections.Input
base.OnFocusLost(e); base.OnFocusLost(e);
} }
private void tryPersistKeyBinding(RealmKeyBinding keyBinding, bool advanceToNextBinding)
{
List<RealmKeyBinding> bindings = GetAllSectionBindings();
RealmKeyBinding? existingBinding = keyBinding.KeyCombination.Equals(new KeyCombination(InputKey.None))
? null
: bindings.FirstOrDefault(other => other.ID != keyBinding.ID && other.KeyCombination.Equals(keyBinding.KeyCombination));
if (existingBinding == null)
{
realm.WriteAsync(r => r.Find<RealmKeyBinding>(keyBinding.ID)!.KeyCombinationString = keyBinding.KeyCombination.ToString());
BindingUpdated?.Invoke(this, new KeyBindingUpdatedEventArgs(bindingConflictResolved: false, advanceToNextBinding));
return;
}
var keyBindingBeforeUpdate = bindings.Single(other => other.ID == keyBinding.ID);
showBindingConflictPopover(
new KeyBindingConflictInfo(
new ConflictingKeyBinding(existingBinding.ID, existingBinding.GetAction(rulesets), existingBinding.KeyCombination, new KeyCombination(InputKey.None)),
new ConflictingKeyBinding(keyBindingBeforeUpdate.ID, Action, keyBinding.KeyCombination, keyBindingBeforeUpdate.KeyCombination)));
}
/// <summary> /// <summary>
/// Updates the bind target to the currently hovered key button or the first if clicked anywhere else. /// Updates the bind target to the currently hovered key button or the first if clicked anywhere else.
/// </summary> /// </summary>
@ -471,12 +510,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
if (bindTarget != null) bindTarget.IsBinding = true; if (bindTarget != null) bindTarget.IsBinding = true;
} }
private void updateStoreFromButton(KeyButton button) =>
realm.WriteAsync(r => r.Find<RealmKeyBinding>(button.KeyBinding.ID)!.KeyCombinationString = button.KeyBinding.KeyCombinationString);
private void updateIsDefaultValue() private void updateIsDefaultValue()
{ {
isDefault.Value = bindings.Select(b => b.KeyCombination).SequenceEqual(Defaults); isDefault.Value = KeyBindings.Select(b => b.KeyCombination).SequenceEqual(Defaults);
} }
private partial class CancelButton : RoundedButton private partial class CancelButton : RoundedButton
@ -496,144 +532,5 @@ namespace osu.Game.Overlays.Settings.Sections.Input
Size = new Vector2(80, 20); Size = new Vector2(80, 20);
} }
} }
public partial class KeyButton : Container
{
public readonly RealmKeyBinding KeyBinding;
private readonly Box box;
public readonly OsuSpriteText Text;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[Resolved]
private ReadableKeyCombinationProvider keyCombinationProvider { get; set; } = null!;
private bool isBinding;
public bool IsBinding
{
get => isBinding;
set
{
if (value == isBinding) return;
isBinding = value;
updateHoverState();
}
}
public KeyButton(RealmKeyBinding keyBinding)
{
if (keyBinding.IsManaged)
throw new ArgumentException("Key binding should not be attached as we make temporary changes", nameof(keyBinding));
KeyBinding = keyBinding;
Margin = new MarginPadding(padding);
Masking = true;
CornerRadius = padding;
Height = height;
AutoSizeAxes = Axes.X;
Children = new Drawable[]
{
new Container
{
AlwaysPresent = true,
Width = 80,
Height = height,
},
box = new Box
{
RelativeSizeAxes = Axes.Both,
},
Text = new OsuSpriteText
{
Font = OsuFont.Numeric.With(size: 10),
Margin = new MarginPadding(5),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
new HoverSounds()
};
}
protected override void LoadComplete()
{
base.LoadComplete();
keyCombinationProvider.KeymapChanged += updateKeyCombinationText;
updateKeyCombinationText();
}
[BackgroundDependencyLoader]
private void load()
{
updateHoverState();
}
protected override bool OnHover(HoverEvent e)
{
updateHoverState();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateHoverState();
base.OnHoverLost(e);
}
private void updateHoverState()
{
if (isBinding)
{
box.FadeColour(colourProvider.Light2, transition_time, Easing.OutQuint);
Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint);
}
else
{
box.FadeColour(IsHovered ? colourProvider.Light4 : colourProvider.Background6, transition_time, Easing.OutQuint);
Text.FadeColour(IsHovered ? Color4.Black : Color4.White, transition_time, Easing.OutQuint);
}
}
/// <summary>
/// Update from a key combination, only allowing a single non-modifier key to be specified.
/// </summary>
/// <param name="fullState">A <see cref="KeyCombination"/> generated from the full input state.</param>
/// <param name="triggerKey">The key which triggered this update, and should be used as the binding.</param>
public void UpdateKeyCombination(KeyCombination fullState, InputKey triggerKey) =>
UpdateKeyCombination(new KeyCombination(fullState.Keys.Where(KeyCombination.IsModifierKey).Append(triggerKey)));
public void UpdateKeyCombination(KeyCombination newCombination)
{
if (KeyBinding.RulesetName != null && !RealmKeyBindingStore.CheckValidForGameplay(newCombination))
return;
KeyBinding.KeyCombination = newCombination;
updateKeyCombinationText();
}
private void updateKeyCombinationText()
{
Scheduler.AddOnce(updateText);
void updateText() => Text.Text = keyCombinationProvider.GetReadableString(KeyBinding.KeyCombination);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (keyCombinationProvider.IsNotNull())
keyCombinationProvider.KeymapChanged -= updateKeyCombinationText;
}
}
} }
} }

View File

@ -0,0 +1,78 @@
// 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;
using System.Diagnostics;
using osu.Framework.Extensions;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
namespace osu.Game.Overlays.Settings.Sections.Input
{
public partial class KeyBindingRow : IHasPopover
{
private KeyBindingConflictInfo? pendingKeyBindingConflict;
public Popover GetPopover()
{
Debug.Assert(pendingKeyBindingConflict != null);
return new KeyBindingConflictPopover(pendingKeyBindingConflict)
{
BindingConflictResolved = () => BindingUpdated?.Invoke(this, new KeyBindingUpdatedEventArgs(bindingConflictResolved: true, canAdvanceToNextBinding: false))
};
}
private void showBindingConflictPopover(KeyBindingConflictInfo conflictInfo)
{
pendingKeyBindingConflict = conflictInfo;
this.ShowPopover();
}
/// <summary>
/// Contains information about the key binding conflict to be resolved.
/// </summary>
public class KeyBindingConflictInfo
{
public ConflictingKeyBinding Existing { get; }
public ConflictingKeyBinding New { get; }
/// <summary>
/// Contains information about the key binding conflict to be resolved.
/// </summary>
public KeyBindingConflictInfo(ConflictingKeyBinding existingBinding, ConflictingKeyBinding newBinding)
{
Existing = existingBinding;
New = newBinding;
}
}
public class ConflictingKeyBinding
{
public Guid ID { get; }
public object Action { get; }
public KeyCombination CombinationWhenChosen { get; }
public KeyCombination CombinationWhenNotChosen { get; }
public ConflictingKeyBinding(Guid id, object action, KeyCombination combinationWhenChosen, KeyCombination combinationWhenNotChosen)
{
ID = id;
Action = action;
CombinationWhenChosen = combinationWhenChosen;
CombinationWhenNotChosen = combinationWhenNotChosen;
}
}
public class KeyBindingUpdatedEventArgs
{
public bool BindingConflictResolved { get; }
public bool CanAdvanceToNextBinding { get; }
public KeyBindingUpdatedEventArgs(bool bindingConflictResolved, bool canAdvanceToNextBinding)
{
BindingConflictResolved = bindingConflictResolved;
CanAdvanceToNextBinding = canAdvanceToNextBinding;
}
}
}
}

View File

@ -0,0 +1,183 @@
// 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;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
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.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osuTK.Graphics;
namespace osu.Game.Overlays.Settings.Sections.Input
{
public partial class KeyBindingRow
{
public partial class KeyButton : Container
{
public Bindable<RealmKeyBinding> KeyBinding { get; } = new Bindable<RealmKeyBinding>();
private readonly Box box;
public readonly OsuSpriteText Text;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[Resolved]
private ReadableKeyCombinationProvider keyCombinationProvider { get; set; } = null!;
private bool isBinding;
public bool IsBinding
{
get => isBinding;
set
{
if (value == isBinding) return;
isBinding = value;
updateHoverState();
}
}
public KeyButton()
{
Margin = new MarginPadding(padding);
Masking = true;
CornerRadius = padding;
Height = height;
AutoSizeAxes = Axes.X;
Children = new Drawable[]
{
new Container
{
AlwaysPresent = true,
Width = 80,
Height = height,
},
box = new Box
{
RelativeSizeAxes = Axes.Both,
},
Text = new OsuSpriteText
{
Font = OsuFont.Numeric.With(size: 10),
Margin = new MarginPadding(5),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
new HoverSounds()
};
}
protected override void LoadComplete()
{
base.LoadComplete();
KeyBinding.BindValueChanged(_ =>
{
if (KeyBinding.Value.IsManaged)
throw new ArgumentException("Key binding should not be attached as we make temporary changes", nameof(KeyBinding));
updateKeyCombinationText();
});
keyCombinationProvider.KeymapChanged += updateKeyCombinationText;
updateKeyCombinationText();
}
[BackgroundDependencyLoader]
private void load()
{
updateHoverState();
FinishTransforms(true);
}
protected override bool OnHover(HoverEvent e)
{
updateHoverState();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateHoverState();
base.OnHoverLost(e);
}
private void updateHoverState()
{
if (isBinding)
{
box.FadeColour(colourProvider.Light2, transition_time, Easing.OutQuint);
Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint);
}
else
{
box.FadeColour(IsHovered ? colourProvider.Light4 : colourProvider.Background6, transition_time, Easing.OutQuint);
Text.FadeColour(IsHovered ? Color4.Black : Color4.White, transition_time, Easing.OutQuint);
}
}
/// <summary>
/// Update from a key combination, only allowing a single non-modifier key to be specified.
/// </summary>
/// <param name="fullState">A <see cref="KeyCombination"/> generated from the full input state.</param>
/// <param name="triggerKey">The key which triggered this update, and should be used as the binding.</param>
public void UpdateKeyCombination(KeyCombination fullState, InputKey triggerKey) =>
UpdateKeyCombination(new KeyCombination(fullState.Keys.Where(KeyCombination.IsModifierKey).Append(triggerKey)));
public void UpdateKeyCombination(KeyCombination newCombination)
{
if (KeyBinding.Value.RulesetName != null && !RealmKeyBindingStore.CheckValidForGameplay(newCombination))
return;
KeyBinding.Value.KeyCombination = newCombination;
updateKeyCombinationText();
}
private void updateKeyCombinationText()
{
Scheduler.AddOnce(updateText);
void updateText()
{
LocalisableString keyCombinationString = keyCombinationProvider.GetReadableString(KeyBinding.Value.KeyCombination);
float alpha = 1;
if (LocalisableString.IsNullOrEmpty(keyCombinationString))
{
keyCombinationString = InputSettingsStrings.ActionHasNoKeyBinding;
alpha = 0.4f;
}
Text.Text = keyCombinationString;
Text.Alpha = alpha;
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (keyCombinationProvider.IsNotNull())
keyCombinationProvider.KeymapChanged -= updateKeyCombinationText;
}
}
}
}

View File

@ -5,15 +5,14 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Rulesets;
using osu.Game.Localisation; using osu.Game.Localisation;
using osuTK; using osuTK;
using Realms;
namespace osu.Game.Overlays.Settings.Sections.Input namespace osu.Game.Overlays.Settings.Sections.Input
{ {
@ -27,48 +26,83 @@ namespace osu.Game.Overlays.Settings.Sections.Input
protected IEnumerable<KeyBinding> Defaults { get; init; } = Array.Empty<KeyBinding>(); protected IEnumerable<KeyBinding> Defaults { get; init; } = Array.Empty<KeyBinding>();
public RulesetInfo? Ruleset { get; protected set; } [Resolved]
private RealmAccess realm { get; set; } = null!;
private readonly int? variant; protected KeyBindingsSubsection()
protected KeyBindingsSubsection(int? variant)
{ {
this.variant = variant;
FlowContent.Spacing = new Vector2(0, 3); FlowContent.Spacing = new Vector2(0, 3);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(RealmAccess realm) private void load()
{ {
string? rulesetName = Ruleset?.ShortName; var bindings = getAllBindings();
var bindings = realm.Run(r => r.All<RealmKeyBinding>()
.Where(b => b.RulesetName == rulesetName && b.Variant == variant)
.Detach());
foreach (var defaultGroup in Defaults.GroupBy(d => d.Action)) foreach (var defaultGroup in Defaults.GroupBy(d => d.Action))
{ {
int intKey = (int)defaultGroup.Key; int intKey = (int)defaultGroup.Key;
// one row per valid action. var row = CreateKeyBindingRow(defaultGroup.Key, defaultGroup)
Add(new KeyBindingRow(defaultGroup.Key, bindings.Where(b => b.ActionInt.Equals(intKey)).ToList()) .With(row =>
{ {
AllowMainMouseButtons = Ruleset != null, row.BindingUpdated = onBindingUpdated;
Defaults = defaultGroup.Select(d => d.KeyCombination), row.GetAllSectionBindings = getAllBindings;
BindingUpdated = onBindingUpdated
}); });
row.KeyBindings.AddRange(bindings.Where(b => b.ActionInt.Equals(intKey)));
Add(row);
} }
Add(new ResetButton Add(new ResetButton
{ {
Action = () => Children.OfType<KeyBindingRow>().ForEach(k => k.RestoreDefaults()) Action = () =>
{
realm.Write(r =>
{
// can't use `RestoreDefaults()` for each key binding row here as it might trigger binding conflicts along the way.
foreach (var row in Children.OfType<KeyBindingRow>())
{
foreach (var (currentBinding, defaultBinding) in row.KeyBindings.Zip(row.Defaults))
r.Find<RealmKeyBinding>(currentBinding.ID)!.KeyCombinationString = defaultBinding.ToString();
}
});
reloadAllBindings();
}
}); });
} }
private void onBindingUpdated(KeyBindingRow sender) protected abstract IEnumerable<RealmKeyBinding> GetKeyBindings(Realm realm);
private List<RealmKeyBinding> getAllBindings() => realm.Run(r =>
{ {
if (AutoAdvanceTarget) r.Refresh();
return GetKeyBindings(r).Detach();
});
protected virtual KeyBindingRow CreateKeyBindingRow(object action, IEnumerable<KeyBinding> defaults)
=> new KeyBindingRow(action)
{
AllowMainMouseButtons = false,
Defaults = defaults.Select(d => d.KeyCombination),
};
private void reloadAllBindings()
{
var bindings = getAllBindings();
foreach (var row in Children.OfType<KeyBindingRow>())
{
row.KeyBindings.Clear();
row.KeyBindings.AddRange(bindings.Where(b => b.ActionInt.Equals((int)row.Action)));
}
}
private void onBindingUpdated(KeyBindingRow sender, KeyBindingRow.KeyBindingUpdatedEventArgs args)
{
if (args.BindingConflictResolved)
reloadAllBindings();
if (AutoAdvanceTarget && args.CanAdvanceToNextBinding)
{ {
var next = Children.SkipWhile(c => c != sender).Skip(1).FirstOrDefault(); var next = Children.SkipWhile(c => c != sender).Skip(1).FirstOrDefault();
if (next != null) if (next != null)

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 osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -18,7 +19,11 @@ namespace osu.Game.Overlays.Settings.Sections.Input
public RulesetBindingsSection(RulesetInfo ruleset) public RulesetBindingsSection(RulesetInfo ruleset)
{ {
this.ruleset = ruleset; this.ruleset = ruleset;
}
[BackgroundDependencyLoader]
private void load()
{
var r = ruleset.CreateInstance(); var r = ruleset.CreateInstance();
foreach (int variant in r.AvailableVariants) foreach (int variant in r.AvailableVariants)

View File

@ -1,8 +1,13 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Framework.Input.Bindings;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using Realms;
namespace osu.Game.Overlays.Settings.Sections.Input namespace osu.Game.Overlays.Settings.Sections.Input
{ {
@ -12,15 +17,33 @@ namespace osu.Game.Overlays.Settings.Sections.Input
protected override LocalisableString Header { get; } protected override LocalisableString Header { get; }
public RulesetInfo Ruleset { get; }
private readonly int variant;
public VariantBindingsSubsection(RulesetInfo ruleset, int variant) public VariantBindingsSubsection(RulesetInfo ruleset, int variant)
: base(variant)
{ {
Ruleset = ruleset; Ruleset = ruleset;
this.variant = variant;
var rulesetInstance = ruleset.CreateInstance(); var rulesetInstance = ruleset.CreateInstance();
Header = rulesetInstance.GetVariantName(variant); Header = rulesetInstance.GetVariantName(variant);
Defaults = rulesetInstance.GetDefaultKeyBindings(variant); Defaults = rulesetInstance.GetDefaultKeyBindings(variant);
} }
protected override IEnumerable<RealmKeyBinding> GetKeyBindings(Realm realm)
{
string rulesetName = Ruleset.ShortName;
return realm.All<RealmKeyBinding>()
.Where(b => b.RulesetName == rulesetName && b.Variant == variant);
}
protected override KeyBindingRow CreateKeyBindingRow(object action, IEnumerable<KeyBinding> defaults)
=> new KeyBindingRow(action)
{
AllowMainMouseButtons = true,
Defaults = defaults.Select(d => d.KeyCombination),
};
} }
} }

View File

@ -14,6 +14,7 @@ using osu.Framework.Extensions.Color4Extensions;
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.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
@ -106,7 +107,10 @@ namespace osu.Game.Overlays
} }
}; };
Add(SectionsContainer = new SettingsSectionsContainer Add(new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Child = SectionsContainer = new SettingsSectionsContainer
{ {
Masking = true, Masking = true,
EdgeEffect = new EdgeEffectParameters EdgeEffect = new EdgeEffectParameters
@ -139,6 +143,7 @@ namespace osu.Game.Overlays
} }
}, },
Footer = CreateFooter().With(f => f.Alpha = 0) Footer = CreateFooter().With(f => f.Alpha = 0)
}
}); });
if (showSidebar) if (showSidebar)

View File

@ -3,15 +3,16 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
@ -21,8 +22,10 @@ namespace osu.Game.Rulesets.UI
public BindableBool Active { get; } = new BindableBool(); public BindableBool Active { get; } = new BindableBool();
public const float DEFAULT_HEIGHT = 30; public const float DEFAULT_HEIGHT = 30;
private const float width = 73;
private readonly IMod mod; protected readonly IMod Mod;
private readonly bool showExtendedInformation;
private readonly Box background; private readonly Box background;
private readonly OsuSpriteText acronymText; private readonly OsuSpriteText acronymText;
@ -33,14 +36,49 @@ namespace osu.Game.Rulesets.UI
private Color4 activeBackgroundColour; private Color4 activeBackgroundColour;
private Color4 inactiveBackgroundColour; private Color4 inactiveBackgroundColour;
public ModSwitchTiny(IMod mod) private readonly CircularContainer extendedContent;
{ private readonly Box extendedBackground;
this.mod = mod; private readonly OsuSpriteText extendedText;
Size = new Vector2(73, DEFAULT_HEIGHT); private ModSettingChangeTracker? modSettingsChangeTracker;
InternalChild = new CircularContainer public ModSwitchTiny(IMod mod, bool showExtendedInformation = false)
{
Mod = mod;
this.showExtendedInformation = showExtendedInformation;
AutoSizeAxes = Axes.X;
Height = DEFAULT_HEIGHT;
InternalChildren = new Drawable[]
{
extendedContent = new CircularContainer
{
Name = "extended content",
Width = 100 + DEFAULT_HEIGHT / 2,
RelativeSizeAxes = Axes.Y,
Masking = true,
X = width,
Margin = new MarginPadding { Left = -DEFAULT_HEIGHT },
Children = new Drawable[]
{
extendedBackground = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
},
extendedText = new OsuSpriteText
{
Margin = new MarginPadding { Left = 3 * DEFAULT_HEIGHT / 4 },
Font = OsuFont.Default.With(size: 30f, weight: FontWeight.Bold),
UseFullGlyphHeight = false,
Text = mod.ExtendedIconInformation,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
}
},
new CircularContainer
{
Width = width,
RelativeSizeAxes = Axes.Y,
Masking = true, Masking = true,
Children = new Drawable[] Children = new Drawable[]
{ {
@ -59,7 +97,8 @@ namespace osu.Game.Rulesets.UI
{ {
Top = 4 Top = 4
} }
} },
},
} }
}; };
} }
@ -68,7 +107,7 @@ namespace osu.Game.Rulesets.UI
private void load(OsuColour colours, OverlayColourProvider? colourProvider) private void load(OsuColour colours, OverlayColourProvider? colourProvider)
{ {
inactiveBackgroundColour = colourProvider?.Background5 ?? colours.Gray3; inactiveBackgroundColour = colourProvider?.Background5 ?? colours.Gray3;
activeBackgroundColour = colours.ForModType(mod.Type); activeBackgroundColour = colours.ForModType(Mod.Type);
inactiveForegroundColour = colourProvider?.Background2 ?? colours.Gray5; inactiveForegroundColour = colourProvider?.Background2 ?? colours.Gray5;
activeForegroundColour = Interpolation.ValueAt<Colour4>(0.1f, Colour4.Black, activeForegroundColour, 0, 1); activeForegroundColour = Interpolation.ValueAt<Colour4>(0.1f, Colour4.Black, activeForegroundColour, 0, 1);
@ -80,12 +119,37 @@ namespace osu.Game.Rulesets.UI
Active.BindValueChanged(_ => updateState(), true); Active.BindValueChanged(_ => updateState(), true);
FinishTransforms(true); FinishTransforms(true);
if (Mod is Mod actualMod)
{
modSettingsChangeTracker = new ModSettingChangeTracker(new[] { actualMod });
modSettingsChangeTracker.SettingChanged = _ => updateExtendedInformation();
}
updateExtendedInformation();
}
private void updateExtendedInformation()
{
bool showExtended = showExtendedInformation && !string.IsNullOrEmpty(Mod.ExtendedIconInformation);
extendedContent.Alpha = showExtended ? 1 : 0;
extendedText.Text = Mod.ExtendedIconInformation;
} }
private void updateState() private void updateState()
{ {
acronymText.FadeColour(Active.Value ? activeForegroundColour : inactiveForegroundColour, 200, Easing.OutQuint); acronymText.FadeColour(Active.Value ? activeForegroundColour : inactiveForegroundColour, 200, Easing.OutQuint);
background.FadeColour(Active.Value ? activeBackgroundColour : inactiveBackgroundColour, 200, Easing.OutQuint); background.FadeColour(Active.Value ? activeBackgroundColour : inactiveBackgroundColour, 200, Easing.OutQuint);
extendedText.Colour = Active.Value ? activeBackgroundColour.Lighten(0.2f) : inactiveBackgroundColour;
extendedBackground.Colour = Active.Value ? activeBackgroundColour.Darken(2.4f) : inactiveBackgroundColour.Darken(2.8f);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
modSettingsChangeTracker?.Dispose();
} }
} }
} }

View File

@ -346,7 +346,7 @@ namespace osu.Game.Scoring
case HitResult.LargeBonus: case HitResult.LargeBonus:
case HitResult.SmallBonus: case HitResult.SmallBonus:
if (MaximumStatistics.TryGetValue(r.result, out int count) && count > 0) if (MaximumStatistics.TryGetValue(r.result, out int count) && count > 0)
yield return new HitResultDisplayStatistic(r.result, value, null, r.displayName); yield return new HitResultDisplayStatistic(r.result, value, count, r.displayName);
break; break;

View File

@ -7,6 +7,7 @@ using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Lounge; using osu.Game.Screens.OnlinePlay.Lounge;
@ -90,6 +91,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
protected override LoungeSubScreen CreateLounge() => new MultiplayerLoungeSubScreen(); protected override LoungeSubScreen CreateLounge() => new MultiplayerLoungeSubScreen();
public void Join(Room room, string? password) => Schedule(() => Lounge.Join(room, password));
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);

View File

@ -26,14 +26,17 @@ namespace osu.Game.Screens.OnlinePlay
[Cached] [Cached]
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum); protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
public IScreen CurrentSubScreen => screenStack.CurrentScreen;
public override bool CursorVisible => (screenStack?.CurrentScreen as IOnlinePlaySubScreen)?.CursorVisible ?? true; public override bool CursorVisible => (screenStack?.CurrentScreen as IOnlinePlaySubScreen)?.CursorVisible ?? true;
// this is required due to PlayerLoader eventually being pushed to the main stack // this is required due to PlayerLoader eventually being pushed to the main stack
// while leases may be taken out by a subscreen. // while leases may be taken out by a subscreen.
public override bool DisallowExternalBeatmapRulesetChanges => true; public override bool DisallowExternalBeatmapRulesetChanges => true;
protected LoungeSubScreen Lounge { get; private set; }
private MultiplayerWaveContainer waves; private MultiplayerWaveContainer waves;
private LoungeSubScreen loungeSubScreen;
private ScreenStack screenStack; private ScreenStack screenStack;
[Cached(Type = typeof(IRoomManager))] [Cached(Type = typeof(IRoomManager))]
@ -89,7 +92,7 @@ namespace osu.Game.Screens.OnlinePlay
screenStack.ScreenPushed += screenPushed; screenStack.ScreenPushed += screenPushed;
screenStack.ScreenExited += screenExited; screenStack.ScreenExited += screenExited;
screenStack.Push(loungeSubScreen = CreateLounge()); screenStack.Push(Lounge = CreateLounge());
apiState.BindTo(API.State); apiState.BindTo(API.State);
apiState.BindValueChanged(onlineStateChanged, true); apiState.BindValueChanged(onlineStateChanged, true);
@ -120,10 +123,10 @@ namespace osu.Game.Screens.OnlinePlay
Mods.SetDefault(); Mods.SetDefault();
if (loungeSubScreen.IsCurrentScreen()) if (Lounge.IsCurrentScreen())
loungeSubScreen.OnEntering(e); Lounge.OnEntering(e);
else else
loungeSubScreen.MakeCurrent(); Lounge.MakeCurrent();
} }
public override void OnResuming(ScreenTransitionEvent e) public override void OnResuming(ScreenTransitionEvent e)
@ -224,8 +227,6 @@ namespace osu.Game.Screens.OnlinePlay
((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity); ((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity);
} }
public IScreen CurrentSubScreen => screenStack.CurrentScreen;
protected abstract string ScreenTitle { get; } protected abstract string ScreenTitle { get; }
protected virtual RoomManager CreateRoomManager() => new RoomManager(); protected virtual RoomManager CreateRoomManager() => new RoomManager();

View File

@ -279,8 +279,10 @@ namespace osu.Game.Screens.Play
{ {
if (!this.IsCurrentScreen()) return; if (!this.IsCurrentScreen()) return;
if (PerformExit(false))
// The hotkey overlay dims the screen.
// If the operation succeeds, we want to make sure we stay dimmed to keep continuity.
fadeOut(true); fadeOut(true);
PerformExit(false);
}, },
}, },
}); });
@ -298,8 +300,10 @@ namespace osu.Game.Screens.Play
{ {
if (!this.IsCurrentScreen()) return; if (!this.IsCurrentScreen()) return;
if (Restart(true))
// The hotkey overlay dims the screen.
// If the operation succeeds, we want to make sure we stay dimmed to keep continuity.
fadeOut(true); fadeOut(true);
Restart(true);
}, },
}, },
}); });
@ -565,20 +569,9 @@ namespace osu.Game.Screens.Play
/// Whether the pause or fail dialog should be shown before performing an exit. /// Whether the pause or fail dialog should be shown before performing an exit.
/// If <see langword="true"/> and a dialog is not yet displayed, the exit will be blocked and the relevant dialog will display instead. /// If <see langword="true"/> and a dialog is not yet displayed, the exit will be blocked and the relevant dialog will display instead.
/// </param> /// </param>
protected void PerformExit(bool showDialogFirst) /// <returns>Whether this call resulted in a final exit.</returns>
protected bool PerformExit(bool showDialogFirst)
{ {
// there is a chance that an exit request occurs after the transition to results has already started.
// even in such a case, the user has shown intent, so forcefully return to this screen (to proceed with the upwards exit process).
if (!this.IsCurrentScreen())
{
ValidForResume = false;
// in the potential case that this instance has already been exited, this is required to avoid a crash.
if (this.GetChildScreen() != null)
this.MakeCurrent();
return;
}
bool pauseOrFailDialogVisible = bool pauseOrFailDialogVisible =
PauseOverlay.State.Value == Visibility.Visible || FailOverlay.State.Value == Visibility.Visible; PauseOverlay.State.Value == Visibility.Visible || FailOverlay.State.Value == Visibility.Visible;
@ -588,7 +581,7 @@ namespace osu.Game.Screens.Play
if (ValidForResume && GameplayState.HasFailed) if (ValidForResume && GameplayState.HasFailed)
{ {
failAnimationContainer.FinishTransforms(true); failAnimationContainer.FinishTransforms(true);
return; return false;
} }
// even if this call has requested a dialog, there is a chance the current player mode doesn't support pausing. // even if this call has requested a dialog, there is a chance the current player mode doesn't support pausing.
@ -597,16 +590,24 @@ namespace osu.Game.Screens.Play
// in the case a dialog needs to be shown, attempt to pause and show it. // in the case a dialog needs to be shown, attempt to pause and show it.
// this may fail (see internal checks in Pause()) but the fail cases are temporary, so don't fall through to Exit(). // this may fail (see internal checks in Pause()) but the fail cases are temporary, so don't fall through to Exit().
Pause(); Pause();
return; return false;
} }
} }
// if an exit has been requested, cancel any pending completion (the user has shown intention to exit). // Matching osu!stable behaviour, if the results screen is pending and the user requests an exit,
resultsDisplayDelegate?.Cancel(); // show the results instead.
if (GameplayState.HasPassed && !isRestarting)
{
progressToResults(false);
return false;
}
// import current score if possible. // import current score if possible.
prepareAndImportScoreAsync(); prepareAndImportScoreAsync();
// Screen may not be current if a restart has been performed.
if (this.IsCurrentScreen())
{
// The actual exit is performed if // The actual exit is performed if
// - the pause / fail dialog was not requested // - the pause / fail dialog was not requested
// - the pause / fail dialog was requested but is already displayed (user showing intention to exit). // - the pause / fail dialog was requested but is already displayed (user showing intention to exit).
@ -614,6 +615,9 @@ namespace osu.Game.Screens.Play
this.Exit(); this.Exit();
} }
return true;
}
private void performUserRequestedSkip() private void performUserRequestedSkip()
{ {
// user requested skip // user requested skip
@ -660,10 +664,11 @@ namespace osu.Game.Screens.Play
/// <remarks>This can be called from a child screen in order to trigger the restart process.</remarks> /// <remarks>This can be called from a child screen in order to trigger the restart process.</remarks>
/// </summary> /// </summary>
/// <param name="quickRestart">Whether a quick restart was requested (skipping intro etc.).</param> /// <param name="quickRestart">Whether a quick restart was requested (skipping intro etc.).</param>
public void Restart(bool quickRestart = false) /// <returns>Whether this call resulted in a restart.</returns>
public bool Restart(bool quickRestart = false)
{ {
if (!Configuration.AllowRestart) if (!Configuration.AllowRestart)
return; return false;
isRestarting = true; isRestarting = true;
@ -673,7 +678,7 @@ namespace osu.Game.Screens.Play
RestartRequested?.Invoke(quickRestart); RestartRequested?.Invoke(quickRestart);
PerformExit(false); return PerformExit(false);
} }
/// <summary> /// <summary>
@ -729,9 +734,6 @@ namespace osu.Game.Screens.Play
// is no chance that a user could return to the (already completed) Player instance from a child screen. // is no chance that a user could return to the (already completed) Player instance from a child screen.
ValidForResume = false; ValidForResume = false;
if (!Configuration.ShowResults)
return;
bool storyboardStillRunning = DimmableStoryboard.ContentDisplayed && !DimmableStoryboard.HasStoryboardEnded.Value; bool storyboardStillRunning = DimmableStoryboard.ContentDisplayed && !DimmableStoryboard.HasStoryboardEnded.Value;
// If the current beatmap has a storyboard, this method will be called again on storyboard completion. // If the current beatmap has a storyboard, this method will be called again on storyboard completion.
@ -754,10 +756,16 @@ namespace osu.Game.Screens.Play
/// <param name="withDelay">Whether a minimum delay (<see cref="RESULTS_DISPLAY_DELAY"/>) should be added before the screen is displayed.</param> /// <param name="withDelay">Whether a minimum delay (<see cref="RESULTS_DISPLAY_DELAY"/>) should be added before the screen is displayed.</param>
private void progressToResults(bool withDelay) private void progressToResults(bool withDelay)
{ {
resultsDisplayDelegate?.Cancel(); if (!Configuration.ShowResults)
return;
// Setting this early in the process means that even if something were to go wrong in the order of events following, there
// is no chance that a user could return to the (already completed) Player instance from a child screen.
ValidForResume = false;
double delay = withDelay ? RESULTS_DISPLAY_DELAY : 0; double delay = withDelay ? RESULTS_DISPLAY_DELAY : 0;
resultsDisplayDelegate?.Cancel();
resultsDisplayDelegate = new ScheduledDelegate(() => resultsDisplayDelegate = new ScheduledDelegate(() =>
{ {
if (prepareScoreForDisplayTask == null) if (prepareScoreForDisplayTask == null)
@ -1200,9 +1208,12 @@ namespace osu.Game.Screens.Play
float fadeOutDuration = instant ? 0 : 250; float fadeOutDuration = instant ? 0 : 250;
this.FadeOut(fadeOutDuration); this.FadeOut(fadeOutDuration);
if (this.IsCurrentScreen())
{
ApplyToBackground(b => b.IgnoreUserSettings.Value = true); ApplyToBackground(b => b.IgnoreUserSettings.Value = true);
storyboardReplacesBackground.Value = false; storyboardReplacesBackground.Value = false;
} }
}
#endregion #endregion

View File

@ -414,6 +414,8 @@ namespace osu.Game.Screens.Play
quickRestart = quickRestartRequested; quickRestart = quickRestartRequested;
hideOverlays = true; hideOverlays = true;
ValidForResume = true; ValidForResume = true;
this.MakeCurrent();
} }
private void contentIn() private void contentIn()

View File

@ -263,6 +263,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
return Task.CompletedTask; return Task.CompletedTask;
} }
public override Task InvitePlayer(int userId)
{
return Task.CompletedTask;
}
public override Task TransferHost(int userId) public override Task TransferHost(int userId)
{ {
userId = clone(userId); userId = clone(userId);

View File

@ -3,6 +3,7 @@
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.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
@ -18,6 +19,7 @@ using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Online.Multiplayer;
namespace osu.Game.Users namespace osu.Game.Users
{ {
@ -61,6 +63,9 @@ namespace osu.Game.Users
[Resolved] [Resolved]
protected OsuColour Colours { get; private set; } = null!; protected OsuColour Colours { get; private set; } = null!;
[Resolved]
private MultiplayerClient? multiplayerClient { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -117,6 +122,16 @@ namespace osu.Game.Users
})); }));
} }
if (
// TODO: uncomment this once lazer / osu-web is updating online states
// User.IsOnline &&
multiplayerClient?.Room != null &&
multiplayerClient.Room.Users.All(u => u.UserID != User.Id)
)
{
items.Add(new OsuMenuItem(ContextMenuStrings.InvitePlayer, MenuItemType.Standard, () => multiplayerClient.InvitePlayer(User.Id)));
}
return items.ToArray(); return items.ToArray();
} }
} }

View File

@ -21,13 +21,13 @@
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="AutoMapper" Version="12.0.1" /> <PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="DiffPlex" Version="1.7.1" /> <PackageReference Include="DiffPlex" Version="1.7.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.53" /> <PackageReference Include="HtmlAgilityPack" Version="1.11.54" />
<PackageReference Include="Humanizer" Version="2.14.1" /> <PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="MessagePack" Version="2.5.124" /> <PackageReference Include="MessagePack" Version="2.5.129" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.11" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="7.0.11" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="7.0.11" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="7.0.12" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.11" /> <PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.12" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="7.1.2" /> <PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="7.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
@ -38,8 +38,8 @@
<PackageReference Include="Realm" Version="11.5.0" /> <PackageReference Include="Realm" Version="11.5.0" />
<PackageReference Include="ppy.osu.Framework" Version="2023.1012.0" /> <PackageReference Include="ppy.osu.Framework" Version="2023.1012.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2023.1003.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2023.1003.0" />
<PackageReference Include="Sentry" Version="3.39.1" /> <PackageReference Include="Sentry" Version="3.40.0" />
<PackageReference Include="SharpCompress" Version="0.33.0" /> <PackageReference Include="SharpCompress" Version="0.34.1" />
<PackageReference Include="NUnit" Version="3.13.3" /> <PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6" /> <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" /> <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />