mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Merge branch 'master' into tournament-resolution-fixes
This commit is contained in:
commit
3ccd0ca1b0
@ -1,8 +1,11 @@
|
||||
// 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;
|
||||
|
||||
@ -10,12 +13,18 @@ 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(
|
||||
TournamentMatch match1 = null!;
|
||||
TournamentMatch match2 = null!;
|
||||
|
||||
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" } })
|
||||
{
|
||||
@ -23,7 +32,7 @@ namespace osu.Game.Tournament.Tests.Components
|
||||
Team2Score = { Value = 1 },
|
||||
};
|
||||
|
||||
var match2 = new TournamentMatch(
|
||||
match2 = new TournamentMatch(
|
||||
new TournamentTeam
|
||||
{
|
||||
FlagName = { Value = "RO" },
|
||||
@ -64,6 +73,7 @@ namespace osu.Game.Tournament.Tests.Components
|
||||
|
||||
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" } });
|
||||
@ -78,6 +88,9 @@ namespace osu.Game.Tournament.Tests.Components
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -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
|
||||
|
@ -14,6 +14,7 @@ using osu.Framework.Graphics.UserInterface;
|
||||
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;
|
||||
@ -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();
|
||||
|
||||
@ -43,6 +46,13 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
|
||||
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();
|
||||
}
|
||||
@ -68,8 +78,12 @@ namespace osu.Game.Tournament.Screens.Editors
|
||||
{
|
||||
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, () =>
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ using osu.Framework.Graphics.Containers;
|
||||
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;
|
||||
@ -41,35 +42,60 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
|
||||
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
|
||||
{
|
||||
Scale = new Vector2(1.1f),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Alpha = 0,
|
||||
Colour = Color4.YellowGreen,
|
||||
Child = new Box { RelativeSizeAxes = Axes.Both }
|
||||
},
|
||||
CurrentMatchSelectionBox = new Container
|
||||
{
|
||||
Scale = new Vector2(1.05f, 1.1f),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
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)
|
||||
Spacing = new Vector2(spacing)
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(-10),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
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,
|
||||
}
|
||||
},
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(-(spacing + border_thickness)),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
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,
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
@ -97,7 +123,6 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
Position = new Vector2(pos.NewValue.X, pos.NewValue.Y);
|
||||
Changed?.Invoke();
|
||||
}, true);
|
||||
|
||||
updateTeams();
|
||||
}
|
||||
|
||||
@ -225,10 +250,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
if (editorInfo != null)
|
||||
{
|
||||
globalSelection = editorInfo.Selected.GetBoundCopy();
|
||||
globalSelection.BindValueChanged(s =>
|
||||
{
|
||||
if (s.NewValue != Match) Selected = false;
|
||||
});
|
||||
globalSelection.BindValueChanged(s => Selected = s.NewValue == Match, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,8 +334,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
|
||||
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()
|
||||
|
@ -62,22 +62,28 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
// 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)
|
||||
{
|
||||
editorInfo.Selected.Value.Date.Value = round.NewValue.StartDate.Value;
|
||||
editorInfo.Selected.TriggerChange();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
|
Loading…
Reference in New Issue
Block a user