1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +08:00

Convert TournamentTeam props to use binadbles

This commit is contained in:
Dean Herbert 2019-06-17 16:28:58 +09:00
parent e58d259498
commit 93fc14426b
17 changed files with 103 additions and 79 deletions

View File

@ -6,12 +6,15 @@
<option name="PASS_PARENT_ENVS" value="1" /> <option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" /> <option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" /> <option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/osu.Game.Tests/osu.Game.Tests.csproj" /> <option name="PROJECT_PATH" value="$PROJECT_DIR$/osu.Game.Tests/osu.Game.Tests.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" /> <option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" /> <option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" /> <option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" /> <option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value=".NETCoreApp,Version=v2.1" /> <option name="PROJECT_TFM" value=".NETCoreApp,Version=v2.2" />
<method /> <method v="2">
<option name="Build" enabled="true" />
</method>
</configuration> </configuration>
</component> </component>

View File

@ -1,8 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
@ -58,11 +58,11 @@ namespace osu.Game.Tournament.Tests
{ {
Team1 = Team1 =
{ {
Value = new TournamentTeam { Players = new List<User> { redUser } } Value = new TournamentTeam { Players = new BindableList<User> { redUser } }
}, },
Team2 = Team2 =
{ {
Value = new TournamentTeam { Players = new List<User> { blueUser } } Value = new TournamentTeam { Players = new BindableList<User> { blueUser } }
} }
}; };

View File

@ -27,8 +27,8 @@ namespace osu.Game.Tournament.Tests
Container<DrawableMatchPairing> level2; Container<DrawableMatchPairing> level2;
var pairing1 = new MatchPairing( var pairing1 = new MatchPairing(
new TournamentTeam { FlagName = "AU", FullName = "Australia", }, new TournamentTeam { FlagName = { Value = "AU" }, FullName = { Value = "Australia" }, },
new TournamentTeam { FlagName = "JP", FullName = "Japan", Acronym = "JPN" }) new TournamentTeam { FlagName = { Value = "JP" }, FullName = { Value = "Japan" }, Acronym = { Value = "JPN" } })
{ {
Team1Score = { Value = 4 }, Team1Score = { Value = 4 },
Team2Score = { Value = 1 }, Team2Score = { Value = 1 },
@ -37,8 +37,8 @@ namespace osu.Game.Tournament.Tests
var pairing2 = new MatchPairing( var pairing2 = new MatchPairing(
new TournamentTeam new TournamentTeam
{ {
FlagName = "RO", FlagName = { Value = "RO" },
FullName = "Romania", FullName = { Value = "Romania" },
} }
); );
@ -77,7 +77,7 @@ namespace osu.Game.Tournament.Tests
level1.Children[1].Pairing.Progression.Value = level2.Children[0].Pairing; level1.Children[1].Pairing.Progression.Value = level2.Children[0].Pairing;
AddRepeatStep("change scores", () => pairing1.Team2Score.Value++, 4); AddRepeatStep("change scores", () => pairing1.Team2Score.Value++, 4);
AddStep("add new team", () => pairing2.Team2.Value = new TournamentTeam { FlagName = "PT", FullName = "Portugal" }); AddStep("add new team", () => pairing2.Team2.Value = new TournamentTeam { FlagName = { Value = "PT" }, FullName = { Value = "Portugal" } });
AddStep("Add progression", () => level1.Children[2].Pairing.Progression.Value = level2.Children[1].Pairing); AddStep("Add progression", () => level1.Children[2].Pairing.Progression.Value = level2.Children[1].Pairing);
AddStep("start match", () => pairing2.StartMatch()); AddStep("start match", () => pairing2.StartMatch());

View File

@ -19,8 +19,8 @@ namespace osu.Game.Tournament.Tests
private void load() private void load()
{ {
var pairing = new MatchPairing(); var pairing = new MatchPairing();
pairing.Team1.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym == "USA"); pairing.Team1.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym.Value == "USA");
pairing.Team2.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym == "JPN"); pairing.Team2.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym.Value == "JPN");
pairing.Grouping.Value = Ladder.Groupings.FirstOrDefault(g => g.Name.Value == "Finals"); pairing.Grouping.Value = Ladder.Groupings.FirstOrDefault(g => g.Name.Value == "Finals");
currentMatch.Value = pairing; currentMatch.Value = pairing;

View File

