mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 18:32:55 +08:00
Merge branch 'master' into temporary-directory-test-storage
This commit is contained in:
commit
0aea39f5f1
@ -62,6 +62,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
||||
protected override bool InterpolateMovements => !disjointTrail;
|
||||
|
||||
protected override float IntervalMultiplier => 1 / Math.Max(cursorSize.Value, 1);
|
||||
protected override bool AvoidDrawingNearCursor => !disjointTrail;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
|
@ -138,6 +138,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
||||
protected virtual bool InterpolateMovements => true;
|
||||
|
||||
protected virtual float IntervalMultiplier => 1.0f;
|
||||
protected virtual bool AvoidDrawingNearCursor => false;
|
||||
|
||||
private Vector2? lastPosition;
|
||||
private readonly InputResampler resampler = new InputResampler();
|
||||
@ -171,8 +172,9 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
||||
Vector2 direction = diff / distance;
|
||||
|
||||
float interval = partSize.X / 2.5f * IntervalMultiplier;
|
||||
float stopAt = distance - (AvoidDrawingNearCursor ? interval : 0);
|
||||
|
||||
for (float d = interval; d < distance; d += interval)
|
||||
for (float d = interval; d < stopAt; d += interval)
|
||||
{
|
||||
lastPosition = pos1 + direction * d;
|
||||
addPart(lastPosition.Value);
|
||||
|
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -32,7 +31,6 @@ namespace osu.Game.Tests.Beatmaps
|
||||
private TestBeatmapDifficultyCache difficultyCache;
|
||||
|
||||
private IBindable<StarDifficulty?> starDifficultyBindable;
|
||||
private Queue<ValueChangedEvent<StarDifficulty?>> starDifficultyChangesQueue;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osu)
|
||||
@ -49,14 +47,10 @@ namespace osu.Game.Tests.Beatmaps
|
||||
|
||||
Child = difficultyCache = new TestBeatmapDifficultyCache();
|
||||
|
||||
starDifficultyChangesQueue = new Queue<ValueChangedEvent<StarDifficulty?>>();
|
||||
starDifficultyBindable = difficultyCache.GetBindableDifficulty(importedSet.Beatmaps.First());
|
||||
starDifficultyBindable.BindValueChanged(starDifficultyChangesQueue.Enqueue);
|
||||
});
|
||||
|
||||
AddAssert($"star difficulty -> {BASE_STARS}", () =>
|
||||
starDifficultyChangesQueue.Dequeue().NewValue?.Stars == BASE_STARS &&
|
||||
starDifficultyChangesQueue.Count == 0);
|
||||
AddUntilStep($"star difficulty -> {BASE_STARS}", () => starDifficultyBindable.Value?.Stars == BASE_STARS);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -65,19 +59,13 @@ namespace osu.Game.Tests.Beatmaps
|
||||
OsuModDoubleTime dt = null;
|
||||
|
||||
AddStep("change selected mod to DT", () => SelectedMods.Value = new[] { dt = new OsuModDoubleTime { SpeedChange = { Value = 1.5 } } });
|
||||
AddAssert($"star difficulty -> {BASE_STARS + 1.5}", () =>
|
||||
starDifficultyChangesQueue.Dequeue().NewValue?.Stars == BASE_STARS + 1.5 &&
|
||||
starDifficultyChangesQueue.Count == 0);
|
||||
AddUntilStep($"star difficulty -> {BASE_STARS + 1.5}", () => starDifficultyBindable.Value?.Stars == BASE_STARS + 1.5);
|
||||
|
||||
AddStep("change DT speed to 1.25", () => dt.SpeedChange.Value = 1.25);
|
||||
AddAssert($"star difficulty -> {BASE_STARS + 1.25}", () =>
|
||||
starDifficultyChangesQueue.Dequeue().NewValue?.Stars == BASE_STARS + 1.25 &&
|
||||
starDifficultyChangesQueue.Count == 0);
|
||||
AddUntilStep($"star difficulty -> {BASE_STARS + 1.25}", () => starDifficultyBindable.Value?.Stars == BASE_STARS + 1.25);
|
||||
|
||||
AddStep("change selected mod to NC", () => SelectedMods.Value = new[] { new OsuModNightcore { SpeedChange = { Value = 1.75 } } });
|
||||
AddAssert($"star difficulty -> {BASE_STARS + 1.75}", () =>
|
||||
starDifficultyChangesQueue.Dequeue().NewValue?.Stars == BASE_STARS + 1.75 &&
|
||||
starDifficultyChangesQueue.Count == 0);
|
||||
AddUntilStep($"star difficulty -> {BASE_STARS + 1.75}", () => starDifficultyBindable.Value?.Stars == BASE_STARS + 1.75);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -0,0 +1,72 @@
|
||||
// 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 MessagePack;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||
|
||||
namespace osu.Game.Tests.Online
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestMultiplayerMessagePackSerialization
|
||||
{
|
||||
[Test]
|
||||
public void TestSerialiseRoom()
|
||||
{
|
||||
var room = new MultiplayerRoom(1)
|
||||
{
|
||||
MatchState = new TeamVersusRoomState()
|
||||
};
|
||||
|
||||
var serialized = MessagePackSerializer.Serialize(room);
|
||||
|
||||
var deserialized = MessagePackSerializer.Deserialize<MultiplayerRoom>(serialized);
|
||||
|
||||
Assert.IsTrue(deserialized.MatchState is TeamVersusRoomState);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSerialiseUserStateExpected()
|
||||
{
|
||||
var state = new TeamVersusUserState();
|
||||
|
||||
var serialized = MessagePackSerializer.Serialize(typeof(MatchUserState), state);
|
||||
var deserialized = MessagePackSerializer.Deserialize<MatchUserState>(serialized);
|
||||
|
||||
Assert.IsTrue(deserialized is TeamVersusUserState);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSerialiseUnionFailsWithSingalR()
|
||||
{
|
||||
var state = new TeamVersusUserState();
|
||||
|
||||
// SignalR serialises using the actual type, rather than a base specification.
|
||||
var serialized = MessagePackSerializer.Serialize(typeof(TeamVersusUserState), state);
|
||||
|
||||
// works with explicit type specified.
|
||||
MessagePackSerializer.Deserialize<TeamVersusUserState>(serialized);
|
||||
|
||||
// fails with base (union) type.
|
||||
Assert.Throws<MessagePackSerializationException>(() => MessagePackSerializer.Deserialize<MatchUserState>(serialized));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSerialiseUnionSucceedsWithWorkaround()
|
||||
{
|
||||
var state = new TeamVersusUserState();
|
||||
|
||||
// SignalR serialises using the actual type, rather than a base specification.
|
||||
var serialized = MessagePackSerializer.Serialize(typeof(TeamVersusUserState), state, SignalRUnionWorkaroundResolver.OPTIONS);
|
||||
|
||||
// works with explicit type specified.
|
||||
MessagePackSerializer.Deserialize<TeamVersusUserState>(serialized);
|
||||
|
||||
// works with custom resolver.
|
||||
var deserialized = MessagePackSerializer.Deserialize<MatchUserState>(serialized, SignalRUnionWorkaroundResolver.OPTIONS);
|
||||
Assert.IsTrue(deserialized is TeamVersusUserState);
|
||||
}
|
||||
}
|
||||
}
|
@ -78,6 +78,24 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
AddAssert("clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestClampWhenSeekOutsideBeatmapBounds()
|
||||
{
|
||||
AddStep("stop clock", Clock.Stop);
|
||||
|
||||
AddStep("seek before start time", () => Clock.Seek(-1000));
|
||||
AddAssert("time is clamped to 0", () => Clock.CurrentTime == 0);
|
||||
|
||||
AddStep("seek beyond track length", () => Clock.Seek(Clock.TrackLength + 1000));
|
||||
AddAssert("time is clamped to track length", () => Clock.CurrentTime == Clock.TrackLength);
|
||||
|
||||
AddStep("seek smoothly before start time", () => Clock.SeekSmoothlyTo(-1000));
|
||||
AddAssert("time is clamped to 0", () => Clock.CurrentTime == 0);
|
||||
|
||||
AddStep("seek smoothly beyond track length", () => Clock.SeekSmoothlyTo(Clock.TrackLength + 1000));
|
||||
AddAssert("time is clamped to track length", () => Clock.CurrentTime == Clock.TrackLength);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
Beatmap.Disabled = false;
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
@ -66,7 +65,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
protected class OverlayTestPlayer : TestPlayer
|
||||
{
|
||||
public new OverlayActivation OverlayActivationMode => base.OverlayActivationMode.Value;
|
||||
public new Bindable<bool> LocalUserPlaying => base.LocalUserPlaying;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,131 @@
|
||||
// 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 Moq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Screens.Play;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneGameplayChatDisplay : MultiplayerTestScene
|
||||
{
|
||||
private GameplayChatDisplay chatDisplay;
|
||||
|
||||
[Cached(typeof(ILocalUserPlayInfo))]
|
||||
private ILocalUserPlayInfo localUserInfo;
|
||||
|
||||
private readonly Bindable<bool> localUserPlaying = new Bindable<bool>();
|
||||
|
||||
private TextBox textBox => chatDisplay.ChildrenOfType<TextBox>().First();
|
||||
|
||||
public TestSceneGameplayChatDisplay()
|
||||
{
|
||||
var mockLocalUserInfo = new Mock<ILocalUserPlayInfo>();
|
||||
mockLocalUserInfo.SetupGet(i => i.IsPlaying).Returns(localUserPlaying);
|
||||
|
||||
localUserInfo = mockLocalUserInfo.Object;
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 0.5f,
|
||||
});
|
||||
|
||||
AddStep("expand", () => chatDisplay.Expanded.Value = true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCantClickWhenPlaying()
|
||||
{
|
||||
setLocalUserPlaying(true);
|
||||
|
||||
AddStep("attempt focus chat", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(textBox);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
assertChatFocused(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFocusDroppedWhenPlaying()
|
||||
{
|
||||
assertChatFocused(false);
|
||||
|
||||
AddStep("focus chat", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(textBox);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
setLocalUserPlaying(true);
|
||||
assertChatFocused(false);
|
||||
|
||||
// should still stay non-focused even after entering a new break section.
|
||||
setLocalUserPlaying(false);
|
||||
assertChatFocused(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFocusOnTabKeyWhenExpanded()
|
||||
{
|
||||
setLocalUserPlaying(true);
|
||||
|
||||
assertChatFocused(false);
|
||||
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
||||
assertChatFocused(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFocusOnTabKeyWhenNotExpanded()
|
||||
{
|
||||
AddStep("set not expanded", () => chatDisplay.Expanded.Value = false);
|
||||
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
||||
|
||||
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
||||
assertChatFocused(true);
|
||||
AddUntilStep("is visible", () => chatDisplay.IsPresent);
|
||||
|
||||
AddStep("press enter", () => InputManager.Key(Key.Enter));
|
||||
assertChatFocused(false);
|
||||
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFocusToggleViaAction()
|
||||
{
|
||||
AddStep("set not expanded", () => chatDisplay.Expanded.Value = false);
|
||||
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
||||
|
||||
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
||||
assertChatFocused(true);
|
||||
AddUntilStep("is visible", () => chatDisplay.IsPresent);
|
||||
|
||||
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
||||
assertChatFocused(false);
|
||||
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
||||
}
|
||||
|
||||
private void assertChatFocused(bool isFocused) =>
|
||||
AddAssert($"chat {(isFocused ? "focused" : "not focused")}", () => textBox.HasFocus == isFocused);
|
||||
|
||||
private void setLocalUserPlaying(bool playing) =>
|
||||
AddStep($"local user {(playing ? "playing" : "not playing")}", () => localUserPlaying.Value = playing);
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneLoungeRoomsContainer : OnlinePlayTestScene
|
||||
{
|
||||
protected new BasicTestRoomManager RoomManager => (BasicTestRoomManager)base.RoomManager;
|
||||
protected new TestRequestHandlingRoomManager RoomManager => (TestRequestHandlingRoomManager)base.RoomManager;
|
||||
|
||||
private RoomsContainer container;
|
||||
|
||||
@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddStep("add rooms", () => RoomManager.AddRooms(3));
|
||||
|
||||
AddAssert("has 3 rooms", () => container.Rooms.Count == 3);
|
||||
AddStep("remove first room", () => RoomManager.Rooms.Remove(RoomManager.Rooms.FirstOrDefault()));
|
||||
AddStep("remove first room", () => RoomManager.RemoveRoom(RoomManager.Rooms.FirstOrDefault()));
|
||||
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
|
||||
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
|
||||
|
||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerLoungeSubScreen : OnlinePlayTestScene
|
||||
{
|
||||
protected new BasicTestRoomManager RoomManager => (BasicTestRoomManager)base.RoomManager;
|
||||
protected new TestRequestHandlingRoomManager RoomManager => (TestRequestHandlingRoomManager)base.RoomManager;
|
||||
|
||||
private LoungeSubScreen loungeScreen;
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
// 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.Testing;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerPlayer : MultiplayerTestScene
|
||||
{
|
||||
private MultiplayerPlayer player;
|
||||
|
||||
[SetUpSteps]
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("set beatmap", () =>
|
||||
{
|
||||
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
||||
});
|
||||
|
||||
AddStep("initialise gameplay", () =>
|
||||
{
|
||||
Stack.Push(player = new MultiplayerPlayer(Client.CurrentMatchPlayingItem.Value, Client.Room?.Users.ToArray()));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGameplay()
|
||||
{
|
||||
AddUntilStep("wait for gameplay start", () => player.LocalUserPlaying.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
{
|
||||
public class TestScenePlaylistsLoungeSubScreen : OnlinePlayTestScene
|
||||
{
|
||||
protected new BasicTestRoomManager RoomManager => (BasicTestRoomManager)base.RoomManager;
|
||||
protected new TestRequestHandlingRoomManager RoomManager => (TestRequestHandlingRoomManager)base.RoomManager;
|
||||
|
||||
private LoungeSubScreen loungeScreen;
|
||||
|
||||
|
@ -11,7 +11,6 @@ using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
@ -35,18 +34,6 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
{
|
||||
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
||||
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
|
||||
|
||||
((DummyAPIAccess)API).HandleRequest = req =>
|
||||
{
|
||||
switch (req)
|
||||
{
|
||||
case CreateRoomScoreRequest createRoomScoreRequest:
|
||||
createRoomScoreRequest.TriggerSuccess(new APIScoreToken { ID = 1 });
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
|
@ -76,5 +76,23 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
AddStep("restore default", () => sliderBar.Current.SetDefault());
|
||||
AddUntilStep("restore button hidden", () => restoreDefaultValueButton.Alpha == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWarningTextVisibility()
|
||||
{
|
||||
SettingsNumberBox numberBox = null;
|
||||
|
||||
AddStep("create settings item", () => Child = numberBox = new SettingsNumberBox());
|
||||
AddAssert("warning text not created", () => !numberBox.ChildrenOfType<SettingsNoticeText>().Any());
|
||||
|
||||
AddStep("set warning text", () => numberBox.WarningText = "this is a warning!");
|
||||
AddAssert("warning text created", () => numberBox.ChildrenOfType<SettingsNoticeText>().Single().Alpha == 1);
|
||||
|
||||
AddStep("unset warning text", () => numberBox.WarningText = default);
|
||||
AddAssert("warning text hidden", () => numberBox.ChildrenOfType<SettingsNoticeText>().Single().Alpha == 0);
|
||||
|
||||
AddStep("set warning text again", () => numberBox.WarningText = "another warning!");
|
||||
AddAssert("warning text shown again", () => numberBox.ChildrenOfType<SettingsNoticeText>().Single().Alpha == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -61,10 +62,12 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
));
|
||||
AddStep("scroll up", () => triggerUserScroll(1));
|
||||
AddStep("scroll down", () => triggerUserScroll(-1));
|
||||
AddStep("scroll up a bit", () => triggerUserScroll(0.1f));
|
||||
AddStep("scroll down a bit", () => triggerUserScroll(-0.1f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCorrectSectionSelected()
|
||||
public void TestCorrectSelectionAndVisibleTop()
|
||||
{
|
||||
const int sections_count = 11;
|
||||
float[] alternating = { 0.07f, 0.33f, 0.16f, 0.33f };
|
||||
@ -79,6 +82,12 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
AddStep($"scroll to section {scrollIndex + 1}", () => container.ScrollTo(container.Children[scrollIndex]));
|
||||
AddUntilStep("correct section selected", () => container.SelectedSection.Value == container.Children[scrollIndex]);
|
||||
AddUntilStep("section top is visible", () =>
|
||||
{
|
||||
float scrollPosition = container.ChildrenOfType<UserTrackingScrollContainer>().First().Current;
|
||||
float sectionTop = container.Children[scrollIndex].BoundingBox.Top;
|
||||
return scrollPosition < sectionTop;
|
||||
});
|
||||
}
|
||||
|
||||
for (int i = 1; i < sections_count; i++)
|
||||
|
@ -365,6 +365,10 @@ namespace osu.Game.Beatmaps
|
||||
queryable = beatmaps.BeatmapSetsOverview;
|
||||
break;
|
||||
|
||||
case IncludedDetails.AllButRuleset:
|
||||
queryable = beatmaps.BeatmapSetsWithoutRuleset;
|
||||
break;
|
||||
|
||||
case IncludedDetails.AllButFiles:
|
||||
queryable = beatmaps.BeatmapSetsWithoutFiles;
|
||||
break;
|
||||
@ -384,8 +388,33 @@ namespace osu.Game.Beatmaps
|
||||
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
||||
/// </summary>
|
||||
/// <param name="query">The query.</param>
|
||||
/// <param name="includes">The level of detail to include in the returned objects.</param>
|
||||
/// <returns>Results from the provided query.</returns>
|
||||
public IEnumerable<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.ConsumableItems.AsNoTracking().Where(query);
|
||||
public IEnumerable<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query, IncludedDetails includes = IncludedDetails.All)
|
||||
{
|
||||
IQueryable<BeatmapSetInfo> queryable;
|
||||
|
||||
switch (includes)
|
||||
{
|
||||
case IncludedDetails.Minimal:
|
||||
queryable = beatmaps.BeatmapSetsOverview;
|
||||
break;
|
||||
|
||||
case IncludedDetails.AllButRuleset:
|
||||
queryable = beatmaps.BeatmapSetsWithoutRuleset;
|
||||
break;
|
||||
|
||||
case IncludedDetails.AllButFiles:
|
||||
queryable = beatmaps.BeatmapSetsWithoutFiles;
|
||||
break;
|
||||
|
||||
default:
|
||||
queryable = beatmaps.ConsumableItems;
|
||||
break;
|
||||
}
|
||||
|
||||
return queryable.AsNoTracking().Where(query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
|
||||
@ -554,6 +583,11 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
AllButFiles,
|
||||
|
||||
/// <summary>
|
||||
/// Include everything except ruleset. Used for cases where we aren't sure the ruleset is present but still want to consume the beatmap.
|
||||
/// </summary>
|
||||
AllButRuleset,
|
||||
|
||||
/// <summary>
|
||||
/// Include everything.
|
||||
/// </summary>
|
||||
|
@ -92,6 +92,13 @@ namespace osu.Game.Beatmaps
|
||||
.Include(s => s.Beatmaps)
|
||||
.AsNoTracking();
|
||||
|
||||
public IQueryable<BeatmapSetInfo> BeatmapSetsWithoutRuleset => ContextFactory.Get().BeatmapSetInfo
|
||||
.Include(s => s.Metadata)
|
||||
.Include(s => s.Files).ThenInclude(f => f.FileInfo)
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
||||
.AsNoTracking();
|
||||
|
||||
public IQueryable<BeatmapSetInfo> BeatmapSetsWithoutFiles => ContextFactory.Get().BeatmapSetInfo
|
||||
.Include(s => s.Metadata)
|
||||
.Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset)
|
||||
|
@ -28,6 +28,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Scheduler.Add(() => GetContainingInputManager().ChangeFocus(this), false);
|
||||
}
|
||||
|
||||
public new void KillFocus() => base.KillFocus();
|
||||
|
||||
public bool HoldFocus
|
||||
{
|
||||
get => allowImmediateFocus && focus;
|
||||
|
@ -149,7 +149,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
glowColour = value;
|
||||
|
||||
var effect = EdgeEffect;
|
||||
effect.Colour = value;
|
||||
effect.Colour = Glowing ? value : value.Opacity(0);
|
||||
EdgeEffect = effect;
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ namespace osu.Game.Input.Bindings
|
||||
new KeyBinding(InputKey.Left, GlobalAction.SeekReplayBackward),
|
||||
new KeyBinding(InputKey.Right, GlobalAction.SeekReplayForward),
|
||||
new KeyBinding(InputKey.Control, GlobalAction.HoldForHUD),
|
||||
new KeyBinding(InputKey.Tab, GlobalAction.ToggleChatFocus),
|
||||
};
|
||||
|
||||
public IEnumerable<KeyBinding> SongSelectKeyBindings => new[]
|
||||
@ -280,5 +281,8 @@ namespace osu.Game.Input.Bindings
|
||||
|
||||
[Description("Seek replay backward")]
|
||||
SeekReplayBackward,
|
||||
|
||||
[Description("Toggle chat focus")]
|
||||
ToggleChatFocus
|
||||
}
|
||||
}
|
||||
|
@ -305,9 +305,11 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
req.Perform(this);
|
||||
|
||||
if (req.CompletionState != APIRequestCompletionState.Completed)
|
||||
return false;
|
||||
|
||||
// we could still be in initialisation, at which point we don't want to say we're Online yet.
|
||||
if (IsLoggedIn) state.Value = APIState.Online;
|
||||
|
||||
failureCount = 0;
|
||||
return true;
|
||||
}
|
||||
@ -381,7 +383,7 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLoggedIn => localUser.Value.Id > 1;
|
||||
public bool IsLoggedIn => localUser.Value.Id > 1; // TODO: should this also be true if attempting to connect?
|
||||
|
||||
public void Queue(APIRequest request)
|
||||
{
|
||||
|
@ -84,7 +84,7 @@ namespace osu.Game.Online.API
|
||||
/// The state of this request, from an outside perspective.
|
||||
/// This is used to ensure correct notification events are fired.
|
||||
/// </summary>
|
||||
private APIRequestCompletionState completionState;
|
||||
public APIRequestCompletionState CompletionState { get; private set; }
|
||||
|
||||
public void Perform(IAPIProvider api)
|
||||
{
|
||||
@ -127,10 +127,10 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
lock (completionStateLock)
|
||||
{
|
||||
if (completionState != APIRequestCompletionState.Waiting)
|
||||
if (CompletionState != APIRequestCompletionState.Waiting)
|
||||
return;
|
||||
|
||||
completionState = APIRequestCompletionState.Completed;
|
||||
CompletionState = APIRequestCompletionState.Completed;
|
||||
}
|
||||
|
||||
if (API == null)
|
||||
@ -143,10 +143,10 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
lock (completionStateLock)
|
||||
{
|
||||
if (completionState != APIRequestCompletionState.Waiting)
|
||||
if (CompletionState != APIRequestCompletionState.Waiting)
|
||||
return;
|
||||
|
||||
completionState = APIRequestCompletionState.Failed;
|
||||
CompletionState = APIRequestCompletionState.Failed;
|
||||
}
|
||||
|
||||
if (API == null)
|
||||
@ -161,7 +161,7 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
lock (completionStateLock)
|
||||
{
|
||||
if (completionState != APIRequestCompletionState.Waiting)
|
||||
if (CompletionState != APIRequestCompletionState.Waiting)
|
||||
return;
|
||||
|
||||
WebRequest?.Abort();
|
||||
@ -200,7 +200,7 @@ namespace osu.Game.Online.API
|
||||
get
|
||||
{
|
||||
lock (completionStateLock)
|
||||
return completionState == APIRequestCompletionState.Failed;
|
||||
return CompletionState == APIRequestCompletionState.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays.Chat;
|
||||
@ -22,7 +23,7 @@ namespace osu.Game.Online.Chat
|
||||
{
|
||||
public readonly Bindable<Channel> Channel = new Bindable<Channel>();
|
||||
|
||||
private readonly FocusedTextBox textbox;
|
||||
protected readonly ChatTextBox Textbox;
|
||||
|
||||
protected ChannelManager ChannelManager;
|
||||
|
||||
@ -30,6 +31,8 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
private readonly bool postingTextbox;
|
||||
|
||||
protected readonly Box Background;
|
||||
|
||||
private const float textbox_height = 30;
|
||||
|
||||
/// <summary>
|
||||
@ -44,7 +47,7 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
Background = new Box
|
||||
{
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.8f,
|
||||
@ -54,7 +57,7 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
if (postingTextbox)
|
||||
{
|
||||
AddInternal(textbox = new FocusedTextBox
|
||||
AddInternal(Textbox = new ChatTextBox
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = textbox_height,
|
||||
@ -65,7 +68,7 @@ namespace osu.Game.Online.Chat
|
||||
Origin = Anchor.BottomLeft,
|
||||
});
|
||||
|
||||
textbox.OnCommit += postMessage;
|
||||
Textbox.OnCommit += postMessage;
|
||||
}
|
||||
|
||||
Channel.BindValueChanged(channelChanged);
|
||||
@ -82,7 +85,7 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
private void postMessage(TextBox sender, bool newtext)
|
||||
{
|
||||
var text = textbox.Text.Trim();
|
||||
var text = Textbox.Text.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
return;
|
||||
@ -92,7 +95,7 @@ namespace osu.Game.Online.Chat
|
||||
else
|
||||
ChannelManager?.PostMessage(text, target: Channel.Value);
|
||||
|
||||
textbox.Text = string.Empty;
|
||||
Textbox.Text = string.Empty;
|
||||
}
|
||||
|
||||
protected virtual ChatLine CreateMessage(Message message) => new StandAloneMessage(message);
|
||||
@ -110,6 +113,25 @@ namespace osu.Game.Online.Chat
|
||||
AddInternal(drawableChannel);
|
||||
}
|
||||
|
||||
public class ChatTextBox : FocusedTextBox
|
||||
{
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
BackgroundUnfocused = new Color4(10, 10, 10, 10);
|
||||
BackgroundFocused = new Color4(10, 10, 10, 255);
|
||||
}
|
||||
|
||||
protected override void OnFocusLost(FocusLostEvent e)
|
||||
{
|
||||
base.OnFocusLost(e);
|
||||
FocusLost?.Invoke();
|
||||
}
|
||||
|
||||
public Action FocusLost;
|
||||
}
|
||||
|
||||
public class StandAloneDrawableChannel : DrawableChannel
|
||||
{
|
||||
public Func<Message, ChatLine> CreateChatLineAction;
|
||||
|
@ -148,7 +148,12 @@ namespace osu.Game.Online
|
||||
});
|
||||
|
||||
if (RuntimeInfo.SupportsJIT && preferMessagePack)
|
||||
builder.AddMessagePackProtocol();
|
||||
{
|
||||
builder.AddMessagePackProtocol(options =>
|
||||
{
|
||||
options.SerializerOptions = SignalRUnionWorkaroundResolver.OPTIONS;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// eventually we will precompile resolvers for messagepack, but this isn't working currently
|
||||
|
@ -15,9 +15,9 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[MessagePackObject]
|
||||
[Union(0, typeof(TeamVersusRoomState))]
|
||||
// TODO: this will need to be abstract or interface when/if we get messagepack working. for now it isn't as it breaks json serialisation.
|
||||
public class MatchRoomState
|
||||
[Union(0, typeof(TeamVersusRoomState))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
||||
// TODO: abstract breaks json serialisation. attention will be required for iOS support (unless we get messagepack AOT working instead).
|
||||
public abstract class MatchRoomState
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using MessagePack;
|
||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
@ -11,6 +12,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[MessagePackObject]
|
||||
[Union(0, typeof(ChangeTeamRequest))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
||||
public abstract class MatchUserRequest
|
||||
{
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[MessagePackObject]
|
||||
[Union(0, typeof(TeamVersusUserState))]
|
||||
// TODO: this will need to be abstract or interface when/if we get messagepack working. for now it isn't as it breaks json serialisation.
|
||||
public class MatchUserState
|
||||
[Union(0, typeof(TeamVersusUserState))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
||||
// TODO: abstract breaks json serialisation. attention will be required for iOS support (unless we get messagepack AOT working instead).
|
||||
public abstract class MatchUserState
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
// Importantly, we are intentionally not using MessagePack here to correctly support derived class serialization.
|
||||
// More information on the limitations / reasoning can be found in osu-server-spectator's initialisation code.
|
||||
connector = api.GetHubConnector(nameof(OnlineMultiplayerClient), endpoint, false);
|
||||
connector = api.GetHubConnector(nameof(OnlineMultiplayerClient), endpoint);
|
||||
|
||||
if (connector != null)
|
||||
{
|
||||
|
61
osu.Game/Online/SignalRUnionWorkaroundResolver.cs
Normal file
61
osu.Game/Online/SignalRUnionWorkaroundResolver.cs
Normal file
@ -0,0 +1,61 @@
|
||||
// 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.Collections.Generic;
|
||||
using MessagePack;
|
||||
using MessagePack.Formatters;
|
||||
using MessagePack.Resolvers;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||
|
||||
namespace osu.Game.Online
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles SignalR being unable to comprehend [Union] types correctly by redirecting to a known base (union) type.
|
||||
/// See https://github.com/dotnet/aspnetcore/issues/7298.
|
||||
/// </summary>
|
||||
public class SignalRUnionWorkaroundResolver : IFormatterResolver
|
||||
{
|
||||
public static readonly MessagePackSerializerOptions OPTIONS =
|
||||
MessagePackSerializerOptions.Standard.WithResolver(new SignalRUnionWorkaroundResolver());
|
||||
|
||||
private static readonly Dictionary<Type, IMessagePackFormatter> formatter_map = new Dictionary<Type, IMessagePackFormatter>
|
||||
{
|
||||
{ typeof(TeamVersusUserState), new TypeRedirectingFormatter<TeamVersusUserState, MatchUserState>() },
|
||||
{ typeof(TeamVersusRoomState), new TypeRedirectingFormatter<TeamVersusRoomState, MatchRoomState>() },
|
||||
{ typeof(ChangeTeamRequest), new TypeRedirectingFormatter<ChangeTeamRequest, MatchUserRequest>() },
|
||||
|
||||
// These should not be required. The fallback should work. But something is weird with the way caching is done.
|
||||
// For future adventurers, I would not advise looking into this further. It's likely not worth the effort.
|
||||
{ typeof(MatchUserState), new TypeRedirectingFormatter<MatchUserState, MatchUserState>() },
|
||||
{ typeof(MatchRoomState), new TypeRedirectingFormatter<MatchRoomState, MatchRoomState>() },
|
||||
{ typeof(MatchUserRequest), new TypeRedirectingFormatter<MatchUserRequest, MatchUserRequest>() },
|
||||
{ typeof(MatchServerEvent), new TypeRedirectingFormatter<MatchServerEvent, MatchServerEvent>() },
|
||||
};
|
||||
|
||||
public IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
if (formatter_map.TryGetValue(typeof(T), out var formatter))
|
||||
return (IMessagePackFormatter<T>)formatter;
|
||||
|
||||
return StandardResolver.Instance.GetFormatter<T>();
|
||||
}
|
||||
|
||||
public class TypeRedirectingFormatter<TActual, TBase> : IMessagePackFormatter<TActual>
|
||||
{
|
||||
private readonly IMessagePackFormatter<TBase> baseFormatter;
|
||||
|
||||
public TypeRedirectingFormatter()
|
||||
{
|
||||
baseFormatter = StandardResolver.Instance.GetFormatter<TBase>();
|
||||
}
|
||||
|
||||
public void Serialize(ref MessagePackWriter writer, TActual value, MessagePackSerializerOptions options) =>
|
||||
baseFormatter.Serialize(ref writer, (TBase)(object)value, StandardResolver.Options);
|
||||
|
||||
public TActual Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) =>
|
||||
(TActual)(object)baseFormatter.Deserialize(ref reader, StandardResolver.Options);
|
||||
}
|
||||
}
|
||||
}
|
@ -65,7 +65,7 @@ namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
set
|
||||
{
|
||||
bool hasValue = string.IsNullOrWhiteSpace(value.ToString());
|
||||
bool hasValue = !string.IsNullOrWhiteSpace(value.ToString());
|
||||
|
||||
if (warningText == null)
|
||||
{
|
||||
@ -76,7 +76,7 @@ namespace osu.Game.Overlays.Settings
|
||||
FlowContent.Add(warningText = new SettingsNoticeText(colours) { Margin = new MarginPadding { Bottom = 5 } });
|
||||
}
|
||||
|
||||
warningText.Alpha = hasValue ? 0 : 1;
|
||||
warningText.Alpha = hasValue ? 1 : 0;
|
||||
warningText.Text = value.ToString(); // TODO: Remove ToString() call after TextFlowContainer supports localisation (see https://github.com/ppy/osu-framework/issues/4636).
|
||||
}
|
||||
}
|
||||
|
@ -150,8 +150,6 @@ namespace osu.Game.Screens.Edit
|
||||
if (seekTime < timingPoint.Time && timingPoint != ControlPointInfo.TimingPoints.First())
|
||||
seekTime = timingPoint.Time;
|
||||
|
||||
// Ensure the sought point is within the boundaries
|
||||
seekTime = Math.Clamp(seekTime, 0, TrackLength);
|
||||
SeekSmoothlyTo(seekTime);
|
||||
}
|
||||
|
||||
@ -190,6 +188,9 @@ namespace osu.Game.Screens.Edit
|
||||
seekingOrStopped.Value = IsSeeking = true;
|
||||
|
||||
ClearTransforms();
|
||||
|
||||
// Ensure the sought point is within the boundaries
|
||||
position = Math.Clamp(position, 0, TrackLength);
|
||||
return underlyingClock.Seek(position);
|
||||
}
|
||||
|
||||
@ -288,7 +289,7 @@ namespace osu.Game.Screens.Edit
|
||||
}
|
||||
|
||||
private void transformSeekTo(double seek, double duration = 0, Easing easing = Easing.None)
|
||||
=> this.TransformTo(this.PopulateTransform(new TransformSeek(), seek, duration, easing));
|
||||
=> this.TransformTo(this.PopulateTransform(new TransformSeek(), Math.Clamp(seek, 0, TrackLength), duration, easing));
|
||||
|
||||
private double currentTime
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
@ -109,7 +110,7 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
bool loadThemedIntro()
|
||||
{
|
||||
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapHash);
|
||||
setInfo = beatmaps.QueryBeatmapSets(b => b.Hash == BeatmapHash, IncludedDetails.AllButRuleset).FirstOrDefault();
|
||||
|
||||
if (setInfo == null)
|
||||
return false;
|
||||
|
@ -172,8 +172,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
|
||||
sampleJoin?.Play();
|
||||
lounge?.Join(Room, null);
|
||||
|
||||
return base.OnClick(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
public class PasswordEntryPopover : OsuPopover
|
||||
|
@ -76,6 +76,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load([CanBeNull] IdleTracker idleTracker)
|
||||
{
|
||||
const float controls_area_height = 25f;
|
||||
|
||||
if (idleTracker != null)
|
||||
isIdle.BindTo(idleTracker.IsIdle);
|
||||
|
||||
@ -84,86 +86,73 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
ListingPollingComponent = CreatePollingComponent().With(c => c.Filter.BindTarget = filter),
|
||||
loadingLayer = new LoadingLayer(true),
|
||||
new Container
|
||||
{
|
||||
Name = @"Rooms area",
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding
|
||||
{
|
||||
Left = WaveOverlayContainer.WIDTH_PADDING,
|
||||
Right = WaveOverlayContainer.WIDTH_PADDING,
|
||||
Horizontal = WaveOverlayContainer.WIDTH_PADDING,
|
||||
Top = Header.HEIGHT + controls_area_height + 20,
|
||||
},
|
||||
Child = new GridContainer
|
||||
Child = scrollContainer = new OsuScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RowDimensions = new[]
|
||||
ScrollbarOverlapsContent = false,
|
||||
Child = roomsContainer = new RoomsContainer
|
||||
{
|
||||
new Dimension(GridSizeMode.Absolute, Header.HEIGHT),
|
||||
new Dimension(GridSizeMode.Absolute, 25),
|
||||
new Dimension(GridSizeMode.Absolute, 20)
|
||||
Filter = { BindTarget = filter }
|
||||
}
|
||||
},
|
||||
},
|
||||
loadingLayer = new LoadingLayer(true),
|
||||
new FillFlowContainer
|
||||
{
|
||||
Name = @"Header area flow",
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Horizontal = WaveOverlayContainer.WIDTH_PADDING },
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = Header.HEIGHT,
|
||||
Child = searchTextBox = new LoungeSearchTextBox
|
||||
{
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Width = 0.6f,
|
||||
},
|
||||
},
|
||||
Content = new[]
|
||||
new Container
|
||||
{
|
||||
new Drawable[]
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = controls_area_height,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
searchTextBox = new LoungeSearchTextBox
|
||||
Buttons.WithChild(CreateNewRoomButton().With(d =>
|
||||
{
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Width = 0.6f,
|
||||
},
|
||||
},
|
||||
new Drawable[]
|
||||
{
|
||||
new Container
|
||||
d.Anchor = Anchor.BottomLeft;
|
||||
d.Origin = Anchor.BottomLeft;
|
||||
d.Size = new Vector2(150, 37.5f);
|
||||
d.Action = () => Open();
|
||||
})),
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Depth = float.MinValue, // Contained filters should appear over the top of rooms.
|
||||
Children = new Drawable[]
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(10),
|
||||
ChildrenEnumerable = CreateFilterControls().Select(f => f.With(d =>
|
||||
{
|
||||
Buttons.WithChild(CreateNewRoomButton().With(d =>
|
||||
{
|
||||
d.Anchor = Anchor.BottomLeft;
|
||||
d.Origin = Anchor.BottomLeft;
|
||||
d.Size = new Vector2(150, 37.5f);
|
||||
d.Action = () => Open();
|
||||
})),
|
||||
new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(10),
|
||||
ChildrenEnumerable = CreateFilterControls().Select(f => f.With(d =>
|
||||
{
|
||||
d.Anchor = Anchor.TopRight;
|
||||
d.Origin = Anchor.TopRight;
|
||||
}))
|
||||
}
|
||||
}
|
||||
d.Anchor = Anchor.TopRight;
|
||||
d.Origin = Anchor.TopRight;
|
||||
}))
|
||||
}
|
||||
},
|
||||
null,
|
||||
new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
scrollContainer = new OsuScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
ScrollbarOverlapsContent = false,
|
||||
Child = roomsContainer = new RoomsContainer
|
||||
{
|
||||
Filter = { BindTarget = filter }
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -19,9 +19,12 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
[Resolved(CanBeNull = true)]
|
||||
private ChannelManager channelManager { get; set; }
|
||||
|
||||
public MatchChatDisplay()
|
||||
private readonly bool leaveChannelOnDispose;
|
||||
|
||||
public MatchChatDisplay(bool leaveChannelOnDispose = true)
|
||||
: base(true)
|
||||
{
|
||||
this.leaveChannelOnDispose = leaveChannelOnDispose;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -42,7 +45,9 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
channelManager?.LeaveChannel(Channel.Value);
|
||||
|
||||
if (leaveChannelOnDispose)
|
||||
channelManager?.LeaveChannel(Channel.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
111
osu.Game/Screens/OnlinePlay/Multiplayer/GameplayChatDisplay.cs
Normal file
111
osu.Game/Screens/OnlinePlay/Multiplayer/GameplayChatDisplay.cs
Normal file
@ -0,0 +1,111 @@
|
||||
// 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.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||
using osu.Game.Screens.Play;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
public class GameplayChatDisplay : MatchChatDisplay, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
[Resolved]
|
||||
private ILocalUserPlayInfo localUserInfo { get; set; }
|
||||
|
||||
private IBindable<bool> localUserPlaying = new Bindable<bool>();
|
||||
|
||||
public override bool PropagatePositionalInputSubTree => !localUserPlaying.Value;
|
||||
|
||||
public Bindable<bool> Expanded = new Bindable<bool>();
|
||||
|
||||
private readonly Bindable<bool> expandedFromTextboxFocus = new Bindable<bool>();
|
||||
|
||||
private const float height = 100;
|
||||
|
||||
public override bool PropagateNonPositionalInputSubTree => true;
|
||||
|
||||
public GameplayChatDisplay()
|
||||
: base(leaveChannelOnDispose: false)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
||||
Background.Alpha = 0.2f;
|
||||
|
||||
Textbox.FocusLost = () => expandedFromTextboxFocus.Value = false;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
localUserPlaying = localUserInfo.IsPlaying.GetBoundCopy();
|
||||
localUserPlaying.BindValueChanged(playing =>
|
||||
{
|
||||
// for now let's never hold focus. this avoid misdirected gameplay keys entering chat.
|
||||
// note that this is done within this callback as it triggers an un-focus as well.
|
||||
Textbox.HoldFocus = false;
|
||||
|
||||
// only hold focus (after sending a message) during breaks
|
||||
Textbox.ReleaseFocusOnCommit = playing.NewValue;
|
||||
}, true);
|
||||
|
||||
Expanded.BindValueChanged(_ => updateExpandedState(), true);
|
||||
expandedFromTextboxFocus.BindValueChanged(focus =>
|
||||
{
|
||||
if (focus.NewValue)
|
||||
updateExpandedState();
|
||||
else
|
||||
{
|
||||
// on finishing typing a message there should be a brief delay before hiding.
|
||||
using (BeginDelayedSequence(600))
|
||||
updateExpandedState();
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.ToggleChatFocus:
|
||||
if (Textbox.HasFocus)
|
||||
{
|
||||
Schedule(() => Textbox.KillFocus());
|
||||
}
|
||||
else
|
||||
{
|
||||
expandedFromTextboxFocus.Value = true;
|
||||
|
||||
// schedule required to ensure the textbox has become present from above bindable update.
|
||||
Schedule(() => Textbox.TakeFocus());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(GlobalAction action)
|
||||
{
|
||||
}
|
||||
|
||||
private void updateExpandedState()
|
||||
{
|
||||
if (Expanded.Value || expandedFromTextboxFocus.Value)
|
||||
{
|
||||
this.FadeIn(300, Easing.OutQuint);
|
||||
this.ResizeHeightTo(height, 500, Easing.OutQuint);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.FadeOut(300, Easing.OutQuint);
|
||||
this.ResizeHeightTo(0, 500, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -68,6 +68,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(5)
|
||||
});
|
||||
|
||||
// todo: this should be implemented via a custom HUD implementation, and correctly masked to the main content area.
|
||||
@ -78,7 +79,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
|
||||
((IBindable<bool>)leaderboard.Expanded).BindTo(HUDOverlay.ShowHud);
|
||||
|
||||
leaderboardFlow.Add(l);
|
||||
leaderboardFlow.Insert(0, l);
|
||||
|
||||
if (leaderboard.TeamScores.Count >= 2)
|
||||
{
|
||||
@ -87,10 +88,15 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
Team1Score = { BindTarget = leaderboard.TeamScores.First().Value },
|
||||
Team2Score = { BindTarget = leaderboard.TeamScores.Last().Value },
|
||||
Expanded = { BindTarget = HUDOverlay.ShowHud },
|
||||
}, leaderboardFlow.Add);
|
||||
}, scoreDisplay => leaderboardFlow.Insert(1, scoreDisplay));
|
||||
}
|
||||
});
|
||||
|
||||
LoadComponentAsync(new GameplayChatDisplay
|
||||
{
|
||||
Expanded = { BindTarget = HUDOverlay.ShowHud },
|
||||
}, chat => leaderboardFlow.Insert(2, chat));
|
||||
|
||||
HUDOverlay.Add(loadingDisplay = new LoadingLayer(true) { Depth = float.MaxValue });
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,9 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private readonly Bindable<bool> storyboardReplacesBackground = new Bindable<bool>();
|
||||
|
||||
protected readonly Bindable<bool> LocalUserPlaying = new Bindable<bool>();
|
||||
public IBindable<bool> LocalUserPlaying => localUserPlaying;
|
||||
|
||||
private readonly Bindable<bool> localUserPlaying = new Bindable<bool>();
|
||||
|
||||
public int RestartCount;
|
||||
|
||||
@ -442,7 +444,7 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
bool inGameplay = !DrawableRuleset.HasReplayLoaded.Value && !DrawableRuleset.IsPaused.Value && !breakTracker.IsBreakTime.Value;
|
||||
OverlayActivationMode.Value = inGameplay ? OverlayActivation.Disabled : OverlayActivation.UserTriggered;
|
||||
LocalUserPlaying.Value = inGameplay;
|
||||
localUserPlaying.Value = inGameplay;
|
||||
}
|
||||
|
||||
private void updateSampleDisabledState()
|
||||
|
@ -1,150 +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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="RoomManager"/> for use in multiplayer test scenes. Should generally not be used by itself outside of a <see cref="MultiplayerTestScene"/>.
|
||||
/// A <see cref="RoomManager"/> for use in multiplayer test scenes, backed by a <see cref="TestRoomRequestsHandler"/>.
|
||||
/// Should generally not be used by itself outside of a <see cref="MultiplayerTestScene"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This implementation will pretend to be a server, handling room retrieval and manipulation requests
|
||||
/// and returning a roughly expected state, without the need for a server to be running.
|
||||
/// </remarks>
|
||||
public class TestRequestHandlingMultiplayerRoomManager : MultiplayerRoomManager
|
||||
{
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
public IReadOnlyList<Room> ServerSideRooms => handler.ServerSideRooms;
|
||||
|
||||
[Resolved]
|
||||
private OsuGameBase game { get; set; }
|
||||
|
||||
public IReadOnlyList<Room> ServerSideRooms => serverSideRooms;
|
||||
private readonly List<Room> serverSideRooms = new List<Room>();
|
||||
|
||||
private int currentRoomId;
|
||||
private int currentPlaylistItemId;
|
||||
private readonly TestRoomRequestsHandler handler = new TestRoomRequestsHandler();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(IAPIProvider api, OsuGameBase game)
|
||||
{
|
||||
int currentScoreId = 0;
|
||||
|
||||
// Handling here is pretending to be a server, while also updating the local state to match
|
||||
// how the server would eventually respond and update the RoomManager.
|
||||
((DummyAPIAccess)api).HandleRequest = req =>
|
||||
{
|
||||
switch (req)
|
||||
{
|
||||
case CreateRoomRequest createRoomRequest:
|
||||
var apiRoom = new Room();
|
||||
|
||||
apiRoom.CopyFrom(createRoomRequest.Room);
|
||||
|
||||
// Passwords are explicitly not copied between rooms.
|
||||
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
|
||||
apiRoom.Password.Value = createRoomRequest.Room.Password.Value;
|
||||
|
||||
AddServerSideRoom(apiRoom);
|
||||
|
||||
var responseRoom = new APICreatedRoom();
|
||||
responseRoom.CopyFrom(createResponseRoom(apiRoom, false));
|
||||
|
||||
createRoomRequest.TriggerSuccess(responseRoom);
|
||||
return true;
|
||||
|
||||
case JoinRoomRequest joinRoomRequest:
|
||||
{
|
||||
var room = ServerSideRooms.Single(r => r.RoomID.Value == joinRoomRequest.Room.RoomID.Value);
|
||||
|
||||
if (joinRoomRequest.Password != room.Password.Value)
|
||||
{
|
||||
joinRoomRequest.TriggerFailure(new InvalidOperationException("Invalid password."));
|
||||
return true;
|
||||
}
|
||||
|
||||
joinRoomRequest.TriggerSuccess();
|
||||
return true;
|
||||
}
|
||||
|
||||
case PartRoomRequest partRoomRequest:
|
||||
partRoomRequest.TriggerSuccess();
|
||||
return true;
|
||||
|
||||
case GetRoomsRequest getRoomsRequest:
|
||||
var roomsWithoutParticipants = new List<Room>();
|
||||
|
||||
foreach (var r in ServerSideRooms)
|
||||
roomsWithoutParticipants.Add(createResponseRoom(r, false));
|
||||
|
||||
getRoomsRequest.TriggerSuccess(roomsWithoutParticipants);
|
||||
return true;
|
||||
|
||||
case GetRoomRequest getRoomRequest:
|
||||
getRoomRequest.TriggerSuccess(createResponseRoom(ServerSideRooms.Single(r => r.RoomID.Value == getRoomRequest.RoomId), true));
|
||||
return true;
|
||||
|
||||
case GetBeatmapSetRequest getBeatmapSetRequest:
|
||||
var onlineReq = new GetBeatmapSetRequest(getBeatmapSetRequest.ID, getBeatmapSetRequest.Type);
|
||||
onlineReq.Success += res => getBeatmapSetRequest.TriggerSuccess(res);
|
||||
onlineReq.Failure += e => getBeatmapSetRequest.TriggerFailure(e);
|
||||
|
||||
// Get the online API from the game's dependencies.
|
||||
game.Dependencies.Get<IAPIProvider>().Queue(onlineReq);
|
||||
return true;
|
||||
|
||||
case CreateRoomScoreRequest createRoomScoreRequest:
|
||||
createRoomScoreRequest.TriggerSuccess(new APIScoreToken { ID = 1 });
|
||||
return true;
|
||||
|
||||
case SubmitRoomScoreRequest submitRoomScoreRequest:
|
||||
submitRoomScoreRequest.TriggerSuccess(new MultiplayerScore
|
||||
{
|
||||
ID = currentScoreId++,
|
||||
Accuracy = 1,
|
||||
EndedAt = DateTimeOffset.Now,
|
||||
Passed = true,
|
||||
Rank = ScoreRank.S,
|
||||
MaxCombo = 1000,
|
||||
TotalScore = 1000000,
|
||||
User = api.LocalUser.Value,
|
||||
Statistics = new Dictionary<HitResult, int>()
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
((DummyAPIAccess)api).HandleRequest = request => handler.HandleRequest(request, api.LocalUser.Value, game);
|
||||
}
|
||||
|
||||
public void AddServerSideRoom(Room room)
|
||||
{
|
||||
room.RoomID.Value ??= currentRoomId++;
|
||||
for (int i = 0; i < room.Playlist.Count; i++)
|
||||
room.Playlist[i].ID = currentPlaylistItemId++;
|
||||
|
||||
serverSideRooms.Add(room);
|
||||
}
|
||||
|
||||
private Room createResponseRoom(Room room, bool withParticipants)
|
||||
{
|
||||
var responseRoom = new Room();
|
||||
responseRoom.CopyFrom(room);
|
||||
responseRoom.Password.Value = null;
|
||||
if (!withParticipants)
|
||||
responseRoom.RecentParticipants.Clear();
|
||||
return responseRoom;
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds a room to a local "server-side" list that's returned when a <see cref="GetRoomsRequest"/> is fired.
|
||||
/// </summary>
|
||||
/// <param name="room">The room.</param>
|
||||
public void AddServerSideRoom(Room room) => handler.AddServerSideRoom(room);
|
||||
}
|
||||
}
|
||||
|
@ -1,111 +0,0 @@
|
||||
// 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.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.OnlinePlay;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
{
|
||||
/// <summary>
|
||||
/// A very simple <see cref="RoomManager"/> for use in online play test scenes.
|
||||
/// </summary>
|
||||
public class BasicTestRoomManager : IRoomManager
|
||||
{
|
||||
public event Action RoomsUpdated;
|
||||
|
||||
public readonly BindableList<Room> Rooms = new BindableList<Room>();
|
||||
|
||||
public Action<Room, string> JoinRoomRequested;
|
||||
|
||||
public IBindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
|
||||
|
||||
IBindableList<Room> IRoomManager.Rooms => Rooms;
|
||||
|
||||
private int currentRoomId;
|
||||
|
||||
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||
{
|
||||
room.RoomID.Value ??= Rooms.Select(r => r.RoomID.Value).Where(id => id != null).Select(id => id.Value).DefaultIfEmpty().Max() + 1;
|
||||
onSuccess?.Invoke(room);
|
||||
|
||||
AddOrUpdateRoom(room);
|
||||
}
|
||||
|
||||
public void AddOrUpdateRoom(Room room)
|
||||
{
|
||||
var existing = Rooms.FirstOrDefault(r => r.RoomID.Value != null && r.RoomID.Value == room.RoomID.Value);
|
||||
|
||||
if (existing != null)
|
||||
existing.CopyFrom(room);
|
||||
else
|
||||
Rooms.Add(room);
|
||||
|
||||
RoomsUpdated?.Invoke();
|
||||
}
|
||||
|
||||
public void RemoveRoom(Room room)
|
||||
{
|
||||
Rooms.Remove(room);
|
||||
RoomsUpdated?.Invoke();
|
||||
}
|
||||
|
||||
public void ClearRooms()
|
||||
{
|
||||
Rooms.Clear();
|
||||
RoomsUpdated?.Invoke();
|
||||
}
|
||||
|
||||
public void JoinRoom(Room room, string password, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||
{
|
||||
JoinRoomRequested?.Invoke(room, password);
|
||||
onSuccess?.Invoke(room);
|
||||
}
|
||||
|
||||
public void PartRoom()
|
||||
{
|
||||
}
|
||||
|
||||
public void AddRooms(int count, RulesetInfo ruleset = null, bool withPassword = false)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var room = new Room
|
||||
{
|
||||
RoomID = { Value = currentRoomId },
|
||||
Position = { Value = currentRoomId },
|
||||
Name = { Value = $"Room {currentRoomId}" },
|
||||
Host = { Value = new User { Username = "Host" } },
|
||||
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
|
||||
Category = { Value = i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal },
|
||||
Password = { Value = withPassword ? "password" : string.Empty }
|
||||
};
|
||||
|
||||
if (ruleset != null)
|
||||
{
|
||||
room.Playlist.Add(new PlaylistItem
|
||||
{
|
||||
Ruleset = { Value = ruleset },
|
||||
Beatmap =
|
||||
{
|
||||
Value = new BeatmapInfo
|
||||
{
|
||||
Metadata = new BeatmapMetadata()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
CreateRoom(room);
|
||||
|
||||
currentRoomId++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -71,6 +71,6 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
drawableComponents.Add(drawable);
|
||||
}
|
||||
|
||||
protected virtual IRoomManager CreateRoomManager() => new BasicTestRoomManager();
|
||||
protected virtual IRoomManager CreateRoomManager() => new TestRequestHandlingRoomManager();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
// 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.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
{
|
||||
/// <summary>
|
||||
/// A very simple <see cref="RoomManager"/> for use in online play test scenes.
|
||||
/// </summary>
|
||||
public class TestRequestHandlingRoomManager : RoomManager
|
||||
{
|
||||
public Action<Room, string> JoinRoomRequested;
|
||||
|
||||
private int currentRoomId;
|
||||
|
||||
private readonly TestRoomRequestsHandler handler = new TestRoomRequestsHandler();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IAPIProvider api, OsuGameBase game)
|
||||
{
|
||||
((DummyAPIAccess)api).HandleRequest = request => handler.HandleRequest(request, api.LocalUser.Value, game);
|
||||
}
|
||||
|
||||
public override void JoinRoom(Room room, string password = null, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||
{
|
||||
JoinRoomRequested?.Invoke(room, password);
|
||||
base.JoinRoom(room, password, onSuccess, onError);
|
||||
}
|
||||
|
||||
public void AddRooms(int count, RulesetInfo ruleset = null, bool withPassword = false)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var room = new Room
|
||||
{
|
||||
RoomID = { Value = -currentRoomId },
|
||||
Name = { Value = $@"Room {currentRoomId}" },
|
||||
Host = { Value = new User { Username = @"Host" } },
|
||||
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
|
||||
Category = { Value = i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal },
|
||||
};
|
||||
|
||||
if (withPassword)
|
||||
room.Password.Value = @"password";
|
||||
|
||||
if (ruleset != null)
|
||||
{
|
||||
room.Playlist.Add(new PlaylistItem
|
||||
{
|
||||
Ruleset = { Value = ruleset },
|
||||
Beatmap =
|
||||
{
|
||||
Value = new BeatmapInfo
|
||||
{
|
||||
Metadata = new BeatmapMetadata()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
CreateRoom(room);
|
||||
|
||||
currentRoomId++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
147
osu.Game/Tests/Visual/OnlinePlay/TestRoomRequestsHandler.cs
Normal file
147
osu.Game/Tests/Visual/OnlinePlay/TestRoomRequestsHandler.cs
Normal file
@ -0,0 +1,147 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a handler which pretends to be a server, handling room retrieval and manipulation requests
|
||||
/// and returning a roughly expected state, without the need for a server to be running.
|
||||
/// </summary>
|
||||
public class TestRoomRequestsHandler
|
||||
{
|
||||
public IReadOnlyList<Room> ServerSideRooms => serverSideRooms;
|
||||
|
||||
private readonly List<Room> serverSideRooms = new List<Room>();
|
||||
|
||||
private int currentRoomId;
|
||||
private int currentPlaylistItemId;
|
||||
private int currentScoreId;
|
||||
|
||||
/// <summary>
|
||||
/// Handles an API request, while also updating the local state to match
|
||||
/// how the server would eventually respond and update an <see cref="RoomManager"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The API request to handle.</param>
|
||||
/// <param name="localUser">The local user to store in responses where required.</param>
|
||||
/// <param name="game">The game base for cases where actual online requests need to be sent.</param>
|
||||
/// <returns>Whether the request was successfully handled.</returns>
|
||||
public bool HandleRequest(APIRequest request, User localUser, OsuGameBase game)
|
||||
{
|
||||
switch (request)
|
||||
{
|
||||
case CreateRoomRequest createRoomRequest:
|
||||
var apiRoom = new Room();
|
||||
|
||||
apiRoom.CopyFrom(createRoomRequest.Room);
|
||||
|
||||
// Passwords are explicitly not copied between rooms.
|
||||
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
|
||||
apiRoom.Password.Value = createRoomRequest.Room.Password.Value;
|
||||
|
||||
AddServerSideRoom(apiRoom);
|
||||
|
||||
var responseRoom = new APICreatedRoom();
|
||||
responseRoom.CopyFrom(createResponseRoom(apiRoom, false));
|
||||
|
||||
createRoomRequest.TriggerSuccess(responseRoom);
|
||||
return true;
|
||||
|
||||
case JoinRoomRequest joinRoomRequest:
|
||||
{
|
||||
var room = ServerSideRooms.Single(r => r.RoomID.Value == joinRoomRequest.Room.RoomID.Value);
|
||||
|
||||
if (joinRoomRequest.Password != room.Password.Value)
|
||||
{
|
||||
joinRoomRequest.TriggerFailure(new InvalidOperationException("Invalid password."));
|
||||
return true;
|
||||
}
|
||||
|
||||
joinRoomRequest.TriggerSuccess();
|
||||
return true;
|
||||
}
|
||||
|
||||
case PartRoomRequest partRoomRequest:
|
||||
partRoomRequest.TriggerSuccess();
|
||||
return true;
|
||||
|
||||
case GetRoomsRequest getRoomsRequest:
|
||||
var roomsWithoutParticipants = new List<Room>();
|
||||
|
||||
foreach (var r in ServerSideRooms)
|
||||
roomsWithoutParticipants.Add(createResponseRoom(r, false));
|
||||
|
||||
getRoomsRequest.TriggerSuccess(roomsWithoutParticipants);
|
||||
return true;
|
||||
|
||||
case GetRoomRequest getRoomRequest:
|
||||
getRoomRequest.TriggerSuccess(createResponseRoom(ServerSideRooms.Single(r => r.RoomID.Value == getRoomRequest.RoomId), true));
|
||||
return true;
|
||||
|
||||
case GetBeatmapSetRequest getBeatmapSetRequest:
|
||||
var onlineReq = new GetBeatmapSetRequest(getBeatmapSetRequest.ID, getBeatmapSetRequest.Type);
|
||||
onlineReq.Success += res => getBeatmapSetRequest.TriggerSuccess(res);
|
||||
onlineReq.Failure += e => getBeatmapSetRequest.TriggerFailure(e);
|
||||
|
||||
// Get the online API from the game's dependencies.
|
||||
game.Dependencies.Get<IAPIProvider>().Queue(onlineReq);
|
||||
return true;
|
||||
|
||||
case CreateRoomScoreRequest createRoomScoreRequest:
|
||||
createRoomScoreRequest.TriggerSuccess(new APIScoreToken { ID = 1 });
|
||||
return true;
|
||||
|
||||
case SubmitRoomScoreRequest submitRoomScoreRequest:
|
||||
submitRoomScoreRequest.TriggerSuccess(new MultiplayerScore
|
||||
{
|
||||
ID = currentScoreId++,
|
||||
Accuracy = 1,
|
||||
EndedAt = DateTimeOffset.Now,
|
||||
Passed = true,
|
||||
Rank = ScoreRank.S,
|
||||
MaxCombo = 1000,
|
||||
TotalScore = 1000000,
|
||||
User = localUser,
|
||||
Statistics = new Dictionary<HitResult, int>()
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a room to a local "server-side" list that's returned when a <see cref="GetRoomsRequest"/> is fired.
|
||||
/// </summary>
|
||||
/// <param name="room">The room.</param>
|
||||
public void AddServerSideRoom(Room room)
|
||||
{
|
||||
room.RoomID.Value ??= currentRoomId++;
|
||||
for (int i = 0; i < room.Playlist.Count; i++)
|
||||
room.Playlist[i].ID = currentPlaylistItemId++;
|
||||
|
||||
serverSideRooms.Add(room);
|
||||
}
|
||||
|
||||
private Room createResponseRoom(Room room, bool withParticipants)
|
||||
{
|
||||
var responseRoom = new Room();
|
||||
responseRoom.CopyFrom(room);
|
||||
responseRoom.Password.Value = null;
|
||||
if (!withParticipants)
|
||||
responseRoom.RecentParticipants.Clear();
|
||||
return responseRoom;
|
||||
}
|
||||
}
|
||||
}
|
@ -105,8 +105,9 @@
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBeProtected_002EGlobal/@EntryIndexedValue">HINT</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeCastWithTypeCheck/@EntryIndexedValue">HINT</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeConditionalExpression/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeIntoNegatedPattern/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeIntoPattern/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeSequentialChecks/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MergeSequentialPatterns/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MethodHasAsyncOverload/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MethodHasAsyncOverloadWithCancellation/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MethodSupportsCancellation/@EntryIndexedValue">WARNING</s:String>
|
||||
|
Loading…
Reference in New Issue
Block a user