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-09-21 20:52:25 +00:00
|
|
|
|
2018-11-17 03:14:15 +00:00
|
|
|
using System;
|
2018-09-21 20:52:25 +00:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-02 04:40:43 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-09-21 20:52:25 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-16 11:30:12 +00:00
|
|
|
using osu.Framework.Input.Events;
|
2018-09-21 20:52:25 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-09-23 17:17:07 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-09-24 14:30:37 +00:00
|
|
|
using osu.Game.Overlays.Settings;
|
2018-09-21 20:52:25 +00:00
|
|
|
using osu.Game.Screens.Play.PlayerSettings;
|
2018-11-17 05:05:22 +00:00
|
|
|
using osu.Game.Tournament.Components;
|
2018-09-21 20:52:25 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Ladder.Components
|
|
|
|
{
|
|
|
|
public class LadderEditorSettings : PlayerSettingsGroup
|
|
|
|
{
|
|
|
|
private const int padding = 10;
|
|
|
|
|
|
|
|
protected override string Title => @"ladder";
|
|
|
|
|
2018-09-23 17:17:07 +00:00
|
|
|
private OsuTextBox textboxTeam1;
|
|
|
|
private OsuTextBox textboxTeam2;
|
2018-09-24 14:30:37 +00:00
|
|
|
private SettingsDropdown<TournamentGrouping> groupingDropdown;
|
2018-09-24 17:31:48 +00:00
|
|
|
private PlayerCheckbox losersCheckbox;
|
2018-11-17 03:14:15 +00:00
|
|
|
private DateTextBox dateTimeBox;
|
2018-09-21 20:52:25 +00:00
|
|
|
|
|
|
|
[Resolved]
|
2018-11-06 05:49:20 +00:00
|
|
|
private LadderEditorInfo editorInfo { get; set; }
|
2018-09-21 20:52:25 +00:00
|
|
|
|
2018-11-09 08:39:46 +00:00
|
|
|
[Resolved]
|
|
|
|
private LadderInfo ladderInfo { get; set; }
|
|
|
|
|
2018-09-21 20:52:25 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2018-11-09 08:39:46 +00:00
|
|
|
var teamEntries = ladderInfo.Teams;
|
2018-09-21 20:52:25 +00: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-23 17:17:07 +00:00
|
|
|
textboxTeam1 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 },
|
2018-09-21 20:52:25 +00: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-23 17:17:07 +00:00
|
|
|
textboxTeam2 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 },
|
2018-09-24 14:30:37 +00:00
|
|
|
groupingDropdown = new SettingsDropdown<TournamentGrouping>
|
|
|
|
{
|
2019-06-14 08:56:47 +00:00
|
|
|
Bindable = new Bindable<TournamentGrouping>(),
|
2018-09-24 14:30:37 +00:00
|
|
|
},
|
2018-09-24 17:31:48 +00:00
|
|
|
losersCheckbox = new PlayerCheckbox
|
|
|
|
{
|
|
|
|
LabelText = "Losers Bracket",
|
|
|
|
Bindable = new Bindable<bool>()
|
2018-11-17 03:14:15 +00:00
|
|
|
},
|
|
|
|
dateTimeBox = new DateTextBox
|
|
|
|
{
|
|
|
|
Bindable = new Bindable<DateTimeOffset>()
|
2018-09-24 17:31:48 +00:00
|
|
|
}
|
2018-09-21 20:52:25 +00:00
|
|
|
};
|
|
|
|
|
2019-06-14 08:56:47 +00:00
|
|
|
var groupingOptions = ladderInfo.Groupings.Prepend(new TournamentGrouping());
|
|
|
|
|
|
|
|
void updateDropdownItems()
|
|
|
|
{
|
|
|
|
groupingOptions = ladderInfo.Groupings.Prepend(new TournamentGrouping());
|
|
|
|
groupingDropdown.Items = groupingOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
ladderInfo.Groupings.ItemsRemoved += _ => updateDropdownItems();
|
|
|
|
ladderInfo.Groupings.ItemsAdded += _ => updateDropdownItems();
|
|
|
|
|
2018-09-21 20:52:25 +00:00
|
|
|
editorInfo.Selected.ValueChanged += selection =>
|
|
|
|
{
|
2019-03-02 04:40:43 +00: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-21 20:52:25 +00:00
|
|
|
};
|
|
|
|
|
2018-09-23 17:17:07 +00:00
|
|
|
textboxTeam1.OnCommit = (val, newText) =>
|
2018-09-21 20:52:25 +00:00
|
|
|
{
|
2018-09-23 17:17:07 +00:00
|
|
|
if (newText && editorInfo.Selected.Value != null)
|
|
|
|
editorInfo.Selected.Value.Team1.Value = teamEntries.FirstOrDefault(t => t.Acronym == val.Text);
|
2018-09-21 20:52:25 +00:00
|
|
|
};
|
|
|
|
|
2018-09-23 17:17:07 +00:00
|
|
|
textboxTeam2.OnCommit = (val, newText) =>
|
2018-09-21 20:52:25 +00:00
|
|
|
{
|
2018-09-23 17:17:07 +00:00
|
|
|
if (newText && editorInfo.Selected.Value != null)
|
|
|
|
editorInfo.Selected.Value.Team2.Value = teamEntries.FirstOrDefault(t => t.Acronym == val.Text);
|
2018-09-21 20:52:25 +00:00
|
|
|
};
|
|
|
|
|
2018-09-24 14:30:37 +00:00
|
|
|
groupingDropdown.Bindable.ValueChanged += grouping =>
|
|
|
|
{
|
|
|
|
if (editorInfo.Selected.Value != null)
|
2018-11-17 03:14:15 +00:00
|
|
|
{
|
2019-03-02 04:40:43 +00:00
|
|
|
editorInfo.Selected.Value.Grouping.Value = grouping.NewValue;
|
2019-05-15 03:08:23 +00:00
|
|
|
|
2019-03-02 04:40:43 +00:00
|
|
|
if (editorInfo.Selected.Value.Date.Value < grouping.NewValue.StartDate.Value)
|
2018-11-17 03:14:15 +00:00
|
|
|
{
|
2019-03-02 04:40:43 +00:00
|
|
|
editorInfo.Selected.Value.Date.Value = grouping.NewValue.StartDate.Value;
|
2018-11-17 03:14:15 +00:00
|
|
|
editorInfo.Selected.TriggerChange();
|
|
|
|
}
|
|
|
|
}
|
2018-09-24 14:30:37 +00:00
|
|
|
};
|
|
|
|
|
2018-09-24 17:31:48 +00:00
|
|
|
losersCheckbox.Current.ValueChanged += losers =>
|
|
|
|
{
|
|
|
|
if (editorInfo.Selected.Value != null)
|
2019-03-02 04:40:43 +00:00
|
|
|
editorInfo.Selected.Value.Losers.Value = losers.NewValue;
|
2018-09-24 17:31:48 +00:00
|
|
|
};
|
2018-11-17 03:14:15 +00:00
|
|
|
|
|
|
|
dateTimeBox.Bindable.ValueChanged += date =>
|
|
|
|
{
|
|
|
|
if (editorInfo.Selected.Value != null)
|
2019-03-02 04:40:43 +00:00
|
|
|
editorInfo.Selected.Value.Date.Value = date.NewValue;
|
2018-11-17 03:14:15 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
this.FadeIn();
|
2018-09-21 20:52:25 +00:00
|
|
|
}
|
2018-11-16 11:30:12 +00:00
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
}
|
2018-09-21 20:52:25 +00:00
|
|
|
}
|
|
|
|
}
|