1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 02:02:56 +08:00
osu-lazer/osu.Game.Tournament/Screens/Gameplay/GameplayScreen.cs

306 lines
10 KiB
C#
Raw Normal View History

2019-03-04 12:24:19 +08:00
// 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.
2018-11-06 18:23:03 +08:00
2018-11-08 19:15:22 +08:00
using osu.Framework.Allocation;
2019-03-02 12:40:43 +08:00
using osu.Framework.Bindables;
2018-11-08 19:15:22 +08:00
using osu.Framework.Graphics;
2018-11-15 20:28:42 +08:00
using osu.Framework.Graphics.Containers;
2018-11-10 23:45:48 +08:00
using osu.Framework.Graphics.Shapes;
2018-11-11 00:50:09 +08:00
using osu.Framework.Threading;
2018-11-08 19:15:22 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
2018-11-08 19:15:22 +08:00
using osu.Game.Tournament.Components;
2018-11-10 23:45:48 +08:00
using osu.Game.Tournament.IPC;
2019-06-18 13:51:48 +08:00
using osu.Game.Tournament.Models;
2018-11-15 20:28:42 +08:00
using osu.Game.Tournament.Screens.Gameplay.Components;
using osu.Game.Tournament.Screens.MapPool;
using osu.Game.Tournament.Screens.TeamWin;
using osuTK.Graphics;
2018-11-08 19:15:22 +08:00
2018-11-06 18:23:03 +08:00
namespace osu.Game.Tournament.Screens.Gameplay
{
2022-11-24 13:32:20 +08:00
public partial class GameplayScreen : BeatmapInfoScreen
2018-11-06 18:23:03 +08:00
{
2018-11-09 15:26:09 +08:00
private readonly BindableBool warmup = new BindableBool();
2018-11-09 15:10:58 +08:00
2018-11-10 23:45:48 +08:00
public readonly Bindable<TourneyState> State = new Bindable<TourneyState>();
2023-07-25 19:50:55 +08:00
private OsuButton warmupButton = null!;
private MatchIPCInfo ipc = null!;
2018-11-15 20:28:42 +08:00
2023-07-30 00:57:44 +08:00
[Resolved]
2023-07-25 19:50:55 +08:00
private TournamentSceneManager? sceneManager { get; set; }
2019-06-14 15:57:29 +08:00
[Resolved]
2023-07-25 19:50:55 +08:00
private TournamentMatchChatDisplay chat { get; set; } = null!;
2019-06-14 15:57:29 +08:00
2023-07-25 19:50:55 +08:00
private Drawable chroma = null!;
2018-11-08 19:15:22 +08:00
[BackgroundDependencyLoader]
private void load(MatchIPCInfo ipc)
2018-11-08 19:15:22 +08:00
{
2018-11-10 23:45:48 +08:00
this.ipc = ipc;
2018-11-17 20:27:02 +08:00
AddRangeInternal(new Drawable[]
2018-11-08 19:15:22 +08:00
{
new TourneyVideo("gameplay")
2020-03-06 15:06:23 +08:00
{
Loop = true,
RelativeSizeAxes = Axes.Both,
},
2020-03-12 13:26:22 +08:00
header = new MatchHeader
{
ShowLogo = false,
2020-03-12 13:26:22 +08:00
},
new Container
2018-11-10 23:45:48 +08:00
{
2018-11-15 20:28:42 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Y = 110,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Children = new[]
2018-11-15 20:28:42 +08:00
{
chroma = new Container
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Height = 512,
Children = new Drawable[]
{
new ChromaArea
{
Name = "Left chroma",
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
},
new ChromaArea
{
Name = "Right chroma",
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Width = 0.5f,
}
}
},
2018-11-15 20:28:42 +08:00
}
2018-11-10 23:45:48 +08:00
},
scoreDisplay = new TournamentMatchScoreDisplay
{
2020-03-07 15:22:52 +08:00
Y = -147,
Anchor = Anchor.BottomCentre,
2020-03-07 15:22:52 +08:00
Origin = Anchor.TopCentre,
},
2018-11-09 15:10:58 +08:00
new ControlPanel
{
Children = new Drawable[]
2018-11-08 19:15:22 +08:00
{
warmupButton = new TourneyButton
2018-11-09 15:10:58 +08:00
{
RelativeSizeAxes = Axes.X,
Text = "Toggle warmup",
2018-11-11 00:29:42 +08:00
Action = () => warmup.Toggle()
2018-11-16 17:14:42 +08:00
},
new TourneyButton
2018-11-16 17:14:42 +08:00
{
RelativeSizeAxes = Axes.X,
Text = "Toggle chat",
Action = () => { State.Value = State.Value == TourneyState.Idle ? TourneyState.Playing : TourneyState.Idle; }
},
new SettingsSlider<int>
{
LabelText = "Chroma width",
Current = LadderInfo.ChromaKeyWidth,
KeyboardStep = 1,
},
new SettingsSlider<int>
{
LabelText = "Players per team",
Current = LadderInfo.PlayersPerTeam,
KeyboardStep = 1,
},
2018-11-08 19:15:22 +08:00
}
2018-11-09 15:10:58 +08:00
}
2018-11-08 19:15:22 +08:00
});
2018-11-10 23:45:48 +08:00
LadderInfo.ChromaKeyWidth.BindValueChanged(width => chroma.Width = width.NewValue, true);
2020-03-07 13:46:40 +08:00
warmup.BindValueChanged(w =>
{
warmupButton.Alpha = !w.NewValue ? 0.5f : 1;
header.ShowScores = !w.NewValue;
}, true);
2018-11-10 23:45:48 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
State.BindTo(ipc.State);
State.BindValueChanged(_ => updateState(), true);
}
2023-07-25 19:50:55 +08:00
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch?> match)
{
base.CurrentMatchChanged(match);
if (match.NewValue == null)
return;
warmup.Value = match.NewValue.Team1Score.Value + match.NewValue.Team2Score.Value == 0;
scheduledScreenChange?.Cancel();
}
2023-07-25 19:50:55 +08:00
private ScheduledDelegate? scheduledScreenChange;
private ScheduledDelegate? scheduledContract;
2023-07-25 19:50:55 +08:00
private TournamentMatchScoreDisplay scoreDisplay = null!;
2018-11-11 00:50:09 +08:00
private TourneyState lastState;
2023-07-25 19:50:55 +08:00
private MatchHeader header = null!;
private void contract()
{
2023-07-25 19:50:55 +08:00
if (!IsLoaded)
return;
scheduledContract?.Cancel();
SongBar.Expanded = false;
scoreDisplay.FadeOut(100);
2023-07-25 19:50:55 +08:00
using (chat.BeginDelayedSequence(500))
chat.Expand();
}
private void expand()
{
2023-07-25 19:50:55 +08:00
if (!IsLoaded)
return;
scheduledContract?.Cancel();
2023-07-25 19:50:55 +08:00
chat.Contract();
using (BeginDelayedSequence(300))
{
scoreDisplay.FadeIn(100);
SongBar.Expanded = true;
}
}
private void updateState()
2018-11-10 23:45:48 +08:00
{
2018-11-22 16:33:48 +08:00
try
2018-11-10 23:45:48 +08:00
{
scheduledScreenChange?.Cancel();
if (State.Value == TourneyState.Ranking)
2018-11-22 16:33:48 +08:00
{
if (warmup.Value || CurrentMatch.Value == null) return;
2018-11-10 23:45:48 +08:00
2019-03-02 12:40:43 +08:00
if (ipc.Score1.Value > ipc.Score2.Value)
CurrentMatch.Value.Team1Score.Value++;
2018-11-22 16:33:48 +08:00
else
CurrentMatch.Value.Team2Score.Value++;
2018-11-22 16:33:48 +08:00
}
2018-11-08 19:15:22 +08:00
switch (State.Value)
2018-11-22 16:33:48 +08:00
{
case TourneyState.Idle:
contract();
if (LadderInfo.AutoProgressScreens.Value)
2018-11-22 16:33:48 +08:00
{
const float delay_before_progression = 4000;
// if we've returned to idle and the last screen was ranking
// we should automatically proceed after a short delay
if (lastState == TourneyState.Ranking && !warmup.Value)
{
if (CurrentMatch.Value?.Completed.Value == true)
scheduledScreenChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(TeamWinScreen)); }, delay_before_progression);
else if (CurrentMatch.Value?.Completed.Value == false)
scheduledScreenChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(MapPoolScreen)); }, delay_before_progression);
}
2018-11-22 16:33:48 +08:00
}
2018-11-22 16:33:48 +08:00
break;
2018-11-22 16:33:48 +08:00
case TourneyState.Ranking:
scheduledContract = Scheduler.AddDelayed(contract, 10000);
2018-11-22 16:33:48 +08:00
break;
2018-11-22 16:33:48 +08:00
default:
expand();
break;
}
}
finally
{
lastState = State.Value;
2018-11-11 00:29:42 +08:00
}
2018-11-09 15:10:58 +08:00
}
public override void Hide()
{
scheduledScreenChange?.Cancel();
base.Hide();
}
public override void Show()
{
updateState();
base.Show();
}
2022-11-24 13:32:20 +08:00
private partial class ChromaArea : CompositeDrawable
{
[Resolved]
2023-07-25 19:50:55 +08:00
private LadderInfo ladder { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
// chroma key area for stable gameplay
Colour = new Color4(0, 255, 0, 255);
ladder.PlayersPerTeam.BindValueChanged(performLayout, true);
}
private void performLayout(ValueChangedEvent<int> playerCount)
{
switch (playerCount.NewValue)
{
case 3:
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
Height = 0.5f,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Height = 0.5f,
},
};
break;
default:
InternalChild = new Box
{
RelativeSizeAxes = Axes.Both,
};
break;
}
}
}
2018-11-06 18:23:03 +08:00
}
}