1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 05:27:23 +08:00
osu-lazer/osu.Game.Tournament/Screens/Gameplay/GameplayScreen.cs

200 lines
7.3 KiB
C#
Raw Normal View History

2018-11-06 18:23:03 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
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.Tournament.Components;
2018-11-10 23:45:48 +08:00
using osu.Game.Tournament.IPC;
2018-11-15 20:28:42 +08:00
using osu.Game.Tournament.Screens.Gameplay.Components;
2018-11-10 23:45:48 +08:00
using osu.Game.Tournament.Screens.Ladder.Components;
using osu.Game.Tournament.Screens.MapPool;
using osu.Game.Tournament.Screens.TeamWin;
using osuTK;
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
{
public class GameplayScreen : BeatmapInfoScreen
{
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
private readonly Bindable<MatchPairing> currentMatch = new Bindable<MatchPairing>();
public readonly Bindable<TourneyState> State = new Bindable<TourneyState>();
private TriangleButton warmupButton;
2018-11-15 20:28:42 +08:00
private MatchIPCInfo ipc;
private readonly Color4 red = new Color4(186, 0, 18, 255);
private readonly Color4 blue = new Color4(17, 136, 170, 255);
2018-11-10 23:45:48 +08:00
[Resolved]
private TournamentSceneManager sceneManager { get; set; }
2018-11-08 19:15:22 +08:00
[BackgroundDependencyLoader]
private void load(LadderInfo ladder, MatchIPCInfo ipc, MatchChatDisplay chat)
2018-11-08 19:15:22 +08:00
{
2018-11-17 20:27:02 +08:00
this.chat = chat;
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
{
2018-11-10 16:26:21 +08:00
new MatchHeader(),
new Container
2018-11-10 23:45:48 +08:00
{
2018-11-15 20:28:42 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2018-11-18 11:39:25 +08:00
Y = 5,
2018-11-10 23:45:48 +08:00
Anchor = Anchor.Centre,
2018-11-15 20:28:42 +08:00
Origin = Anchor.Centre,
Children = new Drawable[]
{
new Box
{
// chroma key area for stable gameplay
Name = "chroma",
RelativeSizeAxes = Axes.X,
Height = 512,
Colour = new Color4(0, 255, 0, 255),
},
2018-11-15 20:28:42 +08:00
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Y = -4,
2018-11-15 20:28:42 +08:00
Children = new Drawable[]
{
new Circle
{
Name = "top bar red",
RelativeSizeAxes = Axes.X,
2018-11-18 11:39:25 +08:00
Height = 8,
2018-11-15 20:28:42 +08:00
Width = 0.5f,
Colour = red,
},
new Circle
{
Name = "top bar blue",
RelativeSizeAxes = Axes.X,
Height = 8,
2018-11-15 20:28:42 +08:00
Width = 0.5f,
Colour = blue,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
}
},
}
2018-11-10 23:45:48 +08:00
},
scoreDisplay = new MatchScoreDisplay
{
2018-11-18 11:39:25 +08:00
Y = -60,
Scale = new Vector2(0.8f),
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
},
2018-11-09 15:10:58 +08:00
new ControlPanel
{
Children = new Drawable[]
2018-11-08 19:15:22 +08:00
{
2018-11-10 23:45:48 +08:00
warmupButton = new TriangleButton
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 TriangleButton
{
RelativeSizeAxes = Axes.X,
Text = "Toggle chat",
Action = () => { State.Value = State.Value == TourneyState.Idle ? TourneyState.Playing : TourneyState.Idle; }
2018-11-09 15:10:58 +08:00
}
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
State.BindTo(ipc.State);
State.BindValueChanged(stateChanged, true);
2018-11-10 23:45:48 +08:00
2019-03-02 12:40:43 +08:00
currentMatch.BindValueChanged(m => warmup.Value = m.NewValue.Team1Score.Value + m.NewValue.Team2Score.Value == 0);
2018-11-10 23:45:48 +08:00
currentMatch.BindTo(ladder.CurrentMatch);
2018-11-11 00:29:42 +08:00
2019-03-02 12:40:43 +08:00
warmup.BindValueChanged(w => warmupButton.Alpha = !w.NewValue ? 0.5f : 1, true);
2018-11-10 23:45:48 +08:00
}
private ScheduledDelegate scheduledOperation;
private MatchChatDisplay chat;
private MatchScoreDisplay scoreDisplay;
2018-11-11 00:50:09 +08:00
private TourneyState lastState;
2019-03-02 12:40:43 +08:00
private void stateChanged(ValueChangedEvent<TourneyState> state)
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
{
2019-03-02 12:40:43 +08:00
if (state.NewValue == TourneyState.Ranking)
2018-11-22 16:33:48 +08:00
{
if (warmup.Value) return;
2018-11-10 23:45:48 +08:00
2019-03-02 12:40:43 +08:00
if (ipc.Score1.Value > ipc.Score2.Value)
2018-11-22 16:33:48 +08:00
currentMatch.Value.Team1Score.Value++;
else
currentMatch.Value.Team2Score.Value++;
}
2018-11-08 19:15:22 +08:00
2018-11-22 16:33:48 +08:00
scheduledOperation?.Cancel();
2018-11-11 00:50:09 +08:00
2018-11-22 16:33:48 +08:00
void expand()
{
2018-11-22 16:33:48 +08:00
chat.Expand();
using (BeginDelayedSequence(300, true))
{
scoreDisplay.FadeIn(100);
SongBar.Expanded = true;
}
}
2018-11-17 14:31:03 +08:00
2018-11-22 16:33:48 +08:00
void contract()
{
SongBar.Expanded = false;
scoreDisplay.FadeOut(100);
using (chat.BeginDelayedSequence(500))
chat.Contract();
}
2018-11-17 14:31:03 +08:00
2019-03-02 12:40:43 +08:00
switch (state.NewValue)
2018-11-22 16:33:48 +08:00
{
case TourneyState.Idle:
contract();
2018-11-22 16:33:48 +08:00
if (lastState == TourneyState.Ranking && !warmup.Value)
{
2019-03-02 12:40:43 +08:00
if (currentMatch.Value?.Completed.Value == true)
2018-11-22 16:33:48 +08:00
scheduledOperation = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(TeamWinScreen)); }, 4000);
2019-03-02 12:40:43 +08:00
else if (currentMatch.Value?.Completed.Value == false)
2018-11-22 16:33:48 +08:00
scheduledOperation = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(MapPoolScreen)); }, 4000);
}
2018-11-22 16:33:48 +08:00
break;
case TourneyState.Ranking:
scheduledOperation = Scheduler.AddDelayed(contract, 10000);
break;
default:
chat.Expand();
expand();
break;
}
}
finally
{
2019-03-02 12:40:43 +08:00
lastState = state.NewValue;
2018-11-11 00:29:42 +08:00
}
2018-11-09 15:10:58 +08:00
}
2018-11-06 18:23:03 +08:00
}
}