From 4baadf63192d00f985fe25ba47e3683079644a4d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 18 Jun 2019 16:10:23 +0900 Subject: [PATCH] Add map pool editing functionality to round editor --- .../Components/TournamentBeatmapPanel.cs | 2 +- osu.Game.Tournament/Models/TournamentRound.cs | 2 +- .../Screens/Editors/RoundEditorScreen.cs | 189 +++++++++++++++++- .../Screens/Editors/TeamEditorScreen.cs | 4 +- 4 files changed, 191 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs b/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs index f7ca25adba..d5e28c1e3e 100644 --- a/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs +++ b/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs @@ -81,7 +81,7 @@ namespace osu.Game.Tournament.Components Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, Text = new LocalisedString(( - $"{Beatmap.Metadata.ArtistUnicode} - {Beatmap.Metadata.TitleUnicode}", + $"{Beatmap.Metadata.ArtistUnicode ?? Beatmap.Metadata.Artist} - {Beatmap.Metadata.TitleUnicode ?? Beatmap.Metadata.Title}", $"{Beatmap.Metadata.Artist} - {Beatmap.Metadata.Title}")), Font = OsuFont.GetFont(weight: FontWeight.Bold, italics: true), }, diff --git a/osu.Game.Tournament/Models/TournamentRound.cs b/osu.Game.Tournament/Models/TournamentRound.cs index 35215e90c5..1b900d5a22 100644 --- a/osu.Game.Tournament/Models/TournamentRound.cs +++ b/osu.Game.Tournament/Models/TournamentRound.cs @@ -20,7 +20,7 @@ namespace osu.Game.Tournament.Models public readonly BindableInt BestOf = new BindableInt(9) { Default = 9, MinValue = 3, MaxValue = 23 }; [JsonProperty] - public readonly List Beatmaps = new List(); + public readonly BindableList Beatmaps = new BindableList(); public readonly Bindable StartDate = new Bindable(); diff --git a/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs b/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs index 125e0a966c..b2c3a97cbc 100644 --- a/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs +++ b/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs @@ -2,12 +2,18 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Game.Beatmaps; using osu.Game.Graphics; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; using osu.Game.Overlays.Settings; +using osu.Game.Rulesets; using osu.Game.Tournament.Components; using osu.Game.Tournament.Models; using osuTK; @@ -43,9 +49,16 @@ namespace osu.Game.Tournament.Screens.Editors public RoundRow(TournamentRound round) { - Margin = new MarginPadding(10); - Round = round; + + Masking = true; + CornerRadius = 10; + + RoundBeatmapEditor beatmapEditor = new RoundBeatmapEditor(round) + { + Width = 0.95f + }; + InternalChildren = new Drawable[] { new Box @@ -87,6 +100,14 @@ namespace osu.Game.Tournament.Screens.Editors Width = 0.33f, Bindable = Round.BestOf }, + new SettingsButton + { + Width = 0.2f, + Margin = new MarginPadding(10), + Text = "Add beatmap", + Action = () => beatmapEditor.CreateNew() + }, + beatmapEditor } }, new DangerousSettingsButton @@ -107,6 +128,170 @@ namespace osu.Game.Tournament.Screens.Editors RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; } + + public class RoundBeatmapEditor : CompositeDrawable + { + private readonly TournamentRound round; + private readonly FillFlowContainer flow; + + public RoundBeatmapEditor(TournamentRound round) + { + this.round = round; + + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + + InternalChild = flow = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + LayoutDuration = 200, + LayoutEasing = Easing.OutQuint, + ChildrenEnumerable = round.Beatmaps.Select(p => new RoundBeatmapRow(round, p)) + }; + } + + public void CreateNew() + { + var user = new RoundBeatmap(); + round.Beatmaps.Add(user); + flow.Add(new RoundBeatmapRow(round, user)); + } + + public class RoundBeatmapRow : CompositeDrawable + { + private readonly RoundBeatmap beatmap; + + [Resolved] + protected IAPIProvider API { get; private set; } + + private readonly Bindable beatmapId = new Bindable(); + + private readonly Bindable mods = new Bindable(); + + private readonly Container drawableContainer; + + public RoundBeatmapRow(TournamentRound team, RoundBeatmap beatmap) + { + this.beatmap = beatmap; + + Margin = new MarginPadding(10); + + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + + Masking = true; + CornerRadius = 5; + + InternalChildren = new Drawable[] + { + new Box + { + Colour = OsuColour.Gray(0.2f), + RelativeSizeAxes = Axes.Both, + }, + new FillFlowContainer + { + Margin = new MarginPadding(5), + Padding = new MarginPadding { Right = 160 }, + Spacing = new Vector2(5), + Direction = FillDirection.Horizontal, + AutoSizeAxes = Axes.Both, + Children = new Drawable[] + { + new SettingsTextBox + { + LabelText = "Beatmap ID", + RelativeSizeAxes = Axes.None, + Width = 200, + Bindable = beatmapId, + }, + new SettingsTextBox + { + LabelText = "Mods", + RelativeSizeAxes = Axes.None, + Width = 200, + Bindable = mods, + }, + drawableContainer = new Container + { + Size = new Vector2(100, 70), + }, + } + }, + new DangerousSettingsButton + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + RelativeSizeAxes = Axes.None, + Width = 150, + Text = "Delete Beatmap", + Action = () => + { + Expire(); + team.Beatmaps.Remove(beatmap); + }, + } + }; + } + + [BackgroundDependencyLoader] + private void load(RulesetStore rulesets) + { + beatmapId.Value = beatmap.ID.ToString(); + beatmapId.BindValueChanged(idString => + { + int parsed; + + int.TryParse(idString.NewValue, out parsed); + + beatmap.ID = parsed; + + if (idString.NewValue != idString.OldValue) + beatmap.BeatmapInfo = null; + + if (beatmap.BeatmapInfo != null) + { + updatePanel(); + return; + } + + var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmap.ID }); + + req.Success += res => + { + beatmap.BeatmapInfo = res.ToBeatmap(rulesets); + updatePanel(); + }; + + req.Failure += _ => + { + beatmap.BeatmapInfo = null; + updatePanel(); + }; + + API.Queue(req); + }, true); + + mods.Value = beatmap.Mods; + mods.BindValueChanged(modString => beatmap.Mods = modString.NewValue); + } + + private void updatePanel() + { + drawableContainer.Clear(); + + if (beatmap.BeatmapInfo != null) + drawableContainer.Child = new TournamentBeatmapPanel(beatmap.BeatmapInfo, beatmap.Mods) + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Width = 300 + }; + } + } + } } } } diff --git a/osu.Game.Tournament/Screens/Editors/TeamEditorScreen.cs b/osu.Game.Tournament/Screens/Editors/TeamEditorScreen.cs index a2e8e61064..990975afa1 100644 --- a/osu.Game.Tournament/Screens/Editors/TeamEditorScreen.cs +++ b/osu.Game.Tournament/Screens/Editors/TeamEditorScreen.cs @@ -102,7 +102,7 @@ namespace osu.Game.Tournament.Screens.Editors Width = 0.11f, Margin = new MarginPadding(10), Text = "Add player", - Action = () => playerEditor.AddUser() + Action = () => playerEditor.CreateNew() }, new DangerousSettingsButton { @@ -167,7 +167,7 @@ namespace osu.Game.Tournament.Screens.Editors }; } - public void AddUser() + public void CreateNew() { var user = new User(); team.Players.Add(user);