@ -19,8 +19,8 @@ namespace osu.Game.Tournament.Tests
private void load() private void load()
{ {
var pairing = new MatchPairing(); var pairing = new MatchPairing();
pairing.Team1.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym == "USA"); pairing.Team1.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym.Value == "USA");
pairing.Team2.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym == "JPN"); pairing.Team2.Value = Ladder.Teams.FirstOrDefault(t => t.Acronym.Value == "JPN");
pairing.Grouping.Value = Ladder.Groupings.FirstOrDefault(g => g.Name.Value == "Finals"); pairing.Grouping.Value = Ladder.Groupings.FirstOrDefault(g => g.Name.Value == "Finals");
currentMatch.Value = pairing; currentMatch.Value = pairing;

View File

@ -30,7 +30,7 @@ namespace osu.Game.Tournament.Components
AcronymText = new OsuSpriteText AcronymText = new OsuSpriteText
{ {
Text = team?.Acronym?.ToUpperInvariant() ?? string.Empty, Text = team?.Acronym.Value?.ToUpperInvariant() ?? string.Empty,
Font = OsuFont.GetFont(weight: FontWeight.Regular), Font = OsuFont.GetFont(weight: FontWeight.Regular),
}; };
} }

View File

@ -2,8 +2,8 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Tournament.Components namespace osu.Game.Tournament.Components
@ -14,33 +14,38 @@ namespace osu.Game.Tournament.Components
/// <summary> /// <summary>
/// The name of this team. /// The name of this team.
/// </summary> /// </summary>
public string FullName; public Bindable<string> FullName = new Bindable<string>(string.Empty);
private string flagName;
/// <summary> /// <summary>
/// Name of the file containing the flag. /// Name of the file containing the flag.
/// </summary> /// </summary>
public string FlagName public Bindable<string> FlagName = new Bindable<string>(string.Empty);
{
get => flagName ?? Acronym?.Substring(0, 2);
set => flagName = value;
}
private string acronym;
/// <summary> /// <summary>
/// Short acronym which appears in the group boxes post-selection. /// Short acronym which appears in the group boxes post-selection.
/// </summary> /// </summary>
public string Acronym public Bindable<string> Acronym = new Bindable<string>(string.Empty);
{
get => acronym ?? FullName?.Substring(0, 3);
set => acronym = value;
}
[JsonProperty] [JsonProperty]
public List<User> Players { get; set; } = new List<User>(); public BindableList<User> Players { get; set; } = new BindableList<User>();
public override string ToString() => FullName ?? Acronym; 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;
};
}
public override string ToString() => FullName.Value ?? Acronym.Value;
} }
} }

View File

@ -85,7 +85,7 @@ namespace osu.Game.Tournament.Screens.Drawings.Components
public bool ContainsTeam(string fullName) public bool ContainsTeam(string fullName)
{ {
return allTeams.Any(t => t.Team.FullName == fullName); return allTeams.Any(t => t.Team.FullName.Value == fullName);
} }
public bool RemoveTeam(TournamentTeam team) public bool RemoveTeam(TournamentTeam team)
@ -113,7 +113,7 @@ namespace osu.Game.Tournament.Screens.Drawings.Components
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
foreach (GroupTeam gt in allTeams) foreach (GroupTeam gt in allTeams)
sb.AppendLine(gt.Team.FullName); sb.AppendLine(gt.Team.FullName.Value);
return sb.ToString(); return sb.ToString();
} }
@ -132,7 +132,7 @@ namespace osu.Game.Tournament.Screens.Drawings.Components
AcronymText.Anchor = Anchor.TopCentre; AcronymText.Anchor = Anchor.TopCentre;
AcronymText.Origin = Anchor.TopCentre; AcronymText.Origin = Anchor.TopCentre;
AcronymText.Text = team.Acronym.ToUpperInvariant(); AcronymText.Text = team.Acronym.Value.ToUpperInvariant();
AcronymText.Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 10); AcronymText.Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 10);
InternalChildren = new Drawable[] InternalChildren = new Drawable[]

View File

@ -50,9 +50,9 @@ namespace osu.Game.Tournament.Screens.Drawings.Components
teams.Add(new TournamentTeam teams.Add(new TournamentTeam
{ {
FullName = split[1].Trim(), FullName = { Value = split[1].Trim(), },
Acronym = split.Length >= 3 ? split[2].Trim() : null, Acronym = { Value = split.Length >= 3 ? split[2].Trim() : null, },
FlagName = split[0].Trim() FlagName = { Value = split[0].Trim() }
}); });
} }
} }

View File

