Merge pull request #14112 from peppy/multiplayer-rename-game-type

Rename `GameType` to `MatchType` and make `enum` instead of `class`
This commit is contained in:
Dan Balasescu 2021-08-03 19:47:21 +09:00 committed by GitHub
commit ceca184b12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 170 additions and 247 deletions

View File

@ -1,18 +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 osu.Framework.Graphics;
using osu.Game.Graphics;
namespace osu.Game.Online.Rooms
{
public abstract class GameType
{
public abstract string Name { get; }
public abstract Drawable GetIcon(OsuColour colours, float size);
public override int GetHashCode() => GetType().GetHashCode();
public override bool Equals(object obj) => GetType() == obj?.GetType();
}
}

View File

@ -1,25 +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 osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osuTK;
namespace osu.Game.Online.Rooms.GameTypes
{
public class GameTypePlaylists : GameType
{
public override string Name => "Playlists";
public override Drawable GetIcon(OsuColour colours, float size) => new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Regular.Clock,
Size = new Vector2(size),
Colour = colours.Blue,
Shadow = false
};
}
}

View File

@ -1,28 +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 osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osuTK;
namespace osu.Game.Online.Rooms.GameTypes
{
public class GameTypeTag : GameType
{
public override string Name => "Tag";
public override Drawable GetIcon(OsuColour colours, float size)
{
return new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.Sync,
Size = new Vector2(size),
Colour = colours.Blue,
Shadow = false,
};
}
}
}

View File

@ -1,45 +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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osuTK;
namespace osu.Game.Online.Rooms.GameTypes
{
public class GameTypeTagTeam : GameType
{
public override string Name => "Tag Team";
public override Drawable GetIcon(OsuColour colours, float size)
{
return new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2f),
Children = new[]
{
new SpriteIcon
{
Icon = FontAwesome.Solid.Sync,
Size = new Vector2(size * 0.75f),
Colour = colours.Blue,
Shadow = false,
},
new SpriteIcon
{
Icon = FontAwesome.Solid.Sync,
Size = new Vector2(size * 0.75f),
Colour = colours.Pink,
Shadow = false,
},
},
};
}
}
}

View File

@ -1,32 +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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osuTK;
namespace osu.Game.Online.Rooms.GameTypes
{
public class GameTypeTeamVersus : GameType
{
public override string Name => "Team Versus";
public override Drawable GetIcon(OsuColour colours, float size)
{
return new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(2f),
Children = new[]
{
new VersusRow(colours.Blue, colours.Pink, size * 0.5f),
new VersusRow(colours.Blue, colours.Pink, size * 0.5f),
},
};
}
}
}

View File

@ -1,22 +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 osu.Framework.Graphics;
using osu.Game.Graphics;
namespace osu.Game.Online.Rooms.GameTypes
{
public class GameTypeVersus : GameType
{
public override string Name => "Versus";
public override Drawable GetIcon(OsuColour colours, float size)
{
return new VersusRow(colours.Blue, colours.Blue, size * 0.6f)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
}
}
}

View File

@ -1,55 +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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Online.Rooms.GameTypes
{
public class VersusRow : FillFlowContainer
{
public VersusRow(Color4 first, Color4 second, float size)
{
var triangleSize = new Vector2(size);
AutoSizeAxes = Axes.Both;
Spacing = new Vector2(2f, 0f);
Children = new[]
{
new Container
{
Size = triangleSize,
Colour = first,
Children = new[]
{
new EquilateralTriangle
{
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Rotation = 90,
EdgeSmoothness = new Vector2(1f),
},
},
},
new Container
{
Size = triangleSize,
Colour = second,
Children = new[]
{
new EquilateralTriangle
{
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Rotation = -90,
EdgeSmoothness = new Vector2(1f),
},
},
},
};
}
}
}

View File

@ -0,0 +1,18 @@
// 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.ComponentModel;
namespace osu.Game.Online.Rooms
{
public enum MatchType
{
Playlists,
[Description("Head to head")]
HeadToHead,
[Description("Team VS")]
TeamVersus,
}
}

View File

