1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 05:22:54 +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="USE_EXTERNAL_CONSOLE" 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_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value=".NETCoreApp,Version=v2.1" />
<method />
<option name="PROJECT_TFM" value=".NETCoreApp,Version=v2.2" />
<method v="2">
<option name="Build" enabled="true" />
</method>
</configuration>
</component>

View File

@ -1,8 +1,8 @@
// 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.
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Online.Chat;
using osu.Game.Tests.Visual;
@ -58,11 +58,11 @@ namespace osu.Game.Tournament.Tests
{
Team1 =
{
Value = new TournamentTeam { Players = new List<User> { redUser } }
Value = new TournamentTeam { Players = new BindableList<User> { redUser } }
},
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;
var pairing1 = new MatchPairing(
new TournamentTeam { FlagName = "AU", FullName = "Australia", },
new TournamentTeam { FlagName = "JP", FullName = "Japan", Acronym = "JPN" })
new TournamentTeam { FlagName = { Value = "AU" }, FullName = { Value = "Australia" }, },
new TournamentTeam { FlagName = { Value = "JP" }, FullName = { Value = "Japan" }, Acronym = { Value = "JPN" } })
{
Team1Score = { Value = 4 },
Team2Score = { Value = 1 },
@ -37,8 +37,8 @@ namespace osu.Game.Tournament.Tests
var pairing2 = new MatchPairing(
new TournamentTeam
{
FlagName = "RO",
FullName = "Romania",
FlagName = { Value = "RO" },
FullName = { Value = "Romania" },
}
);
@ -77,7 +77,7 @@ namespace osu.Game.Tournament.Tests
level1.Children[1].Pairing.Progression.Value = level2.Children[0].Pairing;
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("start match", () => pairing2.StartMatch());

View File

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

View File

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

View File

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

View File

@ -2,8 +2,8 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Users;
namespace osu.Game.Tournament.Components
@ -14,33 +14,38 @@ namespace osu.Game.Tournament.Components
/// <summary>
/// The name of this team.
/// </summary>
public string FullName;
private string flagName;
public Bindable<string> FullName = new Bindable<string>(string.Empty);
/// <summary>
/// Name of the file containing the flag.
/// </summary>
public string FlagName
{
get => flagName ?? Acronym?.Substring(0, 2);
set => flagName = value;
}
private string acronym;
public Bindable<string> FlagName = new Bindable<string>(string.Empty);
/// <summary>
/// Short acronym which appears in the group boxes post-selection.
/// </summary>
public string Acronym
{
get => acronym ?? FullName?.Substring(0, 3);
set => acronym = value;
}
public Bindable<string> Acronym = new Bindable<string>(string.Empty);
[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)
{
return allTeams.Any(t => t.Team.FullName == fullName);
return allTeams.Any(t => t.Team.FullName.Value == fullName);
}
public bool RemoveTeam(TournamentTeam team)
@ -113,7 +113,7 @@ namespace osu.Game.Tournament.Screens.Drawings.Components
{
StringBuilder sb = new StringBuilder();
foreach (GroupTeam gt in allTeams)
sb.AppendLine(gt.Team.FullName);
sb.AppendLine(gt.Team.FullName.Value);
return sb.ToString();
}
@ -132,7 +132,7 @@ namespace osu.Game.Tournament.Screens.Drawings.Components
AcronymText.Anchor = 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);
InternalChildren = new Drawable[]

View File

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

View File

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

View File

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

View File

@ -89,8 +89,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
editorInfo.Selected.ValueChanged += selection =>
{
textboxTeam1.Text = selection.NewValue?.Team1.Value?.Acronym;
textboxTeam2.Text = selection.NewValue?.Team2.Value?.Acronym;
textboxTeam1.Text = selection.NewValue?.Team1.Value?.Acronym.Value;
textboxTeam2.Text = selection.NewValue?.Team2.Value?.Acronym.Value;
groupingDropdown.Bindable.Value = selection.NewValue?.Grouping.Value;
losersCheckbox.Current.Value = selection.NewValue?.Losers.Value ?? false;
dateTimeBox.Bindable.Value = selection.NewValue?.Date.Value ?? DateTimeOffset.UtcNow;
@ -99,13 +99,13 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
textboxTeam1.OnCommit = (val, newText) =>
{
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) =>
{
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 =>

View File

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

View File

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

View File

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

View File

@ -1,8 +1,8 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
@ -11,7 +11,6 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Screens.Ladder.Components;
using osuTK;
namespace osu.Game.Tournament.Screens.Teams
@ -66,13 +65,7 @@ namespace osu.Game.Tournament.Screens.Teams
private void addNew()
{
var team = new TournamentTeam
{
StartDate =
{
Value = DateTimeOffset.UtcNow
}
};
var team = new TournamentTeam();
items.Add(new TeamRow(team));
LadderInfo.Teams.Add(team);
@ -82,6 +75,8 @@ namespace osu.Game.Tournament.Screens.Teams
{
public readonly TournamentTeam Team;
private readonly Container drawableContainer;
[Resolved]
private LadderInfo ladderInfo { get; set; }
@ -90,6 +85,7 @@ namespace osu.Game.Tournament.Screens.Teams
Margin = new MarginPadding(10);
Team = team;
InternalChildren = new Drawable[]
{
new Box
@ -110,26 +106,26 @@ namespace osu.Game.Tournament.Screens.Teams
new SettingsTextBox
{
LabelText = "Name",
Width = 0.33f,
Width = 0.25f,
Bindable = Team.FullName
},
new SettingsTextBox
{
LabelText = "Acronym",
Width = 0.25f,
Bindable = Team.Acronym
},
new SettingsTextBox
{
LabelText = "Description",
Width = 0.33f,
Bindable = Team.Description
LabelText = "Flag",
Width = 0.25f,
Bindable = Team.FlagName
},
new DateTextBox
drawableContainer = new Container
{
LabelText = "Start Time",
Width = 0.33f,
Bindable = Team.StartDate
},
new SettingsSlider<int>
{
LabelText = "Best of",
Width = 0.33f,
Bindable = Team.BestOf
Width = 0.22f,
RelativeSizeAxes = Axes.X,
Height = 50,
},
}
},
@ -150,6 +146,26 @@ namespace osu.Game.Tournament.Screens.Teams
RelativeSizeAxes = Axes.X;
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
foreach (var pairing in ladder.Pairings)
{
pairing.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym == pairing.Team1Acronym);
pairing.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym == pairing.Team2Acronym);
pairing.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == pairing.Team1Acronym);
pairing.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == pairing.Team2Acronym);
foreach (var conditional in pairing.ConditionalPairings)
{
conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym == conditional.Team1Acronym);
conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym == conditional.Team2Acronym);
conditional.Team1.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team1Acronym);
conditional.Team2.Value = ladder.Teams.FirstOrDefault(t => t.Acronym.Value == conditional.Team2Acronym);
conditional.Grouping.Value = pairing.Grouping.Value;
}
}
@ -207,7 +207,7 @@ namespace osu.Game.Tournament
foreach (var t in ladder.Teams)
{
if (!string.IsNullOrEmpty(t.FullName))
if (!string.IsNullOrEmpty(t.FullName.Value))
continue;
var result = countries.FirstOrDefault(c => c.Acronym == t.Acronym);