2019-06-14 19:32:02 +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.
|
|
|
|
|
2019-06-17 19:47:45 +08:00
|
|
|
using System.Linq;
|
2019-06-14 19:32:02 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-06-17 15:28:58 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-06-14 19:32:02 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-06-17 19:47:45 +08:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
2019-06-14 19:32:02 +08:00
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
using osu.Game.Tournament.Components;
|
2019-06-18 13:51:48 +08:00
|
|
|
using osu.Game.Tournament.Models;
|
2019-06-17 19:47:45 +08:00
|
|
|
using osu.Game.Users;
|
2019-06-14 19:32:02 +08:00
|
|
|
using osuTK;
|
|
|
|
|
2019-06-18 13:51:48 +08:00
|
|
|
namespace osu.Game.Tournament.Screens.Editors
|
2019-06-14 19:32:02 +08:00
|
|
|
{
|
2019-06-18 14:15:28 +08:00
|
|
|
public class TeamEditorScreen : TournamentScreen, IProvideVideo
|
2019-06-14 19:32:02 +08:00
|
|
|
{
|
|
|
|
private readonly FillFlowContainer<TeamRow> items;
|
|
|
|
|
2019-06-18 14:15:28 +08:00
|
|
|
public TeamEditorScreen()
|
2019-06-14 19:32:02 +08:00
|
|
|
{
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.Gray(0.2f),
|
|
|
|
},
|
|
|
|
new OsuScrollContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Width = 0.9f,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Child = items = new FillFlowContainer<TeamRow>
|
|
|
|
{
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2019-06-17 19:47:45 +08:00
|
|
|
LayoutDuration = 200,
|
|
|
|
LayoutEasing = Easing.OutQuint,
|
2019-06-17 19:59:17 +08:00
|
|
|
Spacing = new Vector2(20)
|
2019-06-14 19:32:02 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
new ControlPanel
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new TriangleButton
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Text = "Add new",
|
|
|
|
Action = addNew
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2019-06-18 13:44:15 +08:00
|
|
|
foreach (var t in LadderInfo.Teams)
|
|
|
|
items.Add(new TeamRow(t));
|
2019-06-14 19:32:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addNew()
|
|
|
|
{
|
2019-06-17 15:28:58 +08:00
|
|
|
var team = new TournamentTeam();
|
2019-06-14 19:32:02 +08:00
|
|
|
|
|
|
|
items.Add(new TeamRow(team));
|
|
|
|
LadderInfo.Teams.Add(team);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TeamRow : CompositeDrawable
|
|
|
|
{
|
|
|
|
public readonly TournamentTeam Team;
|
|
|
|
|
2019-06-17 15:28:58 +08:00
|
|
|
private readonly Container drawableContainer;
|
|
|
|
|
2019-06-14 19:32:02 +08:00
|
|
|
[Resolved]
|
|
|
|
private LadderInfo ladderInfo { get; set; }
|
|
|
|
|
|
|
|
public TeamRow(TournamentTeam team)
|
|
|
|
{
|
2019-06-17 19:59:17 +08:00
|
|
|
Team = team;
|
2019-06-17 19:47:45 +08:00
|
|
|
|
2019-06-17 19:59:17 +08:00
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 10;
|
2019-06-14 19:32:02 +08:00
|
|
|
|
2019-06-17 19:59:17 +08:00
|
|
|
PlayerEditor playerEditor = new PlayerEditor(Team)
|
|
|
|
{
|
|
|
|
Width = 0.95f
|
|
|
|
};
|
2019-06-17 15:28:58 +08:00
|
|
|
|
2019-06-14 19:32:02 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = OsuColour.Gray(0.1f),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2019-06-17 19:59:17 +08:00
|
|
|
drawableContainer = new Container
|
|
|
|
{
|
|
|
|
Size = new Vector2(100, 50),
|
|
|
|
Margin = new MarginPadding(10),
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
},
|
2019-06-14 19:32:02 +08:00
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Margin = new MarginPadding(5),
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Direction = FillDirection.Full,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new SettingsTextBox
|
|
|
|
{
|
|
|
|
LabelText = "Name",
|
2019-06-17 19:59:17 +08:00
|
|
|
Width = 0.2f,
|
2019-06-17 15:28:58 +08:00
|
|
|
Bindable = Team.FullName
|
2019-06-14 19:32:02 +08:00
|
|
|
},
|
|
|
|
new SettingsTextBox
|
|
|
|
{
|
2019-06-17 15:28:58 +08:00
|
|
|
LabelText = "Acronym",
|
2019-06-17 19:59:17 +08:00
|
|
|
Width = 0.2f,
|
2019-06-17 15:28:58 +08:00
|
|
|
Bindable = Team.Acronym
|
2019-06-14 19:32:02 +08:00
|
|
|
},
|
2019-06-17 15:28:58 +08:00
|
|
|
new SettingsTextBox
|
2019-06-14 19:32:02 +08:00
|
|
|
{
|
2019-06-17 15:28:58 +08:00
|
|
|
LabelText = "Flag",
|
2019-06-17 19:59:17 +08:00
|
|
|
Width = 0.2f,
|
2019-06-17 15:28:58 +08:00
|
|
|
Bindable = Team.FlagName
|
2019-06-14 19:32:02 +08:00
|
|
|
},
|
2019-06-17 19:47:45 +08:00
|
|
|
new SettingsButton
|
|
|
|
{
|
2019-06-17 19:59:17 +08:00
|
|
|
Width = 0.11f,
|
|
|
|
Margin = new MarginPadding(10),
|
2019-06-17 19:47:45 +08:00
|
|
|
Text = "Add player",
|
|
|
|
Action = () => playerEditor.AddUser()
|
|
|
|
},
|
|
|
|
new DangerousSettingsButton
|
|
|
|
{
|
2019-06-17 19:59:17 +08:00
|
|
|
Width = 0.11f,
|
2019-06-17 19:47:45 +08:00
|
|
|
Text = "Delete Team",
|
2019-06-17 19:59:17 +08:00
|
|
|
Margin = new MarginPadding(10),
|
2019-06-17 19:47:45 +08:00
|
|
|
Action = () =>
|
|
|
|
{
|
|
|
|
Expire();
|
|
|
|
ladderInfo.Teams.Remove(Team);
|
|
|
|
},
|
2019-06-17 19:59:17 +08:00
|
|
|
},
|
|
|
|
playerEditor
|
2019-06-17 19:47:45 +08:00
|
|
|
}
|
|
|
|
},
|
2019-06-14 19:32:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2019-06-17 15:28:58 +08:00
|
|
|
|
|
|
|
Team.FlagName.BindValueChanged(updateDrawable, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateDrawable(ValueChangedEvent<string> flag)
|
|
|
|
{
|
|
|
|
drawableContainer.Child = new RowTeam(Team);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class RowTeam : DrawableTournamentTeam
|
|
|
|
{
|
|
|
|
public RowTeam(TournamentTeam team)
|
|
|
|
: base(team)
|
|
|
|
{
|
|
|
|
InternalChild = Flag;
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
Flag.Anchor = Anchor.Centre;
|
|
|
|
Flag.Origin = Anchor.Centre;
|
|
|
|
}
|
2019-06-14 19:32:02 +08:00
|
|
|
}
|
2019-06-17 19:47:45 +08:00
|
|
|
|
|
|
|
public class PlayerEditor : CompositeDrawable
|
|
|
|
{
|
|
|
|
private readonly TournamentTeam team;
|
|
|
|
private readonly FillFlowContainer flow;
|
|
|
|
|
|
|
|
public PlayerEditor(TournamentTeam team)
|
|
|
|
{
|
|
|
|
this.team = team;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
InternalChild = flow = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
LayoutDuration = 200,
|
|
|
|
LayoutEasing = Easing.OutQuint,
|
|
|
|
ChildrenEnumerable = team.Players.Select(p => new PlayerRow(team, p))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddUser()
|
|
|
|
{
|
|
|
|
var user = new User();
|
|
|
|
team.Players.Add(user);
|
|
|
|
flow.Add(new PlayerRow(team, user));
|
|
|
|
}
|
|
|
|
|
|
|
|
public class PlayerRow : CompositeDrawable
|
|
|
|
{
|
|
|
|
private readonly User user;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
protected IAPIProvider API { get; private set; }
|
|
|
|
|
|
|
|
private readonly Bindable<string> userId = new Bindable<string>();
|
|
|
|
|
|
|
|
private readonly Container drawableContainer;
|
|
|
|
|
|
|
|
public PlayerRow(TournamentTeam team, User user)
|
|
|
|
{
|
|
|
|
this.user = user;
|
|
|
|
|
|
|
|
Margin = new MarginPadding(10);
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
2019-06-17 19:59:17 +08:00
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 5;
|
|
|
|
|
2019-06-17 19:47:45 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2019-06-17 19:59:17 +08:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = OsuColour.Gray(0.2f),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2019-06-17 19:47:45 +08:00
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Margin = new MarginPadding(5),
|
|
|
|
Padding = new MarginPadding { Right = 160 },
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new SettingsTextBox
|
|
|
|
{
|
|
|
|
LabelText = "User ID",
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
Width = 200,
|
|
|
|
Bindable = userId,
|
|
|
|
},
|
|
|
|
drawableContainer = new Container
|
|
|
|
{
|
2019-06-17 19:59:17 +08:00
|
|
|
Size = new Vector2(100, 70),
|
2019-06-17 19:47:45 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new DangerousSettingsButton
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
Width = 150,
|
|
|
|
Text = "Delete Player",
|
|
|
|
Action = () =>
|
|
|
|
{
|
|
|
|
Expire();
|
|
|
|
team.Players.Remove(user);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
userId.Value = user.Id.ToString();
|
|
|
|
userId.BindValueChanged(idString =>
|
|
|
|
{
|
|
|
|
long parsed;
|
|
|
|
|
|
|
|
long.TryParse(idString.NewValue, out parsed);
|
|
|
|
|
|
|
|
user.Id = parsed;
|
|
|
|
|
|
|
|
if (idString.NewValue != idString.OldValue)
|
|
|
|
user.Username = string.Empty;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(user.Username))
|
|
|
|
{
|
|
|
|
updatePanel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var req = new GetUserRequest(user.Id);
|
|
|
|
|
|
|
|
req.Success += res =>
|
|
|
|
{
|
|
|
|
user.Username = res.Username;
|
|
|
|
updatePanel();
|
|
|
|
};
|
|
|
|
|
|
|
|
req.Failure += _ =>
|
|
|
|
{
|
|
|
|
user.Id = 1;
|
|
|
|
updatePanel();
|
|
|
|
};
|
|
|
|
|
|
|
|
API.Queue(req);
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updatePanel()
|
|
|
|
{
|
|
|
|
drawableContainer.Child = new UserPanel(user) { Width = 300 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-14 19:32:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|