@ -7,7 +7,6 @@ using Newtonsoft.Json;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.IO.Serialization.Converters; using osu.Game.IO.Serialization.Converters;
using osu.Game.Online.Rooms.GameTypes;
using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Utils; using osu.Game.Utils;
@ -63,7 +62,7 @@ namespace osu.Game.Online.Rooms
[Cached] [Cached]
[JsonIgnore] [JsonIgnore]
public readonly Bindable<GameType> Type = new Bindable<GameType>(new GameTypePlaylists()); public readonly Bindable<MatchType> Type = new Bindable<MatchType>();
[Cached] [Cached]
[JsonIgnore] [JsonIgnore]

View File

@ -2,24 +2,28 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.OnlinePlay.Components namespace osu.Game.Screens.OnlinePlay.Components
{ {
public class DrawableGameType : CircularContainer, IHasTooltip public class DrawableGameType : CircularContainer, IHasTooltip
{ {
private readonly GameType type; private readonly MatchType type;
public LocalisableString TooltipText => type.Name; public LocalisableString TooltipText => type.GetLocalisableDescription();
public DrawableGameType(GameType type) public DrawableGameType(MatchType type)
{ {
this.type = type; this.type = type;
Masking = true; Masking = true;
@ -34,10 +38,138 @@ namespace osu.Game.Screens.OnlinePlay.Components
}; };
} }
[Resolved]
private OsuColour colours { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load()
{ {
Add(type.GetIcon(colours, Height / 2)); Add(getIconFor(type));
}
private Drawable getIconFor(MatchType matchType)
{
float size = Height / 2;
switch (matchType)
{
default:
case MatchType.Playlists:
return new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(size),
Icon = FontAwesome.Regular.Clock,
Colour = colours.Blue,
Shadow = false
};
case MatchType.HeadToHead:
return new VersusRow(colours.Blue, colours.Blue, size * 0.6f)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
case MatchType.TeamVersus:
return new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(2f),
Children = new[]
{
new VersusRow(colours.Blue, colours.Pink, size * 0.5f),
new VersusRow(colours.Blue, colours.Pink, size * 0.5f),
},
};
// case MatchType.TagCoop:
// return new SpriteIcon
// {
// Anchor = Anchor.Centre,
// Origin = Anchor.Centre,
// Size = new Vector2(size),
// Icon = FontAwesome.Solid.Sync,
// Colour = colours.Blue,
//
// Shadow = false
// };
// case MatchType.TagTeamCoop:
// return new FillFlowContainer
// {
// Anchor = Anchor.Centre,
// Origin = Anchor.Centre,
// AutoSizeAxes = Axes.Both,
// Direction = FillDirection.Horizontal,
// Spacing = new Vector2(2f),
// Children = new[]
// {
// new SpriteIcon
// {
// Icon = FontAwesome.Solid.Sync,
// Size = new Vector2(size * 0.75f),
// Colour = colours.Blue,
// Shadow = false,
// },
// new SpriteIcon
// {
// Icon = FontAwesome.Solid.Sync,
// Size = new Vector2(size * 0.75f),
// Colour = colours.Pink,
// Shadow = false,
// },
// },
// };
}
}
private class VersusRow : FillFlowContainer
{
public VersusRow(Color4 first, Color4 second, float size)
{
var triangleSize = new Vector2(size);
AutoSizeAxes = Axes.Both;
Spacing = new Vector2(2f, 0f);
Children = new[]
{
new Container
{
Size = triangleSize,
Colour = first,
Children = new[]
{
new EquilateralTriangle
{
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Rotation = 90,
EdgeSmoothness = new Vector2(1f),
},
},
},
new Container
{
Size = triangleSize,
Colour = second,
Children = new[]
{
new EquilateralTriangle
{
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Rotation = -90,
EdgeSmoothness = new Vector2(1f),
},
},
},
};
}
} }
} }
} }

View File

