1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 12:45:09 +08:00

Merge branch 'master' into fix-scheduler-screen-selection-alignment

This commit is contained in:
Bartłomiej Dach 2023-07-25 18:44:44 +02:00
commit 72db0c17ca
No known key found for this signature in database
16 changed files with 277 additions and 54 deletions

View File

@ -1,23 +1,100 @@
// 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 osu.Framework.Allocation;
using System;
using System.Linq;
using Newtonsoft.Json;
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Tournament.Screens.Editors;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Dialog;
using osu.Game.Tournament.Screens.Editors.Components;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tournament.Tests.Screens
{
public partial class TestSceneLadderEditorScreen : TournamentScreenTestScene
{
[BackgroundDependencyLoader]
private void load()
private LadderEditorScreen ladderEditorScreen = null!;
private OsuContextMenuContainer? osuContextMenuContainer;
[SetUp]
public void Setup() => Schedule(() =>
{
Add(new OsuContextMenuContainer
ladderEditorScreen = new LadderEditorScreen();
Add(osuContextMenuContainer = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Child = new LadderEditorScreen()
Child = ladderEditorScreen = new LadderEditorScreen()
});
});
[Test]
public void TestResetBracketTeamsCancelled()
{
Bindable<string> matchBeforeReset = new Bindable<string>();
AddStep("save current match state", () =>
{
matchBeforeReset.Value = JsonConvert.SerializeObject(Ladder.CurrentMatch.Value);
});
AddStep("pull up context menu", () =>
{
InputManager.MoveMouseTo(ladderEditorScreen);
InputManager.Click(MouseButton.Right);
});
AddStep("click Reset teams button", () =>
{
InputManager.MoveMouseTo(osuContextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().Last(p =>
((OsuMenuItem)p.Item).Type == MenuItemType.Destructive), new Vector2(5, 0));
InputManager.Click(MouseButton.Left);
});
AddAssert("dialog displayed", () => DialogOverlay.CurrentDialog is LadderResetTeamsDialog);
AddStep("click cancel", () =>
{
InputManager.MoveMouseTo(DialogOverlay.CurrentDialog.ChildrenOfType<PopupDialogButton>().Last());
InputManager.Click(MouseButton.Left);
});
AddUntilStep("dialog dismissed", () => DialogOverlay.CurrentDialog is not LadderResetTeamsDialog);
AddAssert("assert ladder teams unchanged", () => string.Equals(matchBeforeReset.Value, JsonConvert.SerializeObject(Ladder.CurrentMatch.Value), StringComparison.Ordinal));
}
[Test]
public void TestResetBracketTeams()
{
AddStep("pull up context menu", () =>
{
InputManager.MoveMouseTo(ladderEditorScreen);
InputManager.Click(MouseButton.Right);
});
AddStep("click Reset teams button", () =>
{
InputManager.MoveMouseTo(osuContextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().Last(p =>
((OsuMenuItem)p.Item).Type == MenuItemType.Destructive), new Vector2(5, 0));
InputManager.Click(MouseButton.Left);
});
AddAssert("dialog displayed", () => DialogOverlay.CurrentDialog is LadderResetTeamsDialog);
AddStep("click confirmation", () =>
{
InputManager.MoveMouseTo(DialogOverlay.CurrentDialog.ChildrenOfType<PopupDialogButton>().First());
InputManager.PressButton(MouseButton.Left);
});
AddUntilStep("dialog dismissed", () => DialogOverlay.CurrentDialog is not LadderResetTeamsDialog);
AddStep("release mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("assert ladder teams reset", () => Ladder.CurrentMatch.Value.Team1.Value == null && Ladder.CurrentMatch.Value.Team2.Value == null);
}
}
}

View File

@ -1,13 +1,15 @@
// 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 osu.Framework.Allocation;
using osu.Game.Tournament.Screens.Editors;
namespace osu.Game.Tournament.Tests.Screens
{
public partial class TestSceneRoundEditorScreen : TournamentScreenTestScene
{
public TestSceneRoundEditorScreen()
[BackgroundDependencyLoader]
private void load()
{
Add(new RoundEditorScreen
{

View File

@ -12,7 +12,8 @@ namespace osu.Game.Tournament.Tests.Screens
[Cached]
private readonly LadderInfo ladder = new LadderInfo();
public TestSceneSeedingEditorScreen()
[BackgroundDependencyLoader]
private void load()
{
var match = CreateSampleMatch();

View File

@ -1,13 +1,15 @@
// 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 osu.Framework.Allocation;
using osu.Game.Tournament.Screens.Editors;
namespace osu.Game.Tournament.Tests.Screens
{
public partial class TestSceneTeamEditorScreen : TournamentScreenTestScene
{
public TestSceneTeamEditorScreen()
[BackgroundDependencyLoader]
private void load()
{
Add(new TeamEditorScreen
{

View File

@ -8,6 +8,7 @@ using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Tests.Visual;
using osu.Game.Tournament.IO;
@ -16,8 +17,11 @@ using osu.Game.Tournament.Models;
namespace osu.Game.Tournament.Tests
{
public abstract partial class TournamentTestScene : OsuTestScene
public abstract partial class TournamentTestScene : OsuManualInputManagerTestScene
{
[Cached(typeof(IDialogOverlay))]
protected readonly DialogOverlay DialogOverlay = new DialogOverlay { Depth = float.MinValue };
[Cached]
protected LadderInfo Ladder { get; private set; } = new LadderInfo();
@ -43,6 +47,8 @@ namespace osu.Game.Tournament.Tests
Ruleset.BindTo(Ladder.Ruleset);
Dependencies.CacheAs(new StableInfo(storage));
Add(DialogOverlay);
}
[SetUpSteps]

View File

@ -0,0 +1,20 @@
// 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.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using osu.Game.Tournament.Models;
namespace osu.Game.Tournament.Screens.Editors.Components
{
public partial class DeleteRoundDialog : DangerousActionDialog
{
public DeleteRoundDialog(TournamentRound round, Action action)
{
HeaderText = round.Name.Value.Length > 0 ? $@"Delete round ""{round.Name.Value}""?" : @"Delete unnamed round?";
Icon = FontAwesome.Solid.Trash;
DangerousAction = action;
}
}
}

View File

@ -0,0 +1,22 @@
// 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.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using osu.Game.Tournament.Models;
namespace osu.Game.Tournament.Screens.Editors.Components
{
public partial class DeleteTeamDialog : DangerousActionDialog
{
public DeleteTeamDialog(TournamentTeam team, Action action)
{
HeaderText = team.FullName.Value.Length > 0 ? $@"Delete team ""{team.FullName.Value}""?" :
team.Acronym.Value.Length > 0 ? $@"Delete team ""{team.Acronym.Value}""?" :
@"Delete unnamed team?";
Icon = FontAwesome.Solid.Trash;
DangerousAction = action;
}
}
}

View File

@ -0,0 +1,19 @@
// 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.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Tournament.Screens.Editors.Components
{
public partial class LadderResetTeamsDialog : DangerousActionDialog
{
public LadderResetTeamsDialog(Action action)
{
HeaderText = @"Reset teams?";
Icon = FontAwesome.Solid.Undo;
DangerousAction = action;
}
}
}

View File

@ -0,0 +1,19 @@
// 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.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Tournament.Screens.Editors.Components
{
public partial class TournamentClearAllDialog : DangerousActionDialog
{
public TournamentClearAllDialog(Action action)
{
HeaderText = @"Clear all?";
Icon = FontAwesome.Solid.Trash;
DangerousAction = action;
}
}
}

View File

@ -6,6 +6,7 @@
using System;
using System.Drawing;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -16,7 +17,9 @@ 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.Overlays;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors.Components;
using osu.Game.Tournament.Screens.Ladder;
using osu.Game.Tournament.Screens.Ladder.Components;
using osuTK;
@ -34,6 +37,10 @@ namespace osu.Game.Tournament.Screens.Editors
private WarningBox rightClickMessage;
[Resolved(canBeNull: true)]
[CanBeNull]
private IDialogOverlay dialogOverlay { get; set; }
protected override bool DrawLoserPaths => true;
[BackgroundDependencyLoader]
@ -87,8 +94,11 @@ namespace osu.Game.Tournament.Screens.Editors
}),
new OsuMenuItem("Reset teams", MenuItemType.Destructive, () =>
{
foreach (var p in MatchesContainer)
p.Match.Reset();
dialogOverlay?.Push(new LadderResetTeamsDialog(() =>
{
foreach (var p in MatchesContainer)
p.Match.Reset();
}));
})
};
}

View File

@ -11,9 +11,11 @@ using osu.Game.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors.Components;
using osuTK;
namespace osu.Game.Tournament.Screens.Editors
@ -29,6 +31,9 @@ namespace osu.Game.Tournament.Screens.Editors
[Resolved]
private LadderInfo ladderInfo { get; set; } = null!;
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
public RoundRow(TournamentRound round)
{
Model = round;
@ -99,11 +104,11 @@ namespace osu.Game.Tournament.Screens.Editors
RelativeSizeAxes = Axes.None,
Width = 150,
Text = "Delete Round",
Action = () =>
Action = () => dialogOverlay?.Push(new DeleteRoundDialog(Model, () =>
{
Expire();
ladderInfo.Rounds.Remove(Model);
},
}))
}
};

View File

@ -11,8 +11,10 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors.Components;
using osu.Game.Tournament.Screens.Drawings.Components;
using osu.Game.Users;
using osuTK;
@ -61,6 +63,9 @@ namespace osu.Game.Tournament.Screens.Editors
[Resolved]
private TournamentSceneManager? sceneManager { get; set; }
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
[Resolved]
private LadderInfo ladderInfo { get; set; } = null!;
@ -157,11 +162,11 @@ namespace osu.Game.Tournament.Screens.Editors
Text = "Delete Team",
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Action = () =>
Action = () => dialogOverlay?.Push(new DeleteTeamDialog(Model, () =>
{
Expire();
ladderInfo.Teams.Remove(Model);
},
})),
},
}
},

View File

@ -13,7 +13,9 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Screens.Editors.Components;
using osuTK;
namespace osu.Game.Tournament.Screens.Editors
@ -24,6 +26,9 @@ namespace osu.Game.Tournament.Screens.Editors
{
protected abstract BindableList<TModel> Storage { get; }
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
private FillFlowContainer<TDrawable> flow = null!;
[Resolved]
@ -79,7 +84,10 @@ namespace osu.Game.Tournament.Screens.Editors
RelativeSizeAxes = Axes.X,
BackgroundColour = colours.Pink3,
Text = "Clear all",
Action = Storage.Clear
Action = () =>
{
dialogOverlay?.Push(new TournamentClearAllDialog(() => Storage.Clear()));
}
},
}
}

View File

@ -139,7 +139,7 @@ namespace osu.Game.Tournament.Screens.Gameplay
base.LoadComplete();
State.BindTo(ipc.State);
State.BindValueChanged(stateChanged, true);
State.BindValueChanged(_ => updateState(), true);
}
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
@ -150,20 +150,47 @@ namespace osu.Game.Tournament.Screens.Gameplay
return;
warmup.Value = match.NewValue.Team1Score.Value + match.NewValue.Team2Score.Value == 0;
scheduledOperation?.Cancel();
scheduledScreenChange?.Cancel();
}
private ScheduledDelegate scheduledOperation;
private ScheduledDelegate scheduledScreenChange;
private ScheduledDelegate scheduledContract;
private TournamentMatchScoreDisplay scoreDisplay;
private TourneyState lastState;
private MatchHeader header;
private void stateChanged(ValueChangedEvent<TourneyState> state)
private void contract()
{
scheduledContract?.Cancel();
SongBar.Expanded = false;
scoreDisplay.FadeOut(100);
using (chat?.BeginDelayedSequence(500))
chat?.Expand();
}
private void expand()
{
scheduledContract?.Cancel();
chat?.Contract();
using (BeginDelayedSequence(300))
{
scoreDisplay.FadeIn(100);
SongBar.Expanded = true;
}
}
private void updateState()
{
try
{
if (state.NewValue == TourneyState.Ranking)
scheduledScreenChange?.Cancel();
if (State.Value == TourneyState.Ranking)
{
if (warmup.Value || CurrentMatch.Value == null) return;
@ -173,28 +200,7 @@ namespace osu.Game.Tournament.Screens.Gameplay
CurrentMatch.Value.Team2Score.Value++;
}
scheduledOperation?.Cancel();
void expand()
{
chat?.Contract();
using (BeginDelayedSequence(300))
{
scoreDisplay.FadeIn(100);
SongBar.Expanded = true;
}
}
void contract()
{
SongBar.Expanded = false;
scoreDisplay.FadeOut(100);
using (chat?.BeginDelayedSequence(500))
chat?.Expand();
}
switch (state.NewValue)
switch (State.Value)
{
case TourneyState.Idle:
contract();
@ -208,30 +214,41 @@ namespace osu.Game.Tournament.Screens.Gameplay
if (lastState == TourneyState.Ranking && !warmup.Value)
{
if (CurrentMatch.Value?.Completed.Value == true)
scheduledOperation = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(TeamWinScreen)); }, delay_before_progression);
scheduledScreenChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(TeamWinScreen)); }, delay_before_progression);
else if (CurrentMatch.Value?.Completed.Value == false)
scheduledOperation = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(MapPoolScreen)); }, delay_before_progression);
scheduledScreenChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(MapPoolScreen)); }, delay_before_progression);
}
}
break;
case TourneyState.Ranking:
scheduledOperation = Scheduler.AddDelayed(contract, 10000);
scheduledContract = Scheduler.AddDelayed(contract, 10000);
break;
default:
chat.Contract();
expand();
break;
}
}
finally
{
lastState = state.NewValue;
lastState = State.Value;
}
}
public override void Hide()
{
scheduledScreenChange?.Cancel();
base.Hide();
}
public override void Show()
{
updateState();
base.Show();
}
private partial class ChromaArea : CompositeDrawable
{
[Resolved]

View File

@ -37,6 +37,8 @@ namespace osu.Game.Tournament.Screens.MapPool
private OsuButton buttonRedPick;
private OsuButton buttonBluePick;
private ScheduledDelegate scheduledScreenChange;
[BackgroundDependencyLoader]
private void load(MatchIPCInfo ipc)
{
@ -188,8 +190,6 @@ namespace osu.Game.Tournament.Screens.MapPool
setNextMode();
}
private ScheduledDelegate scheduledChange;
private void addForBeatmap(int beatmapId)
{
if (CurrentMatch.Value == null)
@ -216,12 +216,18 @@ namespace osu.Game.Tournament.Screens.MapPool
{
if (pickType == ChoiceType.Pick && CurrentMatch.Value.PicksBans.Any(i => i.Type == ChoiceType.Pick))
{
scheduledChange?.Cancel();
scheduledChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(GameplayScreen)); }, 10000);
scheduledScreenChange?.Cancel();
scheduledScreenChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(GameplayScreen)); }, 10000);
}
}
}
public override void Hide()
{
scheduledScreenChange?.Cancel();
base.Hide();
}
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
base.CurrentMatchChanged(match);

View File

@ -17,6 +17,7 @@ using osu.Framework.Platform;
using osu.Game.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Tournament.Models;
using osuTK.Graphics;
@ -41,6 +42,9 @@ namespace osu.Game.Tournament
private LoadingSpinner loadingSpinner;
[Cached(typeof(IDialogOverlay))]
private readonly DialogOverlay dialogOverlay = new DialogOverlay();
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager frameworkConfig, GameHost host)
{
@ -95,12 +99,12 @@ namespace osu.Game.Tournament
{
RelativeSizeAxes = Axes.Both,
Child = new TournamentSceneManager()
}
},
dialogOverlay
}, drawables =>
{
loadingSpinner.Hide();
loadingSpinner.Expire();
AddRange(drawables);
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>