1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 16:57:25 +08:00
osu-lazer/osu.Game.Tournament/TournamentSceneManager.cs

239 lines
8.9 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.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Platform;
2019-11-08 16:26:24 +08:00
using osu.Framework.Threading;
using osu.Game.Graphics;
2018-11-17 20:27:02 +08:00
using osu.Game.Tournament.Components;
2019-06-18 13:51:48 +08:00
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens;
using osu.Game.Tournament.Screens.Drawings;
2019-06-18 13:51:48 +08:00
using osu.Game.Tournament.Screens.Editors;
2018-11-06 18:23:03 +08:00
using osu.Game.Tournament.Screens.Gameplay;
using osu.Game.Tournament.Screens.Ladder;
using osu.Game.Tournament.Screens.MapPool;
2018-11-11 09:13:17 +08:00
using osu.Game.Tournament.Screens.Schedule;
using osu.Game.Tournament.Screens.Showcase;
using osu.Game.Tournament.Screens.TeamIntro;
2018-11-11 09:39:04 +08:00
using osu.Game.Tournament.Screens.TeamWin;
using osuTK;
using osuTK.Graphics;
2019-06-18 13:51:48 +08:00
namespace osu.Game.Tournament
{
[Cached]
2019-06-14 16:17:47 +08:00
public class TournamentSceneManager : CompositeDrawable
{
private Container screens;
private TourneyVideo video;
2018-11-17 20:27:02 +08:00
[Cached]
2019-06-18 12:44:38 +08:00
private TournamentMatchChatDisplay chat = new TournamentMatchChatDisplay();
2018-11-17 20:27:02 +08:00
private Container chatContainer;
private FillFlowContainer buttons;
2018-11-17 20:27:02 +08:00
2019-06-14 16:17:47 +08:00
public TournamentSceneManager()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(LadderInfo ladder, Storage storage)
{
InternalChildren = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
X = 200,
FillMode = FillMode.Fit,
2018-11-17 20:27:02 +08:00
FillAspectRatio = 16 / 9f,
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Size = new Vector2(0.8f, 1),
//Masking = true,
Children = new Drawable[]
{
video = new TourneyVideo(storage.GetStream("BG Logoless - OWC.m4v"))
{
Loop = true,
RelativeSizeAxes = Axes.Both,
},
screens = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
2019-09-23 03:45:23 +08:00
new SetupScreen(),
new ScheduleScreen(),
new LadderScreen(),
new LadderEditorScreen(),
2019-06-18 14:15:28 +08:00
new TeamEditorScreen(),
2019-06-18 13:44:15 +08:00
new RoundEditorScreen(),
new ShowcaseScreen(),
new MapPoolScreen(),
new TeamIntroScreen(),
new DrawingsScreen(),
new GameplayScreen(),
new TeamWinScreen()
}
},
2018-11-17 20:27:02 +08:00
chatContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Child = chat
},
}
},
2018-11-17 12:39:55 +08:00
new Container
{
RelativeSizeAxes = Axes.Y,
Width = 200,
Children = new Drawable[]
{
new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both,
},
buttons = new FillFlowContainer
2018-11-17 12:39:55 +08:00
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(2),
Padding = new MarginPadding(2),
2018-11-17 12:39:55 +08:00
Children = new Drawable[]
{
new ScreenButton(typeof(SetupScreen)) { Text = "Setup", RequestSelection = SetScreen },
new Separator(),
new ScreenButton(typeof(TeamEditorScreen)) { Text = "Team Editor", RequestSelection = SetScreen },
new ScreenButton(typeof(RoundEditorScreen)) { Text = "Rounds Editor", RequestSelection = SetScreen },
new ScreenButton(typeof(LadderEditorScreen)) { Text = "Bracket Editor", RequestSelection = SetScreen },
new Separator(),
new ScreenButton(typeof(ScheduleScreen)) { Text = "Schedule", RequestSelection = SetScreen },
new ScreenButton(typeof(LadderScreen)) { Text = "Bracket", RequestSelection = SetScreen },
new Separator(),
new ScreenButton(typeof(TeamIntroScreen)) { Text = "TeamIntro", RequestSelection = SetScreen },
new Separator(),
new ScreenButton(typeof(MapPoolScreen)) { Text = "MapPool", RequestSelection = SetScreen },
new ScreenButton(typeof(GameplayScreen)) { Text = "Gameplay", RequestSelection = SetScreen },
new Separator(),
new ScreenButton(typeof(TeamWinScreen)) { Text = "Win", RequestSelection = SetScreen },
new Separator(),
new ScreenButton(typeof(DrawingsScreen)) { Text = "Drawings", RequestSelection = SetScreen },
new ScreenButton(typeof(ShowcaseScreen)) { Text = "Showcase", RequestSelection = SetScreen },
2018-11-17 12:39:55 +08:00
}
},
},
},
};
2019-11-08 16:26:24 +08:00
foreach (var drawable in screens)
drawable.Hide();
SetScreen(typeof(SetupScreen));
}
2019-11-08 16:26:24 +08:00
private float depth;
private Drawable currentScreen;
private ScheduledDelegate scheduledHide;
public void SetScreen(Type screenType)
{
2019-11-08 16:26:24 +08:00
var target = screens.FirstOrDefault(s => s.GetType() == screenType);
if (target == null || currentScreen == target) return;
2019-11-08 16:26:24 +08:00
if (scheduledHide?.Completed == false)
{
2019-11-08 16:26:24 +08:00
scheduledHide.RunTask();
scheduledHide.Cancel(); // see https://github.com/ppy/osu-framework/issues/2967
scheduledHide = null;
}
2018-11-17 20:27:02 +08:00
2019-11-08 16:26:24 +08:00
var lastScreen = currentScreen;
currentScreen = target;
if (currentScreen is IProvideVideo)
{
video.FadeOut(200);
// delay the hide to avoid a double-fade transition.
scheduledHide = Scheduler.AddDelayed(() => lastScreen?.Hide(), TournamentScreen.FADE_DELAY);
}
else
{
lastScreen?.Hide();
video.Show();
}
screens.ChangeChildDepth(currentScreen, depth--);
currentScreen.Show();
switch (currentScreen)
2018-11-17 20:27:02 +08:00
{
case GameplayScreen _:
case MapPoolScreen _:
2019-11-08 16:26:24 +08:00
chatContainer.FadeIn(TournamentScreen.FADE_DELAY);
2018-11-17 20:27:02 +08:00
break;
2018-11-17 20:27:02 +08:00
default:
2019-11-08 16:26:24 +08:00
chatContainer.FadeOut(TournamentScreen.FADE_DELAY);
2018-11-17 20:27:02 +08:00
break;
}
foreach (var s in buttons.OfType<ScreenButton>())
s.IsSelected = screenType == s.Type;
}
private class Separator : CompositeDrawable
{
public Separator()
{
RelativeSizeAxes = Axes.X;
Height = 20;
}
}
private class ScreenButton : TourneyButton
{
public readonly Type Type;
public ScreenButton(Type type)
{
Type = type;
BackgroundColour = OsuColour.Gray(0.2f);
Action = () => RequestSelection(type);
RelativeSizeAxes = Axes.X;
}
private bool isSelected;
public Action<Type> RequestSelection;
public bool IsSelected
{
get => isSelected;
set
{
if (value == isSelected)
return;
isSelected = value;
BackgroundColour = isSelected ? Color4.SkyBlue : OsuColour.Gray(0.2f);
SpriteText.Colour = isSelected ? Color4.Black : Color4.White;
}
}
}
}
}