@ -9,31 +9,29 @@ using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.GameTypes;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
using osuTK; using osuTK;
namespace osu.Game.Screens.OnlinePlay.Match.Components namespace osu.Game.Screens.OnlinePlay.Match.Components
{ {
public class GameTypePicker : DisableableTabControl<GameType> public class MatchTypePicker : DisableableTabControl<MatchType>
{ {
private const float height = 40; private const float height = 40;
private const float selection_width = 3; private const float selection_width = 3;
protected override TabItem<GameType> CreateTabItem(GameType value) => new GameTypePickerItem(value); protected override TabItem<MatchType> CreateTabItem(MatchType value) => new GameTypePickerItem(value);
protected override Dropdown<GameType> CreateDropdown() => null; protected override Dropdown<MatchType> CreateDropdown() => null;
public GameTypePicker() public MatchTypePicker()
{ {
Height = height + selection_width * 2; Height = height + selection_width * 2;
TabContainer.Spacing = new Vector2(10 - selection_width * 2); TabContainer.Spacing = new Vector2(10 - selection_width * 2);
AddItem(new GameTypeTag()); AddItem(MatchType.HeadToHead);
AddItem(new GameTypeVersus()); AddItem(MatchType.TeamVersus);
AddItem(new GameTypeTagTeam()); // TODO: remove after osu-web is updated to set the correct default type.
AddItem(new GameTypeTeamVersus()); AddItem(MatchType.Playlists);
AddItem(new GameTypePlaylists());
} }
private class GameTypePickerItem : DisableableTabItem private class GameTypePickerItem : DisableableTabItem
@ -42,7 +40,7 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
private readonly CircularContainer hover, selection; private readonly CircularContainer hover, selection;
public GameTypePickerItem(GameType value) public GameTypePickerItem(MatchType value)
: base(value) : base(value)
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;

View File

@ -6,6 +6,7 @@ using System.Diagnostics;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.ExceptionExtensions; using osu.Framework.Extensions.ExceptionExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -43,7 +44,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
public OsuTextBox NameField, MaxParticipantsField; public OsuTextBox NameField, MaxParticipantsField;
public RoomAvailabilityPicker AvailabilityPicker; public RoomAvailabilityPicker AvailabilityPicker;
public GameTypePicker TypePicker; public MatchTypePicker TypePicker;
public OsuTextBox PasswordTextBox; public OsuTextBox PasswordTextBox;
public TriangleButton ApplyButton; public TriangleButton ApplyButton;
@ -157,7 +158,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
Spacing = new Vector2(7), Spacing = new Vector2(7),
Children = new Drawable[] Children = new Drawable[]
{ {
TypePicker = new GameTypePicker TypePicker = new MatchTypePicker
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Enabled = { Value = false } Enabled = { Value = false }
@ -265,7 +266,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
loadingLayer = new LoadingLayer(true) loadingLayer = new LoadingLayer(true)
}; };
TypePicker.Current.BindValueChanged(type => typeLabel.Text = type.NewValue?.Name ?? string.Empty, true); TypePicker.Current.BindValueChanged(type => typeLabel.Text = type.NewValue.GetLocalisableDescription(), true);
RoomName.BindValueChanged(name => NameField.Text = name.NewValue, true); RoomName.BindValueChanged(name => NameField.Text = name.NewValue, true);
Availability.BindValueChanged(availability => AvailabilityPicker.Current.Value = availability.NewValue, true); Availability.BindValueChanged(availability => AvailabilityPicker.Current.Value = availability.NewValue, true);
Type.BindValueChanged(type => TypePicker.Current.Value = type.NewValue, true); Type.BindValueChanged(type => TypePicker.Current.Value = type.NewValue, true);

View File

@ -30,7 +30,7 @@ namespace osu.Game.Screens.OnlinePlay
protected Bindable<RoomStatus> Status { get; private set; } protected Bindable<RoomStatus> Status { get; private set; }
[Resolved(typeof(Room))] [Resolved(typeof(Room))]
protected Bindable<GameType> Type { get; private set; } protected Bindable<MatchType> Type { get; private set; }
[Resolved(typeof(Room))] [Resolved(typeof(Room))]
protected BindableList<PlaylistItem> Playlist { get; private set; } protected BindableList<PlaylistItem> Playlist { get; private set; }