@ -169,7 +169,7 @@ namespace osu.Game.Tournament.Screens.Drawings
{ {
groupsContainer.AddTeam(team); groupsContainer.AddTeam(team);
fullTeamNameText.Text = team.FullName; fullTeamNameText.Text = team.FullName.Value;
fullTeamNameText.FadeIn(200); fullTeamNameText.FadeIn(200);
writeResults(groupsContainer.GetStringRepresentation()); writeResults(groupsContainer.GetStringRepresentation());
@ -204,7 +204,7 @@ namespace osu.Game.Tournament.Screens.Drawings
foreach (TournamentTeam t in TeamList.Teams) foreach (TournamentTeam t in TeamList.Teams)
{ {
if (groupsContainer.ContainsTeam(t.FullName)) if (groupsContainer.ContainsTeam(t.FullName.Value))
continue; continue;
allTeams.Add(t); allTeams.Add(t);
@ -240,7 +240,7 @@ namespace osu.Game.Tournament.Screens.Drawings
continue; continue;
// ReSharper disable once AccessToModifiedClosure // ReSharper disable once AccessToModifiedClosure
TournamentTeam teamToAdd = allTeams.FirstOrDefault(t => t.FullName == line); TournamentTeam teamToAdd = allTeams.FirstOrDefault(t => t.FullName.Value == line);
if (teamToAdd == null) if (teamToAdd == null)
continue; continue;

View File

@ -172,7 +172,7 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
Flag, Flag,
new OsuSpriteText new OsuSpriteText
{ {
Text = team?.FullName.ToUpper() ?? "???", Text = team?.FullName.Value.ToUpper() ?? "???",
X = (flip ? -1 : 1) * 90, X = (flip ? -1 : 1) * 90,
Y = -10, Y = -10,
Colour = colour, Colour = colour,

View File

@ -89,8 +89,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
editorInfo.Selected.ValueChanged += selection => editorInfo.Selected.ValueChanged += selection =>
{ {
textboxTeam1.Text = selection.NewValue?.Team1.Value?.Acronym; textboxTeam1.Text = selection.NewValue?.Team1.Value?.Acronym.Value;
textboxTeam2.Text = selection.NewValue?.Team2.Value?.Acronym; textboxTeam2.Text = selection.NewValue?.Team2.Value?.Acronym.Value;
groupingDropdown.Bindable.Value = selection.NewValue?.Grouping.Value; groupingDropdown.Bindable.Value = selection.NewValue?.Grouping.Value;
losersCheckbox.Current.Value = selection.NewValue?.Losers.Value ?? false; losersCheckbox.Current.Value = selection.NewValue?.Losers.Value ?? false;
dateTimeBox.Bindable.Value = selection.NewValue?.Date.Value ?? DateTimeOffset.UtcNow; dateTimeBox.Bindable.Value = selection.NewValue?.Date.Value ?? DateTimeOffset.UtcNow;
@ -99,13 +99,13 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
textboxTeam1.OnCommit = (val, newText) => textboxTeam1.OnCommit = (val, newText) =>
{ {
if (newText && editorInfo.Selected.Value != null) if (newText && editorInfo.Selected.Value != null)
editorInfo.Selected.Value.Team1.Value = teamEntries.FirstOrDefault(t => t.Acronym == val.Text); editorInfo.Selected.Value.Team1.Value = teamEntries.FirstOrDefault(t => t.Acronym.Value == val.Text);
}; };
textboxTeam2.OnCommit = (val, newText) => textboxTeam2.OnCommit = (val, newText) =>
{ {
if (newText && editorInfo.Selected.Value != null) if (newText && editorInfo.Selected.Value != null)
editorInfo.Selected.Value.Team2.Value = teamEntries.FirstOrDefault(t => t.Acronym == val.Text); editorInfo.Selected.Value.Team2.Value = teamEntries.FirstOrDefault(t => t.Acronym.Value == val.Text);
}; };
groupingDropdown.Bindable.ValueChanged += grouping => groupingDropdown.Bindable.ValueChanged += grouping =>

View File

@ -73,8 +73,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
public MatchPairing() public MatchPairing()
{ {
Team1.BindValueChanged(t => Team1Acronym = t.NewValue?.Acronym, true); Team1.BindValueChanged(t => Team1Acronym = t.NewValue?.Acronym.Value, true);
Team2.BindValueChanged(t => Team2Acronym = t.NewValue?.Acronym, true); Team2.BindValueChanged(t => Team2Acronym = t.NewValue?.Acronym.Value, true);
} }
public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null) public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null)

View File

@ -199,7 +199,7 @@ namespace osu.Game.Tournament.Screens.TeamIntro
Flag, Flag,
new OsuSpriteText new OsuSpriteText
{ {
Text = team?.FullName.ToUpper() ?? "???", Text = team?.FullName.Value.ToUpper() ?? "???",
Font = TournamentFont.GetFont(TournamentTypeface.Aquatico, 40, FontWeight.Light), Font = TournamentFont.GetFont(TournamentTypeface.Aquatico, 40, FontWeight.Light),
Colour = Color4.Black, Colour = Color4.Black,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,

View File

@ -203,7 +203,7 @@ namespace osu.Game.Tournament.Screens.TeamWin
Flag, Flag,
new OsuSpriteText new OsuSpriteText
{ {
Text = team?.FullName.ToUpper() ?? "???", Text = team?.FullName.Value.ToUpper() ?? "???",
Font = TournamentFont.GetFont(TournamentTypeface.Aquatico, 40, FontWeight.Light), Font = TournamentFont.GetFont(TournamentTypeface.Aquatico, 40, FontWeight.Light),
Colour = Color4.Black, Colour = Color4.Black,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,

View File

@ -1,8 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
@ -11,7 +11,6 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Components; using osu.Game.Tournament.Components;
using osu.Game.Tournament.Screens.Ladder.Components;
using osuTK; using osuTK;
namespace osu.Game.Tournament.Screens.Teams namespace osu.Game.Tournament.Screens.Teams
@ -66,13 +65,7 @@ namespace osu.Game.Tournament.Screens.Teams
private void addNew() private void addNew()
{ {
var team = new TournamentTeam var team = new TournamentTeam();
{
StartDate =
{
Value = DateTimeOffset.UtcNow
}
};
items.Add(new TeamRow(team)); items.Add(new TeamRow(team));
LadderInfo.Teams.Add(team); LadderInfo.Teams.Add(team);
@ -82,6 +75,8 @@ namespace osu.Game.Tournament.Screens.Teams
{ {
public readonly TournamentTeam Team; public readonly TournamentTeam Team;
private readonly Container drawableContainer;
[Resolved] [Resolved]
private LadderInfo ladderInfo { get; set; } private LadderInfo ladderInfo { get; set; }
@ -90,6 +85,7 @@ namespace osu.Game.Tournament.Screens.Teams
Margin = new MarginPadding(10); Margin = new MarginPadding(10);
Team = team; Team = team;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
new Box new Box
@ -110,26 +106,26 @@ namespace osu.Game.Tournament.Screens.Teams
new SettingsTextBox new SettingsTextBox
{ {
LabelText = "Name", LabelText = "Name",
Width = 0.33f, Width = 0.25f,
Bindable = Team.FullName
},
new SettingsTextBox
{
LabelText = "Acronym",
Width = 0.25f,
Bindable = Team.Acronym Bindable = Team.Acronym
}, },
new SettingsTextBox new SettingsTextBox
{ {
LabelText = "Description", LabelText = "Flag",
Width = 0.33f, Width = 0.25f,
Bindable = Team.Description Bindable = Team.FlagName
}, },
new DateTextBox drawableContainer = new Container
{ {
LabelText = "Start Time", Width = 0.22f,
Width = 0.33f, RelativeSizeAxes = Axes.X,
Bindable = Team.StartDate Height = 50,
},
new SettingsSlider<int>
{
LabelText = "Best of",
Width = 0.33f,
Bindable = Team.BestOf
}, },
} }
}, },
@ -150,6 +146,26 @@ namespace osu.Game.Tournament.Screens.Teams
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
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;
}
} }
} }
} }

View File

@ -100,13 +100,13 @@ namespace osu.Game.Tournament
// assign teams // assign teams
foreach (var pairing in ladder.Pairings) foreach (var pairing in ladder.Pairings)
{ {
pairing.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym == pairing.Team1Acronym); pairing.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == pairing.Team1Acronym);
pairing.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym == pairing.Team2Acronym); pairing.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == pairing.Team2Acronym);
foreach (var conditional in pairing.ConditionalPairings) foreach (var conditional in pairing.ConditionalPairings)
{ {
conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym == conditional.Team1Acronym); conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team1Acronym);
conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym == conditional.Team2Acronym); conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team2Acronym);
conditional.Grouping.Value = pairing.Grouping.Value; conditional.Grouping.Value = pairing.Grouping.Value;
} }
} }
@ -207,7 +207,7 @@ namespace osu.Game.Tournament
foreach (var t in ladder.Teams) foreach (var t in ladder.Teams)
{ {
if (!string.IsNullOrEmpty(t.FullName)) if (!string.IsNullOrEmpty(t.FullName.Value))
continue; continue;
var result = countries.FirstOrDefault(c => c.Acronym == t.Acronym); var result = countries.FirstOrDefault(c => c.Acronym == t.Acronym);