Merge pull request #6211 from peppy/tournament-setup

Add an onboarding screen for tournament client
This commit is contained in:
Dan Balasescu 2019-09-24 17:44:45 +09:00 committed by GitHub
commit 79b64bdaa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 267 additions and 87 deletions

View File

@ -0,0 +1,17 @@
// 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 osu.Framework.Allocation;
using osu.Game.Tournament.Screens;
namespace osu.Game.Tournament.Tests.Screens
{
public class TestSceneSetupScreen : TournamentTestScene
{
[BackgroundDependencyLoader]
private void load()
{
Add(new SetupScreen());
}
}
}

View File

@ -9,6 +9,7 @@ using osu.Framework.Allocation;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Platform.Windows; using osu.Framework.Platform.Windows;
using osu.Framework.Threading;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
using osu.Game.Online.API; using osu.Game.Online.API;
@ -26,103 +27,120 @@ namespace osu.Game.Tournament.IPC
[Resolved] [Resolved]
protected RulesetStore Rulesets { get; private set; } protected RulesetStore Rulesets { get; private set; }
[Resolved]
private GameHost host { get; set; }
[Resolved]
private LadderInfo ladder { get; set; }
private int lastBeatmapId; private int lastBeatmapId;
private ScheduledDelegate scheduled;
public Storage Storage { get; private set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(LadderInfo ladder, GameHost host) private void load()
{ {
StableStorage stable; LocateStableStorage();
}
public Storage LocateStableStorage()
{
scheduled?.Cancel();
Storage = null;
try try
{ {
stable = new StableStorage(host as DesktopGameHost); Storage = new StableStorage(host as DesktopGameHost);
const string file_ipc_filename = "ipc.txt";
const string file_ipc_state_filename = "ipc-state.txt";
const string file_ipc_scores_filename = "ipc-scores.txt";
const string file_ipc_channel_filename = "ipc-channel.txt";
if (Storage.Exists(file_ipc_filename))
scheduled = Scheduler.AddDelayed(delegate
{
try
{
using (var stream = Storage.GetStream(file_ipc_filename))
using (var sr = new StreamReader(stream))
{
var beatmapId = int.Parse(sr.ReadLine());
var mods = int.Parse(sr.ReadLine());
if (lastBeatmapId != beatmapId)
{
lastBeatmapId = beatmapId;
var existing = ladder.CurrentMatch.Value?.Round.Value?.Beatmaps.FirstOrDefault(b => b.ID == beatmapId && b.BeatmapInfo != null);
if (existing != null)
Beatmap.Value = existing.BeatmapInfo;
else
{
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId });
req.Success += b => Beatmap.Value = b.ToBeatmap(Rulesets);
API.Queue(req);
}
}
Mods.Value = (LegacyMods)mods;
}
}
catch
{
// file might be in use.
}
try
{
using (var stream = Storage.GetStream(file_ipc_channel_filename))
using (var sr = new StreamReader(stream))
{
ChatChannel.Value = sr.ReadLine();
}
}
catch (Exception)
{
// file might be in use.
}
try
{
using (var stream = Storage.GetStream(file_ipc_state_filename))
using (var sr = new StreamReader(stream))
{
State.Value = (TourneyState)Enum.Parse(typeof(TourneyState), sr.ReadLine());
}
}
catch (Exception)
{
// file might be in use.
}
try
{
using (var stream = Storage.GetStream(file_ipc_scores_filename))
using (var sr = new StreamReader(stream))
{
Score1.Value = int.Parse(sr.ReadLine());
Score2.Value = int.Parse(sr.ReadLine());
}
}
catch (Exception)
{
// file might be in use.
}
}, 250, true);
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Error(e, "Stable installation could not be found; disabling file based IPC"); Logger.Error(e, "Stable installation could not be found; disabling file based IPC");
return;
} }
const string file_ipc_filename = "ipc.txt"; return Storage;
const string file_ipc_state_filename = "ipc-state.txt";
const string file_ipc_scores_filename = "ipc-scores.txt";
const string file_ipc_channel_filename = "ipc-channel.txt";
if (stable.Exists(file_ipc_filename))
Scheduler.AddDelayed(delegate
{
try
{
using (var stream = stable.GetStream(file_ipc_filename))
using (var sr = new StreamReader(stream))
{
var beatmapId = int.Parse(sr.ReadLine());
var mods = int.Parse(sr.ReadLine());
if (lastBeatmapId != beatmapId)
{
lastBeatmapId = beatmapId;
var existing = ladder.CurrentMatch.Value?.Round.Value?.Beatmaps.FirstOrDefault(b => b.ID == beatmapId && b.BeatmapInfo != null);
if (existing != null)
Beatmap.Value = existing.BeatmapInfo;
else
{
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId });
req.Success += b => Beatmap.Value = b.ToBeatmap(Rulesets);
API.Queue(req);
}
}
Mods.Value = (LegacyMods)mods;
}
}
catch
{
// file might be in use.
}
try
{
using (var stream = stable.GetStream(file_ipc_channel_filename))
using (var sr = new StreamReader(stream))
{
ChatChannel.Value = sr.ReadLine();
}
}
catch (Exception)
{
// file might be in use.
}
try
{
using (var stream = stable.GetStream(file_ipc_state_filename))
using (var sr = new StreamReader(stream))
{
State.Value = (TourneyState)Enum.Parse(typeof(TourneyState), sr.ReadLine());
}
}
catch (Exception)
{
// file might be in use.
}
try
{
using (var stream = stable.GetStream(file_ipc_scores_filename))
using (var sr = new StreamReader(stream))
{
Score1.Value = int.Parse(sr.ReadLine());
Score2.Value = int.Parse(sr.ReadLine());
}
}
catch (Exception)
{
// file might be in use.
}
}, 250, true);
} }
/// <summary> /// <summary>

