2018-05-16 08:14:10 +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-12-11 16:32:01 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-12-27 19:06:07 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2018-05-16 08:14:10 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-12-27 19:06:07 +08:00
|
|
|
|
using osu.Framework.Logging;
|
2018-05-16 08:14:10 +08:00
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-12-19 15:56:51 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-12-27 19:06:07 +08:00
|
|
|
|
using osu.Game.Input;
|
2018-12-26 15:46:50 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2018-12-19 15:56:51 +08:00
|
|
|
|
using osu.Game.Online.Multiplayer;
|
|
|
|
|
using osu.Game.Overlays.BeatmapSet.Buttons;
|
2018-05-28 11:28:11 +08:00
|
|
|
|
using osu.Game.Screens.Menu;
|
2018-12-10 18:20:41 +08:00
|
|
|
|
using osu.Game.Screens.Multi.Lounge;
|
2018-12-18 16:07:47 +08:00
|
|
|
|
using osu.Game.Screens.Multi.Match;
|
2018-12-19 15:56:51 +08:00
|
|
|
|
using osuTK;
|
2018-05-16 08:14:10 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multi
|
|
|
|
|
{
|
2018-12-11 16:32:01 +08:00
|
|
|
|
[Cached]
|
2018-12-27 16:12:47 +08:00
|
|
|
|
public class Multiplayer : OsuScreen, IOnlineComponent
|
2018-05-16 08:14:10 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly MultiplayerWaveContainer waves;
|
|
|
|
|
|
2018-12-27 19:06:07 +08:00
|
|
|
|
public override bool AllowBeatmapRulesetChange => currentSubScreen?.AllowBeatmapRulesetChange ?? base.AllowBeatmapRulesetChange;
|
2018-12-14 16:35:18 +08:00
|
|
|
|
|
2018-12-19 15:56:51 +08:00
|
|
|
|
private readonly OsuButton createButton;
|
2018-12-26 19:05:57 +08:00
|
|
|
|
private readonly LoungeSubScreen loungeSubScreen;
|
2018-12-19 15:56:51 +08:00
|
|
|
|
|
2018-12-27 19:06:07 +08:00
|
|
|
|
private OsuScreen currentSubScreen;
|
2018-12-14 16:35:18 +08:00
|
|
|
|
|
2018-12-25 10:45:50 +08:00
|
|
|
|
[Cached(Type = typeof(IRoomManager))]
|
2018-12-22 11:45:36 +08:00
|
|
|
|
private RoomManager roomManager;
|
|
|
|
|
|
2018-12-26 15:46:50 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private APIAccess api { get; set; }
|
|
|
|
|
|
2018-05-16 08:14:10 +08:00
|
|
|
|
public Multiplayer()
|
|
|
|
|
{
|
2018-12-11 16:32:01 +08:00
|
|
|
|
Child = waves = new MultiplayerWaveContainer
|
2018-05-16 08:14:10 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-11 16:32:01 +08:00
|
|
|
|
waves.AddRange(new Drawable[]
|
2018-05-16 08:14:10 +08:00
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = OsuColour.FromHex(@"3e3a44"),
|
|
|
|
|
},
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ColourLight = OsuColour.FromHex(@"3c3842"),
|
|
|
|
|
ColourDark = OsuColour.FromHex(@"393540"),
|
|
|
|
|
TriangleScale = 5,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Top = Header.HEIGHT },
|
2018-12-26 19:05:57 +08:00
|
|
|
|
Child = loungeSubScreen = new LoungeSubScreen(Push),
|
2018-05-16 08:14:10 +08:00
|
|
|
|
},
|
2018-12-26 19:05:57 +08:00
|
|
|
|
new Header(loungeSubScreen),
|
2018-12-19 15:56:51 +08:00
|
|
|
|
createButton = new HeaderButton
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Size = new Vector2(150, Header.HEIGHT - 20),
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 10,
|
|
|
|
|
Right = 10,
|
|
|
|
|
},
|
|
|
|
|
Text = "Create room",
|
2018-12-26 19:21:30 +08:00
|
|
|
|
Action = () => loungeSubScreen.Push(new Room
|
2018-12-26 15:46:50 +08:00
|
|
|
|
{
|
|
|
|
|
Name = { Value = $"{api.LocalUser}'s awesome room" }
|
|
|
|
|
}),
|
2018-12-22 11:45:36 +08:00
|
|
|
|
},
|
|
|
|
|
roomManager = new RoomManager()
|
2018-12-11 16:32:01 +08:00
|
|
|
|
});
|
2018-12-26 19:05:57 +08:00
|
|
|
|
|
|
|
|
|
screenAdded(loungeSubScreen);
|
|
|
|
|
loungeSubScreen.Exited += _ => Exit();
|
2018-05-16 08:14:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 19:06:07 +08:00
|
|
|
|
private readonly IBindable<bool> isIdle = new BindableBool();
|
|
|
|
|
|
2018-12-27 19:17:27 +08:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2018-12-27 19:06:07 +08:00
|
|
|
|
private void load(IdleTracker idleTracker)
|
2018-12-27 16:12:47 +08:00
|
|
|
|
{
|
|
|
|
|
api.Register(this);
|
2018-12-27 19:17:27 +08:00
|
|
|
|
|
|
|
|
|
if (idleTracker != null)
|
|
|
|
|
isIdle.BindTo(idleTracker.IsIdle);
|
2018-12-27 19:06:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
isIdle.BindValueChanged(updatePollingRate, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updatePollingRate(bool idle)
|
|
|
|
|
{
|
|
|
|
|
roomManager.TimeBetweenPolls = !IsCurrentScreen || !(currentSubScreen is LoungeSubScreen) ? 0 : (idle ? 120000 : 15000);
|
|
|
|
|
Logger.Log($"Polling adjusted to {roomManager.TimeBetweenPolls}");
|
2018-12-27 16:12:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void APIStateChanged(APIAccess api, APIState state)
|
|
|
|
|
{
|
|
|
|
|
if (state != APIState.Online)
|
|
|
|
|
forcefullyExit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void forcefullyExit()
|
|
|
|
|
{
|
|
|
|
|
// This is temporary since we don't currently have a way to force screens to be exited
|
|
|
|
|
if (IsCurrentScreen)
|
|
|
|
|
Exit();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MakeCurrent();
|
|
|
|
|
Schedule(forcefullyExit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 08:14:10 +08:00
|
|
|
|
protected override void OnEntering(Screen last)
|
|
|
|
|
{
|
2018-12-26 19:05:57 +08:00
|
|
|
|
Content.FadeIn();
|
|
|
|
|
|
2018-05-16 08:14:10 +08:00
|
|
|
|
base.OnEntering(last);
|
|
|
|
|
waves.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnExiting(Screen next)
|
|
|
|
|
{
|
|
|
|
|
waves.Hide();
|
2018-12-18 16:07:47 +08:00
|
|
|
|
|
2018-12-26 19:05:57 +08:00
|
|
|
|
Content.Delay(WaveContainer.DISAPPEAR_DURATION).FadeOut();
|
|
|
|
|
|
2018-12-27 19:06:07 +08:00
|
|
|
|
cancelLooping();
|
2018-12-26 19:05:57 +08:00
|
|
|
|
loungeSubScreen.MakeCurrent();
|
2018-12-27 19:06:07 +08:00
|
|
|
|
updatePollingRate(isIdle.Value);
|
2018-12-20 19:58:34 +08:00
|
|
|
|
|
2018-05-16 08:14:10 +08:00
|
|
|
|
return base.OnExiting(next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnResuming(Screen last)
|
|
|
|
|
{
|
|
|
|
|
base.OnResuming(last);
|
2018-12-11 16:32:01 +08:00
|
|
|
|
|
|
|
|
|
Content.FadeIn(250);
|
|
|
|
|
Content.ScaleTo(1, 250, Easing.OutSine);
|
2018-12-27 19:06:07 +08:00
|
|
|
|
|
|
|
|
|
updatePollingRate(isIdle.Value);
|
2018-05-16 08:14:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnSuspending(Screen next)
|
|
|
|
|
{
|
2018-12-11 16:32:01 +08:00
|
|
|
|
Content.ScaleTo(1.1f, 250, Easing.InSine);
|
|
|
|
|
Content.FadeOut(250);
|
|
|
|
|
|
2018-12-26 21:37:09 +08:00
|
|
|
|
cancelLooping();
|
2018-12-27 19:06:07 +08:00
|
|
|
|
roomManager.TimeBetweenPolls = 0;
|
2018-12-26 21:37:09 +08:00
|
|
|
|
|
2018-05-16 08:14:10 +08:00
|
|
|
|
base.OnSuspending(next);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 21:37:09 +08:00
|
|
|
|
private void cancelLooping()
|
|
|
|
|
{
|
|
|
|
|
var track = Beatmap.Value.Track;
|
|
|
|
|
if (track != null)
|
|
|
|
|
track.Looping = false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-28 11:28:11 +08:00
|
|
|
|
protected override void LogoExiting(OsuLogo logo)
|
|
|
|
|
{
|
|
|
|
|
// the wave overlay transition takes longer than expected to run.
|
|
|
|
|
logo.Delay(WaveContainer.DISAPPEAR_DURATION / 2).FadeOut();
|
|
|
|
|
base.LogoExiting(logo);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-18 16:07:47 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2018-12-26 21:37:09 +08:00
|
|
|
|
if (!IsCurrentScreen) return;
|
|
|
|
|
|
2018-12-27 19:06:07 +08:00
|
|
|
|
if (currentSubScreen is MatchSubScreen)
|
2018-12-18 16:07:47 +08:00
|
|
|
|
{
|
|
|
|
|
var track = Beatmap.Value.Track;
|
|
|
|
|
if (track != null)
|
|
|
|
|
{
|
|
|
|
|
track.Looping = true;
|
|
|
|
|
|
|
|
|
|
if (!track.IsRunning)
|
|
|
|
|
{
|
|
|
|
|
Game.Audio.AddItemToList(track);
|
|
|
|
|
track.Seek(Beatmap.Value.Metadata.PreviewTime);
|
|
|
|
|
track.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-19 15:56:51 +08:00
|
|
|
|
|
|
|
|
|
createButton.Hide();
|
2018-12-18 16:07:47 +08:00
|
|
|
|
}
|
2018-12-27 19:06:07 +08:00
|
|
|
|
else if (currentSubScreen is LoungeSubScreen)
|
2018-12-19 15:56:51 +08:00
|
|
|
|
createButton.Show();
|
2018-12-18 16:07:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-14 16:35:18 +08:00
|
|
|
|
private void screenAdded(Screen newScreen)
|
|
|
|
|
{
|
2018-12-27 19:06:07 +08:00
|
|
|
|
currentSubScreen = (OsuScreen)newScreen;
|
|
|
|
|
updatePollingRate(isIdle.Value);
|
2018-12-14 16:35:18 +08:00
|
|
|
|
|
|
|
|
|
newScreen.ModePushed += screenAdded;
|
|
|
|
|
newScreen.Exited += screenRemoved;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void screenRemoved(Screen newScreen)
|
|
|
|
|
{
|
2018-12-27 19:06:07 +08:00
|
|
|
|
if (currentSubScreen is MatchSubScreen)
|
2018-12-26 21:37:09 +08:00
|
|
|
|
cancelLooping();
|
2018-12-18 16:07:47 +08:00
|
|
|
|
|
2018-12-27 19:06:07 +08:00
|
|
|
|
currentSubScreen = (OsuScreen)newScreen;
|
|
|
|
|
updatePollingRate(isIdle.Value);
|
2018-12-14 16:35:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 16:12:47 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
api?.Unregister(this);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 08:14:10 +08:00
|
|
|
|
private class MultiplayerWaveContainer : WaveContainer
|
|
|
|
|
{
|
|
|
|
|
protected override bool StartHidden => true;
|
|
|
|
|
|
|
|
|
|
public MultiplayerWaveContainer()
|
|
|
|
|
{
|
|
|
|
|
FirstWaveColour = OsuColour.FromHex(@"654d8c");
|
|
|
|
|
SecondWaveColour = OsuColour.FromHex(@"554075");
|
|
|
|
|
ThirdWaveColour = OsuColour.FromHex(@"44325e");
|
|
|
|
|
FourthWaveColour = OsuColour.FromHex(@"392850");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|