1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 10:17:32 +08:00
osu-lazer/osu.Game.Tournament/Screens/Groupings/GroupingsEditorScreen.cs

154 lines
5.2 KiB
C#
Raw Normal View History

2018-10-13 18:45:59 +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-16 19:30:12 +08:00
using System;
using System.Linq;
using osu.Framework.Allocation;
2018-11-17 11:04:19 +08:00
using osu.Framework.Configuration;
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.Graphics;
using osu.Game.Graphics.UserInterface;
2018-10-13 06:10:13 +08:00
using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Screens.Ladder.Components;
2018-11-16 19:30:12 +08:00
namespace osu.Game.Tournament.Screens.Groupings
2018-10-13 06:10:13 +08:00
{
2018-11-16 19:30:12 +08:00
public class GroupingsEditorScreen : TournamentScreen, IProvideVideo
2018-10-13 06:10:13 +08:00
{
private readonly FillFlowContainer<GroupingRow> items;
2018-11-16 19:30:12 +08:00
public GroupingsEditorScreen()
2018-10-13 06:10:13 +08:00
{
2018-11-17 11:04:19 +08:00
AddRange(new Drawable[]
2018-10-13 06:10:13 +08:00
{
2018-11-17 11:04:19 +08:00
new Box
{
2018-11-17 11:04:19 +08:00
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f),
},
new FillFlowContainer
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.Both,
Width = 0.9f,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Children = new Drawable[]
{
2018-11-17 11:04:19 +08:00
items = new FillFlowContainer<GroupingRow>
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
new TriangleButton
{
Margin = new MarginPadding(20),
Width = 100,
Text = "Add",
Action = addNew
},
}
}
2018-10-13 06:10:13 +08:00
});
}
[BackgroundDependencyLoader]
private void load()
{
2018-11-16 19:30:12 +08:00
foreach (var g in LadderInfo.Groupings)
items.Add(new GroupingRow(g, updateGroupings));
}
protected override void LoadComplete()
{
base.LoadComplete();
Scheduler.AddDelayed(() => LadderInfo.Groupings = items.Children.Select(c => c.Grouping).ToList(), 500, true);
2018-10-13 06:10:13 +08:00
}
2018-11-16 19:30:12 +08:00
private void addNew()
{
2018-11-17 11:04:19 +08:00
items.Add(new GroupingRow(new TournamentGrouping { StartDate = { Value = DateTimeOffset.UtcNow } }, updateGroupings));
2018-11-16 19:30:12 +08:00
updateGroupings();
}
2018-11-17 11:04:19 +08:00
private void updateGroupings()
2018-11-16 19:30:12 +08:00
{
LadderInfo.Groupings = items.Children.Select(c => c.Grouping).ToList();
}
2018-10-13 06:10:13 +08:00
public class GroupingRow : CompositeDrawable
{
public readonly TournamentGrouping Grouping;
2018-11-16 19:30:12 +08:00
public GroupingRow(TournamentGrouping grouping, Action onDelete)
2018-10-13 06:10:13 +08:00
{
Grouping = grouping;
InternalChildren = new Drawable[]
{
new FillFlowContainer
{
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 { Width = 0.3f, Bindable = Grouping.Name },
new SettingsTextBox { Width = 0.3f, Bindable = Grouping.Description },
new SettingsSlider<int> { LabelText = "Best of", Width = 0.3f, Bindable = Grouping.BestOf },
new DangerousSettingsButton
{
Width = 0.1f,
Text = "Delete",
2018-11-16 19:30:12 +08:00
Action = () =>
{
Expire();
onDelete();
}
},
2018-11-17 11:04:19 +08:00
new DateTextBox { Width = 0.3f, Bindable = Grouping.StartDate },
2018-10-13 06:10:13 +08:00
}
}
};
RelativeSizeAxes = Axes.X;
2018-11-17 11:04:19 +08:00
AutoSizeAxes = Axes.Y;
}
}
}
public class DateTextBox : SettingsTextBox
{
public DateTextBox()
{
base.Bindable = new Bindable<string>();
((OsuTextBox)Control).OnCommit = (sender, newText) => {
try
{
bindable.Value = DateTimeOffset.Parse(sender.Text);
}
catch
{
bindable.TriggerChange();
}
};
}
// hold a reference to the provided bindable so we don't have to in every settings section.
private Bindable<DateTimeOffset> bindable;
public new Bindable<DateTimeOffset> Bindable
{
get { return bindable; }
set
{
bindable = value;
bindable.BindValueChanged(dto => base.Bindable.Value = dto.ToUniversalTime().ToString(), true);
2018-10-13 06:10:13 +08:00
}
}
}
}