View File

@ -0,0 +1,142 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Screens.Edit.Setup.Components.LabelledComponents;
using osu.Game.Tournament.IPC;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tournament.Screens
{
public class SetupScreen : TournamentScreen, IProvideVideo
{
private FillFlowContainer fillFlow;
private LoginOverlay loginOverlay;
[Resolved]
private MatchIPCInfo ipc { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
[BackgroundDependencyLoader]
private void load()
{
InternalChild = fillFlow = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Padding = new MarginPadding(10),
Spacing = new Vector2(10),
};
api.LocalUser.BindValueChanged(_ => Schedule(reload));
reload();
}
private void reload()
{
var fileBasedIpc = ipc as FileBasedIPC;
fillFlow.Children = new Drawable[]
{
new ActionableInfo
{
Label = "Current IPC source",
ButtonText = "Refresh",
Action = () =>
{
fileBasedIpc?.LocateStableStorage();
reload();
},
Value = fileBasedIpc?.Storage?.GetFullPath(string.Empty) ?? "Not found",
Failing = fileBasedIpc?.Storage == null,
Description = "The osu!stable installation which is currently being used as a data source. If a source is not found, make sure you have created an empty ipc.txt in your stable cutting-edge installation, and that it is registered as the default osu! install."
},
new ActionableInfo
{
Label = "Current User",
ButtonText = "Change Login",
Action = () =>
{
api.Logout();
if (loginOverlay == null)
{
AddInternal(loginOverlay = new LoginOverlay
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
});
}
loginOverlay.State.Value = Visibility.Visible;
},
Value = api?.LocalUser.Value.Username,
Failing = api?.IsLoggedIn != true,
Description = "In order to access the API and display metadata, a login is required."
}
};
}
private class ActionableInfo : LabelledComponent
{
private OsuButton button;
public ActionableInfo()
: base(true)
{
}
public string ButtonText
{
set => button.Text = value;
}
public string Value
{
set => valueText.Text = value;
}
public bool Failing
{
set => valueText.Colour = value ? Color4.Red : Color4.White;
}
public Action Action;
private OsuSpriteText valueText;
protected override Drawable CreateComponent() => new Container
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{
valueText = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
button = new TriangleButton
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Size = new Vector2(100, 30),
Action = () => Action?.Invoke()
},
}
};
}
}
}

View File

@ -69,6 +69,7 @@ namespace osu.Game.Tournament
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
new SetupScreen(),
new ScheduleScreen(), new ScheduleScreen(),
new LadderScreen(), new LadderScreen(),
new LadderEditorScreen(), new LadderEditorScreen(),
@ -106,6 +107,8 @@ namespace osu.Game.Tournament
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Children = new Drawable[] Children = new Drawable[]
{ {
new OsuButton { RelativeSizeAxes = Axes.X, Text = "Setup", Action = () => SetScreen(typeof(SetupScreen)) },
new Container { RelativeSizeAxes = Axes.X, Height = 50 },
new OsuButton { RelativeSizeAxes = Axes.X, Text = "Team Editor", Action = () => SetScreen(typeof(TeamEditorScreen)) }, new OsuButton { RelativeSizeAxes = Axes.X, Text = "Team Editor", Action = () => SetScreen(typeof(TeamEditorScreen)) },
new OsuButton { RelativeSizeAxes = Axes.X, Text = "Rounds Editor", Action = () => SetScreen(typeof(RoundEditorScreen)) }, new OsuButton { RelativeSizeAxes = Axes.X, Text = "Rounds Editor", Action = () => SetScreen(typeof(RoundEditorScreen)) },
new OsuButton { RelativeSizeAxes = Axes.X, Text = "Bracket Editor", Action = () => SetScreen(typeof(LadderEditorScreen)) }, new OsuButton { RelativeSizeAxes = Axes.X, Text = "Bracket Editor", Action = () => SetScreen(typeof(LadderEditorScreen)) },
@ -127,7 +130,7 @@ namespace osu.Game.Tournament
}, },
}; };
SetScreen(typeof(ScheduleScreen)); SetScreen(typeof(SetupScreen));
} }
public void SetScreen(Type screenType) public void SetScreen(Type screenType)

View File

@ -67,7 +67,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
api?.Register(this); api?.Register(this);
} }
public void APIStateChanged(IAPIProvider api, APIState state) public void APIStateChanged(IAPIProvider api, APIState state) => Schedule(() =>
{ {
form = null; form = null;
@ -184,7 +184,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
} }
if (form != null) GetContainingInputManager()?.ChangeFocus(form); if (form != null) GetContainingInputManager()?.ChangeFocus(form);
} });
public override bool AcceptsFocus => true; public override bool AcceptsFocus => true;