Make beatmap selection work

This commit is contained in:
smoogipoo 2018-12-06 12:21:30 +09:00
parent 5f0bde581c
commit eadbe4c470
6 changed files with 106 additions and 76 deletions

View File

@ -1,43 +0,0 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Screens.Multi.Screens.Match;
namespace osu.Game.Tests.Visual
{
[TestFixture]
public class TestCaseMatchHeader : OsuTestCase
{
public TestCaseMatchHeader()
{
Header header = new Header();
Add(header);
AddStep(@"set beatmap set", () => header.BeatmapSet = new BeatmapSetInfo
{
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new BeatmapSetOnlineCovers
{
Cover = @"https://assets.ppy.sh/beatmaps/760757/covers/cover.jpg?1526944540",
},
},
});
AddStep(@"change beatmap set", () => header.BeatmapSet = new BeatmapSetInfo
{
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new BeatmapSetOnlineCovers
{
Cover = @"https://assets.ppy.sh/beatmaps/761883/covers/cover.jpg?1525557400",
},
},
});
AddStep(@"null beatmap set", () => header.BeatmapSet = null);
}
}
}

View File

@ -0,0 +1,50 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Beatmaps.Drawables
{
public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<WorkingBeatmap>
{
public readonly IBindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
[Resolved]
private OsuGameBase game { get; set; }
public UpdateableBeatmapBackgroundSprite()
{
Beatmap.BindValueChanged(b => Schedule(() => Model = b));
}
protected override Drawable CreateDrawable(WorkingBeatmap model)
{
Drawable drawable = model == null ? (Drawable)new DefaultSprite() : new BeatmapBackgroundSprite(model);
drawable.RelativeSizeAxes = Axes.Both;
drawable.Anchor = Anchor.Centre;
drawable.Origin = Anchor.Centre;
drawable.FillMode = FillMode.Fill;
return drawable;
}
protected override double FadeDuration => 400;
private class DefaultSprite : Sprite
{
[Resolved]
private IBindableBeatmap gameBeatmap { get; set; }
[BackgroundDependencyLoader]
private void load()
{
Texture = gameBeatmap.Default.Background;
}
}
}
}

View File

@ -44,9 +44,14 @@ namespace osu.Game.Screens.Multi.Components
private readonly Bindable<User> hostBind = new Bindable<User>();
private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
private readonly Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
private readonly Bindable<BeatmapInfo> roomBeatmap = new Bindable<BeatmapInfo>();
private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>();
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
[Resolved]
private BeatmapManager beatmaps { get; set; }
public readonly Room Room;
private SelectionState state;
@ -101,7 +106,7 @@ namespace osu.Game.Screens.Multi.Components
private void load(OsuColour colours)
{
Box sideStrip;
UpdateableBeatmapSetCover cover;
UpdateableBeatmapBackgroundSprite background;
OsuSpriteText name, status;
ParticipantInfo participantInfo;
BeatmapTitle beatmapTitle;
@ -137,12 +142,13 @@ namespace osu.Game.Screens.Multi.Components
RelativeSizeAxes = Axes.Y,
Width = side_strip_width,
},
cover = new UpdateableBeatmapSetCover
new Container
{
Width = cover_width,
RelativeSizeAxes = Axes.Y,
Width = cover_width,
Masking = true,
Margin = new MarginPadding { Left = side_strip_width },
Child = background = new UpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both }
},
new Container
{
@ -216,9 +222,11 @@ namespace osu.Game.Screens.Multi.Components
d.FadeColour(s.GetAppropriateColour(colours), transition_duration);
};
beatmapBind.ValueChanged += b =>
background.Beatmap.BindTo(beatmap);
roomBeatmap.ValueChanged += b =>
{
cover.BeatmapSet = b?.BeatmapSet;
beatmap.Value = beatmaps.GetWorkingBeatmap(b);
beatmapTitle.Beatmap = b;
modeTypeInfo.Beatmap = b;
};
@ -227,7 +235,7 @@ namespace osu.Game.Screens.Multi.Components
hostBind.BindTo(Room.Host);
statusBind.BindTo(Room.Status);
typeBind.BindTo(Room.Type);
beatmapBind.BindTo(Room.Beatmap);
roomBeatmap.BindTo(Room.Beatmap);
participantsBind.BindTo(Room.Participants);
}

View File

