1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 20:33:21 +08:00

Make Room.Category non-bindable

This commit is contained in:
Dan Balasescu 2024-11-13 18:27:32 +09:00
parent 8694f7e1cc
commit bde7b8e610
No known key found for this signature in database
13 changed files with 86 additions and 55 deletions

View File

@ -50,7 +50,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
}
},
EndDate = { Value = DateTimeOffset.Now.AddHours(12) },
Category = { Value = RoomCategory.DailyChallenge }
Category = RoomCategory.DailyChallenge
};
AddStep("add room", () => API.Perform(new CreateRoomRequest(room)));
@ -73,7 +73,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
}
},
EndDate = { Value = DateTimeOffset.Now.AddHours(12) },
Category = { Value = RoomCategory.DailyChallenge }
Category = RoomCategory.DailyChallenge
};
AddStep("add room", () => API.Perform(new CreateRoomRequest(room)));
@ -102,7 +102,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
}
},
EndDate = { Value = DateTimeOffset.Now.AddHours(12) },
Category = { Value = RoomCategory.DailyChallenge }
Category = RoomCategory.DailyChallenge
};
AddStep("add room", () => API.Perform(new CreateRoomRequest(room)));

View File

@ -80,7 +80,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
},
StartDate = { Value = DateTimeOffset.Now },
EndDate = { Value = DateTimeOffset.Now.AddHours(24) },
Category = { Value = RoomCategory.DailyChallenge }
Category = RoomCategory.DailyChallenge
}));
});
AddStep("signal client", () => metadataClient.DailyChallengeUpdated(new DailyChallengeInfo { RoomID = roomId }));

View File

@ -110,13 +110,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Name = "Spotlight room",
Status = { Value = new RoomStatusOpen() },
Category = { Value = RoomCategory.Spotlight },
Category = RoomCategory.Spotlight,
}),
createLoungeRoom(new Room
{
Name = "Featured artist room",
Status = { Value = new RoomStatusOpen() },
Category = { Value = RoomCategory.FeaturedArtist },
Category = RoomCategory.FeaturedArtist,
}),
}
};

View File

@ -55,20 +55,20 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddAssert("has 5 rooms", () => container.Rooms.Count == 5);
AddAssert("all spotlights at top", () => container.Rooms
.SkipWhile(r => r.Room.Category.Value == RoomCategory.Spotlight)
.All(r => r.Room.Category.Value == RoomCategory.Normal));
.SkipWhile(r => r.Room.Category == RoomCategory.Spotlight)
.All(r => r.Room.Category == RoomCategory.Normal));
AddStep("remove first room", () => RoomManager.RemoveRoom(RoomManager.Rooms.First(r => r.RoomID == 0)));
AddAssert("has 4 rooms", () => container.Rooms.Count == 4);
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID != 0));
AddStep("select first room", () => container.Rooms.First().TriggerClick());
AddAssert("first spotlight selected", () => checkRoomSelected(RoomManager.Rooms.First(r => r.Category.Value == RoomCategory.Spotlight)));
AddAssert("first spotlight selected", () => checkRoomSelected(RoomManager.Rooms.First(r => r.Category == RoomCategory.Spotlight)));
AddStep("remove last room", () => RoomManager.RemoveRoom(RoomManager.Rooms.MinBy(r => r.RoomID)));
AddAssert("first spotlight still selected", () => checkRoomSelected(RoomManager.Rooms.First(r => r.Category.Value == RoomCategory.Spotlight)));
AddAssert("first spotlight still selected", () => checkRoomSelected(RoomManager.Rooms.First(r => r.Category == RoomCategory.Spotlight)));
AddStep("remove spotlight room", () => RoomManager.RemoveRoom(RoomManager.Rooms.Single(r => r.Category.Value == RoomCategory.Spotlight)));
AddStep("remove spotlight room", () => RoomManager.RemoveRoom(RoomManager.Rooms.Single(r => r.Category == RoomCategory.Spotlight)));
AddAssert("selection vacated", () => checkRoomSelected(null));
}

View File

@ -39,12 +39,24 @@ namespace osu.Game.Online.Rooms
set => SetField(ref name, value);
}
/// <summary>
/// The room host. Will be <c>null</c> while the room has not yet been created.
/// </summary>
public APIUser? Host
{
get => host;
set => SetField(ref host, value);
}
/// <summary>
/// The room category.
/// </summary>
public RoomCategory Category
{
get => category;
set => SetField(ref category, value);
}
/// <summary>
/// Represents the current item selected within the room.
/// </summary>
@ -66,6 +78,10 @@ namespace osu.Game.Online.Rooms
[JsonProperty("host")]
private APIUser? host;
[JsonProperty("category")]
[JsonConverter(typeof(SnakeCaseStringEnumConverter))]
private RoomCategory category;
[JsonProperty("current_playlist_item")]
private PlaylistItem? currentPlaylistItem;
@ -85,18 +101,6 @@ namespace osu.Game.Online.Rooms
[Cached]
public readonly Bindable<RoomDifficultyRange> DifficultyRange = new Bindable<RoomDifficultyRange>();
[Cached]
public readonly Bindable<RoomCategory> Category = new Bindable<RoomCategory>();
// Todo: osu-framework bug (https://github.com/ppy/osu-framework/issues/4106)
[JsonProperty("category")]
[JsonConverter(typeof(SnakeCaseStringEnumConverter))]
private RoomCategory category
{
get => Category.Value;
set => Category.Value = value;
}
[Cached]
public readonly Bindable<int?> MaxAttempts = new Bindable<int?>();
@ -220,7 +224,7 @@ namespace osu.Game.Online.Rooms
RoomID = other.RoomID;
Name = other.Name;
Category.Value = other.Category.Value;
Category = other.Category;
if (other.Host != null && Host?.Id != other.Host.Id)
Host = other.Host;

