1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 14:07:52 +08:00
osu-lazer/osu.Game.Tournament/Screens/Ladder/Components/LadderEditorSettings.cs

158 lines
5.6 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-09-22 04:52:25 +08:00
2018-11-17 11:14:15 +08:00
using System;
2018-09-22 04:52:25 +08:00
using System.Linq;
using osu.Framework.Allocation;
2019-03-02 12:40:43 +08:00
using osu.Framework.Bindables;
2018-09-22 04:52:25 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-11-16 19:30:12 +08:00
using osu.Framework.Input.Events;
2018-09-22 04:52:25 +08:00
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;
2018-11-17 13:05:22 +08:00
using osu.Game.Tournament.Components;
2018-09-22 04:52:25 +08:00
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-11-17 11:14:15 +08:00
private DateTextBox dateTimeBox;
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
[Resolved]
private LadderInfo ladderInfo { get; set; }
2018-09-22 04:52:25 +08:00
[BackgroundDependencyLoader]
private void load()
{
var teamEntries = ladderInfo.Teams;
2018-09-22 04:52:25 +08:00
2018-11-15 13:12:41 +08:00
var groupingOptions = ladderInfo.Groupings.Prepend(new TournamentGrouping());
2018-09-24 22:30:37 +08:00
2018-09-22 04:52:25 +08:00
Children = new Drawable[]
{
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-11-15 13:12:41 +08:00
Bindable = new Bindable<TournamentGrouping> { Default = groupingOptions.First() },
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-11-17 11:14:15 +08:00
},
dateTimeBox = new DateTextBox
{
Bindable = new Bindable<DateTimeOffset>()
2018-09-25 01:31:48 +08:00
}
2018-09-22 04:52:25 +08:00
};
editorInfo.Selected.ValueChanged += selection =>
{
2019-03-02 12:40:43 +08:00
textboxTeam1.Text = selection.NewValue?.Team1.Value?.Acronym;
textboxTeam2.Text = selection.NewValue?.Team2.Value?.Acronym;
groupingDropdown.Bindable.Value = selection.NewValue?.Grouping.Value ?? groupingOptions.First();
losersCheckbox.Current.Value = selection.NewValue?.Losers.Value ?? false;
dateTimeBox.Bindable.Value = selection.NewValue?.Date.Value ?? DateTimeOffset.UtcNow;
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)
2018-11-17 11:14:15 +08:00
{
2019-03-02 12:40:43 +08:00
editorInfo.Selected.Value.Grouping.Value = grouping.NewValue;
2019-03-02 12:40:43 +08:00
if (editorInfo.Selected.Value.Date.Value < grouping.NewValue.StartDate.Value)
2018-11-17 11:14:15 +08:00
{
2019-03-02 12:40:43 +08:00
editorInfo.Selected.Value.Date.Value = grouping.NewValue.StartDate.Value;
2018-11-17 11:14:15 +08:00
editorInfo.Selected.TriggerChange();
}
}
2018-09-24 22:30:37 +08:00
};
2018-09-25 01:31:48 +08:00
losersCheckbox.Current.ValueChanged += losers =>
{
if (editorInfo.Selected.Value != null)
2019-03-02 12:40:43 +08:00
editorInfo.Selected.Value.Losers.Value = losers.NewValue;
2018-09-25 01:31:48 +08:00
};
2018-11-17 11:14:15 +08:00
dateTimeBox.Bindable.ValueChanged += date =>
{
if (editorInfo.Selected.Value != null)
2019-03-02 12:40:43 +08:00
editorInfo.Selected.Value.Date.Value = date.NewValue;
2018-11-17 11:14:15 +08:00
};
}
protected override void LoadComplete()
{
base.LoadComplete();
this.FadeIn();
2018-09-22 04:52:25 +08:00
}
2018-11-16 19:30:12 +08:00
protected override bool OnHover(HoverEvent e)
{
return false;
}
protected override void OnHoverLost(HoverLostEvent e)
{
}
2018-09-22 04:52:25 +08:00
}
}