@ -32,13 +32,15 @@ namespace osu.Game.Screens.Multi.Components
private readonly Bindable<User> hostBind = new Bindable<User>();
private readonly Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
private readonly Bindable<GameType> typeBind = new Bindable<GameType>();
private readonly Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
private readonly Bindable<BeatmapInfo> roomBeatmap = new Bindable<BeatmapInfo>();
private readonly Bindable<int?> maxParticipantsBind = new Bindable<int?>();
private readonly Bindable<IEnumerable<User>> participantsBind = new Bindable<IEnumerable<User>>();
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
private OsuColour colours;
private Box statusStrip;
private UpdateableBeatmapSetCover cover;
private UpdateableBeatmapBackgroundSprite background;
private ParticipantCount participantCount;
private FillFlowContainer topFlow, participantsFlow;
private OsuSpriteText name, status;
@ -46,6 +48,9 @@ namespace osu.Game.Screens.Multi.Components
private ScrollContainer participantsScroll;
private ParticipantInfo participantInfo;
[Resolved]
private BeatmapManager beatmaps { get; set; }
private Room room;
public Room Room
{
@ -59,7 +64,7 @@ namespace osu.Game.Screens.Multi.Components
hostBind.UnbindBindings();
statusBind.UnbindBindings();
typeBind.UnbindBindings();
beatmapBind.UnbindBindings();
roomBeatmap.UnbindBindings();
maxParticipantsBind.UnbindBindings();
participantsBind.UnbindBindings();
@ -69,7 +74,7 @@ namespace osu.Game.Screens.Multi.Components
hostBind.BindTo(room.Host);
statusBind.BindTo(room.Status);
typeBind.BindTo(room.Type);
beatmapBind.BindTo(room.Beatmap);
roomBeatmap.BindTo(room.Beatmap);
maxParticipantsBind.BindTo(room.MaxParticipants);
participantsBind.BindTo(room.Participants);
}
@ -104,10 +109,7 @@ namespace osu.Game.Screens.Multi.Components
Masking = true,
Children = new Drawable[]
{
cover = new UpdateableBeatmapSetCover
{
RelativeSizeAxes = Axes.Both,
},
background = new UpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both },
new Box
{
RelativeSizeAxes = Axes.Both,
@ -207,9 +209,11 @@ namespace osu.Game.Screens.Multi.Components
maxParticipantsBind.ValueChanged += m => participantCount.Max = m;
statusBind.ValueChanged += displayStatus;
beatmapBind.ValueChanged += b =>
background.Beatmap.BindTo(beatmap);
roomBeatmap.ValueChanged += b =>
{
cover.BeatmapSet = b?.BeatmapSet;
beatmap.Value = beatmaps.GetWorkingBeatmap(b);
beatmapTypeInfo.Beatmap = b;
};
@ -243,7 +247,7 @@ namespace osu.Game.Screens.Multi.Components
{
if (Room == null)
{
cover.BeatmapSet = null;
beatmap.Value = null;
participantsFlow.FadeOut(transition_duration);
participantCount.FadeOut(transition_duration);
beatmapTypeInfo.FadeOut(transition_duration);
@ -261,7 +265,7 @@ namespace osu.Game.Screens.Multi.Components
participantInfo.FadeIn(transition_duration);
statusBind.TriggerChange();
beatmapBind.TriggerChange();
roomBeatmap.TriggerChange();
}
}

View File

@ -3,6 +3,7 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
@ -24,16 +25,12 @@ namespace osu.Game.Screens.Multi.Screens.Match
{
public const float HEIGHT = 200;
public readonly IBindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
private readonly Box tabStrip;
private readonly UpdateableBeatmapSetCover cover;
public readonly PageTabControl<MatchHeaderPage> Tabs;
public BeatmapSetInfo BeatmapSet
{
set => cover.BeatmapSet = value;
}
public Action OnRequestSelectBeatmap;
public Header()
@ -42,12 +39,14 @@ namespace osu.Game.Screens.Multi.Screens.Match
Height = HEIGHT;
BeatmapSelectButton beatmapButton;
UpdateableBeatmapBackgroundSprite background;
Children = new Drawable[]
{
cover = new UpdateableBeatmapSetCover
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Child = background = new UpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both }
},
new Box
{
@ -90,6 +89,8 @@ namespace osu.Game.Screens.Multi.Screens.Match
};
beatmapButton.Action = () => OnRequestSelectBeatmap?.Invoke();
background.Beatmap.BindTo(Beatmap);
}
[BackgroundDependencyLoader]

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -22,19 +23,24 @@ namespace osu.Game.Screens.Multi.Screens.Match
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<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
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;
public override string Title => room.Name.Value;
public override string ShortTitle => "room";
[Resolved]
private BeatmapManager beatmapManager { get; set; }
public Match(Room room)
{
this.room = room;
Header header;
RoomSettingsOverlay settings;
Info info;
@ -68,13 +74,9 @@ namespace osu.Game.Screens.Multi.Screens.Match
};
header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect());
header.Beatmap.BindTo(Beatmap);
beatmapBind.BindTo(room.Beatmap);
beatmapBind.BindValueChanged(b =>
{
header.BeatmapSet = b?.BeatmapSet;
info.Beatmap = b;
}, true);
roomBeatmap.BindValueChanged(b => info.Beatmap = b, true);
header.Tabs.Current.ValueChanged += t =>
{
@ -110,5 +112,13 @@ namespace osu.Game.Screens.Multi.Screens.Match
participantsBind.BindTo(room.Participants);
participantsBind.BindValueChanged(p => participants.Users = p, true);
}
[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);
}
}
}