osu/osu.Game.Tournament/Screens/Gameplay/GameplayScreen.cs

175 lines
6.2 KiB
C#
Raw Normal View History

2018-11-06 10:23:03 +00: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 11:15:22 +00:00
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
2018-11-15 12:28:42 +00:00
using osu.Framework.Graphics.Containers;
2018-11-10 15:45:48 +00:00
using osu.Framework.Graphics.Shapes;
2018-11-08 11:15:22 +00:00
using osu.Framework.Graphics.Textures;
2018-11-10 16:50:09 +00:00
using osu.Framework.Threading;
2018-11-08 11:15:22 +00:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Tournament.Components;
2018-11-10 15:45:48 +00:00
using osu.Game.Tournament.IPC;
2018-11-15 12:28:42 +00:00
using osu.Game.Tournament.Screens.Gameplay.Components;
2018-11-10 15:45:48 +00:00
using osu.Game.Tournament.Screens.Ladder.Components;
using OpenTK.Graphics;
2018-11-08 11:15:22 +00:00
2018-11-06 10:23:03 +00:00
namespace osu.Game.Tournament.Screens.Gameplay
{
public class GameplayScreen : BeatmapInfoScreen
{
2018-11-09 07:26:09 +00:00
private readonly BindableBool warmup = new BindableBool();
2018-11-09 07:10:58 +00:00
2018-11-10 15:45:48 +00:00
private readonly Bindable<MatchPairing> currentMatch = new Bindable<MatchPairing>();
public readonly Bindable<TourneyState> State = new Bindable<TourneyState>();
private TriangleButton warmupButton;
2018-11-15 12:28:42 +00: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 15:45:48 +00:00
2018-11-08 11:15:22 +00:00
[BackgroundDependencyLoader]
2018-11-17 12:27:02 +00:00
private void load(LadderInfo ladder, TextureStore textures, MatchIPCInfo ipc, MatchChatDisplay chat)
2018-11-08 11:15:22 +00:00
{
2018-11-17 12:27:02 +00:00
this.chat = chat;
2018-11-10 15:45:48 +00:00
this.ipc = ipc;
2018-11-17 12:27:02 +00:00
2018-11-09 07:10:58 +00:00
AddRange(new Drawable[]
2018-11-08 11:15:22 +00:00
{
2018-11-10 08:26:21 +00:00
new MatchHeader(),
2018-11-15 12:28:42 +00:00
new FillFlowContainer
2018-11-10 15:45:48 +00:00
{
2018-11-15 12:28:42 +00:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
2018-11-10 15:45:48 +00:00
Anchor = Anchor.Centre,
2018-11-15 12:28:42 +00:00
Origin = Anchor.Centre,
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Circle
{
Name = "top bar red",
RelativeSizeAxes = Axes.X,
Height = 10,
Width = 0.5f,
Colour = red,
},
new Circle
{
Name = "top bar blue",
RelativeSizeAxes = Axes.X,
Height = 10,
Width = 0.5f,
Colour = blue,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
}
},
new Box
{
// chroma key area for stable gameplay
Name = "chroma",
RelativeSizeAxes = Axes.X,
Height = 480,
Colour = new Color4(0, 255, 0, 255),
},
}
2018-11-10 15:45:48 +00:00
},
scoreDisplay = new MatchScoreDisplay
{
Y = -65,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
},
2018-11-09 07:10:58 +00:00
new ControlPanel
{
Children = new Drawable[]
2018-11-08 11:15:22 +00:00
{
2018-11-10 15:45:48 +00:00
warmupButton = new TriangleButton
2018-11-09 07:10:58 +00:00
{
RelativeSizeAxes = Axes.X,
Text = "Toggle warmup",
2018-11-10 16:29:42 +00:00
Action = () => warmup.Toggle()
2018-11-16 09:14:42 +00:00
},
new TriangleButton
{
RelativeSizeAxes = Axes.X,
Text = "Toggle chat",
Action = () => { State.Value = State.Value == TourneyState.Idle ? TourneyState.Playing : TourneyState.Idle; }
2018-11-09 07:10:58 +00:00
}
2018-11-08 11:15:22 +00:00
}
2018-11-09 07:10:58 +00:00
}
2018-11-08 11:15:22 +00:00
});
2018-11-10 15:45:48 +00:00
State.BindTo(ipc.State);
State.BindValueChanged(stateChanged, true);
2018-11-10 15:45:48 +00:00
2018-11-11 00:22:57 +00:00
currentMatch.BindValueChanged(m => warmup.Value = m.Team1Score + m.Team2Score == 0);
2018-11-10 15:45:48 +00:00
currentMatch.BindTo(ladder.CurrentMatch);
2018-11-10 16:29:42 +00:00
2018-11-11 00:22:57 +00:00
warmup.BindValueChanged(w => warmupButton.Alpha = !w ? 0.5f : 1, true);
2018-11-10 15:45:48 +00:00
}
2018-11-10 16:50:09 +00:00
private ScheduledDelegate scheduledBarContract;
private MatchChatDisplay chat;
private MatchScoreDisplay scoreDisplay;
2018-11-10 16:50:09 +00:00
2018-11-10 15:45:48 +00:00
private void stateChanged(TourneyState state)
{
if (state == TourneyState.Ranking)
{
if (warmup.Value) return;
if (ipc.Score1 > ipc.Score2)
currentMatch.Value.Team1Score.Value++;
else
currentMatch.Value.Team2Score.Value++;
}
2018-11-08 11:15:22 +00:00
2018-11-10 16:50:09 +00:00
scheduledBarContract?.Cancel();
2018-11-17 06:31:03 +00:00
void expand()
{
2018-11-17 12:27:02 +00:00
chat.Expand();
using (BeginDelayedSequence(300, true))
{
scoreDisplay.FadeIn(100);
2018-11-17 06:31:03 +00:00
SongBar.Expanded = true;
}
2018-11-17 06:31:03 +00:00
}
void contract()
{
SongBar.Expanded = false;
scoreDisplay.FadeOut(100);
2018-11-17 06:31:03 +00:00
using (chat.BeginDelayedSequence(500))
2018-11-17 12:27:02 +00:00
chat.Contract();
2018-11-17 06:31:03 +00:00
}
2018-11-10 16:50:09 +00:00
switch (state)
2018-11-10 16:29:42 +00:00
{
2018-11-10 16:50:09 +00:00
case TourneyState.Idle:
2018-11-17 06:31:03 +00:00
contract();
2018-11-10 16:50:09 +00:00
break;
case TourneyState.Ranking:
2018-11-17 06:31:03 +00:00
scheduledBarContract = Scheduler.AddDelayed(contract, 10000);
2018-11-10 16:50:09 +00:00
break;
default:
2018-11-17 12:27:02 +00:00
chat.Expand();
2018-11-17 06:31:03 +00:00
expand();
2018-11-10 16:50:09 +00:00
break;
2018-11-10 16:29:42 +00:00
}
2018-11-09 07:10:58 +00:00
}
2018-11-06 10:23:03 +00:00
}
}