osu/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

291 lines
11 KiB
C#
Raw Permalink Normal View History

2019-03-04 04:24:19 +00: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-10-13 10:45:59 +00:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2018-10-12 22:10:13 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-11-17 03:04:19 +00:00
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
2018-10-12 22:10:13 +00:00
using osu.Game.Overlays.Settings;
2018-11-17 05:05:22 +00:00
using osu.Game.Tournament.Components;
2019-06-18 05:51:48 +00:00
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors.Components;
using osuTK;
2018-10-12 22:10:13 +00:00
2019-06-18 05:51:48 +00:00
namespace osu.Game.Tournament.Screens.Editors
2018-10-12 22:10:13 +00:00
{
public partial class RoundEditorScreen : TournamentEditorScreen<RoundEditorScreen.RoundRow, TournamentRound>
2018-10-12 22:10:13 +00:00
{
protected override BindableList<TournamentRound> Storage => LadderInfo.Rounds;
public partial class RoundRow : CompositeDrawable, IModelBacked<TournamentRound>
2018-10-12 22:10:13 +00:00
{
public TournamentRound Model { get; }
2018-10-12 22:10:13 +00:00
[Resolved]
private LadderInfo ladderInfo { get; set; } = null!;
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
2019-06-18 05:44:15 +00:00
public RoundRow(TournamentRound round)
2018-10-12 22:10:13 +00:00
{
Model = round;
Masking = true;
CornerRadius = 10;
RoundBeatmapEditor beatmapEditor = new RoundBeatmapEditor(round)
{
Width = 0.95f
};
2018-10-12 22:10:13 +00:00
InternalChildren = new Drawable[]
{
new Box
{
Colour = OsuColour.Gray(0.1f),
RelativeSizeAxes = Axes.Both,
},
2018-10-12 22:10:13 +00:00
new FillFlowContainer
{
Margin = new MarginPadding(5),
Padding = new MarginPadding { Right = 160 },
Spacing = new Vector2(5),
2018-11-17 03:04:19 +00:00
Direction = FillDirection.Full,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2018-10-12 22:10:13 +00:00
Children = new Drawable[]
{
new SettingsTextBox
{
LabelText = "Name",
Width = 0.33f,
Current = Model.Name
},
new SettingsTextBox
{
LabelText = "Description",
Width = 0.33f,
Current = Model.Description
},
new DateTextBox
{
LabelText = "Start Time",
Width = 0.33f,
Current = Model.StartDate
},
new SettingsSlider<int>
{
LabelText = "# of Bans",
Width = 0.33f,
Current = Model.BanCount
},
new SettingsSlider<int>
{
LabelText = "Best of",
Width = 0.33f,
Current = Model.BestOf
},
new SettingsButton
{
Width = 0.2f,
Margin = new MarginPadding(10),
Text = "Add beatmap",
Action = () => beatmapEditor.CreateNew()
},
beatmapEditor
2018-10-12 22:10:13 +00:00
}
},
new DangerousSettingsButton
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.None,
Width = 150,
Text = "Delete Round",
2023-07-21 19:17:14 +00:00
Action = () => dialogOverlay?.Push(new DeleteRoundDialog(Model, () =>
{
Expire();
ladderInfo.Rounds.Remove(Model);
2023-07-21 19:17:14 +00:00
}))
2018-10-12 22:10:13 +00:00
}
};
RelativeSizeAxes = Axes.X;
2018-11-17 03:04:19 +00:00
AutoSizeAxes = Axes.Y;
}
public partial 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,
ChildrenEnumerable = round.Beatmaps.Select(p => new RoundBeatmapRow(round, p))
};
}
public void CreateNew()
{
var b = new RoundBeatmap();
round.Beatmaps.Add(b);
flow.Add(new RoundBeatmapRow(round, b));
}
public partial class RoundBeatmapRow : CompositeDrawable
{
public RoundBeatmap Model { get; }
[Resolved]
protected IAPIProvider API { get; private set; } = null!;
private readonly Bindable<int?> beatmapId = new Bindable<int?>();
private readonly Bindable<string> mods = new Bindable<string>(string.Empty);
private readonly Container drawableContainer;
public RoundBeatmapRow(TournamentRound team, RoundBeatmap beatmap)
{
Model = 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 SettingsNumberBox
{
LabelText = "Beatmap ID",
RelativeSizeAxes = Axes.None,
Width = 200,
Current = beatmapId,
},
new SettingsTextBox
{
LabelText = "Mods",
RelativeSizeAxes = Axes.None,
Width = 200,
Current = 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]
2022-01-15 00:06:39 +00:00
private void load()
{
beatmapId.Value = Model.ID;
beatmapId.BindValueChanged(id =>
{
Model.ID = id.NewValue ?? 0;
if (id.NewValue != id.OldValue)
Model.Beatmap = null;
if (Model.Beatmap != null)
{
updatePanel();
return;
}
var req = new GetBeatmapRequest(new APIBeatmap { OnlineID = Model.ID });
req.Success += res =>
{
Model.Beatmap = new TournamentBeatmap(res);
updatePanel();
};
req.Failure += _ =>
{
Model.Beatmap = null;
updatePanel();
};
API.Queue(req);
}, true);
mods.Value = Model.Mods;
mods.BindValueChanged(modString => Model.Mods = modString.NewValue);
}
private void updatePanel() => Schedule(() =>
{
drawableContainer.Clear();
if (Model.Beatmap != null)
2019-11-11 11:53:22 +00:00
{
drawableContainer.Child = new TournamentBeatmapPanel(Model.Beatmap, Model.Mods)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Width = 300
};
2019-11-11 11:53:22 +00:00
}
});
}
}
2018-11-17 03:04:19 +00:00
}
protected override RoundRow CreateDrawable(TournamentRound model) => new RoundRow(model);
2018-11-17 03:04:19 +00:00
}
2018-10-12 22:10:13 +00:00
}