mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
Refactor bindable shenanigans in Match
This commit is contained in:
parent
d68b4bb8e7
commit
29263d7154
@ -19,10 +19,10 @@ namespace osu.Game.Tests.Visual
|
||||
Info info = new Info();
|
||||
Add(info);
|
||||
|
||||
AddStep(@"set name", () => info.Name = @"Room Name?");
|
||||
AddStep(@"set availability", () => info.Availability = RoomAvailability.FriendsOnly);
|
||||
AddStep(@"set status", () => info.Status = new RoomStatusPlaying());
|
||||
AddStep(@"set beatmap", () => info.Beatmap = new BeatmapInfo
|
||||
AddStep(@"set name", () => info.Name.Value = @"Room Name?");
|
||||
AddStep(@"set availability", () => info.Availability.Value = RoomAvailability.FriendsOnly);
|
||||
AddStep(@"set status", () => info.Status.Value = new RoomStatusPlaying());
|
||||
AddStep(@"set beatmap", () => info.Beatmap.Value = new BeatmapInfo
|
||||
{
|
||||
StarDifficulty = 2.4,
|
||||
Ruleset = rulesets.GetRuleset(0),
|
||||
@ -34,14 +34,14 @@ namespace osu.Game.Tests.Visual
|
||||
},
|
||||
});
|
||||
|
||||
AddStep(@"set type", () => info.Type = new GameTypeTagTeam());
|
||||
AddStep(@"set type", () => info.Type.Value = new GameTypeTagTeam());
|
||||
|
||||
AddStep(@"change name", () => info.Name = @"Room Name!");
|
||||
AddStep(@"change availability", () => info.Availability = RoomAvailability.InviteOnly);
|
||||
AddStep(@"change status", () => info.Status = new RoomStatusOpen());
|
||||
AddStep(@"null beatmap", () => info.Beatmap = null);
|
||||
AddStep(@"change type", () => info.Type = new GameTypeTeamVersus());
|
||||
AddStep(@"change beatmap", () => info.Beatmap = new BeatmapInfo
|
||||
AddStep(@"change name", () => info.Name.Value = @"Room Name!");
|
||||
AddStep(@"change availability", () => info.Availability.Value = RoomAvailability.InviteOnly);
|
||||
AddStep(@"change status", () => info.Status.Value = new RoomStatusOpen());
|
||||
AddStep(@"null beatmap", () => info.Beatmap.Value = null);
|
||||
AddStep(@"change type", () => info.Type.Value = new GameTypeTeamVersus());
|
||||
AddStep(@"change beatmap", () => info.Beatmap.Value = new BeatmapInfo
|
||||
{
|
||||
StarDifficulty = 4.2,
|
||||
Ruleset = rulesets.GetRuleset(3),
|
||||
|
@ -19,8 +19,8 @@ namespace osu.Game.Tests.Visual
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
});
|
||||
|
||||
AddStep(@"set max to null", () => participants.Max = null);
|
||||
AddStep(@"set users", () => participants.Users = new[]
|
||||
AddStep(@"set max to null", () => participants.MaxParticipants.Value = null);
|
||||
AddStep(@"set users", () => participants.Users.Value = new[]
|
||||
{
|
||||
new User
|
||||
{
|
||||
@ -48,9 +48,9 @@ namespace osu.Game.Tests.Visual
|
||||
},
|
||||
});
|
||||
|
||||
AddStep(@"set max", () => participants.Max = 10);
|
||||
AddStep(@"clear users", () => participants.Users = new User[] { });
|
||||
AddStep(@"set max to null", () => participants.Max = null);
|
||||
AddStep(@"set max", () => participants.MaxParticipants.Value = 10);
|
||||
AddStep(@"clear users", () => participants.Users.Value = new User[] { });
|
||||
AddStep(@"set max to null", () => participants.MaxParticipants.Value = null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge
|
||||
|
||||
public override string Title => "Lounge";
|
||||
|
||||
protected override Container<Drawable> TransitionContent => content;
|
||||
protected override Drawable TransitionContent => content;
|
||||
|
||||
public Lounge()
|
||||
{
|
||||
|
@ -23,60 +23,26 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
{
|
||||
public const float HEIGHT = 128;
|
||||
|
||||
private readonly OsuSpriteText name, availabilityStatus;
|
||||
private readonly BeatmapTypeInfo beatmapTypeInfo;
|
||||
private readonly OsuSpriteText availabilityStatus;
|
||||
private readonly ReadyButton readyButton;
|
||||
|
||||
private OsuColour colours;
|
||||
|
||||
public Bindable<bool> Ready => readyButton.Ready;
|
||||
|
||||
public string Name
|
||||
{
|
||||
set { name.Text = value; }
|
||||
}
|
||||
|
||||
private RoomAvailability availability;
|
||||
public RoomAvailability Availability
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == availability) return;
|
||||
availability = value;
|
||||
|
||||
if (IsLoaded)
|
||||
updateAvailabilityStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private RoomStatus status;
|
||||
public RoomStatus Status
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == status) return;
|
||||
status = value;
|
||||
|
||||
if (IsLoaded)
|
||||
updateAvailabilityStatus();
|
||||
}
|
||||
}
|
||||
|
||||
public BeatmapInfo Beatmap
|
||||
{
|
||||
set { beatmapTypeInfo.Beatmap = value; }
|
||||
}
|
||||
|
||||
public GameType Type
|
||||
{
|
||||
set { beatmapTypeInfo.Type = value; }
|
||||
}
|
||||
public readonly Bindable<string> Name = new Bindable<string>();
|
||||
public readonly Bindable<RoomAvailability> Availability = new Bindable<RoomAvailability>();
|
||||
public readonly Bindable<RoomStatus> Status = new Bindable<RoomStatus>();
|
||||
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
||||
public readonly Bindable<GameType> Type = new Bindable<GameType>();
|
||||
|
||||
public Info()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = HEIGHT;
|
||||
|
||||
BeatmapTypeInfo beatmapTypeInfo;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
@ -103,9 +69,10 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
name = new OsuSpriteText
|
||||
new OsuSpriteText
|
||||
{
|
||||
TextSize = 30,
|
||||
Current = Name
|
||||
},
|
||||
availabilityStatus = new OsuSpriteText
|
||||
{
|
||||
@ -131,6 +98,11 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Availability.BindValueChanged(_ => updateAvailabilityStatus());
|
||||
Status.BindValueChanged(_ => updateAvailabilityStatus());
|
||||
Beatmap.BindValueChanged(b => beatmapTypeInfo.Beatmap = b);
|
||||
Type.BindValueChanged(t => beatmapTypeInfo.Type = t);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -148,10 +120,13 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
|
||||
private void updateAvailabilityStatus()
|
||||
{
|
||||
if (status != null)
|
||||
if (!IsLoaded)
|
||||
return;
|
||||
|
||||
if (Status.Value != null)
|
||||
{
|
||||
availabilityStatus.FadeColour(status.GetAppropriateColour(colours), 100);
|
||||
availabilityStatus.Text = $"{availability.GetDescription()}, {status.Message}";
|
||||
availabilityStatus.FadeColour(Status.Value.GetAppropriateColour(colours), 100);
|
||||
availabilityStatus.Text = $"{Availability.Value.GetDescription()}, {Status.Value.Message}";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,15 +20,14 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
private readonly Participants participants;
|
||||
|
||||
private readonly Bindable<string> nameBind = new Bindable<string>();
|
||||
private readonly Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
|
||||
private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
|
||||
private readonly Bindable<RoomAvailability> availabilityBind = new Bindable<RoomAvailability>();
|
||||
private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
|
||||
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
|
||||
private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>();
|
||||
|
||||
private readonly Bindable<BeatmapInfo> roomBeatmap = new Bindable<BeatmapInfo>();
|
||||
|
||||
protected override Container<Drawable> TransitionContent => participants;
|
||||
protected override Drawable TransitionContent => participants;
|
||||
|
||||
public override string Title => room.Name.Value;
|
||||
|
||||
@ -41,6 +40,14 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
{
|
||||
this.room = room;
|
||||
|
||||
nameBind.BindTo(room.Name);
|
||||
beatmapBind.BindTo(room.Beatmap);
|
||||
statusBind.BindTo(room.Status);
|
||||
availabilityBind.BindTo(room.Availability);
|
||||
typeBind.BindTo(room.Type);
|
||||
participantsBind.BindTo(room.Participants);
|
||||
maxParticipantsBind.BindTo(room.MaxParticipants);
|
||||
|
||||
Header header;
|
||||
RoomSettingsOverlay settings;
|
||||
Info info;
|
||||
@ -76,8 +83,6 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect());
|
||||
header.Beatmap.BindTo(Beatmap);
|
||||
|
||||
roomBeatmap.BindValueChanged(b => info.Beatmap = b, true);
|
||||
|
||||
header.Tabs.Current.ValueChanged += t =>
|
||||
{
|
||||
if (t == MatchHeaderPage.Settings)
|
||||
@ -94,31 +99,22 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
|
||||
settings.Applied = () => settings.Hide();
|
||||
|
||||
nameBind.BindTo(room.Name);
|
||||
nameBind.BindValueChanged(n => info.Name = n, true);
|
||||
info.Beatmap.BindTo(beatmapBind);
|
||||
info.Name.BindTo(nameBind);
|
||||
info.Status.BindTo(statusBind);
|
||||
info.Availability.BindTo(availabilityBind);
|
||||
info.Type.BindTo(typeBind);
|
||||
|
||||
statusBind.BindTo(room.Status);
|
||||
statusBind.BindValueChanged(s => info.Status = s, true);
|
||||
|
||||
availabilityBind.BindTo(room.Availability);
|
||||
availabilityBind.BindValueChanged(a => info.Availability = a, true);
|
||||
|
||||
typeBind.BindTo(room.Type);
|
||||
typeBind.BindValueChanged(t => info.Type = t, true);
|
||||
|
||||
maxParticipantsBind.BindTo(room.MaxParticipants);
|
||||
maxParticipantsBind.BindValueChanged(m => { participants.Max = m; }, true);
|
||||
|
||||
participantsBind.BindTo(room.Participants);
|
||||
participantsBind.BindValueChanged(p => participants.Users = p, true);
|
||||
participants.Users.BindTo(participantsBind);
|
||||
participants.MaxParticipants.BindTo(maxParticipantsBind);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
roomBeatmap.BindTo(room.Beatmap);
|
||||
roomBeatmap.BindValueChanged(b => Beatmap.Value = beatmapManager.GetWorkingBeatmap(room.Beatmap.Value), true);
|
||||
Beatmap.BindValueChanged(b => roomBeatmap.Value = b.BeatmapInfo);
|
||||
beatmapBind.BindTo(room.Beatmap);
|
||||
beatmapBind.BindValueChanged(b => Beatmap.Value = beatmapManager.GetWorkingBeatmap(room.Beatmap.Value), true);
|
||||
Beatmap.BindValueChanged(b => beatmapBind.Value = b.BeatmapInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Overlays.SearchableList;
|
||||
@ -12,35 +13,23 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Multi.Screens.Match
|
||||
{
|
||||
public class Participants : Container
|
||||
public class Participants : CompositeDrawable
|
||||
{
|
||||
private readonly ParticipantCount count;
|
||||
private readonly FillFlowContainer<UserPanel> usersFlow;
|
||||
public readonly Bindable<IEnumerable<User>> Users = new Bindable<IEnumerable<User>>();
|
||||
public readonly Bindable<int?> MaxParticipants = new Bindable<int?>();
|
||||
|
||||
public IEnumerable<User> Users
|
||||
public new MarginPadding Padding
|
||||
{
|
||||
set
|
||||
{
|
||||
usersFlow.Children = value.Select(u => new UserPanel(u)
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
Width = 300,
|
||||
OnLoadComplete = d => d.FadeInFromZero(60),
|
||||
}).ToList();
|
||||
|
||||
count.Count = value.Count();
|
||||
}
|
||||
}
|
||||
|
||||
public int? Max
|
||||
{
|
||||
set => count.Max = value;
|
||||
get => base.Padding;
|
||||
set => base.Padding = value;
|
||||
}
|
||||
|
||||
public Participants()
|
||||
{
|
||||
Child = new Container
|
||||
FillFlowContainer<UserPanel> usersFlow;
|
||||
ParticipantCount count;
|
||||
|
||||
InternalChild = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Horizontal = SearchableListOverlay.WIDTH_PADDING },
|
||||
@ -70,6 +59,21 @@ namespace osu.Game.Screens.Multi.Screens.Match
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Users.BindValueChanged(v =>
|
||||
{
|
||||
usersFlow.Children = v.Select(u => new UserPanel(u)
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
Width = 300,
|
||||
OnLoadComplete = d => d.FadeInFromZero(60),
|
||||
}).ToList();
|
||||
|
||||
count.Count = v.Count();
|
||||
});
|
||||
|
||||
MaxParticipants.BindValueChanged(v => count.Max = v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Graphics.Containers;
|
||||
|
||||
@ -10,7 +9,7 @@ namespace osu.Game.Screens.Multi.Screens
|
||||
{
|
||||
public abstract class MultiplayerScreen : OsuScreen, IMultiplayerScreen
|
||||
{
|
||||
protected virtual Container<Drawable> TransitionContent => Content;
|
||||
protected virtual Drawable TransitionContent => Content;
|
||||
|
||||
public virtual string ShortTitle => Title;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user