Skip to content

Commit

Permalink
Merge branch 'master' into tournament-resolution-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Jul 24, 2023
2 parents 62121ea + 3af5c2b commit 3ccd0ca
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,69 +1,79 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Ladder.Components;

namespace osu.Game.Tournament.Tests.Components
{
public partial class TestSceneDrawableTournamentMatch : TournamentTestScene
{
public TestSceneDrawableTournamentMatch()
[Test]
public void TestBasic()
{
Container<DrawableTournamentMatch> level1;
Container<DrawableTournamentMatch> level2;
Container<DrawableTournamentMatch> level1 = null!;
Container<DrawableTournamentMatch> level2 = null!;

var match1 = new TournamentMatch(
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 },
};
TournamentMatch match1 = null!;
TournamentMatch match2 = null!;

var match2 = new TournamentMatch(
new TournamentTeam
AddStep("setup test", () =>
{
match1 = new TournamentMatch(
new TournamentTeam { FlagName = { Value = "AU" }, FullName = { Value = "Australia" }, },
new TournamentTeam { FlagName = { Value = "JP" }, FullName = { Value = "Japan" }, Acronym = { Value = "JPN" } })
{
FlagName = { Value = "RO" },
FullName = { Value = "Romania" },
}
);
Team1Score = { Value = 4 },
Team2Score = { Value = 1 },
};

Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
match2 = new TournamentMatch(
new TournamentTeam
{
FlagName = { Value = "RO" },
FullName = { Value = "Romania" },
}
);

Child = new FillFlowContainer
{
level1 = new FillFlowContainer<DrawableTournamentMatch>
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
AutoSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Children = new[]
level1 = new FillFlowContainer<DrawableTournamentMatch>
{
new DrawableTournamentMatch(match1),
new DrawableTournamentMatch(match2),
new DrawableTournamentMatch(new TournamentMatch()),
}
},
level2 = new FillFlowContainer<DrawableTournamentMatch>
{
AutoSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Margin = new MarginPadding(20),
Children = new[]
AutoSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Children = new[]
{
new DrawableTournamentMatch(match1),
new DrawableTournamentMatch(match2),
new DrawableTournamentMatch(new TournamentMatch()),
}
},
level2 = new FillFlowContainer<DrawableTournamentMatch>
{
new DrawableTournamentMatch(new TournamentMatch()),
new DrawableTournamentMatch(new TournamentMatch())
AutoSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Margin = new MarginPadding(20),
Children = new[]
{
new DrawableTournamentMatch(new TournamentMatch()),
new DrawableTournamentMatch(new TournamentMatch())
}
}
}
}
};
};

level1.Children[0].Match.Progression.Value = level2.Children[0].Match;
level1.Children[1].Match.Progression.Value = level2.Children[0].Match;
level1.Children[0].Match.Progression.Value = level2.Children[0].Match;
level1.Children[1].Match.Progression.Value = level2.Children[0].Match;
});

AddRepeatStep("change scores", () => match1.Team2Score.Value++, 4);
AddStep("add new team", () => match2.Team2.Value = new TournamentTeam { FlagName = { Value = "PT" }, FullName = { Value = "Portugal" } });
Expand All @@ -78,6 +88,9 @@ public TestSceneDrawableTournamentMatch()
AddRepeatStep("change scores", () => level2.Children[0].Match.Team1Score.Value++, 5);

AddRepeatStep("change scores", () => level2.Children[0].Match.Team2Score.Value++, 4);

