1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 13:23:05 +08:00

Add warning message to screens which require a current match to be selected

This commit is contained in:
Dean Herbert 2021-07-16 23:34:28 +09:00
parent 6a781aedb3
commit 71f74f0e98
2 changed files with 54 additions and 20 deletions

View File

@ -21,12 +21,10 @@ using osuTK.Input;
namespace osu.Game.Tournament.Screens.MapPool namespace osu.Game.Tournament.Screens.MapPool
{ {
public class MapPoolScreen : TournamentScreen public class MapPoolScreen : TournamentMatchScreen
{ {
private readonly FillFlowContainer<FillFlowContainer<TournamentBeatmapPanel>> mapFlows; private readonly FillFlowContainer<FillFlowContainer<TournamentBeatmapPanel>> mapFlows;
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
[Resolved(canBeNull: true)] [Resolved(canBeNull: true)]
private TournamentSceneManager sceneManager { get; set; } private TournamentSceneManager sceneManager { get; set; }
@ -96,7 +94,7 @@ namespace osu.Game.Tournament.Screens.MapPool
Action = reset Action = reset
}, },
new ControlPanel.Spacer(), new ControlPanel.Spacer(),
} },
} }
}; };
} }
@ -104,15 +102,12 @@ namespace osu.Game.Tournament.Screens.MapPool
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(MatchIPCInfo ipc) private void load(MatchIPCInfo ipc)
{ {
currentMatch.BindValueChanged(matchChanged);
currentMatch.BindTo(LadderInfo.CurrentMatch);
ipc.Beatmap.BindValueChanged(beatmapChanged); ipc.Beatmap.BindValueChanged(beatmapChanged);
} }
private void beatmapChanged(ValueChangedEvent<BeatmapInfo> beatmap) private void beatmapChanged(ValueChangedEvent<BeatmapInfo> beatmap)
{ {
if (currentMatch.Value == null || currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) < 2) if (CurrentMatch.Value == null || CurrentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) < 2)
return; return;
// if bans have already been placed, beatmap changes result in a selection being made autoamtically // if bans have already been placed, beatmap changes result in a selection being made autoamtically
@ -137,12 +132,12 @@ namespace osu.Game.Tournament.Screens.MapPool
{ {
const TeamColour roll_winner = TeamColour.Red; //todo: draw from match const TeamColour roll_winner = TeamColour.Red; //todo: draw from match
var nextColour = (currentMatch.Value.PicksBans.LastOrDefault()?.Team ?? roll_winner) == TeamColour.Red ? TeamColour.Blue : TeamColour.Red; var nextColour = (CurrentMatch.Value.PicksBans.LastOrDefault()?.Team ?? roll_winner) == TeamColour.Red ? TeamColour.Blue : TeamColour.Red;
if (pickType == ChoiceType.Ban && currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2) if (pickType == ChoiceType.Ban && CurrentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2)
setMode(pickColour, ChoiceType.Pick); setMode(pickColour, ChoiceType.Pick);
else else
setMode(nextColour, currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2 ? ChoiceType.Pick : ChoiceType.Ban); setMode(nextColour, CurrentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2 ? ChoiceType.Pick : ChoiceType.Ban);
} }
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
@ -156,11 +151,11 @@ namespace osu.Game.Tournament.Screens.MapPool
addForBeatmap(map.Beatmap.OnlineBeatmapID.Value); addForBeatmap(map.Beatmap.OnlineBeatmapID.Value);
else else
{ {
var existing = currentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == map.Beatmap.OnlineBeatmapID); var existing = CurrentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == map.Beatmap.OnlineBeatmapID);
if (existing != null) if (existing != null)
{ {
currentMatch.Value.PicksBans.Remove(existing); CurrentMatch.Value.PicksBans.Remove(existing);
setNextMode(); setNextMode();
} }
} }
@ -173,7 +168,7 @@ namespace osu.Game.Tournament.Screens.MapPool
private void reset() private void reset()
{ {
currentMatch.Value.PicksBans.Clear(); CurrentMatch.Value.PicksBans.Clear();
setNextMode(); setNextMode();
} }
@ -181,18 +176,18 @@ namespace osu.Game.Tournament.Screens.MapPool
private void addForBeatmap(int beatmapId) private void addForBeatmap(int beatmapId)
{ {
if (currentMatch.Value == null) if (CurrentMatch.Value == null)
return; return;
if (currentMatch.Value.Round.Value.Beatmaps.All(b => b.BeatmapInfo.OnlineBeatmapID != beatmapId)) if (CurrentMatch.Value.Round.Value.Beatmaps.All(b => b.BeatmapInfo.OnlineBeatmapID != beatmapId))
// don't attempt to add if the beatmap isn't in our pool // don't attempt to add if the beatmap isn't in our pool
return; return;
if (currentMatch.Value.PicksBans.Any(p => p.BeatmapID == beatmapId)) if (CurrentMatch.Value.PicksBans.Any(p => p.BeatmapID == beatmapId))
// don't attempt to add if already exists. // don't attempt to add if already exists.
return; return;
currentMatch.Value.PicksBans.Add(new BeatmapChoice CurrentMatch.Value.PicksBans.Add(new BeatmapChoice
{ {
Team = pickColour, Team = pickColour,
Type = pickType, Type = pickType,
@ -201,17 +196,22 @@ namespace osu.Game.Tournament.Screens.MapPool
setNextMode(); setNextMode();
if (pickType == ChoiceType.Pick && currentMatch.Value.PicksBans.Any(i => i.Type == ChoiceType.Pick)) if (pickType == ChoiceType.Pick && CurrentMatch.Value.PicksBans.Any(i => i.Type == ChoiceType.Pick))
{ {
scheduledChange?.Cancel(); scheduledChange?.Cancel();
scheduledChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(GameplayScreen)); }, 10000); scheduledChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(GameplayScreen)); }, 10000);
} }
} }
private void matchChanged(ValueChangedEvent<TournamentMatch> match) protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{ {
base.CurrentMatchChanged(match);
mapFlows.Clear(); mapFlows.Clear();
if (match.NewValue == null)
return;
int totalRows = 0; int totalRows = 0;
if (match.NewValue.Round.Value != null) if (match.NewValue.Round.Value != null)

View File

@ -0,0 +1,34 @@
// 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.Bindables;
using osu.Game.Tournament.Models;
namespace osu.Game.Tournament.Screens
{
public abstract class TournamentMatchScreen : TournamentScreen
{
protected readonly Bindable<TournamentMatch> CurrentMatch = new Bindable<TournamentMatch>();
private WarningBox noMatchWarning;
protected override void LoadComplete()
{
base.LoadComplete();
CurrentMatch.BindTo(LadderInfo.CurrentMatch);
CurrentMatch.BindValueChanged(CurrentMatchChanged, true);
}
protected virtual void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
if (match.NewValue == null)
{
AddInternal(noMatchWarning = new WarningBox("Choose a match first from the brackets screen"));
return;
}
noMatchWarning?.Expire();
noMatchWarning = null;
}
}
}