2018-11-06 15:15:03 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2018-11-08 05:29:04 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Configuration;
|
2018-11-06 13:49:09 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-08 05:29:04 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-11-18 08:29:18 +08:00
|
|
|
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.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-11-06 13:49:09 +08:00
|
|
|
using osu.Game.Tournament.Components;
|
2018-11-08 05:36:36 +08:00
|
|
|
using osu.Game.Tournament.IPC;
|
2018-11-18 08:29:18 +08:00
|
|
|
using osu.Game.Tournament.Screens.Gameplay;
|
2018-11-15 20:28:42 +08:00
|
|
|
using osu.Game.Tournament.Screens.Gameplay.Components;
|
2018-11-06 13:49:09 +08:00
|
|
|
using osu.Game.Tournament.Screens.Ladder.Components;
|
|
|
|
using OpenTK;
|
2018-11-08 05:47:42 +08:00
|
|
|
using OpenTK.Graphics;
|
2018-11-08 05:29:04 +08:00
|
|
|
using OpenTK.Input;
|
2018-11-06 13:49:09 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.MapPool
|
|
|
|
{
|
2018-11-11 00:39:02 +08:00
|
|
|
public class MapPoolScreen : TournamentScreen
|
2018-11-06 13:49:09 +08:00
|
|
|
{
|
2018-11-17 15:06:43 +08:00
|
|
|
private readonly FillFlowContainer<FillFlowContainer<TournamentBeatmapPanel>> mapFlows;
|
2018-11-08 05:29:04 +08:00
|
|
|
|
|
|
|
private readonly Bindable<MatchPairing> currentMatch = new Bindable<MatchPairing>();
|
2018-11-06 13:49:09 +08:00
|
|
|
|
2018-11-08 05:36:36 +08:00
|
|
|
private TeamColour pickColour;
|
|
|
|
private ChoiceType pickType;
|
|
|
|
|
|
|
|
private readonly TriangleButton buttonRedBan;
|
|
|
|
private readonly TriangleButton buttonBlueBan;
|
|
|
|
private readonly TriangleButton buttonRedPick;
|
|
|
|
private readonly TriangleButton buttonBluePick;
|
|
|
|
|
2018-11-08 05:29:04 +08:00
|
|
|
public MapPoolScreen()
|
|
|
|
{
|
2018-11-06 13:49:09 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2018-11-10 16:26:21 +08:00
|
|
|
new MatchHeader(),
|
2018-11-17 15:06:43 +08:00
|
|
|
mapFlows = new FillFlowContainer<FillFlowContainer<TournamentBeatmapPanel>>
|
2018-11-06 13:49:09 +08:00
|
|
|
{
|
2018-11-10 16:26:21 +08:00
|
|
|
Y = 100,
|
2018-11-16 18:49:17 +08:00
|
|
|
Spacing = new Vector2(10, 20),
|
2018-11-06 13:49:09 +08:00
|
|
|
Padding = new MarginPadding(50),
|
2018-11-17 15:06:43 +08:00
|
|
|
Direction = FillDirection.Vertical,
|
2018-11-06 13:49:09 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-11-08 05:29:04 +08:00
|
|
|
},
|
|
|
|
new ControlPanel
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "Current Mode"
|
|
|
|
},
|
|
|
|
buttonRedBan = new TriangleButton
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Text = "Red Ban",
|
|
|
|
Action = () => setMode(TeamColour.Red, ChoiceType.Ban)
|
|
|
|
},
|
|
|
|
buttonBlueBan = new TriangleButton
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Text = "Blue Ban",
|
|
|
|
Action = () => setMode(TeamColour.Blue, ChoiceType.Ban)
|
|
|
|
},
|
|
|
|
buttonRedPick = new TriangleButton
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Text = "Red Pick",
|
|
|
|
Action = () => setMode(TeamColour.Red, ChoiceType.Pick)
|
|
|
|
},
|
|
|
|
buttonBluePick = new TriangleButton
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Text = "Blue Pick",
|
|
|
|
Action = () => setMode(TeamColour.Blue, ChoiceType.Pick)
|
2018-11-08 05:47:42 +08:00
|
|
|
},
|
|
|
|
new ControlPanel.Spacer(),
|
|
|
|
new TriangleButton
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Text = "Reset",
|
|
|
|
Action = reset
|
|
|
|
},
|
2018-11-08 05:29:04 +08:00
|
|
|
}
|
2018-11-06 13:49:09 +08:00
|
|
|
}
|
|
|
|
};
|
2018-11-08 05:29:04 +08:00
|
|
|
}
|
|
|
|
|
2018-11-08 05:36:36 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2018-11-15 20:28:42 +08:00
|
|
|
private void load(LadderInfo ladder, MatchIPCInfo ipc)
|
2018-11-08 05:36:36 +08:00
|
|
|
{
|
|
|
|
currentMatch.BindValueChanged(matchChanged);
|
|
|
|
currentMatch.BindTo(ladder.CurrentMatch);
|
2018-11-08 05:29:04 +08:00
|
|
|
|
2018-11-08 05:36:36 +08:00
|
|
|
ipc.Beatmap.BindValueChanged(beatmapChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void beatmapChanged(BeatmapInfo beatmap)
|
|
|
|
{
|
2018-11-10 23:48:22 +08:00
|
|
|
if (currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) < 2)
|
|
|
|
return;
|
|
|
|
|
2018-11-08 05:36:36 +08:00
|
|
|
if (beatmap.OnlineBeatmapID != null)
|
|
|
|
addForBeatmap(beatmap.OnlineBeatmapID.Value);
|
|
|
|
}
|
2018-11-08 05:29:04 +08:00
|
|
|
|
|
|
|
private void setMode(TeamColour colour, ChoiceType choiceType)
|
|
|
|
{
|
|
|
|
pickColour = colour;
|
|
|
|
pickType = choiceType;
|
|
|
|
|
2018-11-08 05:47:42 +08:00
|
|
|
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);
|
|
|
|
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();
|
|
|
|
}
|
2018-11-06 13:49:09 +08:00
|
|
|
|
2018-11-18 08:29:18 +08:00
|
|
|
[Resolved]
|
|
|
|
private TournamentSceneManager sceneManager { get; set; }
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2018-11-08 05:36:36 +08:00
|
|
|
if (currentMatch.Value.Grouping.Value.Beatmaps.All(b => b.BeatmapInfo.OnlineBeatmapID != beatmapId))
|
|
|
|
// 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();
|
2018-11-18 08:29:18 +08:00
|
|
|
|
|
|
|
if (pickType == ChoiceType.Pick)
|
|
|
|
{
|
|
|
|
scheduledChange?.Cancel();
|
|
|
|
scheduledChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(GameplayScreen)); }, 10000);
|
|
|
|
}
|
2018-11-08 05:29:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void matchChanged(MatchPairing match)
|
|
|
|
{
|
2018-11-17 15:06:43 +08:00
|
|
|
mapFlows.Clear();
|
2018-11-08 19:14:50 +08:00
|
|
|
|
|
|
|
if (match.Grouping.Value != null)
|
|
|
|
{
|
2018-11-17 15:06:43 +08:00
|
|
|
FillFlowContainer<TournamentBeatmapPanel> currentFlow = null;
|
|
|
|
string currentMod = null;
|
|
|
|
|
2018-11-08 19:14:50 +08:00
|
|
|
foreach (var b in match.Grouping.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, 20),
|
|
|
|
Direction = FillDirection.Full,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
});
|
|
|
|
|
|
|
|
currentMod = b.Mods;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentFlow.Add(new TournamentBeatmapPanel(b.BeatmapInfo, b.Mods)
|
2018-11-08 19:14:50 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
});
|
2018-11-17 15:06:43 +08:00
|
|
|
}
|
2018-11-08 19:14:50 +08:00
|
|
|
}
|
2018-11-06 13:49:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|