AddStep("select as current", () => match1.Current.Value = true);
AddStep("select as editing", () => this.ChildrenOfType<DrawableTournamentMatch>().Last().Selected = true);
}
}
}
19 changes: 7 additions & 12 deletions osu.Game.Tournament/Components/DateTextBox.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using System;
using osu.Framework.Bindables;
using osu.Game.Graphics.UserInterface;
Expand All @@ -12,24 +10,21 @@ namespace osu.Game.Tournament.Components
{
public partial class DateTextBox : SettingsTextBox
{
public new Bindable<DateTimeOffset> Current
private readonly BindableWithCurrent<DateTimeOffset> current = new BindableWithCurrent<DateTimeOffset>();

public new Bindable<DateTimeOffset>? Current
{
get => current;
set
{
current = value.GetBoundCopy();
current.BindValueChanged(dto =>
base.Current.Value = dto.NewValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), true);
}
set => current.Current = value;
}

// hold a reference to the provided bindable so we don't have to in every settings section.
private Bindable<DateTimeOffset> current = new Bindable<DateTimeOffset>();

public DateTextBox()
{
base.Current = new Bindable<string>(string.Empty);

current.BindValueChanged(dto =>
base.Current.Value = dto.NewValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), true);

((OsuTextBox)Control).OnCommit += (sender, _) =>
{
try
Expand Down
18 changes: 16 additions & 2 deletions osu.Game.Tournament/Screens/Editors/LadderEditorScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Ladder;
Expand All @@ -26,6 +27,8 @@ namespace osu.Game.Tournament.Screens.Editors
[Cached]
public partial class LadderEditorScreen : LadderScreen, IHasContextMenu
{
public const float GRID_SPACING = 10;

[Cached]
private LadderEditorInfo editorInfo = new LadderEditorInfo();

Expand All @@ -43,6 +46,13 @@ private void load()

AddInternal(rightClickMessage = new WarningBox("Right click to place and link matches"));

ScrollContent.Add(new RectangularPositionSnapGrid(Vector2.Zero)
{
Spacing = new Vector2(GRID_SPACING),
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue
});

LadderInfo.Matches.CollectionChanged += (_, _) => updateMessage();
updateMessage();
}
Expand All @@ -68,8 +78,12 @@ public MenuItem[] ContextMenuItems
{
new OsuMenuItem("Create new match", MenuItemType.Highlighted, () =>
{
var pos = MatchesContainer.ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position);
LadderInfo.Matches.Add(new TournamentMatch { Position = { Value = new Point((int)pos.X, (int)pos.Y) } });
Vector2 pos = MatchesContainer.ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position);
TournamentMatch newMatch = new TournamentMatch { Position = { Value = new Point((int)pos.X, (int)pos.Y) } };

LadderInfo.Matches.Add(newMatch);

editorInfo.Selected.Value = newMatch;
}),
new OsuMenuItem("Reset teams", MenuItemType.Destructive, () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors;
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
Expand Down Expand Up @@ -41,35 +42,60 @@ public DrawableTournamentMatch(TournamentMatch match, bool editor = false)

AutoSizeAxes = Axes.Both;

Margin = new MarginPadding(5);
const float border_thickness = 5;
const float spacing = 2;

InternalChildren = new[]
Margin = new MarginPadding(10);

InternalChildren = new Drawable[]
{
selectionBox = new Container
Flow = new FillFlowContainer<DrawableMatchTeam>
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(spacing)
},
new Container
{
Scale = new Vector2(1.1f),
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(-10),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0,
Colour = Color4.YellowGreen,
Child = new Box { RelativeSizeAxes = Axes.Both }
Child = selectionBox = new Container
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Masking = true,
BorderColour = Color4.YellowGreen,
BorderThickness = border_thickness,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
AlwaysPresent = true,
Alpha = 0,
}
},
},
CurrentMatchSelectionBox = new Container
new Container
{
Scale = new Vector2(1.05f, 1.1f),
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(-(spacing + border_thickness)),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0,
Colour = Color4.White,
Child = new Box { RelativeSizeAxes = Axes.Both }
},
Flow = new FillFlowContainer<DrawableMatchTeam>
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(2)
Child = CurrentMatchSelectionBox = new Container
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
BorderColour = Color4.White,
BorderThickness = border_thickness,
Masking = true,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
AlwaysPresent = true,
Alpha = 0,
}
},
}
};

Expand Down Expand Up @@ -97,7 +123,6 @@ public DrawableTournamentMatch(TournamentMatch match, bool editor = false)
Position = new Vector2(pos.NewValue.X, pos.NewValue.Y);
Changed?.Invoke();
}, true);

updateTeams();
}

Expand Down Expand Up @@ -225,10 +250,7 @@ protected override void LoadComplete()
if (editorInfo != null)
{
globalSelection = editorInfo.Selected.GetBoundCopy();
globalSelection.BindValueChanged(s =>
{
if (s.NewValue != Match) Selected = false;
});
globalSelection.BindValueChanged(s => Selected = s.NewValue == Match, true);
}
}

Expand Down Expand Up @@ -312,8 +334,8 @@ protected override void OnDrag(DragEvent e)

private Vector2 snapToGrid(Vector2 pos) =>
new Vector2(
(int)(pos.X / 10) * 10,
(int)(pos.Y / 10) * 10
(int)(pos.X / LadderEditorScreen.GRID_SPACING) * LadderEditorScreen.GRID_SPACING,
(int)(pos.Y / LadderEditorScreen.GRID_SPACING) * LadderEditorScreen.GRID_SPACING
);

public void Remove()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,28 @@ private void load()
// ensure any ongoing edits are committed out to the *current* selection before changing to a new one.
GetContainingInputManager().TriggerFocusContention(null);

roundDropdown.Current = selection.NewValue?.Round;
losersCheckbox.Current = selection.NewValue?.Losers;
dateTimeBox.Current = selection.NewValue?.Date;
// Required to avoid cyclic failure in BindableWithCurrent (TriggerChange called during the Current_Set process).
// Arguable a framework issue but since we haven't hit it anywhere else a local workaround seems best.
roundDropdown.Current.ValueChanged -= roundDropdownChanged;

team1Dropdown.Current = selection.NewValue?.Team1;
team2Dropdown.Current = selection.NewValue?.Team2;
roundDropdown.Current = selection.NewValue.Round;
losersCheckbox.Current = selection.NewValue.Losers;
dateTimeBox.Current = selection.NewValue.Date;

team1Dropdown.Current = selection.NewValue.Team1;
team2Dropdown.Current = selection.NewValue.Team2;

roundDropdown.Current.ValueChanged += roundDropdownChanged;
};
}

roundDropdown.Current.ValueChanged += round =>
private void roundDropdownChanged(ValueChangedEvent<TournamentRound> round)
{
if (editorInfo.Selected.Value?.Date.Value < round.NewValue?.StartDate.Value)
{
if (editorInfo.Selected.Value?.Date.Value < round.NewValue?.StartDate.Value)
{
editorInfo.Selected.Value.Date.Value = round.NewValue.StartDate.Value;
editorInfo.Selected.TriggerChange();
}
};
editorInfo.Selected.Value.Date.Value = round.NewValue.StartDate.Value;
editorInfo.Selected.TriggerChange();
}
}

protected override void LoadComplete()
Expand Down

0 comments on commit 3ccd0ca

Please sign in to comment.