1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:43:20 +08:00
osu-lazer/osu.Game.Tournament/Screens/MapPool/MapPoolScreen.cs

265 lines
9.7 KiB
C#
Raw Normal View History

2019-03-04 12:24:19 +08:00
// 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.
2018-11-06 15:15:03 +08:00
2018-11-08 05:29:04 +08:00
using System.Linq;
using osu.Framework.Allocation;
2019-03-02 12:40:43 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-11-08 05:29:04 +08:00
using osu.Framework.Input.Events;
using osu.Framework.Threading;
2018-11-08 05:36:36 +08:00
using osu.Game.Beatmaps;
2018-11-08 05:29:04 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Tournament.Components;
2018-11-08 05:36:36 +08:00
using osu.Game.Tournament.IPC;
2019-06-18 13:51:48 +08:00
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Gameplay;
2018-11-15 20:28:42 +08:00
using osu.Game.Tournament.Screens.Gameplay.Components;
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
namespace osu.Game.Tournament.Screens.MapPool
{
public class MapPoolScreen : TournamentScreen
{
2018-11-17 15:06:43 +08:00
private readonly FillFlowContainer<FillFlowContainer<TournamentBeatmapPanel>> mapFlows;
2018-11-08 05:29:04 +08:00
2019-06-18 13:57:05 +08:00
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
2019-06-14 16:20:15 +08:00
[Resolved(canBeNull: true)]
private TournamentSceneManager sceneManager { get; set; }
2018-11-08 05:36:36 +08:00
private TeamColour pickColour;
private ChoiceType pickType;
2019-06-18 16:17:46 +08:00
private readonly OsuButton buttonRedBan;
private readonly OsuButton buttonBlueBan;
private readonly OsuButton buttonRedPick;
private readonly OsuButton buttonBluePick;
2018-11-08 05:36:36 +08:00
2018-11-08 05:29:04 +08:00
public MapPoolScreen()
{
InternalChildren = new Drawable[]
{
2020-05-15 03:51:39 +08:00
new TourneyVideo("mappool")
{
Loop = true,
RelativeSizeAxes = Axes.Both,
},
2018-11-10 16:26:21 +08:00
new MatchHeader(),
2018-11-17 15:06:43 +08:00
mapFlows = new FillFlowContainer<FillFlowContainer<TournamentBeatmapPanel>>
{
2020-03-13 13:09:09 +08:00
Y = 160,
Spacing = new Vector2(10, 10),
2018-11-17 15:06:43 +08:00
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2018-11-08 05:29:04 +08:00
},
new ControlPanel
{
Children = new Drawable[]
{
new TournamentSpriteText
2018-11-08 05:29:04 +08:00
{
Text = "Current Mode"
},
buttonRedBan = new TourneyButton
2018-11-08 05:29:04 +08:00
{
RelativeSizeAxes = Axes.X,
Text = "Red Ban",
Action = () => setMode(TeamColour.Red, ChoiceType.Ban)
},
buttonBlueBan = new TourneyButton
2018-11-08 05:29:04 +08:00
{
RelativeSizeAxes = Axes.X,
Text = "Blue Ban",
Action = () => setMode(TeamColour.Blue, ChoiceType.Ban)
},
buttonRedPick = new TourneyButton
2018-11-08 05:29:04 +08:00
{
RelativeSizeAxes = Axes.X,
Text = "Red Pick",
Action = () => setMode(TeamColour.Red, ChoiceType.Pick)
},
buttonBluePick = new TourneyButton
2018-11-08 05:29:04 +08:00
{
RelativeSizeAxes = Axes.X,
Text = "Blue Pick",
Action = () => setMode(TeamColour.Blue, ChoiceType.Pick)
2018-11-08 05:47:42 +08:00
},
new ControlPanel.Spacer(),
new TourneyButton
2018-11-08 05:47:42 +08:00
{
RelativeSizeAxes = Axes.X,
Text = "Reset",
Action = reset
},
new ControlPanel.Spacer(),
2018-11-08 05:29:04 +08:00
}
}
};
2018-11-08 05:29:04 +08:00
}
2018-11-08 05:36:36 +08:00
[BackgroundDependencyLoader]
private void load(MatchIPCInfo ipc)
2018-11-08 05:36:36 +08:00
{
currentMatch.BindValueChanged(matchChanged);
currentMatch.BindTo(LadderInfo.CurrentMatch);
2018-11-08 05:29:04 +08:00
2018-11-08 05:36:36 +08:00
ipc.Beatmap.BindValueChanged(beatmapChanged);
}
2019-03-02 12:40:43 +08:00
private void beatmapChanged(ValueChangedEvent<BeatmapInfo> beatmap)
2018-11-08 05:36:36 +08:00
{
if (currentMatch.Value == null || currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) < 2)
2018-11-10 23:48:22 +08:00
return;
// if bans have already been placed, beatmap changes result in a selection being made autoamtically
2019-03-02 12:40:43 +08:00
if (beatmap.NewValue.OnlineBeatmapID != null)
addForBeatmap(beatmap.NewValue.OnlineBeatmapID.Value);
2018-11-08 05:36:36 +08:00
}
2018-11-08 05:29:04 +08:00
private void setMode(TeamColour colour, ChoiceType choiceType)
{
pickColour = colour;
pickType = choiceType;
2019-11-12 18:37:20 +08:00
static Color4 setColour(bool active) => active ? Color4.White : Color4.Gray;
2018-11-08 05:29:04 +08:00
2018-11-08 05:47:42 +08:00
buttonRedBan.Colour = setColour(pickColour == TeamColour.Red && pickType == ChoiceType.Ban);
buttonBlueBan.Colour = setColour(pickColour == TeamColour.Blue && pickType == ChoiceType.Ban);
buttonRedPick.Colour = setColour(pickColour == TeamColour.Red && pickType == ChoiceType.Pick);
buttonBluePick.Colour = setColour(pickColour == TeamColour.Blue && pickType == ChoiceType.Pick);
2018-11-08 05:29:04 +08:00
}
private void setNextMode()
{
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;
2018-11-10 23:48:22 +08:00
if (pickType == ChoiceType.Ban && currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2)
setMode(pickColour, ChoiceType.Pick);
else
setMode(nextColour, currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2 ? ChoiceType.Pick : ChoiceType.Ban);
2018-11-08 05:29:04 +08:00
}
protected override bool OnMouseDown(MouseDownEvent e)
{
2018-11-17 15:06:43 +08:00
var maps = mapFlows.Select(f => f.FirstOrDefault(m => m.ReceivePositionalInputAt(e.ScreenSpaceMousePosition)));
var map = maps.FirstOrDefault(m => m != null);
2018-11-08 05:29:04 +08:00
if (map != null)
{
2018-11-08 05:36:36 +08:00
if (e.Button == MouseButton.Left && map.Beatmap.OnlineBeatmapID != null)
addForBeatmap(map.Beatmap.OnlineBeatmapID.Value);
2018-11-08 05:29:04 +08:00
else
{
var existing = currentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == map.Beatmap.OnlineBeatmapID);
2018-11-08 05:29:04 +08:00
if (existing != null)
{
currentMatch.Value.PicksBans.Remove(existing);
setNextMode();
}
}
return true;
}
return base.OnMouseDown(e);
}
2018-11-08 05:47:42 +08:00
private void reset()
{
currentMatch.Value.PicksBans.Clear();
setNextMode();
}
private ScheduledDelegate scheduledChange;
2018-11-08 05:36:36 +08:00
private void addForBeatmap(int beatmapId)
2018-11-08 05:29:04 +08:00
{
2018-11-08 12:08:59 +08:00
if (currentMatch.Value == null)
return;
2019-06-18 13:44:15 +08:00
if (currentMatch.Value.Round.Value.Beatmaps.All(b => b.BeatmapInfo.OnlineBeatmapID != beatmapId))
2018-11-08 05:36:36 +08:00
// don't attempt to add if the beatmap isn't in our pool
return;
if (currentMatch.Value.PicksBans.Any(p => p.BeatmapID == beatmapId))
// don't attempt to add if already exists.
return;
currentMatch.Value.PicksBans.Add(new BeatmapChoice
{
Team = pickColour,
Type = pickType,
BeatmapID = beatmapId
});
setNextMode();
if (pickType == ChoiceType.Pick && currentMatch.Value.PicksBans.Any(i => i.Type == ChoiceType.Pick))
{
scheduledChange?.Cancel();
scheduledChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(GameplayScreen)); }, 10000);
}
2018-11-08 05:29:04 +08:00
}
2019-06-18 13:57:05 +08:00
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
2018-11-08 05:29:04 +08:00
{
2018-11-17 15:06:43 +08:00
mapFlows.Clear();
int totalRows = 0;
2019-06-18 13:44:15 +08:00
if (match.NewValue.Round.Value != null)
{
2018-11-17 15:06:43 +08:00
FillFlowContainer<TournamentBeatmapPanel> currentFlow = null;
string currentMod = null;
int flowCount = 0;
2019-06-18 13:44:15 +08:00
foreach (var b in match.NewValue.Round.Value.Beatmaps)
2018-11-17 15:06:43 +08:00
{
if (currentFlow == null || currentMod != b.Mods)
{
mapFlows.Add(currentFlow = new FillFlowContainer<TournamentBeatmapPanel>
{
Spacing = new Vector2(10, 5),
2018-11-17 15:06:43 +08:00
Direction = FillDirection.Full,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
});
currentMod = b.Mods;
totalRows++;
flowCount = 0;
}
if (++flowCount > 2)
{
totalRows++;
2020-03-11 14:34:52 +08:00
flowCount = 1;
2018-11-17 15:06:43 +08:00
}
currentFlow.Add(new TournamentBeatmapPanel(b.BeatmapInfo, b.Mods)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Height = 42,
});
2018-11-17 15:06:43 +08:00
}
}
2020-03-13 13:25:25 +08:00
mapFlows.Padding = new MarginPadding(5)
{
// remove horizontal padding to increase flow width to 3 panels
2020-03-13 13:25:25 +08:00
Horizontal = totalRows > 9 ? 0 : 100
};
}
}
}