1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 02:22:59 +08:00
osu-lazer/osu.Game.Tournament/Screens/Ladder/Components/LadderEditorSettings.cs

134 lines
5.1 KiB
C#
Raw Normal View History

2018-09-22 04:52:25 +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-09-24 22:30:37 +08:00
using System.Collections.Generic;
2018-09-22 04:52:25 +08:00
using System.Linq;
using osu.Framework.Allocation;
2018-09-24 22:30:37 +08:00
using osu.Framework.Configuration;
2018-09-22 04:52:25 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Sprites;
2018-09-24 01:17:07 +08:00
using osu.Game.Graphics.UserInterface;
2018-09-24 22:30:37 +08:00
using osu.Game.Overlays.Settings;
2018-09-22 04:52:25 +08:00
using osu.Game.Screens.Play.PlayerSettings;
namespace osu.Game.Tournament.Screens.Ladder.Components
{
public class LadderEditorSettings : PlayerSettingsGroup
{
private const int padding = 10;
protected override string Title => @"ladder";
2018-09-24 01:17:07 +08:00
private OsuTextBox textboxTeam1;
private OsuTextBox textboxTeam2;
2018-09-24 22:30:37 +08:00
private SettingsDropdown<TournamentGrouping> groupingDropdown;
2018-09-25 01:31:48 +08:00
private PlayerCheckbox losersCheckbox;
2018-09-22 04:52:25 +08:00
[Resolved]
2018-11-06 13:49:20 +08:00
private LadderEditorInfo editorInfo { get; set; }
2018-09-22 04:52:25 +08:00
[BackgroundDependencyLoader]
private void load()
{
2018-09-24 01:17:07 +08:00
var teamEntries = editorInfo.Teams;
2018-09-22 04:52:25 +08:00
2018-09-25 01:31:48 +08:00
var groupingOptions = editorInfo.Groupings.Select(g => new KeyValuePair<string, TournamentGrouping>(g.Name, g))
.Prepend(new KeyValuePair<string, TournamentGrouping>("None", new TournamentGrouping()));
2018-09-24 22:30:37 +08:00
2018-09-22 04:52:25 +08:00
Children = new Drawable[]
{
new PlayerCheckbox
{
Bindable = editorInfo.EditingEnabled,
LabelText = "Enable editing"
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = padding },
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Team1",
},
},
},
2018-09-24 01:17:07 +08:00
textboxTeam1 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 },
2018-09-22 04:52:25 +08:00
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = padding },
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Team2",
},
},
},
2018-09-24 01:17:07 +08:00
textboxTeam2 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 },
2018-09-24 22:30:37 +08:00
groupingDropdown = new SettingsDropdown<TournamentGrouping>
{
2018-09-25 04:54:42 +08:00
Bindable = new Bindable<TournamentGrouping> { Default = groupingOptions.First().Value },
2018-09-24 22:30:37 +08:00
Items = groupingOptions
},
2018-09-25 01:31:48 +08:00
losersCheckbox = new PlayerCheckbox
{
LabelText = "Losers Bracket",
Bindable = new Bindable<bool>()
}
2018-09-22 04:52:25 +08:00
};
editorInfo.Selected.ValueChanged += selection =>
{
2018-09-24 01:17:07 +08:00
textboxTeam1.Text = selection?.Team1.Value?.Acronym;
textboxTeam2.Text = selection?.Team2.Value?.Acronym;
2018-09-24 22:30:37 +08:00
groupingDropdown.Bindable.Value = selection?.Grouping.Value ?? groupingOptions.First().Value;
2018-09-25 01:31:48 +08:00
losersCheckbox.Current.Value = selection?.Losers.Value ?? false;
2018-09-22 04:52:25 +08:00
};
2018-09-24 01:17:07 +08:00
textboxTeam1.OnCommit = (val, newText) =>
2018-09-22 04:52:25 +08:00
{
2018-09-24 01:17:07 +08:00
if (newText && editorInfo.Selected.Value != null)
editorInfo.Selected.Value.Team1.Value = teamEntries.FirstOrDefault(t => t.Acronym == val.Text);
2018-09-22 04:52:25 +08:00
};
2018-09-24 01:17:07 +08:00
textboxTeam2.OnCommit = (val, newText) =>
2018-09-22 04:52:25 +08:00
{
2018-09-24 01:17:07 +08:00
if (newText && editorInfo.Selected.Value != null)
editorInfo.Selected.Value.Team2.Value = teamEntries.FirstOrDefault(t => t.Acronym == val.Text);
2018-09-22 04:52:25 +08:00
};
2018-09-24 22:30:37 +08:00
groupingDropdown.Bindable.ValueChanged += grouping =>
{
if (editorInfo.Selected.Value != null)
editorInfo.Selected.Value.Grouping.Value = grouping;
};
2018-09-25 01:31:48 +08:00
losersCheckbox.Current.ValueChanged += losers =>
{
if (editorInfo.Selected.Value != null)
editorInfo.Selected.Value.Losers.Value = losers;
};
// sliderBestOf.Bindable.ValueChanged += val =>
// {
// if (editorInfo.Selected.Value != null) editorInfo.Selected.Value.BestOf.Value = (int)val;
// };
2018-09-22 04:52:25 +08:00
editorInfo.EditingEnabled.ValueChanged += enabled =>
{
if (!enabled) editorInfo.Selected.Value = null;
};
}
}
}