osu/osu.Game.Tournament/Screens/Groupings/GroupingsEditorScreen.cs

166 lines
5.5 KiB
C#
Raw 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
2018-11-16 11:30:12 +00:00
using System;
using System.Linq;
using osu.Framework.Allocation;
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.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
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;
2018-10-12 22:10:13 +00:00
using osu.Game.Tournament.Screens.Ladder.Components;
using osuTK;
2018-10-12 22:10:13 +00:00
2018-11-16 11:30:12 +00:00
namespace osu.Game.Tournament.Screens.Groupings
2018-10-12 22:10:13 +00:00
{
2018-11-16 11:30:12 +00:00
public class GroupingsEditorScreen : TournamentScreen, IProvideVideo
2018-10-12 22:10:13 +00:00
{
private readonly FillFlowContainer<GroupingRow> items;
2018-11-16 11:30:12 +00:00
public GroupingsEditorScreen()
2018-10-12 22:10:13 +00:00
{
AddRangeInternal(new Drawable[]
2018-10-12 22:10:13 +00:00
{
2018-11-17 03:04:19 +00:00
new Box
{
2018-11-17 03:04:19 +00:00
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f),
},
new OsuScrollContainer
2018-11-17 03:04:19 +00:00
{
RelativeSizeAxes = Axes.Both,
Width = 0.9f,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Child = items = new FillFlowContainer<GroupingRow>
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
},
new ControlPanel
{
2018-11-17 03:04:19 +00:00
Children = new Drawable[]
{
2018-11-17 03:04:19 +00:00
new TriangleButton
{
RelativeSizeAxes = Axes.X,
Text = "Add new",
2018-11-17 03:04:19 +00:00
Action = addNew
},
}
}
2018-10-12 22:10:13 +00:00
});
}
[BackgroundDependencyLoader]
private void load()
{
2018-11-16 11:30:12 +00:00
foreach (var g in LadderInfo.Groupings)
items.Add(new GroupingRow(g, updateGroupings));
}
protected override void LoadComplete()
{
base.LoadComplete();
Scheduler.AddDelayed(updateGroupings, 500, true);
2018-10-12 22:10:13 +00:00
}
2018-11-16 11:30:12 +00:00
private void addNew()
{
items.Add(new GroupingRow(new TournamentGrouping
{
StartDate =
{
Value = DateTimeOffset.UtcNow
}
}, updateGroupings));
2018-11-16 11:30:12 +00:00
updateGroupings();
}
2018-11-17 05:05:22 +00:00
private void updateGroupings()
2018-11-16 11:30:12 +00:00
{
LadderInfo.Groupings.Clear();
LadderInfo.Groupings.AddRange(items.Children.Select(c => c.Grouping));
2018-11-16 11:30:12 +00:00
}
2018-10-12 22:10:13 +00:00
public class GroupingRow : CompositeDrawable
{
public readonly TournamentGrouping Grouping;
2018-11-16 11:30:12 +00:00
public GroupingRow(TournamentGrouping grouping, Action onDelete)
2018-10-12 22:10:13 +00:00
{
Margin = new MarginPadding(10);
2018-10-12 22:10:13 +00:00
Grouping = grouping;
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,
Bindable = Grouping.Name
},
new SettingsTextBox
{
LabelText = "Description",
Width = 0.33f,
Bindable = Grouping.Description
},
new DateTextBox
{
LabelText = "Start Time",
Width = 0.33f,
Bindable = Grouping.StartDate
},
new SettingsSlider<int>
{
LabelText = "Best of",
Width = 0.33f,
Bindable = Grouping.BestOf
},
2018-10-12 22:10:13 +00:00
}
},
new DangerousSettingsButton
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.None,
Width = 150,
Text = "Delete",
Action = () =>
{
Expire();
onDelete();
},
2018-10-12 22:10:13 +00:00
}
};
RelativeSizeAxes = Axes.X;
2018-11-17 03:04:19 +00:00
AutoSizeAxes = Axes.Y;
}
}
}
2018-10-12 22:10:13 +00:00
}