diff --git a/osu.Game.Tournament.Tests/TestCaseGameplay.cs b/osu.Game.Tournament.Tests/TestCaseGameplay.cs new file mode 100644 index 0000000000..eefcd79661 --- /dev/null +++ b/osu.Game.Tournament.Tests/TestCaseGameplay.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Game.Tests.Visual; +using osu.Game.Tournament.Screens.Gameplay; + +namespace osu.Game.Tournament.Tests +{ + public class TestCaseGameplay : OsuTestCase + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(GameplayScreen) + }; + + [BackgroundDependencyLoader] + private void load() + { + Add(new GameplayScreen()); + } + } +} diff --git a/osu.Game.Tournament.Tests/TestCaseShowcase.cs b/osu.Game.Tournament.Tests/TestCaseShowcase.cs index 66183683d1..dcd4b6aec7 100644 --- a/osu.Game.Tournament.Tests/TestCaseShowcase.cs +++ b/osu.Game.Tournament.Tests/TestCaseShowcase.cs @@ -1,6 +1,8 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using System.Collections.Generic; using osu.Framework.Allocation; using osu.Game.Tests.Visual; using osu.Game.Tournament.Screens.Showcase; @@ -9,6 +11,11 @@ namespace osu.Game.Tournament.Tests { public class TestCaseShowcase : OsuTestCase { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(ShowcaseScreen) + }; + [BackgroundDependencyLoader] private void load() { diff --git a/osu.Game.Tournament/Components/SongBar.cs b/osu.Game.Tournament/Components/SongBar.cs new file mode 100644 index 0000000000..880b80edf8 --- /dev/null +++ b/osu.Game.Tournament/Components/SongBar.cs @@ -0,0 +1,172 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Legacy; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Screens.Menu; +using OpenTK; + +namespace osu.Game.Tournament.Components +{ + public class SongBar : CompositeDrawable + { + private BeatmapInfo beatmap; + + public BeatmapInfo Beatmap + { + get => beatmap; + set + { + if (beatmap == value) + return; + + beatmap = value; + update(); + } + } + + private LegacyMods mods; + + public LegacyMods Mods + { + get => mods; + set + { + mods = value; + update(); + } + } + + private Container panelContents; + + [BackgroundDependencyLoader] + private void load() + { + RelativeSizeAxes = Axes.Both; + + InternalChildren = new Drawable[] + { + new Container + { + Masking = true, + RelativeSizeAxes = Axes.X, + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + Y = -10, + Width = 0.95f, + Height = TournamentBeatmapPanel.HEIGHT, + CornerRadius = TournamentBeatmapPanel.HEIGHT / 2, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = OsuColour.Gray(0.93f), + }, + new Container + { + Masking = true, + CornerRadius = TournamentBeatmapPanel.HEIGHT / 2, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Width = 0.7f, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = OsuColour.Gray(0.86f), + }, + panelContents = new Container + { + RelativeSizeAxes = Axes.Both, + } + } + }, + new OsuLogo + { + Triangles = false, + Colour = OsuColour.Gray(0.33f), + Scale = new Vector2(0.08f), + Margin = new MarginPadding(50), + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + } + } + } + }; + } + + private void update() + { + if (beatmap == null) + { + panelContents.Clear(); + return; + } + + var bpm = beatmap.BeatmapSet.OnlineInfo.BPM; + var length = beatmap.OnlineInfo.Length; + string extra = ""; + + var ar = beatmap.BaseDifficulty.ApproachRate; + if ((mods & LegacyMods.HardRock) > 0) extra = "*"; + + if ((mods & LegacyMods.DoubleTime) > 0) + { + //ar *= 1.5f; + bpm *= 1.5f; + length /= 1.5f; + extra = "*"; + } + + panelContents.Children = new Drawable[] + { + new OsuSpriteText + { + Text = $"Length {length}s", + Margin = new MarginPadding { Horizontal = 15, Vertical = 5 }, + Colour = OsuColour.Gray(0.33f), + Anchor = Anchor.TopLeft, + Origin = Anchor.TopLeft, + }, + new OsuSpriteText + { + Text = $"BPM {bpm:0.#}", + Margin = new MarginPadding { Horizontal = 15, Vertical = 5 }, + Colour = OsuColour.Gray(0.33f), + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft + }, + new OsuSpriteText + { + Text = $"AR {ar:0.#}{extra}", + Margin = new MarginPadding { Horizontal = 15, Vertical = 5 }, + Colour = OsuColour.Gray(0.33f), + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight + }, + new OsuSpriteText + { + Text = $"Star Rating {beatmap.StarDifficulty:0.#}{extra}", + Margin = new MarginPadding { Horizontal = 15, Vertical = 5 }, + Colour = OsuColour.Gray(0.33f), + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight + }, + new TournamentBeatmapPanel(beatmap) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre + } + }; + } + } +} diff --git a/osu.Game.Tournament/Screens/BeatmapInfoScreen.cs b/osu.Game.Tournament/Screens/BeatmapInfoScreen.cs new file mode 100644 index 0000000000..18ba947582 --- /dev/null +++ b/osu.Game.Tournament/Screens/BeatmapInfoScreen.cs @@ -0,0 +1,127 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.IO; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Platform.Windows; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Legacy; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Rulesets; +using osu.Game.Screens; +using osu.Game.Tournament.Components; + +namespace osu.Game.Tournament.Screens +{ + public abstract class BeatmapInfoScreen : OsuScreen + { + [Resolved] + protected APIAccess API { get; private set; } + + [Resolved] + protected RulesetStore Rulesets { get; private set; } + + private int lastBeatmapId; + private int lastMods; + + protected readonly SongBar SongBar; + + protected BeatmapInfoScreen() + { + Add(SongBar = new SongBar + { + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre + }); + } + + [BackgroundDependencyLoader] + private void load() + { + var stable = new StableStorage(); + + const string file_ipc_filename = "ipc.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) + return; + + lastMods = mods; + lastBeatmapId = beatmapId; + + var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId }); + req.Success += success; + API.Queue(req); + } + } + catch + { + // file might be in use. + } + }, 250, true); + } + + private void success(APIBeatmap apiBeatmap) + { + SongBar.FadeInFromZero(300, Easing.OutQuint); + SongBar.Mods = (LegacyMods)lastMods; + SongBar.Beatmap = apiBeatmap.ToBeatmap(Rulesets); + } + + /// + /// A method of accessing an osu-stable install in a controlled fashion. + /// + private class StableStorage : WindowsStorage + { + protected override string LocateBasePath() + { + bool checkExists(string p) + { + return Directory.Exists(Path.Combine(p, "Songs")); + } + + string stableInstallPath; + + try + { + stableInstallPath = "E:\\osu!mappool"; + + if (checkExists(stableInstallPath)) + return stableInstallPath; + } + catch + { + } + + stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!"); + if (checkExists(stableInstallPath)) + return stableInstallPath; + + stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu"); + if (checkExists(stableInstallPath)) + return stableInstallPath; + + return null; + } + + public StableStorage() + : base(string.Empty, null) + { + } + } + } +} diff --git a/osu.Game.Tournament/Screens/Gameplay/GameplayScreen.cs b/osu.Game.Tournament/Screens/Gameplay/GameplayScreen.cs new file mode 100644 index 0000000000..2a9754b066 --- /dev/null +++ b/osu.Game.Tournament/Screens/Gameplay/GameplayScreen.cs @@ -0,0 +1,10 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Tournament.Screens.Gameplay +{ + public class GameplayScreen : BeatmapInfoScreen + { + + } +} diff --git a/osu.Game.Tournament/Screens/Showcase/ShowcaseScreen.cs b/osu.Game.Tournament/Screens/Showcase/ShowcaseScreen.cs index 6c0eac1c23..ce458413a5 100644 --- a/osu.Game.Tournament/Screens/Showcase/ShowcaseScreen.cs +++ b/osu.Game.Tournament/Screens/Showcase/ShowcaseScreen.cs @@ -1,292 +1,9 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using System.IO; -using osu.Framework.Allocation; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Platform.Windows; -using osu.Game.Beatmaps; -using osu.Game.Beatmaps.Legacy; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; -using osu.Game.Online.API; -using osu.Game.Online.API.Requests; -using osu.Game.Online.API.Requests.Responses; -using osu.Game.Rulesets; -using osu.Game.Screens; -using osu.Game.Screens.Menu; -using osu.Game.Tournament.Components; -using OpenTK; - namespace osu.Game.Tournament.Screens.Showcase { - public class SongBar : CompositeDrawable + public class ShowcaseScreen : BeatmapInfoScreen { - private BeatmapInfo beatmap; - - public BeatmapInfo Beatmap - { - get { return beatmap; } - set - { - if (beatmap == value) - return; - - beatmap = value; - update(); - } - } - - private LegacyMods mods; - - public LegacyMods Mods - { - get { return mods; } - set - { - mods = value; - update(); - } - } - - private Container panelContents; - - [BackgroundDependencyLoader] - private void load() - { - RelativeSizeAxes = Axes.Both; - - InternalChildren = new Drawable[] - { - new Container - { - Masking = true, - RelativeSizeAxes = Axes.X, - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre, - Y = -10, - Width = 0.95f, - Height = TournamentBeatmapPanel.HEIGHT, - CornerRadius = TournamentBeatmapPanel.HEIGHT / 2, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = OsuColour.Gray(0.93f), - }, - new Container - { - Masking = true, - CornerRadius = TournamentBeatmapPanel.HEIGHT / 2, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Width = 0.7f, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = OsuColour.Gray(0.86f), - }, - panelContents = new Container - { - RelativeSizeAxes = Axes.Both, - } - } - }, - new OsuLogo - { - Triangles = false, - Colour = OsuColour.Gray(0.33f), - Scale = new Vector2(0.08f), - Margin = new MarginPadding(50), - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - } - } - } - }; - } - - private void update() - { - if (beatmap == null) - { - panelContents.Clear(); - return; - } - - var bpm = beatmap.BeatmapSet.OnlineInfo.BPM; - var length = beatmap.OnlineInfo.Length; - string extra = ""; - - var ar = beatmap.BaseDifficulty.ApproachRate; - if ((mods & LegacyMods.HardRock) > 0) - { - //ar *= 1.4f; - extra = "*"; - } - - if ((mods & LegacyMods.DoubleTime) > 0) - { - //ar *= 1.5f; - bpm *= 1.5f; - length /= 1.5f; - extra = "*"; - } - - panelContents.Children = new Drawable[] - { - new OsuSpriteText - { - Text = $"Length {length}s", - Margin = new MarginPadding { Horizontal = 15, Vertical = 5 }, - Colour = OsuColour.Gray(0.33f), - Anchor = Anchor.TopLeft, - Origin = Anchor.TopLeft, - }, - new OsuSpriteText - { - Text = $"BPM {bpm:0.#}", - Margin = new MarginPadding { Horizontal = 15, Vertical = 5 }, - Colour = OsuColour.Gray(0.33f), - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft - }, - new OsuSpriteText - { - Text = $"AR {ar:0.#}{extra}", - Margin = new MarginPadding { Horizontal = 15, Vertical = 5 }, - Colour = OsuColour.Gray(0.33f), - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight - }, - new OsuSpriteText - { - Text = $"Star Rating {beatmap.StarDifficulty:0.#}{extra}", - Margin = new MarginPadding { Horizontal = 15, Vertical = 5 }, - Colour = OsuColour.Gray(0.33f), - Anchor = Anchor.BottomRight, - Origin = Anchor.BottomRight - }, - new TournamentBeatmapPanel(beatmap) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre - } - }; - } - } - - public class ShowcaseScreen : OsuScreen - { - [Resolved] - private APIAccess api { get; set; } - - [Resolved] - private RulesetStore rulesets { get; set; } - - private int lastBeatmapId; - private int lastMods; - - private readonly SongBar songBar; - - public ShowcaseScreen() - { - Add(songBar = new SongBar - { - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre - }); - } - - [BackgroundDependencyLoader] - private void load() - { - var stable = new StableStorage(); - - const string file_ipc_filename = "ipc.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) - return; - - lastMods = mods; - lastBeatmapId = beatmapId; - - var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId }); - req.Success += success; - api.Queue(req); - } - } - catch - { - // file might be in use. - } - }, 250, true); - } - } - - private void success(APIBeatmap apiBeatmap) - { - songBar.FadeInFromZero(300, Easing.OutQuint); - songBar.Mods = (LegacyMods)lastMods; - songBar.Beatmap = apiBeatmap.ToBeatmap(rulesets); - } - - /// - /// A method of accessing an osu-stable install in a controlled fashion. - /// - private class StableStorage : WindowsStorage - { - protected override string LocateBasePath() - { - bool checkExists(string p) => Directory.Exists(Path.Combine(p, "Songs")); - - string stableInstallPath; - - try - { - stableInstallPath = "E:\\osu!mappool"; - - if (checkExists(stableInstallPath)) - return stableInstallPath; - } - catch - { - } - - stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!"); - if (checkExists(stableInstallPath)) - return stableInstallPath; - - stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu"); - if (checkExists(stableInstallPath)) - return stableInstallPath; - - return null; - } - - public StableStorage() - : base(string.Empty, null) - { - } - } } } diff --git a/osu.Game.Tournament/Screens/TournamentSceneManager.cs b/osu.Game.Tournament/Screens/TournamentSceneManager.cs index 82f17a85c4..87223c04a6 100644 --- a/osu.Game.Tournament/Screens/TournamentSceneManager.cs +++ b/osu.Game.Tournament/Screens/TournamentSceneManager.cs @@ -11,6 +11,7 @@ using osu.Framework.Platform; using osu.Game.Graphics.UserInterface; using osu.Game.Screens; using osu.Game.Tournament.Screens.Drawings; +using osu.Game.Tournament.Screens.Gameplay; using osu.Game.Tournament.Screens.Ladder; using osu.Game.Tournament.Screens.Ladder.Components; using osu.Game.Tournament.Screens.MapPool; @@ -25,6 +26,7 @@ namespace osu.Game.Tournament.Screens { private LadderManager bracket; private MapPoolScreen mapPool; + private GameplayScreen gameplay; private TeamIntroScreen teamIntro; private DrawingsScreen drawings; private Container screens; @@ -54,9 +56,12 @@ namespace osu.Game.Tournament.Screens { new OsuButton { RelativeSizeAxes = Axes.X, Text = "Drawings", Action = () => setScreen(drawings) }, new OsuButton { RelativeSizeAxes = Axes.X, Text = "Showcase", Action = () => setScreen(showcase) }, + new Container { RelativeSizeAxes = Axes.X, Height = 50 }, + new OsuButton { RelativeSizeAxes = Axes.X, Text = "Bracket", Action = () => setScreen(bracket) }, new OsuButton { RelativeSizeAxes = Axes.X, Text = "TeamIntro", Action = () => setScreen(teamIntro) }, new OsuButton { RelativeSizeAxes = Axes.X, Text = "MapPool", Action = () => setScreen(mapPool) }, - new OsuButton { RelativeSizeAxes = Axes.X, Text = "Bracket", Action = () => setScreen(bracket) }, + new Container { RelativeSizeAxes = Axes.X, Height = 50 }, + new OsuButton { RelativeSizeAxes = Axes.X, Text = "Gameplay", Action = () => setScreen(gameplay) }, } }, }, @@ -89,7 +94,8 @@ namespace osu.Game.Tournament.Screens mapPool = new MapPoolScreen(ladder.Groupings.First(g => g.Name == "Finals")), teamIntro = new TeamIntroScreen(ladder.Teams.First(t => t.Acronym == "USA"), ladder.Teams.First(t => t.Acronym == "JPN"), ladder.Groupings.First(g => g.Name == "Finals")), - drawings = new DrawingsScreen() + drawings = new DrawingsScreen(), + gameplay = new GameplayScreen() } }, }