View File

@ -51,7 +51,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
req.Success += result =>
{
result = result.Where(r => r.Category.Value != RoomCategory.DailyChallenge).ToList();
result = result.Where(r => r.Category != RoomCategory.DailyChallenge).ToList();
foreach (var existing in RoomManager.Rooms.ToArray())
{

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -17,13 +15,13 @@ namespace osu.Game.Screens.OnlinePlay.Components
private readonly double transitionDuration;
[Resolved(typeof(Room), nameof(Room.Status))]
private Bindable<RoomStatus> status { get; set; }
private Bindable<RoomStatus> status { get; set; } = null!;
[Resolved(typeof(Room), nameof(Room.Category))]
private Bindable<RoomCategory> category { get; set; }
private readonly Room room;
public StatusColouredContainer(double transitionDuration = 100)
public StatusColouredContainer(Room room, double transitionDuration = 100)
{
this.room = room;
this.transitionDuration = transitionDuration;
}
@ -32,7 +30,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
{
status.BindValueChanged(s =>
{
this.FadeColour(colours.ForRoomCategory(category.Value) ?? s.NewValue.GetAppropriateColour(colours), transitionDuration);
this.FadeColour(colours.ForRoomCategory(room.Category) ?? s.NewValue.GetAppropriateColour(colours), transitionDuration);
}, true);
}
}

View File

@ -164,7 +164,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
specialCategoryPill = new RoomSpecialCategoryPill
specialCategoryPill = new RoomSpecialCategoryPill(Room)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
@ -259,15 +259,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
wrapper.FadeInFromZero(200);
roomCategory.BindTo(Room.Category);
roomCategory.BindValueChanged(c =>
{
if (c.NewValue > RoomCategory.Normal)
specialCategoryPill.Show();
else
specialCategoryPill.Hide();
}, true);
roomType.BindTo(Room.Type);
roomType.BindValueChanged(t =>
{
@ -278,6 +269,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
hasPassword.BindValueChanged(v => passwordIcon.Alpha = v.NewValue ? 1 : 0, true);
updateRoomName();
updateRoomCategory();
};
SelectedItem.BindValueChanged(item => background.Beatmap.Value = item.NewValue?.Beatmap, true);
@ -285,8 +277,16 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.Name))
updateRoomName();
switch (e.PropertyName)
{
case nameof(Room.Name):
updateRoomName();
break;
case nameof(Room.Category):
updateRoomCategory();
break;
}
}
private void updateRoomName()
@ -295,6 +295,14 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
roomName.Text = Room.Name;
}
private void updateRoomCategory()
{
if (Room.Category > RoomCategory.Normal)
specialCategoryPill?.Show();
else
specialCategoryPill?.Hide();
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
return new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent))

View File

@ -1,21 +1,30 @@
// 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;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Online.Rooms;
using osuTK.Graphics;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public partial class RoomSpecialCategoryPill : OnlinePlayPill
{
private readonly Room room;
[Resolved]
private OsuColour colours { get; set; } = null!;
protected override FontUsage Font => base.Font.With(weight: FontWeight.SemiBold);
public RoomSpecialCategoryPill(Room room)
{
this.room = room;
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -23,11 +32,26 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
Pill.Background.Alpha = 1;
TextFlow.Colour = Color4.Black;
Category.BindValueChanged(c =>
{
TextFlow.Text = c.NewValue.GetLocalisableDescription();
Pill.Background.Colour = colours.ForRoomCategory(c.NewValue) ?? colours.Pink;
}, true);
room.PropertyChanged += onRoomPropertyChanged;
updateRoomCategory();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.Category))
updateRoomCategory();
}
private void updateRoomCategory()
{
TextFlow.Text = room.Category.GetLocalisableDescription();
Pill.Background.Colour = colours.ForRoomCategory(room.Category) ?? colours.Pink;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
}
}

View File

@ -169,7 +169,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
foreach (var room in roomFlow)
{
roomFlow.SetLayoutPosition(room, room.Room.Category.Value > RoomCategory.Normal
roomFlow.SetLayoutPosition(room, room.Room.Category > RoomCategory.Normal
// Always show spotlight playlists at the top of the listing.
? float.MinValue
: -(room.Room.RoomID ?? 0));

View File

@ -66,7 +66,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
AddRangeInternal(new Drawable[]
{
new StatusColouredContainer(transition_duration)
new StatusColouredContainer(Room, transition_duration)
{
RelativeSizeAxes = Axes.Both,
Child = selectionBox = new Container

View File

@ -31,9 +31,6 @@ namespace osu.Game.Screens.OnlinePlay
[Resolved(typeof(Room))]
protected Bindable<Room.RoomDifficultyRange> DifficultyRange { get; private set; } = null!;
[Resolved(typeof(Room))]
protected Bindable<RoomCategory> Category { get; private set; } = null!;
[Resolved(typeof(Room))]
protected BindableList<APIUser> RecentParticipants { get; private set; } = null!;

View File

@ -35,7 +35,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
Name = $@"Room {currentRoomId}",
Host = new APIUser { Username = @"Host" },
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
Category = { Value = withSpotlightRooms && i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal },
Category = withSpotlightRooms && i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal,
};
if (withPassword)