1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 06:47:36 +08:00
osu-lazer/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs

298 lines
11 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-10-13 18:45:59 +08:00
2018-11-16 19:30:12 +08:00
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2018-10-13 06:10:13 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-11-17 11:04:19 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
2018-11-17 11:04:19 +08:00
using osu.Game.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
2018-10-13 06:10:13 +08:00
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets;
2018-11-17 13:05:22 +08:00
using osu.Game.Tournament.Components;
2019-06-18 13:51:48 +08:00
using osu.Game.Tournament.Models;
using osuTK;
2018-10-13 06:10:13 +08:00
2019-06-18 13:51:48 +08:00
namespace osu.Game.Tournament.Screens.Editors
2018-10-13 06:10:13 +08:00
{
public class RoundEditorScreen : TournamentEditorScreen<RoundEditorScreen.RoundRow>
2018-10-13 06:10:13 +08:00
{
[BackgroundDependencyLoader]
private void load()
{
2019-06-18 13:44:15 +08:00
foreach (var r in LadderInfo.Rounds)
Flow.Add(new RoundRow(r));
2018-10-13 06:10:13 +08:00
}
protected override void AddNew()
{
2019-06-18 13:44:15 +08:00
var round = new TournamentRound
{
StartDate = { Value = DateTimeOffset.UtcNow }
};
Flow.Add(new RoundRow(round));
2019-06-18 13:44:15 +08:00
LadderInfo.Rounds.Add(round);
2018-11-16 19:30:12 +08:00
}
2019-06-18 13:44:15 +08:00
public class RoundRow : CompositeDrawable
2018-10-13 06:10:13 +08:00
{
2019-06-18 13:44:15 +08:00
public readonly TournamentRound Round;
2018-10-13 06:10:13 +08:00
[Resolved]
private LadderInfo ladderInfo { get; set; }
2019-06-18 13:44:15 +08:00
public RoundRow(TournamentRound round)
2018-10-13 06:10:13 +08:00
{
2019-06-18 13:44:15 +08:00
Round = round;
Masking = true;
CornerRadius = 10;
RoundBeatmapEditor beatmapEditor = new RoundBeatmapEditor(round)
{
Width = 0.95f
};
2018-10-13 06:10:13 +08:00
InternalChildren = new Drawable[]
{
new Box
{
Colour = OsuColour.Gray(0.1f),
RelativeSizeAxes = Axes.Both,
},
2018-10-13 06:10:13 +08:00
new FillFlowContainer
{
Margin = new MarginPadding(5),
Padding = new MarginPadding { Right = 160 },
Spacing = new Vector2(5),
2018-11-17 11:04:19 +08:00
Direction = FillDirection.Full,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2018-10-13 06:10:13 +08:00
Children = new Drawable[]
{
new SettingsTextBox
{
LabelText = "Name",
Width = 0.33f,
2019-06-18 13:44:15 +08:00
Bindable = Round.Name
},
new SettingsTextBox
{
LabelText = "Description",
Width = 0.33f,
2019-06-18 13:44:15 +08:00
Bindable = Round.Description
},
new DateTextBox
{
LabelText = "Start Time",
Width = 0.33f,
2019-06-18 13:44:15 +08:00
Bindable = Round.StartDate
},
new SettingsSlider<int>
{
LabelText = "Best of",
Width = 0.33f,
2019-06-18 13:44:15 +08:00
Bindable = Round.BestOf
},
new SettingsButton
{
Width = 0.2f,
Margin = new MarginPadding(10),
Text = "Add beatmap",
Action = () => beatmapEditor.CreateNew()
},
beatmapEditor
2018-10-13 06:10:13 +08:00
}
},
new DangerousSettingsButton
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.None,
Width = 150,
Text = "Delete Round",
Action = () =>
{
Expire();
2019-06-18 13:44:15 +08:00
ladderInfo.Rounds.Remove(Round);
},
2018-10-13 06:10:13 +08:00
}
};
RelativeSizeAxes = Axes.X;
2018-11-17 11:04:19 +08:00
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<string> beatmapId = new Bindable<string>();
private readonly Bindable<string> mods = new Bindable<string>();
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
};
}
}
}
2018-11-17 11:04:19 +08:00
}
}
2018-10-13 06:10:13 +08:00
}