osu/osu.Game.Tournament/Models/TournamentTeam.cs

55 lines
1.9 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-04-13 09:19:50 +00:00
2018-10-16 07:07:59 +00:00
using System;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Users;
2019-06-18 05:51:48 +00:00
namespace osu.Game.Tournament.Models
2018-04-13 09:19:50 +00:00
{
2019-06-18 06:00:33 +00:00
/// <summary>
/// A team representation. For official tournaments this is generally a country.
/// </summary>
2018-10-16 07:07:59 +00:00
[Serializable]
public class TournamentTeam
2018-04-13 09:19:50 +00:00
{
/// <summary>
/// The name of this team.
/// </summary>
public Bindable<string> FullName = new Bindable<string>(string.Empty);
2018-04-13 09:19:50 +00:00
/// <summary>
/// Name of the file containing the flag.
2018-04-13 09:19:50 +00:00
/// </summary>
public Bindable<string> FlagName = new Bindable<string>(string.Empty);
2018-04-13 09:19:50 +00:00
/// <summary>
/// Short acronym which appears in the group boxes post-selection.
2018-04-13 09:19:50 +00:00
/// </summary>
public Bindable<string> Acronym = new Bindable<string>(string.Empty);
2018-10-16 07:07:59 +00:00
[JsonProperty]
public BindableList<User> Players { get; set; } = new BindableList<User>();
public TournamentTeam()
{
Acronym.ValueChanged += val =>
{
// use a sane default flag name based on acronym.
if (val.OldValue.StartsWith(FlagName.Value, StringComparison.InvariantCultureIgnoreCase))
FlagName.Value = val.NewValue.Length >= 2 ? val.NewValue?.Substring(0, 2).ToUpper() : string.Empty;
};
FullName.ValueChanged += val =>
{
// use a sane acronym based on full name.
if (val.OldValue.StartsWith(Acronym.Value, StringComparison.InvariantCultureIgnoreCase))
Acronym.Value = val.NewValue.Length >= 3 ? val.NewValue?.Substring(0, 3).ToUpper() : string.Empty;
};
}
2018-09-21 20:52:25 +00:00
public override string ToString() => FullName.Value ?? Acronym.Value;
2018-04-13 09:19:50 +00:00
}
}