mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 07:22:55 +08:00
Merge pull request #14120 from peppy/multiplayer-team-vs-team-selection
Add ability to choose Team Versus match type and view / switch teams
This commit is contained in:
commit
5811dff853
191
osu.Game.Tests/Visual/Multiplayer/TestSceneTeamVersus.cs
Normal file
191
osu.Game.Tests/Visual/Multiplayer/TestSceneTeamVersus.cs
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
// 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 NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Online.Multiplayer;
|
||||||
|
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Screens;
|
||||||
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||||
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||||
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
|
||||||
|
using osu.Game.Tests.Resources;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Multiplayer
|
||||||
|
{
|
||||||
|
public class TestSceneTeamVersus : ScreenTestScene
|
||||||
|
{
|
||||||
|
private BeatmapManager beatmaps;
|
||||||
|
private RulesetStore rulesets;
|
||||||
|
private BeatmapSetInfo importedSet;
|
||||||
|
|
||||||
|
private DependenciesScreen dependenciesScreen;
|
||||||
|
private TestMultiplayer multiplayerScreen;
|
||||||
|
private TestMultiplayerClient client;
|
||||||
|
|
||||||
|
[Cached(typeof(UserLookupCache))]
|
||||||
|
private UserLookupCache lookupCache = new TestUserLookupCache();
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(GameHost host, AudioManager audio)
|
||||||
|
{
|
||||||
|
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
||||||
|
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetUpSteps()
|
||||||
|
{
|
||||||
|
base.SetUpSteps();
|
||||||
|
|
||||||
|
AddStep("import beatmap", () =>
|
||||||
|
{
|
||||||
|
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
||||||
|
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("create multiplayer screen", () => multiplayerScreen = new TestMultiplayer());
|
||||||
|
|
||||||
|
AddStep("load dependencies", () =>
|
||||||
|
{
|
||||||
|
client = new TestMultiplayerClient(multiplayerScreen.RoomManager);
|
||||||
|
|
||||||
|
// The screen gets suspended so it stops receiving updates.
|
||||||
|
Child = client;
|
||||||
|
|
||||||
|
LoadScreen(dependenciesScreen = new DependenciesScreen(client));
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for dependencies to load", () => dependenciesScreen.IsLoaded);
|
||||||
|
|
||||||
|
AddStep("load multiplayer", () => LoadScreen(multiplayerScreen));
|
||||||
|
AddUntilStep("wait for multiplayer to load", () => multiplayerScreen.IsLoaded);
|
||||||
|
AddUntilStep("wait for lounge to load", () => this.ChildrenOfType<MultiplayerLoungeSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCreateWithType()
|
||||||
|
{
|
||||||
|
createRoom(() => new Room
|
||||||
|
{
|
||||||
|
Name = { Value = "Test Room" },
|
||||||
|
Type = { Value = MatchType.TeamVersus },
|
||||||
|
Playlist =
|
||||||
|
{
|
||||||
|
new PlaylistItem
|
||||||
|
{
|
||||||
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
||||||
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("room type is team vs", () => client.Room?.Settings.MatchType == MatchType.TeamVersus);
|
||||||
|
AddAssert("user state arrived", () => client.Room?.Users.FirstOrDefault()?.MatchState is TeamVersusUserState);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestChangeTeamsViaButton()
|
||||||
|
{
|
||||||
|
createRoom(() => new Room
|
||||||
|
{
|
||||||
|
Name = { Value = "Test Room" },
|
||||||
|
Type = { Value = MatchType.TeamVersus },
|
||||||
|
Playlist =
|
||||||
|
{
|
||||||
|
new PlaylistItem
|
||||||
|
{
|
||||||
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
||||||
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("user on team 0", () => (client.Room?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 0);
|
||||||
|
|
||||||
|
AddStep("press button", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(multiplayerScreen.ChildrenOfType<TeamDisplay>().First());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddAssert("user on team 1", () => (client.Room?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 1);
|
||||||
|
|
||||||
|
AddStep("press button", () => InputManager.Click(MouseButton.Left));
|
||||||
|
AddAssert("user on team 0", () => (client.Room?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestChangeTypeViaMatchSettings()
|
||||||
|
{
|
||||||
|
createRoom(() => new Room
|
||||||
|
{
|
||||||
|
Name = { Value = "Test Room" },
|
||||||
|
Playlist =
|
||||||
|
{
|
||||||
|
new PlaylistItem
|
||||||
|
{
|
||||||
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
||||||
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("room type is head to head", () => client.Room?.Settings.MatchType == MatchType.HeadToHead);
|
||||||
|
|
||||||
|
AddStep("change to team vs", () => client.ChangeSettings(matchType: MatchType.TeamVersus));
|
||||||
|
|
||||||
|
AddAssert("room type is team vs", () => client.Room?.Settings.MatchType == MatchType.TeamVersus);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createRoom(Func<Room> room)
|
||||||
|
{
|
||||||
|
AddStep("open room", () =>
|
||||||
|
{
|
||||||
|
multiplayerScreen.OpenNewRoom(room());
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
||||||
|
AddWaitStep("wait for transition", 2);
|
||||||
|
|
||||||
|
AddStep("create room", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for join", () => client.Room != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used for the sole purpose of adding <see cref="TestMultiplayerClient"/> as a resolvable dependency.
|
||||||
|
/// </summary>
|
||||||
|
private class DependenciesScreen : OsuScreen
|
||||||
|
{
|
||||||
|
[Cached(typeof(MultiplayerClient))]
|
||||||
|
public readonly TestMultiplayerClient Client;
|
||||||
|
|
||||||
|
public DependenciesScreen(TestMultiplayerClient client)
|
||||||
|
{
|
||||||
|
Client = client;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestMultiplayer : Screens.OnlinePlay.Multiplayer.Multiplayer
|
||||||
|
{
|
||||||
|
public new TestRequestHandlingMultiplayerRoomManager RoomManager { get; private set; }
|
||||||
|
|
||||||
|
protected override RoomManager CreateRoomManager() => RoomManager = new TestRequestHandlingMultiplayerRoomManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -142,6 +142,8 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
APIRoom = room;
|
APIRoom = room;
|
||||||
foreach (var user in joinedRoom.Users)
|
foreach (var user in joinedRoom.Users)
|
||||||
updateUserPlayingState(user.UserID, user.State);
|
updateUserPlayingState(user.UserID, user.State);
|
||||||
|
|
||||||
|
OnRoomJoined();
|
||||||
}, cancellationSource.Token).ConfigureAwait(false);
|
}, cancellationSource.Token).ConfigureAwait(false);
|
||||||
|
|
||||||
// Update room settings.
|
// Update room settings.
|
||||||
@ -149,6 +151,13 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
}, cancellationSource.Token).ConfigureAwait(false);
|
}, cancellationSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fired when the room join sequence is complete
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnRoomJoined()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Joins the <see cref="MultiplayerRoom"/> with a given ID.
|
/// Joins the <see cref="MultiplayerRoom"/> with a given ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -192,8 +201,9 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="name">The new room name, if any.</param>
|
/// <param name="name">The new room name, if any.</param>
|
||||||
/// <param name="password">The new password, if any.</param>
|
/// <param name="password">The new password, if any.</param>
|
||||||
|
/// <param name="matchType">The type of the match, if any.</param>
|
||||||
/// <param name="item">The new room playlist item, if any.</param>
|
/// <param name="item">The new room playlist item, if any.</param>
|
||||||
public Task ChangeSettings(Optional<string> name = default, Optional<string> password = default, Optional<PlaylistItem> item = default)
|
public Task ChangeSettings(Optional<string> name = default, Optional<string> password = default, Optional<MatchType> matchType = default, Optional<PlaylistItem> item = default)
|
||||||
{
|
{
|
||||||
if (Room == null)
|
if (Room == null)
|
||||||
throw new InvalidOperationException("Must be joined to a match to change settings.");
|
throw new InvalidOperationException("Must be joined to a match to change settings.");
|
||||||
@ -219,6 +229,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID,
|
BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID,
|
||||||
BeatmapChecksum = item.GetOr(existingPlaylistItem).Beatmap.Value.MD5Hash,
|
BeatmapChecksum = item.GetOr(existingPlaylistItem).Beatmap.Value.MD5Hash,
|
||||||
RulesetID = item.GetOr(existingPlaylistItem).RulesetID,
|
RulesetID = item.GetOr(existingPlaylistItem).RulesetID,
|
||||||
|
MatchType = matchType.GetOr(Room.Settings.MatchType),
|
||||||
RequiredMods = item.HasValue ? item.Value.AsNonNull().RequiredMods.Select(m => new APIMod(m)).ToList() : Room.Settings.RequiredMods,
|
RequiredMods = item.HasValue ? item.Value.AsNonNull().RequiredMods.Select(m => new APIMod(m)).ToList() : Room.Settings.RequiredMods,
|
||||||
AllowedMods = item.HasValue ? item.Value.AsNonNull().AllowedMods.Select(m => new APIMod(m)).ToList() : Room.Settings.AllowedMods,
|
AllowedMods = item.HasValue ? item.Value.AsNonNull().AllowedMods.Select(m => new APIMod(m)).ToList() : Room.Settings.AllowedMods,
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
{
|
{
|
||||||
public abstract class DisableableTabControl<T> : TabControl<T>
|
public abstract class DisableableTabControl<T> : TabControl<T>
|
||||||
{
|
{
|
||||||
public readonly BindableBool Enabled = new BindableBool();
|
public readonly BindableBool Enabled = new BindableBool(true);
|
||||||
|
|
||||||
protected override void AddTabItem(TabItem<T> tab, bool addToDropdown = true)
|
protected override void AddTabItem(TabItem<T> tab, bool addToDropdown = true)
|
||||||
{
|
{
|
||||||
|
@ -149,7 +149,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
},
|
},
|
||||||
new Section("Game type")
|
new Section("Game type")
|
||||||
{
|
{
|
||||||
Alpha = disabled_alpha,
|
|
||||||
Child = new FillFlowContainer
|
Child = new FillFlowContainer
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
@ -161,7 +160,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
TypePicker = new MatchTypePicker
|
TypePicker = new MatchTypePicker
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Enabled = { Value = false }
|
|
||||||
},
|
},
|
||||||
typeLabel = new OsuSpriteText
|
typeLabel = new OsuSpriteText
|
||||||
{
|
{
|
||||||
@ -305,7 +303,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
||||||
if (client.Room != null)
|
if (client.Room != null)
|
||||||
{
|
{
|
||||||
client.ChangeSettings(name: NameField.Text, password: PasswordTextBox.Text).ContinueWith(t => Schedule(() =>
|
client.ChangeSettings(name: NameField.Text, password: PasswordTextBox.Text, matchType: TypePicker.Current.Value).ContinueWith(t => Schedule(() =>
|
||||||
{
|
{
|
||||||
if (t.IsCompletedSuccessfully)
|
if (t.IsCompletedSuccessfully)
|
||||||
onSuccess(currentRoom.Value);
|
onSuccess(currentRoom.Value);
|
||||||
|
@ -58,7 +58,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
new Room
|
new Room
|
||||||
{
|
{
|
||||||
Name = { Value = $"{API.LocalUser}'s awesome room" },
|
Name = { Value = $"{API.LocalUser}'s awesome room" },
|
||||||
Category = { Value = RoomCategory.Realtime }
|
Category = { Value = RoomCategory.Realtime },
|
||||||
|
Type = { Value = MatchType.HeadToHead },
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override string ScreenTitle => "Multiplayer";
|
protected override string ScreenTitle => "Multiplayer";
|
||||||
|
@ -37,6 +37,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
|||||||
private RulesetStore rulesets { get; set; }
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
private SpriteIcon crown;
|
private SpriteIcon crown;
|
||||||
|
|
||||||
private OsuSpriteText userRankText;
|
private OsuSpriteText userRankText;
|
||||||
private ModDisplay userModsDisplay;
|
private ModDisplay userModsDisplay;
|
||||||
private StateDisplay userStateDisplay;
|
private StateDisplay userStateDisplay;
|
||||||
@ -56,99 +57,108 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
|||||||
|
|
||||||
var backgroundColour = Color4Extensions.FromHex("#33413C");
|
var backgroundColour = Color4Extensions.FromHex("#33413C");
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChild = new GridContainer
|
||||||
{
|
{
|
||||||
crown = new SpriteIcon
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
ColumnDimensions = new[]
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreLeft,
|
new Dimension(GridSizeMode.Absolute, 18),
|
||||||
Origin = Anchor.CentreLeft,
|
new Dimension(GridSizeMode.AutoSize),
|
||||||
Icon = FontAwesome.Solid.Crown,
|
new Dimension()
|
||||||
Size = new Vector2(14),
|
|
||||||
Colour = Color4Extensions.FromHex("#F7E65D"),
|
|
||||||
Alpha = 0
|
|
||||||
},
|
},
|
||||||
new Container
|
Content = new[]
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
new Drawable[]
|
||||||
Padding = new MarginPadding { Left = 24 },
|
|
||||||
Child = new Container
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
crown = new SpriteIcon
|
||||||
Masking = true,
|
|
||||||
CornerRadius = 5,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
{
|
||||||
new Box
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Icon = FontAwesome.Solid.Crown,
|
||||||
|
Size = new Vector2(14),
|
||||||
|
Colour = Color4Extensions.FromHex("#F7E65D"),
|
||||||
|
Alpha = 0
|
||||||
|
},
|
||||||
|
new TeamDisplay(user),
|
||||||
|
new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Masking = true,
|
||||||
|
CornerRadius = 5,
|
||||||
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
new Box
|
||||||
Colour = backgroundColour
|
|
||||||
},
|
|
||||||
new UserCoverBackground
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreRight,
|
|
||||||
Origin = Anchor.CentreRight,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Width = 0.75f,
|
|
||||||
User = user,
|
|
||||||
Colour = ColourInfo.GradientHorizontal(Color4.White.Opacity(0), Color4.White.Opacity(0.25f))
|
|
||||||
},
|
|
||||||
new FillFlowContainer
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Spacing = new Vector2(10),
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
{
|
||||||
new UpdateableAvatar
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = backgroundColour
|
||||||
|
},
|
||||||
|
new UserCoverBackground
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreRight,
|
||||||
|
Origin = Anchor.CentreRight,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Width = 0.75f,
|
||||||
|
User = user,
|
||||||
|
Colour = ColourInfo.GradientHorizontal(Color4.White.Opacity(0), Color4.White.Opacity(0.25f))
|
||||||
|
},
|
||||||
|
new FillFlowContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Spacing = new Vector2(10),
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreLeft,
|
new UpdateableAvatar
|
||||||
Origin = Anchor.CentreLeft,
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
Anchor = Anchor.CentreLeft,
|
||||||
FillMode = FillMode.Fit,
|
Origin = Anchor.CentreLeft,
|
||||||
User = user
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
FillMode = FillMode.Fit,
|
||||||
new UpdateableFlag
|
User = user
|
||||||
{
|
},
|
||||||
Anchor = Anchor.CentreLeft,
|
new UpdateableFlag
|
||||||
Origin = Anchor.CentreLeft,
|
{
|
||||||
Size = new Vector2(30, 20),
|
Anchor = Anchor.CentreLeft,
|
||||||
Country = user?.Country
|
Origin = Anchor.CentreLeft,
|
||||||
},
|
Size = new Vector2(30, 20),
|
||||||
new OsuSpriteText
|
Country = user?.Country
|
||||||
{
|
},
|
||||||
Anchor = Anchor.CentreLeft,
|
new OsuSpriteText
|
||||||
Origin = Anchor.CentreLeft,
|
{
|
||||||
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 18),
|
Anchor = Anchor.CentreLeft,
|
||||||
Text = user?.Username
|
Origin = Anchor.CentreLeft,
|
||||||
},
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 18),
|
||||||
userRankText = new OsuSpriteText
|
Text = user?.Username
|
||||||
{
|
},
|
||||||
Anchor = Anchor.CentreLeft,
|
userRankText = new OsuSpriteText
|
||||||
Origin = Anchor.CentreLeft,
|
{
|
||||||
Font = OsuFont.GetFont(size: 14),
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Font = OsuFont.GetFont(size: 14),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
new Container
|
||||||
new Container
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreRight,
|
|
||||||
Origin = Anchor.CentreRight,
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Margin = new MarginPadding { Right = 70 },
|
|
||||||
Child = userModsDisplay = new ModDisplay
|
|
||||||
{
|
{
|
||||||
Scale = new Vector2(0.5f),
|
Anchor = Anchor.CentreRight,
|
||||||
ExpansionMode = ExpansionMode.AlwaysContracted,
|
Origin = Anchor.CentreRight,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Margin = new MarginPadding { Right = 70 },
|
||||||
|
Child = userModsDisplay = new ModDisplay
|
||||||
|
{
|
||||||
|
Scale = new Vector2(0.5f),
|
||||||
|
ExpansionMode = ExpansionMode.AlwaysContracted,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
userStateDisplay = new StateDisplay
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreRight,
|
||||||
|
Origin = Anchor.CentreRight,
|
||||||
|
Margin = new MarginPadding { Right = 10 },
|
||||||
}
|
}
|
||||||
},
|
|
||||||
userStateDisplay = new StateDisplay
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreRight,
|
|
||||||
Origin = Anchor.CentreRight,
|
|
||||||
Margin = new MarginPadding { Right = 10 },
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,134 @@
|
|||||||
|
// 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.Graphics;
|
||||||
|
using osu.Framework.Graphics.Colour;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Online.Multiplayer;
|
||||||
|
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||||
|
using osu.Game.Users;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||||
|
{
|
||||||
|
internal class TeamDisplay : MultiplayerRoomComposite
|
||||||
|
{
|
||||||
|
private readonly User user;
|
||||||
|
private Drawable box;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private MultiplayerClient client { get; set; }
|
||||||
|
|
||||||
|
public TeamDisplay(User user)
|
||||||
|
{
|
||||||
|
this.user = user;
|
||||||
|
|
||||||
|
RelativeSizeAxes = Axes.Y;
|
||||||
|
Width = 15;
|
||||||
|
|
||||||
|
Margin = new MarginPadding { Horizontal = 3 };
|
||||||
|
|
||||||
|
Alpha = 0;
|
||||||
|
Scale = new Vector2(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
box = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
CornerRadius = 5,
|
||||||
|
Masking = true,
|
||||||
|
Scale = new Vector2(0, 1),
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Child = new Box
|
||||||
|
{
|
||||||
|
Colour = Color4.White,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (user.Id == client.LocalUser?.UserID)
|
||||||
|
{
|
||||||
|
InternalChild = new OsuClickableContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
TooltipText = "Change team",
|
||||||
|
Action = changeTeam,
|
||||||
|
Child = box
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InternalChild = box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeTeam()
|
||||||
|
{
|
||||||
|
client.SendMatchRequest(new ChangeTeamRequest
|
||||||
|
{
|
||||||
|
TeamID = ((client.LocalUser?.MatchState as TeamVersusUserState)?.TeamID + 1) % 2 ?? 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private int? displayedTeam;
|
||||||
|
|
||||||
|
protected override void OnRoomUpdated()
|
||||||
|
{
|
||||||
|
base.OnRoomUpdated();
|
||||||
|
|
||||||
|
// we don't have a way of knowing when an individual user's state has updated, so just handle on RoomUpdated for now.
|
||||||
|
|
||||||
|
var userRoomState = Room?.Users.FirstOrDefault(u => u.UserID == user.Id)?.MatchState;
|
||||||
|
|
||||||
|
const double duration = 400;
|
||||||
|
|
||||||
|
int? newTeam = (userRoomState as TeamVersusUserState)?.TeamID;
|
||||||
|
|
||||||
|
if (newTeam == displayedTeam)
|
||||||
|
return;
|
||||||
|
|
||||||
|
displayedTeam = newTeam;
|
||||||
|
|
||||||
|
if (displayedTeam != null)
|
||||||
|
{
|
||||||
|
box.FadeColour(getColourForTeam(displayedTeam.Value), duration, Easing.OutQuint);
|
||||||
|
box.ScaleTo(new Vector2(box.Scale.X < 0 ? 1 : -1, 1), duration, Easing.OutQuint);
|
||||||
|
|
||||||
|
this.ScaleTo(Vector2.One, duration, Easing.OutQuint);
|
||||||
|
this.FadeIn(duration);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.ScaleTo(new Vector2(0, 1), duration, Easing.OutQuint);
|
||||||
|
this.FadeOut(duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ColourInfo getColourForTeam(int id)
|
||||||
|
{
|
||||||
|
switch (id)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
return colours.Red;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
return colours.Blue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -48,7 +48,11 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
|
|
||||||
protected override Room CreateNewRoom()
|
protected override Room CreateNewRoom()
|
||||||
{
|
{
|
||||||
return new Room { Name = { Value = $"{API.LocalUser}'s awesome playlist" } };
|
return new Room
|
||||||
|
{
|
||||||
|
Name = { Value = $"{API.LocalUser}'s awesome playlist" },
|
||||||
|
Type = { Value = MatchType.Playlists }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string ScreenTitle => "Playlists";
|
protected override string ScreenTitle => "Playlists";
|
||||||
|
@ -14,6 +14,7 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
|
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
@ -132,6 +133,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
Settings =
|
Settings =
|
||||||
{
|
{
|
||||||
Name = apiRoom.Name.Value,
|
Name = apiRoom.Name.Value,
|
||||||
|
MatchType = apiRoom.Type.Value,
|
||||||
BeatmapID = apiRoom.Playlist.Last().BeatmapID,
|
BeatmapID = apiRoom.Playlist.Last().BeatmapID,
|
||||||
RulesetID = apiRoom.Playlist.Last().RulesetID,
|
RulesetID = apiRoom.Playlist.Last().RulesetID,
|
||||||
BeatmapChecksum = apiRoom.Playlist.Last().Beatmap.Value.MD5Hash,
|
BeatmapChecksum = apiRoom.Playlist.Last().Beatmap.Value.MD5Hash,
|
||||||
@ -151,6 +153,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
return Task.FromResult(room);
|
return Task.FromResult(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnRoomJoined()
|
||||||
|
{
|
||||||
|
Debug.Assert(Room != null);
|
||||||
|
|
||||||
|
// emulate the server sending this after the join room. scheduler required to make sure the join room event is fired first (in Join).
|
||||||
|
changeMatchType(Room.Settings.MatchType).Wait();
|
||||||
|
}
|
||||||
|
|
||||||
protected override Task LeaveRoomInternal() => Task.CompletedTask;
|
protected override Task LeaveRoomInternal() => Task.CompletedTask;
|
||||||
|
|
||||||
public override Task TransferHost(int userId) => ((IMultiplayerClient)this).HostChanged(userId);
|
public override Task TransferHost(int userId) => ((IMultiplayerClient)this).HostChanged(userId);
|
||||||
@ -163,6 +173,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
foreach (var user in Room.Users.Where(u => u.State == MultiplayerUserState.Ready))
|
foreach (var user in Room.Users.Where(u => u.State == MultiplayerUserState.Ready))
|
||||||
ChangeUserState(user.UserID, MultiplayerUserState.Idle);
|
ChangeUserState(user.UserID, MultiplayerUserState.Idle);
|
||||||
|
|
||||||
|
await changeMatchType(settings.MatchType).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task ChangeState(MultiplayerUserState newState)
|
public override Task ChangeState(MultiplayerUserState newState)
|
||||||
@ -192,7 +204,30 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task SendMatchRequest(MatchUserRequest request) => Task.CompletedTask;
|
public override async Task SendMatchRequest(MatchUserRequest request)
|
||||||
|
{
|
||||||
|
Debug.Assert(Room != null);
|
||||||
|
Debug.Assert(LocalUser != null);
|
||||||
|
|
||||||
|
switch (request)
|
||||||
|
{
|
||||||
|
case ChangeTeamRequest changeTeam:
|
||||||
|
|
||||||
|
TeamVersusRoomState roomState = (TeamVersusRoomState)Room.MatchState!;
|
||||||
|
TeamVersusUserState userState = (TeamVersusUserState)LocalUser.MatchState!;
|
||||||
|
|
||||||
|
var targetTeam = roomState.Teams.FirstOrDefault(t => t.ID == changeTeam.TeamID);
|
||||||
|
|
||||||
|
if (targetTeam != null)
|
||||||
|
{
|
||||||
|
userState.TeamID = targetTeam.ID;
|
||||||
|
|
||||||
|
await ((IMultiplayerClient)this).MatchUserStateChanged(LocalUser.UserID, userState).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override Task StartMatch()
|
public override Task StartMatch()
|
||||||
{
|
{
|
||||||
@ -218,5 +253,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
return Task.FromResult(set);
|
return Task.FromResult(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task changeMatchType(MatchType type)
|
||||||
|
{
|
||||||
|
Debug.Assert(Room != null);
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case MatchType.HeadToHead:
|
||||||
|
await ((IMultiplayerClient)this).MatchRoomStateChanged(null).ConfigureAwait(false);
|
||||||
|
|
||||||
|
foreach (var user in Room.Users)
|
||||||
|
await ((IMultiplayerClient)this).MatchUserStateChanged(user.UserID, null).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MatchType.TeamVersus:
|
||||||
|
await ((IMultiplayerClient)this).MatchRoomStateChanged(TeamVersusRoomState.CreateDefault()).ConfigureAwait(false);
|
||||||
|
|
||||||
|
foreach (var user in Room.Users)
|
||||||
|
await ((IMultiplayerClient)this).MatchUserStateChanged(user.UserID, new TeamVersusUserState()).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user