diff --git a/osu-framework b/osu-framework index 659cb25892..de1568254c 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 659cb2589252f502d2f29c1c1b3878b8f5910d86 +Subproject commit de1568254c4c9a4ea540ccad94700c5c51f70dc2 diff --git a/osu.Desktop.VisualTests/Benchmark.cs b/osu.Desktop.VisualTests/Benchmark.cs index 506788e93c..9584dc52a4 100644 --- a/osu.Desktop.VisualTests/Benchmark.cs +++ b/osu.Desktop.VisualTests/Benchmark.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Desktop.Platform; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Game; using osu.Game.Modes; using osu.Game.Modes.Catch; diff --git a/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs b/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs index 54f3957014..4e27788d67 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using osu.Framework; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -17,6 +17,7 @@ using osu.Game.Online.Chat; using OpenTK; using osu.Framework.Allocation; using osu.Game.Online.Chat.Drawables; +using osu.Game.Overlays; namespace osu.Desktop.VisualTests.Tests { @@ -25,119 +26,16 @@ namespace osu.Desktop.VisualTests.Tests private ScheduledDelegate messageRequest; public override string Name => @"Chat"; - public override string Description => @"Testing API polling"; - - FlowContainer flow; - - private Scheduler scheduler = new Scheduler(); - - private APIAccess api; - - private ChannelDisplay channelDisplay; - - [BackgroundDependencyLoader] - private void load(APIAccess api) - { - this.api = api; - } + public override string Description => @"Testing chat api and overlay"; public override void Reset() { base.Reset(); - if (api.State != APIState.Online) - api.OnStateChange += delegate { initializeChannels(); }; - else - initializeChannels(); - } - - protected override void Update() - { - scheduler.Update(); - base.Update(); - } - - private long? lastMessageId; - - List careChannels; - - private void initializeChannels() - { - careChannels = new List(); - - if (api.State != APIState.Online) - return; - - Add(flow = new FlowContainer + Add(new ChatOverlay() { - RelativeSizeAxes = Axes.Both, - Direction = FlowDirections.Vertical + State = Visibility.Visible }); - - SpriteText loading; - Add(loading = new SpriteText - { - Text = @"Loading available channels...", - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - TextSize = 40, - }); - - messageRequest?.Cancel(); - - ListChannelsRequest req = new ListChannelsRequest(); - req.Success += delegate (List channels) - { - Scheduler.Add(delegate - { - loading.FadeOut(100); - }); - - addChannel(channels.Find(c => c.Name == @"#osu")); - addChannel(channels.Find(c => c.Name == @"#lobby")); - addChannel(channels.Find(c => c.Name == @"#english")); - - messageRequest = scheduler.AddDelayed(() => FetchNewMessages(api), 1000, true); - }; - api.Queue(req); - } - - private void addChannel(Channel channel) - { - flow.Add(channelDisplay = new ChannelDisplay(channel) - { - Size = new Vector2(1, 0.3f) - }); - - careChannels.Add(channel); - } - - GetMessagesRequest fetchReq; - - public void FetchNewMessages(APIAccess api) - { - if (fetchReq != null) return; - - fetchReq = new GetMessagesRequest(careChannels, lastMessageId); - fetchReq.Success += delegate (List messages) - { - foreach (Message m in messages) - { - careChannels.Find(c => c.Id == m.ChannelId).AddNewMessages(m); - } - - lastMessageId = messages.LastOrDefault()?.Id ?? lastMessageId; - - Debug.Write("success!"); - fetchReq = null; - }; - fetchReq.Failure += delegate - { - Debug.Write("failure!"); - fetchReq = null; - }; - - api.Queue(fetchReq); } } } diff --git a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs index cf0b6cd7ce..70abd6d8c4 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs @@ -2,7 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics; using osu.Framework.MathUtils; using osu.Framework.Timing; diff --git a/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs b/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs index 1e3d8df6c6..7a46ea5ded 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using osu.Framework; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics; using osu.Framework.Timing; using OpenTK; @@ -37,7 +37,7 @@ namespace osu.Desktop.VisualTests.Tests playbackSpeed.ValueChanged += delegate { rateAdjustClock.Rate = playbackSpeed.Value; }; } - HitObjectType mode = HitObjectType.Spinner; + HitObjectType mode = HitObjectType.Slider; BindableNumber playbackSpeed = new BindableDouble(0.5) { MinValue = 0, MaxValue = 1 }; private Container playfieldContainer; @@ -75,6 +75,7 @@ namespace osu.Desktop.VisualTests.Tests Length = 400, Position = new Vector2(-200, 0), Velocity = 1, + TickDistance = 100, })); break; case HitObjectType.Spinner: diff --git a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs index c5ecdfa936..c33a4001de 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseKeyCounter.cs @@ -1,7 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; using OpenTK.Input; diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMenuButtonSystem.cs b/osu.Desktop.VisualTests/Tests/TestCaseMenuButtonSystem.cs index 511f8568db..069cf39164 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMenuButtonSystem.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMenuButtonSystem.cs @@ -1,7 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Sprites; using osu.Game.Screens.Menu; diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs index 67bea2454f..1a811a8588 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs @@ -1,7 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics; using osu.Framework.Timing; using osu.Game.Overlays; diff --git a/osu.Desktop.VisualTests/Tests/TestCaseNotificationManager.cs b/osu.Desktop.VisualTests/Tests/TestCaseNotificationManager.cs index 0b84eeaa30..e3457939f2 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseNotificationManager.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseNotificationManager.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using osu.Framework.Graphics; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.MathUtils; using osu.Framework.Timing; using osu.Game.Overlays; diff --git a/osu.Desktop.VisualTests/Tests/TestCaseOptions.cs b/osu.Desktop.VisualTests/Tests/TestCaseOptions.cs index 1fed512fc5..92a10cc649 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseOptions.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseOptions.cs @@ -1,7 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; using OpenTK.Input; diff --git a/osu.Desktop.VisualTests/Tests/TestCasePauseOverlay.cs b/osu.Desktop.VisualTests/Tests/TestCasePauseOverlay.cs index 81825681f9..9d94189885 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePauseOverlay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePauseOverlay.cs @@ -9,7 +9,7 @@ using osu.Game.Overlays.Pause; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Colour; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics.UserInterface; namespace osu.Desktop.VisualTests.Tests diff --git a/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs b/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs index 47fac4d339..274eeb9440 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using osu.Desktop.VisualTests.Platform; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Game.Database; using osu.Game.Modes; using osu.Game.Screens.Select; diff --git a/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs b/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs index c6baa0a4f0..2f8c37f1bb 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using osu.Framework.Allocation; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.MathUtils; using osu.Framework.Timing; using osu.Game.Beatmaps; @@ -71,7 +71,7 @@ namespace osu.Desktop.VisualTests.Tests Add(new Box { RelativeSizeAxes = Framework.Graphics.Axes.Both, - Colour = Color4.Gray, + Colour = Color4.Black, }); Add(new Player diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs index 891e888d76..d4ac16b86f 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScoreCounter.cs @@ -2,7 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.MathUtils; diff --git a/osu.Desktop.VisualTests/Tests/TestCaseTextAwesome.cs b/osu.Desktop.VisualTests/Tests/TestCaseTextAwesome.cs index 301cf3dd8f..7502c623fe 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseTextAwesome.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseTextAwesome.cs @@ -2,7 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.MathUtils; diff --git a/osu.Desktop.VisualTests/Tests/TestCaseTwoLayerButton.cs b/osu.Desktop.VisualTests/Tests/TestCaseTwoLayerButton.cs index 2fbc9c811d..33ae728fd7 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseTwoLayerButton.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseTwoLayerButton.cs @@ -1,7 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics.UserInterface; diff --git a/osu.Desktop.VisualTests/VisualTestGame.cs b/osu.Desktop.VisualTests/VisualTestGame.cs index 51fcffce57..81b00d4ab2 100644 --- a/osu.Desktop.VisualTests/VisualTestGame.cs +++ b/osu.Desktop.VisualTests/VisualTestGame.cs @@ -2,7 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics.Cursor; using osu.Game.Database; using osu.Game; @@ -21,7 +21,7 @@ namespace osu.Desktop.VisualTests { base.LoadComplete(); - (new BackgroundModeDefault() { Depth = 10 }).Preload(this, AddInternal); + (new BackgroundScreenDefault() { Depth = 10 }).Preload(this, AddInternal); // Have to construct this here, rather than in the constructor, because // we depend on some dependencies to be loaded within OsuGameBase.load(). diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 167d4644b7..3111d72662 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -14,22 +14,32 @@ using osu.Game.Database; using osu.Desktop.Overlays; using System.Reflection; using System.Drawing; +using osu.Game.Screens.Menu; namespace osu.Desktop { class OsuGameDesktop : OsuGame { + private VersionManager versionManager; + + public override bool IsDeployedBuild => versionManager.IsDeployedBuild; + public OsuGameDesktop(string[] args = null) : base(args) { - + versionManager = new VersionManager { Depth = int.MinValue }; } protected override void LoadComplete() { base.LoadComplete(); - (new VersionManager()).Preload(this, Add); + versionManager.Preload(this); + ModeChanged += m => + { + if (!versionManager.IsAlive && m is Intro) + Add(versionManager); + }; } public override void SetHost(BasicGameHost host) diff --git a/osu.Desktop/Overlays/VersionManager.cs b/osu.Desktop/Overlays/VersionManager.cs index 6c34838130..c3f31414de 100644 --- a/osu.Desktop/Overlays/VersionManager.cs +++ b/osu.Desktop/Overlays/VersionManager.cs @@ -1,9 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using System.ComponentModel; using System.Diagnostics; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Overlays; @@ -15,13 +18,19 @@ using osu.Framework.Graphics.Textures; using osu.Game.Graphics; using OpenTK; using OpenTK.Graphics; +using System.Net.Http; +using osu.Framework.Logging; namespace osu.Desktop.Overlays { public class VersionManager : OverlayContainer { private UpdateManager updateManager; - private NotificationManager notification; + private NotificationManager notificationManager; + + AssemblyName assembly = Assembly.GetEntryAssembly().GetName(); + + public bool IsDeployedBuild => assembly.Version.Major > 0; protected override bool HideOnEscape => false; @@ -30,7 +39,7 @@ namespace osu.Desktop.Overlays [BackgroundDependencyLoader] private void load(NotificationManager notification, OsuColour colours, TextureStore textures) { - this.notification = notification; + this.notificationManager = notification; AutoSizeAxes = Axes.Both; Anchor = Anchor.BottomCentre; @@ -40,14 +49,13 @@ namespace osu.Desktop.Overlays bool isDebug = false; Debug.Assert(isDebug = true); - var asm = Assembly.GetEntryAssembly().GetName(); string version; - if (asm.Version.Major == 0) + if (!IsDeployedBuild) { version = @"local " + (isDebug ? @"debug" : @"release"); } else - version = $@"{asm.Version.Major}.{asm.Version.Minor}.{asm.Version.Build}"; + version = $@"{assembly.Version.Major}.{assembly.Version.Minor}.{assembly.Version.Build}"; Children = new Drawable[] { @@ -95,7 +103,8 @@ namespace osu.Desktop.Overlays } }; - updateChecker(); + if (IsDeployedBuild) + updateChecker(); } protected override void LoadComplete() @@ -110,32 +119,71 @@ namespace osu.Desktop.Overlays updateManager?.Dispose(); } - private async void updateChecker() + private async void updateChecker(bool useDeltaPatching = true, UpdateProgressNotification notification = null) { - updateManager = await UpdateManager.GitHubUpdateManager(@"https://github.com/ppy/osu", @"osulazer", null, null, true); + //should we schedule a retry on completion of this check? + bool scheduleRetry = true; - if (!updateManager.IsInstalledApp) - return; - - var info = await updateManager.CheckForUpdate(); - if (info.ReleasesToApply.Count > 0) + try { - ProgressNotification n = new UpdateProgressNotification + if (updateManager == null) updateManager = await UpdateManager.GitHubUpdateManager(@"https://github.com/ppy/osu", @"osulazer", null, null, true); + + var info = await updateManager.CheckForUpdate(!useDeltaPatching); + if (info.ReleasesToApply.Count == 0) + //no updates available. bail and retry later. + return; + + if (notification == null) { - Text = @"Downloading update..." - }; - Schedule(() => notification.Post(n)); - Schedule(() => n.State = ProgressNotificationState.Active); - await updateManager.DownloadReleases(info.ReleasesToApply, (int p) => Schedule(() => n.Progress = p / 100f)); - Schedule(() => n.Text = @"Installing update..."); - await updateManager.ApplyReleases(info, (int p) => Schedule(() => n.Progress = p / 100f)); - Schedule(() => n.State = ProgressNotificationState.Completed); + notification = new UpdateProgressNotification { State = ProgressNotificationState.Active }; + Schedule(() => notificationManager.Post(notification)); + } + Schedule(() => + { + notification.Progress = 0; + notification.Text = @"Downloading update..."; + }); + + try + { + await updateManager.DownloadReleases(info.ReleasesToApply, p => Schedule(() => notification.Progress = p / 100f)); + + Schedule(() => + { + notification.Progress = 0; + notification.Text = @"Installing update..."; + }); + + await updateManager.ApplyReleases(info, p => Schedule(() => notification.Progress = p / 100f)); + + Schedule(() => notification.State = ProgressNotificationState.Completed); + } + catch (Exception) + { + if (useDeltaPatching) + { + //could fail if deltas are unavailable for full update path (https://github.com/Squirrel/Squirrel.Windows/issues/959) + //try again without deltas. + updateChecker(false, notification); + scheduleRetry = false; + } + } } - else + catch (HttpRequestException) { - //check again every 30 minutes. - Scheduler.AddDelayed(updateChecker, 60000 * 30); + //likely have no internet connection. + //we'll ignore this and retry later. + } + finally + { + if (scheduleRetry) + { + //check again in 30 minutes. + Scheduler.AddDelayed(() => updateChecker(), 60000 * 30); + if (notification != null) + notification.State = ProgressNotificationState.Cancelled; + } } } @@ -159,6 +207,25 @@ namespace osu.Desktop.Overlays return true; } }; + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + IconContent.Add(new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + ColourInfo = ColourInfo.GradientVertical(colours.YellowDark, colours.Yellow) + }, + new TextAwesome + { + Anchor = Anchor.Centre, + Icon = FontAwesome.fa_upload, + Colour = Color4.White, + } + }); + } } } } diff --git a/osu.Desktop/osu.Desktop.csproj b/osu.Desktop/osu.Desktop.csproj index 2ab913d706..d85671f5be 100644 --- a/osu.Desktop/osu.Desktop.csproj +++ b/osu.Desktop/osu.Desktop.csproj @@ -137,6 +137,16 @@ + + + ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll + True + + + ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll + True + + @@ -219,7 +229,6 @@ - + diff --git a/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs b/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs new file mode 100644 index 0000000000..47fe1774bd --- /dev/null +++ b/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs @@ -0,0 +1,27 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; +using osu.Game.Modes.Catch.Objects; +using osu.Game.Modes.Objects; +using System; +using System.Collections.Generic; + +namespace osu.Game.Modes.Catch +{ + public class CatchDifficultyCalculator : DifficultyCalculator + { + protected override PlayMode PlayMode => PlayMode.Catch; + + public CatchDifficultyCalculator(Beatmap beatmap) : base(beatmap) + { + } + + protected override HitObjectConverter Converter => new CatchConverter(); + + protected override double ComputeDifficulty(Dictionary categoryDifficulty) + { + return 0; + } + } +} \ No newline at end of file diff --git a/osu.Game.Modes.Catch/CatchRuleset.cs b/osu.Game.Modes.Catch/CatchRuleset.cs index 5db11737f4..48a84617da 100644 --- a/osu.Game.Modes.Catch/CatchRuleset.cs +++ b/osu.Game.Modes.Catch/CatchRuleset.cs @@ -1,14 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; using osu.Game.Graphics; using osu.Game.Modes.Catch.UI; using osu.Game.Modes.Objects; -using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.UI; using osu.Game.Modes.UI; using osu.Game.Beatmaps; +using System; namespace osu.Game.Modes.Catch { @@ -25,5 +24,7 @@ namespace osu.Game.Modes.Catch public override ScoreProcessor CreateScoreProcessor(int hitObjectCount) => null; public override HitObjectParser CreateHitObjectParser() => new NullHitObjectParser(); + + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new CatchDifficultyCalculator(beatmap); } } diff --git a/osu.Game.Modes.Catch/osu.Game.Modes.Catch.csproj b/osu.Game.Modes.Catch/osu.Game.Modes.Catch.csproj index 8d32c23b9b..5e3f0f1d96 100644 --- a/osu.Game.Modes.Catch/osu.Game.Modes.Catch.csproj +++ b/osu.Game.Modes.Catch/osu.Game.Modes.Catch.csproj @@ -47,6 +47,7 @@ + diff --git a/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs b/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs new file mode 100644 index 0000000000..5075c44db6 --- /dev/null +++ b/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs @@ -0,0 +1,30 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; +using osu.Game.Modes.Mania.Objects; +using osu.Game.Modes.Objects; +using System; +using System.Collections.Generic; + +namespace osu.Game.Modes.Mania +{ + public class ManiaDifficultyCalculator : DifficultyCalculator + { + protected override PlayMode PlayMode => PlayMode.Mania; + + private int columns; + + public ManiaDifficultyCalculator(Beatmap beatmap, int columns = 5) : base(beatmap) + { + this.columns = columns; + } + + protected override HitObjectConverter Converter => new ManiaConverter(columns); + + protected override double ComputeDifficulty(Dictionary categoryDifficulty) + { + return 0; + } + } +} \ No newline at end of file diff --git a/osu.Game.Modes.Mania/ManiaRuleset.cs b/osu.Game.Modes.Mania/ManiaRuleset.cs index 654a4ddaa6..28c298be95 100644 --- a/osu.Game.Modes.Mania/ManiaRuleset.cs +++ b/osu.Game.Modes.Mania/ManiaRuleset.cs @@ -1,15 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; using osu.Game.Graphics; using osu.Game.Modes.Mania.UI; using osu.Game.Modes.Objects; -using osu.Game.Modes.Osu; -using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.UI; using osu.Game.Modes.UI; using osu.Game.Beatmaps; +using System; namespace osu.Game.Modes.Mania { @@ -26,5 +24,7 @@ namespace osu.Game.Modes.Mania public override ScoreProcessor CreateScoreProcessor(int hitObjectCount) => null; public override HitObjectParser CreateHitObjectParser() => new NullHitObjectParser(); + + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new ManiaDifficultyCalculator(beatmap); } } diff --git a/osu.Game.Modes.Mania/osu.Game.Modes.Mania.csproj b/osu.Game.Modes.Mania/osu.Game.Modes.Mania.csproj index 7ff501c86d..ecd3fe6423 100644 --- a/osu.Game.Modes.Mania/osu.Game.Modes.Mania.csproj +++ b/osu.Game.Modes.Mania/osu.Game.Modes.Mania.csproj @@ -47,6 +47,7 @@ + diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs index 208bf15328..0e085d63b8 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs @@ -84,18 +84,18 @@ namespace osu.Game.Modes.Osu.Objects.Drawables double hitOffset = Math.Abs(Judgement.TimeOffset); + OsuJudgementInfo osuJudgement = Judgement as OsuJudgementInfo; + if (hitOffset < hit50) { Judgement.Result = HitResult.Hit; - OsuJudgementInfo osuInfo = Judgement as OsuJudgementInfo; - if (hitOffset < hit300) - osuInfo.Score = OsuScoreResult.Hit300; + osuJudgement.Score = OsuScoreResult.Hit300; else if (hitOffset < hit100) - osuInfo.Score = OsuScoreResult.Hit100; + osuJudgement.Score = OsuScoreResult.Hit100; else if (hitOffset < hit50) - osuInfo.Score = OsuScoreResult.Hit50; + osuJudgement.Score = OsuScoreResult.Hit50; } else Judgement.Result = HitResult.Miss; diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs index ef153848d4..c7cc7cfdd7 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -4,7 +4,6 @@ using System.ComponentModel; using osu.Game.Modes.Objects; using osu.Game.Modes.Objects.Drawables; -using osu.Framework.Graphics; namespace osu.Game.Modes.Osu.Objects.Drawables { @@ -19,7 +18,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables { } - public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo(); + public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.Hit300 }; protected override void UpdateState(ArmedState state) { @@ -49,7 +48,37 @@ namespace osu.Game.Modes.Osu.Objects.Drawables public class OsuJudgementInfo : PositionalJudgementInfo { + /// + /// The score the user achieved. + /// public OsuScoreResult Score; + + /// + /// The score which would be achievable on a perfect hit. + /// + public OsuScoreResult MaxScore = OsuScoreResult.Hit300; + + public int ScoreValue => scoreToInt(Score); + + public int MaxScoreValue => scoreToInt(MaxScore); + + private int scoreToInt(OsuScoreResult result) + { + switch (result) + { + default: + return 0; + case OsuScoreResult.Hit50: + return 50; + case OsuScoreResult.Hit100: + return 100; + case OsuScoreResult.Hit300: + return 300; + case OsuScoreResult.SliderTick: + return 10; + } + } + public ComboResult Combo; } @@ -73,5 +102,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables Hit100, [Description(@"300")] Hit300, + [Description(@"10")] + SliderTick } } diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs index 6c4e1fec78..907ce8da63 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs @@ -1,11 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; +using OpenTK; using osu.Framework.Graphics; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Osu.Objects.Drawables.Pieces; -using OpenTK; +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Graphics.Containers; namespace osu.Game.Modes.Osu.Objects.Drawables { @@ -17,6 +19,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables private List components = new List(); + private Container ticks; + SliderBody body; SliderBall ball; @@ -33,6 +37,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables Position = s.StackedPosition, PathWidth = s.Scale * 64, }, + ticks = new Container(), bouncer1 = new SliderBouncer(s, false) { Position = s.Curve.PositionAt(1), @@ -63,6 +68,26 @@ namespace osu.Game.Modes.Osu.Objects.Drawables components.Add(ball); components.Add(bouncer1); components.Add(bouncer2); + + AddNested(initialCircle); + + var repeatDuration = s.Curve.Length / s.Velocity; + foreach (var tick in s.Ticks) + { + var repeatStartTime = s.StartTime + tick.RepeatIndex * repeatDuration; + var fadeInTime = repeatStartTime + (tick.StartTime - repeatStartTime) / 2 - (tick.RepeatIndex == 0 ? TIME_FADEIN : TIME_FADEIN / 2); + var fadeOutTime = repeatStartTime + repeatDuration; + + var drawableTick = new DrawableSliderTick(tick) + { + FadeInTime = fadeInTime, + FadeOutTime = fadeOutTime, + Position = tick.Position, + }; + + ticks.Add(drawableTick); + AddNested(drawableTick); + } } // Since the DrawableSlider itself is just a container without a size we need to @@ -82,7 +107,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables if (repeat > currentRepeat) { - if (ball.Tracking) + if (repeat < slider.RepeatCount && ball.Tracking) PlaySample(); currentRepeat = repeat; } @@ -96,7 +121,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables if (initialCircle.Judgement?.Result != HitResult.Hit) initialCircle.Position = slider.Curve.PositionAt(progress); - components.ForEach(c => c.UpdateProgress(progress, repeat)); + foreach (var c in components) c.UpdateProgress(progress, repeat); + foreach (var t in ticks.Children) t.Tracking = ball.Tracking; } protected override void CheckJudgement(bool userTriggered) @@ -106,8 +132,22 @@ namespace osu.Game.Modes.Osu.Objects.Drawables if (!userTriggered && Time.Current >= HitObject.EndTime) { - j.Score = sc.Score; - j.Result = sc.Result; + var ticksCount = ticks.Children.Count() + 1; + var ticksHit = ticks.Children.Count(t => t.Judgement.Result == HitResult.Hit); + if (sc.Result == HitResult.Hit) + ticksHit++; + + var hitFraction = (double)ticksHit / ticksCount; + if (hitFraction == 1 && sc.Score == OsuScoreResult.Hit300) + j.Score = OsuScoreResult.Hit300; + else if (hitFraction >= 0.5 && sc.Score >= OsuScoreResult.Hit100) + j.Score = OsuScoreResult.Hit100; + else if (hitFraction > 0) + j.Score = OsuScoreResult.Hit50; + else + j.Score = OsuScoreResult.Miss; + + j.Result = j.Score != OsuScoreResult.Miss ? HitResult.Hit : HitResult.Miss; } } diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs new file mode 100644 index 0000000000..47ffe513c1 --- /dev/null +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs @@ -0,0 +1,120 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using osu.Game.Beatmaps.Samples; +using osu.Game.Modes.Objects.Drawables; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Modes.Osu.Objects.Drawables +{ + public class DrawableSliderTick : DrawableOsuHitObject + { + private SliderTick sliderTick; + + public double FadeInTime; + public double FadeOutTime; + + public bool Tracking; + + public override bool RemoveWhenNotAlive => false; + + public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.SliderTick }; + + public DrawableSliderTick(SliderTick sliderTick) : base(sliderTick) + { + this.sliderTick = sliderTick; + + Size = new Vector2(16) * sliderTick.Scale; + + Masking = true; + CornerRadius = Size.X / 2; + + Origin = Anchor.Centre; + + BorderThickness = 2; + BorderColour = Color4.White; + + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = sliderTick.Colour, + Alpha = 0.3f, + } + }; + } + + private SampleChannel sample; + + [BackgroundDependencyLoader] + private void load(AudioManager audio) + { + string sampleSet = (HitObject.Sample?.Set ?? SampleSet.Normal).ToString().ToLower(); + + sample = audio.Sample.Get($@"Gameplay/{sampleSet}-slidertick"); + } + + protected override void PlaySample() + { + sample?.Play(); + } + + + protected override void CheckJudgement(bool userTriggered) + { + var j = Judgement as OsuJudgementInfo; + + if (Judgement.TimeOffset >= 0) + { + j.Result = Tracking ? HitResult.Hit : HitResult.Miss; + j.Score = Tracking ? OsuScoreResult.SliderTick : OsuScoreResult.Miss; + } + } + + protected override void UpdatePreemptState() + { + var animIn = Math.Min(150, sliderTick.StartTime - FadeInTime); + + ScaleTo(0.5f); + ScaleTo(1.2f, animIn); + FadeIn(animIn); + + Delay(animIn); + ScaleTo(1, 150, EasingTypes.Out); + + Delay(-animIn); + } + + protected override void UpdateState(ArmedState state) + { + if (!IsLoaded) return; + + base.UpdateState(state); + + switch (state) + { + case ArmedState.Idle: + Delay(FadeOutTime - sliderTick.StartTime); + FadeOut(); + break; + case ArmedState.Miss: + FadeOut(160); + FadeColour(Color4.Red, 80); + break; + case ArmedState.Hit: + FadeOut(120, EasingTypes.OutQuint); + ScaleTo(Scale * 1.5f, 120, EasingTypes.OutQuint); + break; + } + } + } +} \ No newline at end of file diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSpinner.cs index cd72483d1e..2f6322a046 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSpinner.cs @@ -108,7 +108,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables } } - private Vector2 scaleToCircle => new Vector2(circle.Scale * circle.DrawWidth / DrawWidth) * 0.95f; + private Vector2 scaleToCircle => (circle.Scale * circle.DrawWidth / DrawWidth) * 0.95f; private float spinsPerMinuteNeeded = 100 + (5 * 15); //TODO: read per-map OD and place it on the 5 diff --git a/osu.Game.Modes.Osu/Objects/Drawables/Pieces/ExplodePiece.cs b/osu.Game.Modes.Osu/Objects/Drawables/Pieces/ExplodePiece.cs index 08c7423c23..97228f610f 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/Pieces/ExplodePiece.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/Pieces/ExplodePiece.cs @@ -25,7 +25,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces { BlendingMode = BlendingMode.Additive, RelativeSizeAxes = Axes.Both, - Alpha = 0.1f, + Alpha = 0.2f, } }; } diff --git a/osu.Game.Modes.Osu/Objects/Drawables/Pieces/SliderBody.cs b/osu.Game.Modes.Osu/Objects/Drawables/Pieces/SliderBody.cs index 173bf2c060..7f7d558294 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/Pieces/SliderBody.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/Pieces/SliderBody.cs @@ -8,7 +8,7 @@ using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.OpenGL.Textures; -using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Lines; using osu.Framework.Graphics.Textures; using osu.Game.Configuration; using OpenTK; diff --git a/osu.Game.Modes.Osu/Objects/HitCircle.cs b/osu.Game.Modes.Osu/Objects/HitCircle.cs index aa45ac7fb9..0eaf5abdff 100644 --- a/osu.Game.Modes.Osu/Objects/HitCircle.cs +++ b/osu.Game.Modes.Osu/Objects/HitCircle.cs @@ -1,9 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; + namespace osu.Game.Modes.Osu.Objects { public class HitCircle : OsuHitObject { + public override HitObjectType Type => HitObjectType.Circle; } } diff --git a/osu.Game.Modes.Osu/Objects/OsuHitObject.cs b/osu.Game.Modes.Osu/Objects/OsuHitObject.cs index c23c9a0b64..f454ebc470 100644 --- a/osu.Game.Modes.Osu/Objects/OsuHitObject.cs +++ b/osu.Game.Modes.Osu/Objects/OsuHitObject.cs @@ -25,6 +25,8 @@ namespace osu.Game.Modes.Osu.Objects public float Scale { get; set; } = 1; + public abstract HitObjectType Type { get; } + public override void SetDefaultsFromBeatmap(Beatmap beatmap) { base.SetDefaultsFromBeatmap(beatmap); @@ -36,14 +38,12 @@ namespace osu.Game.Modes.Osu.Objects [Flags] public enum HitObjectType { - Circle = 1, - Slider = 2, - NewCombo = 4, - CircleNewCombo = 5, - SliderNewCombo = 6, - Spinner = 8, + Circle = 1 << 0, + Slider = 1 << 1, + NewCombo = 1 << 2, + Spinner = 1 << 3, ColourHax = 122, - Hold = 128, - ManiaLong = 128, + Hold = 1 << 7, + SliderTick = 1 << 8, } } diff --git a/osu.Game.Modes.Osu/Objects/OsuHitObjectDifficulty.cs b/osu.Game.Modes.Osu/Objects/OsuHitObjectDifficulty.cs new file mode 100644 index 0000000000..4f0dac7407 --- /dev/null +++ b/osu.Game.Modes.Osu/Objects/OsuHitObjectDifficulty.cs @@ -0,0 +1,201 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using System; +using System.Diagnostics; +using System.Linq; + +namespace osu.Game.Modes.Osu.Objects +{ + class OsuHitObjectDifficulty + { + /// + /// Factor by how much speed / aim strain decays per second. + /// + /// + /// These values are results of tweaking a lot and taking into account general feedback. + /// Opinionated observation: Speed is easier to maintain than accurate jumps. + /// + internal static readonly double[] DECAY_BASE = { 0.3, 0.15 }; + + /// + /// Pseudo threshold values to distinguish between "singles" and "streams" + /// + /// + /// Of course the border can not be defined clearly, therefore the algorithm has a smooth transition between those values. + /// They also are based on tweaking and general feedback. + /// + private const double stream_spacing_threshold = 110, + single_spacing_threshold = 125; + + /// + /// Scaling values for weightings to keep aim and speed difficulty in balance. + /// + /// + /// Found from testing a very large map pool (containing all ranked maps) and keeping the average values the same. + /// + private static readonly double[] spacing_weight_scaling = { 1400, 26.25 }; + + /// + /// Almost the normed diameter of a circle (104 osu pixel). That is -after- position transforming. + /// + private const double almost_diameter = 90; + + internal OsuHitObject BaseHitObject; + internal double[] Strains = { 1, 1 }; + + internal int MaxCombo = 1; + + private float scalingFactor; + private float lazySliderLength; + + private Vector2 startPosition; + private Vector2 endPosition; + + internal OsuHitObjectDifficulty(OsuHitObject baseHitObject) + { + BaseHitObject = baseHitObject; + float circleRadius = baseHitObject.Scale * 64; + + Slider slider = BaseHitObject as Slider; + if (slider != null) + MaxCombo += slider.Ticks.Count(); + + // We will scale everything by this factor, so we can assume a uniform CircleSize among beatmaps. + scalingFactor = (52.0f / circleRadius); + if (circleRadius < 30) + { + float smallCircleBonus = Math.Min(30.0f - circleRadius, 5.0f) / 50.0f; + scalingFactor *= 1.0f + smallCircleBonus; + } + + lazySliderLength = 0; + startPosition = baseHitObject.StackedPosition; + + // Calculate approximation of lazy movement on the slider + if (slider != null) + { + float sliderFollowCircleRadius = circleRadius * 3; // Not sure if this is correct, but here we do not need 100% exact values. This comes pretty darn close in my tests. + + // For simplifying this step we use actual osu! coordinates and simply scale the length, that we obtain by the ScalingFactor later + Vector2 cursorPos = startPosition; + + Action addSliderVertex = delegate (Vector2 pos) + { + Vector2 difference = pos - cursorPos; + float distance = difference.Length; + + // Did we move away too far? + if (distance > sliderFollowCircleRadius) + { + // Yep, we need to move the cursor + difference.Normalize(); // Obtain the direction of difference. We do no longer need the actual difference + distance -= sliderFollowCircleRadius; + cursorPos += difference * distance; // We move the cursor just as far as needed to stay in the follow circle + lazySliderLength += distance; + } + }; + + // Actual computation of the first lazy curve + foreach (var tick in slider.Ticks) + addSliderVertex(tick.StackedPosition); + + addSliderVertex(baseHitObject.StackedEndPosition); + + lazySliderLength *= scalingFactor; + endPosition = cursorPos; + } + // We have a normal HitCircle or a spinner + else + endPosition = startPosition; + } + + internal void CalculateStrains(OsuHitObjectDifficulty previousHitObject, double timeRate) + { + calculateSpecificStrain(previousHitObject, OsuDifficultyCalculator.DifficultyType.Speed, timeRate); + calculateSpecificStrain(previousHitObject, OsuDifficultyCalculator.DifficultyType.Aim, timeRate); + } + + // Caution: The subjective values are strong with this one + private static double spacingWeight(double distance, OsuDifficultyCalculator.DifficultyType type) + { + switch (type) + { + case OsuDifficultyCalculator.DifficultyType.Speed: + if (distance > single_spacing_threshold) + return 2.5; + else if (distance > stream_spacing_threshold) + return 1.6 + 0.9 * (distance - stream_spacing_threshold) / (single_spacing_threshold - stream_spacing_threshold); + else if (distance > almost_diameter) + return 1.2 + 0.4 * (distance - almost_diameter) / (stream_spacing_threshold - almost_diameter); + else if (distance > almost_diameter / 2) + return 0.95 + 0.25 * (distance - (almost_diameter / 2)) / (almost_diameter / 2); + else + return 0.95; + + case OsuDifficultyCalculator.DifficultyType.Aim: + return Math.Pow(distance, 0.99); + } + + Debug.Assert(false, "Invalid osu difficulty hit object type."); + return 0; + } + + private void calculateSpecificStrain(OsuHitObjectDifficulty previousHitObject, OsuDifficultyCalculator.DifficultyType type, double timeRate) + { + double addition = 0; + double timeElapsed = (BaseHitObject.StartTime - previousHitObject.BaseHitObject.StartTime) / timeRate; + double decay = Math.Pow(DECAY_BASE[(int)type], timeElapsed / 1000); + + if (BaseHitObject.Type == HitObjectType.Spinner) + { + // Do nothing for spinners + } + else if (BaseHitObject.Type == HitObjectType.Slider) + { + switch (type) + { + case OsuDifficultyCalculator.DifficultyType.Speed: + + // For speed strain we treat the whole slider as a single spacing entity, since "Speed" is about how hard it is to click buttons fast. + // The spacing weight exists to differentiate between being able to easily alternate or having to single. + addition = + spacingWeight(previousHitObject.lazySliderLength + + DistanceTo(previousHitObject), type) * + spacing_weight_scaling[(int)type]; + + break; + case OsuDifficultyCalculator.DifficultyType.Aim: + + // For Aim strain we treat each slider segment and the jump after the end of the slider as separate jumps, since movement-wise there is no difference + // to multiple jumps. + addition = + ( + spacingWeight(previousHitObject.lazySliderLength, type) + + spacingWeight(DistanceTo(previousHitObject), type) + ) * + spacing_weight_scaling[(int)type]; + + break; + } + } + else if (BaseHitObject.Type == HitObjectType.Circle) + { + addition = spacingWeight(DistanceTo(previousHitObject), type) * spacing_weight_scaling[(int)type]; + } + + // Scale addition by the time, that elapsed. Filter out HitObjects that are too close to be played anyway to avoid crazy values by division through close to zero. + // You will never find maps that require this amongst ranked maps. + addition /= Math.Max(timeElapsed, 50); + + Strains[(int)type] = previousHitObject.Strains[(int)type] * decay + addition; + } + + internal double DistanceTo(OsuHitObjectDifficulty other) + { + // Scale the distance by circle size. + return (startPosition - other.endPosition).Length * scalingFactor; + } + } +} diff --git a/osu.Game.Modes.Osu/Objects/Slider.cs b/osu.Game.Modes.Osu/Objects/Slider.cs index 8479d69669..5f6c50fd72 100644 --- a/osu.Game.Modes.Osu/Objects/Slider.cs +++ b/osu.Game.Modes.Osu/Objects/Slider.cs @@ -1,9 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; -using osu.Game.Beatmaps; using OpenTK; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Samples; +using osu.Game.Beatmaps.Timing; +using System; +using System.Collections.Generic; namespace osu.Game.Modes.Osu.Objects { @@ -43,17 +46,72 @@ namespace osu.Game.Modes.Osu.Objects } public double Velocity; + public double TickDistance; public override void SetDefaultsFromBeatmap(Beatmap beatmap) { base.SetDefaultsFromBeatmap(beatmap); - Velocity = 100 / beatmap.BeatLengthAt(StartTime, true) * beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier; + var baseDifficulty = beatmap.BeatmapInfo.BaseDifficulty; + + ControlPoint overridePoint; + ControlPoint timingPoint = beatmap.TimingPointAt(StartTime, out overridePoint); + var velocityAdjustment = overridePoint?.VelocityAdjustment ?? 1; + var baseVelocity = 100 * baseDifficulty.SliderMultiplier / velocityAdjustment; + + Velocity = baseVelocity / timingPoint.BeatLength; + TickDistance = baseVelocity / baseDifficulty.SliderTickRate; } public int RepeatCount = 1; internal readonly SliderCurve Curve = new SliderCurve(); + + public IEnumerable Ticks + { + get + { + if (TickDistance == 0) yield break; + + var length = Curve.Length; + var tickDistance = Math.Min(TickDistance, length); + var repeatDuration = length / Velocity; + + var minDistanceFromEnd = Velocity * 0.01; + + for (var repeat = 0; repeat < RepeatCount; repeat++) + { + var repeatStartTime = StartTime + repeat * repeatDuration; + var reversed = repeat % 2 == 1; + + for (var d = tickDistance; d <= length; d += tickDistance) + { + if (d > length - minDistanceFromEnd) + break; + + var distanceProgress = d / length; + var timeProgress = reversed ? 1 - distanceProgress : distanceProgress; + + yield return new SliderTick + { + RepeatIndex = repeat, + StartTime = repeatStartTime + timeProgress * repeatDuration, + Position = Curve.PositionAt(distanceProgress), + StackHeight = StackHeight, + Scale = Scale, + Colour = Colour, + Sample = new HitSampleInfo + { + Type = SampleType.None, + Set = SampleSet.Soft, + }, + }; + } + } + } + } + + public override HitObjectType Type => HitObjectType.Slider; } public enum CurveTypes diff --git a/osu.Game.Modes.Osu/Objects/SliderTick.cs b/osu.Game.Modes.Osu/Objects/SliderTick.cs new file mode 100644 index 0000000000..392b1f99ca --- /dev/null +++ b/osu.Game.Modes.Osu/Objects/SliderTick.cs @@ -0,0 +1,11 @@ +using OpenTK; + +namespace osu.Game.Modes.Osu.Objects +{ + public class SliderTick : OsuHitObject + { + public int RepeatIndex { get; set; } + + public override HitObjectType Type => HitObjectType.SliderTick; + } +} diff --git a/osu.Game.Modes.Osu/Objects/Spinner.cs b/osu.Game.Modes.Osu/Objects/Spinner.cs index fa1bddf760..095705eb1f 100644 --- a/osu.Game.Modes.Osu/Objects/Spinner.cs +++ b/osu.Game.Modes.Osu/Objects/Spinner.cs @@ -10,5 +10,7 @@ namespace osu.Game.Modes.Osu.Objects public double Length; public override double EndTime => StartTime + Length; + + public override HitObjectType Type => HitObjectType.Spinner; } } diff --git a/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs b/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs new file mode 100644 index 0000000000..24648b1726 --- /dev/null +++ b/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs @@ -0,0 +1,193 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; +using osu.Game.Modes.Osu.Objects; +using System; +using System.Collections.Generic; +using osu.Game.Modes.Objects; + +namespace osu.Game.Modes.Osu +{ + public class OsuDifficultyCalculator : DifficultyCalculator + { + private const double star_scaling_factor = 0.0675; + private const double extreme_scaling_factor = 0.5; + + protected override PlayMode PlayMode => PlayMode.Osu; + + /// + /// HitObjects are stored as a member variable. + /// + internal List DifficultyHitObjects = new List(); + + public OsuDifficultyCalculator(Beatmap beatmap) : base(beatmap) + { + } + + protected override HitObjectConverter Converter => new OsuHitObjectConverter(); + + protected override void PreprocessHitObjects() + { + foreach (var h in Objects) + if (h.Type == HitObjectType.Slider) + ((Slider)h).Curve.Calculate(); + } + + protected override double ComputeDifficulty(Dictionary categoryDifficulty) + { + // Fill our custom DifficultyHitObject class, that carries additional information + DifficultyHitObjects.Clear(); + + foreach (var hitObject in Objects) + DifficultyHitObjects.Add(new OsuHitObjectDifficulty(hitObject)); + + // Sort DifficultyHitObjects by StartTime of the HitObjects - just to make sure. + DifficultyHitObjects.Sort((a, b) => a.BaseHitObject.StartTime.CompareTo(b.BaseHitObject.StartTime)); + + if (!CalculateStrainValues()) return 0; + + double speedDifficulty = CalculateDifficulty(DifficultyType.Speed); + double aimDifficulty = CalculateDifficulty(DifficultyType.Aim); + + // OverallDifficulty is not considered in this algorithm and neither is HpDrainRate. That means, that in this form the algorithm determines how hard it physically is + // to play the map, assuming, that too much of an error will not lead to a death. + // It might be desirable to include OverallDifficulty into map difficulty, but in my personal opinion it belongs more to the weighting of the actual peformance + // and is superfluous in the beatmap difficulty rating. + // If it were to be considered, then I would look at the hit window of normal HitCircles only, since Sliders and Spinners are (almost) "free" 300s and take map length + // into account as well. + + // The difficulty can be scaled by any desired metric. + // In osu!tp it gets squared to account for the rapid increase in difficulty as the limit of a human is approached. (Of course it also gets scaled afterwards.) + // It would not be suitable for a star rating, therefore: + + // The following is a proposal to forge a star rating from 0 to 5. It consists of taking the square root of the difficulty, since by simply scaling the easier + // 5-star maps would end up with one star. + double speedStars = Math.Sqrt(speedDifficulty) * star_scaling_factor; + double aimStars = Math.Sqrt(aimDifficulty) * star_scaling_factor; + + if (categoryDifficulty != null) + { + categoryDifficulty.Add("Aim", aimStars.ToString("0.00")); + categoryDifficulty.Add("Speed", speedStars.ToString("0.00")); + + double hitWindow300 = 30/*HitObjectManager.HitWindow300*/ / TimeRate; + double preEmpt = 450/*HitObjectManager.PreEmpt*/ / TimeRate; + + categoryDifficulty.Add("OD", (-(hitWindow300 - 80.0) / 6.0).ToString("0.00")); + categoryDifficulty.Add("AR", (preEmpt > 1200.0 ? -(preEmpt - 1800.0) / 120.0 : -(preEmpt - 1200.0) / 150.0 + 5.0).ToString("0.00")); + + int maxCombo = 0; + foreach (OsuHitObjectDifficulty hitObject in DifficultyHitObjects) + maxCombo += hitObject.MaxCombo; + + categoryDifficulty.Add("Max combo", maxCombo.ToString()); + } + + // Again, from own observations and from the general opinion of the community a map with high speed and low aim (or vice versa) difficulty is harder, + // than a map with mediocre difficulty in both. Therefore we can not just add both difficulties together, but will introduce a scaling that favors extremes. + double starRating = speedStars + aimStars + Math.Abs(speedStars - aimStars) * extreme_scaling_factor; + // Another approach to this would be taking Speed and Aim separately to a chosen power, which again would be equivalent. This would be more convenient if + // the hit window size is to be considered as well. + + // Note: The star rating is tuned extremely tight! Airman (/b/104229) and Freedom Dive (/b/126645), two of the hardest ranked maps, both score ~4.66 stars. + // Expect the easier kind of maps that officially get 5 stars to obtain around 2 by this metric. The tutorial still scores about half a star. + // Tune by yourself as you please. ;) + + return starRating; + } + + protected bool CalculateStrainValues() + { + // Traverse hitObjects in pairs to calculate the strain value of NextHitObject from the strain value of CurrentHitObject and environment. + List.Enumerator hitObjectsEnumerator = DifficultyHitObjects.GetEnumerator(); + + if (!hitObjectsEnumerator.MoveNext()) return false; + + OsuHitObjectDifficulty currentHitObject = hitObjectsEnumerator.Current; + OsuHitObjectDifficulty nextHitObject; + + // First hitObject starts at strain 1. 1 is the default for strain values, so we don't need to set it here. See DifficultyHitObject. + while (hitObjectsEnumerator.MoveNext()) + { + nextHitObject = hitObjectsEnumerator.Current; + nextHitObject.CalculateStrains(currentHitObject, TimeRate); + currentHitObject = nextHitObject; + } + + return true; + } + + /// + /// In milliseconds. For difficulty calculation we will only look at the highest strain value in each time interval of size STRAIN_STEP. + /// This is to eliminate higher influence of stream over aim by simply having more HitObjects with high strain. + /// The higher this value, the less strains there will be, indirectly giving long beatmaps an advantage. + /// + protected const double STRAIN_STEP = 400; + + /// + /// The weighting of each strain value decays to this number * it's previous value + /// + protected const double DECAY_WEIGHT = 0.9; + + protected double CalculateDifficulty(DifficultyType type) + { + double actualStrainStep = STRAIN_STEP * TimeRate; + + // Find the highest strain value within each strain step + List highestStrains = new List(); + double intervalEndTime = actualStrainStep; + double maximumStrain = 0; // We need to keep track of the maximum strain in the current interval + + OsuHitObjectDifficulty previousHitObject = null; + foreach (OsuHitObjectDifficulty hitObject in DifficultyHitObjects) + { + // While we are beyond the current interval push the currently available maximum to our strain list + while (hitObject.BaseHitObject.StartTime > intervalEndTime) + { + highestStrains.Add(maximumStrain); + + // The maximum strain of the next interval is not zero by default! We need to take the last hitObject we encountered, take its strain and apply the decay + // until the beginning of the next interval. + if (previousHitObject == null) + { + maximumStrain = 0; + } + else + { + double decay = Math.Pow(OsuHitObjectDifficulty.DECAY_BASE[(int)type], (intervalEndTime - previousHitObject.BaseHitObject.StartTime) / 1000); + maximumStrain = previousHitObject.Strains[(int)type] * decay; + } + + // Go to the next time interval + intervalEndTime += actualStrainStep; + } + + // Obtain maximum strain + maximumStrain = Math.Max(hitObject.Strains[(int)type], maximumStrain); + + previousHitObject = hitObject; + } + + // Build the weighted sum over the highest strains for each interval + double difficulty = 0; + double weight = 1; + highestStrains.Sort((a, b) => b.CompareTo(a)); // Sort from highest to lowest strain. + + foreach (double strain in highestStrains) + { + difficulty += weight * strain; + weight *= DECAY_WEIGHT; + } + + return difficulty; + } + + // Those values are used as array indices. Be careful when changing them! + public enum DifficultyType : int + { + Speed = 0, + Aim, + }; + } +} \ No newline at end of file diff --git a/osu.Game.Modes.Osu/OsuRuleset.cs b/osu.Game.Modes.Osu/OsuRuleset.cs index 398060aa73..d05c8193cc 100644 --- a/osu.Game.Modes.Osu/OsuRuleset.cs +++ b/osu.Game.Modes.Osu/OsuRuleset.cs @@ -40,6 +40,8 @@ namespace osu.Game.Modes.Osu public override ScoreProcessor CreateScoreProcessor(int hitObjectCount) => new OsuScoreProcessor(hitObjectCount); + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new OsuDifficultyCalculator(beatmap); + protected override PlayMode PlayMode => PlayMode.Osu; } } diff --git a/osu.Game.Modes.Osu/OsuScoreProcessor.cs b/osu.Game.Modes.Osu/OsuScoreProcessor.cs index 8a9f7d6b2e..9493259558 100644 --- a/osu.Game.Modes.Osu/OsuScoreProcessor.cs +++ b/osu.Game.Modes.Osu/OsuScoreProcessor.cs @@ -36,24 +36,8 @@ namespace osu.Game.Modes.Osu foreach (OsuJudgementInfo j in Judgements) { - switch (j.Score) - { - case OsuScoreResult.Miss: - maxScore += 300; - break; - case OsuScoreResult.Hit50: - score += 50; - maxScore += 300; - break; - case OsuScoreResult.Hit100: - score += 100; - maxScore += 300; - break; - case OsuScoreResult.Hit300: - score += 300; - maxScore += 300; - break; - } + score += j.ScoreValue; + maxScore += j.MaxScoreValue; } TotalScore.Value = score; diff --git a/osu.Game.Modes.Osu/UI/OsuScoreOverlay.cs b/osu.Game.Modes.Osu/UI/OsuScoreOverlay.cs index ba996be326..c7791ab8b4 100644 --- a/osu.Game.Modes.Osu/UI/OsuScoreOverlay.cs +++ b/osu.Game.Modes.Osu/UI/OsuScoreOverlay.cs @@ -13,19 +13,21 @@ namespace osu.Game.Modes.Osu.UI { public class OsuScoreOverlay : ScoreOverlay { - protected override ScoreCounter CreateScoreCounter() => new ScoreCounter() + protected override ScoreCounter CreateScoreCounter() => new ScoreCounter(6) { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - TextSize = 60, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + TextSize = 40, + Position = new Vector2(0, 30), Margin = new MarginPadding { Right = 5 }, }; protected override PercentageCounter CreateAccuracyCounter() => new PercentageCounter() { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - Position = new Vector2(0, 55), + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Position = new Vector2(0, 65), + TextSize = 20, Margin = new MarginPadding { Right = 5 }, }; diff --git a/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj b/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj index 82c5537597..ffe408ad59 100644 --- a/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj +++ b/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj @@ -59,14 +59,18 @@ + + + + diff --git a/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs b/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs new file mode 100644 index 0000000000..69b86a86af --- /dev/null +++ b/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs @@ -0,0 +1,27 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; +using osu.Game.Modes.Objects; +using osu.Game.Modes.Taiko.Objects; +using System; +using System.Collections.Generic; + +namespace osu.Game.Modes.Taiko +{ + public class TaikoDifficultyCalculator : DifficultyCalculator + { + protected override PlayMode PlayMode => PlayMode.Taiko; + + public TaikoDifficultyCalculator(Beatmap beatmap) : base(beatmap) + { + } + + protected override HitObjectConverter Converter => new TaikoConverter(); + + protected override double ComputeDifficulty(Dictionary categoryDifficulty) + { + return 0; + } + } +} \ No newline at end of file diff --git a/osu.Game.Modes.Taiko/TaikoRuleset.cs b/osu.Game.Modes.Taiko/TaikoRuleset.cs index bd20608d57..01e1598e20 100644 --- a/osu.Game.Modes.Taiko/TaikoRuleset.cs +++ b/osu.Game.Modes.Taiko/TaikoRuleset.cs @@ -2,10 +2,8 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Collections.Generic; using osu.Game.Graphics; using osu.Game.Modes.Objects; -using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.UI; using osu.Game.Modes.Taiko.UI; using osu.Game.Modes.UI; @@ -26,5 +24,7 @@ namespace osu.Game.Modes.Taiko public override ScoreProcessor CreateScoreProcessor(int hitObjectCount) => null; public override HitObjectParser CreateHitObjectParser() => new NullHitObjectParser(); + + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new TaikoDifficultyCalculator(beatmap); } } diff --git a/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj b/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj index 47c71ce09b..6d09463d93 100644 --- a/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj +++ b/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj @@ -47,6 +47,7 @@ + diff --git a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs index 6613b5c370..e0d17badcd 100644 --- a/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/OsuLegacyDecoderTest.cs @@ -1,18 +1,15 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.IO; using NUnit.Framework; using OpenTK; using OpenTK.Graphics; -using osu.Game.Beatmaps; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Samples; using osu.Game.Modes; using osu.Game.Modes.Osu; using osu.Game.Modes.Osu.Objects; -using osu.Game.Screens.Play; using osu.Game.Tests.Resources; namespace osu.Game.Tests.Beatmaps.Formats diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 0914d1a2ad..a55e9fa80d 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -26,26 +26,36 @@ namespace osu.Game.Beatmaps return 60000 / BeatLengthAt(time); } - public double BeatLengthAt(double time, bool applyMultipliers = false) + public double BeatLengthAt(double time) { - int point = 0; - int samplePoint = 0; + ControlPoint overridePoint; + ControlPoint timingPoint = TimingPointAt(time, out overridePoint); + return timingPoint.BeatLength; + } - for (int i = 0; i < ControlPoints.Count; i++) - if (ControlPoints[i].Time <= time) + public ControlPoint TimingPointAt(double time, out ControlPoint overridePoint) + { + overridePoint = null; + + ControlPoint timingPoint = null; + foreach (var controlPoint in ControlPoints) + { + // Some beatmaps have the first timingPoint (accidentally) start after the first HitObject(s). + // This null check makes it so that the first ControlPoint that makes a timing change is used as + // the timingPoint for those HitObject(s). + if (controlPoint.Time <= time || timingPoint == null) { - if (ControlPoints[i].TimingChange) - point = i; - else - samplePoint = i; + if (controlPoint.TimingChange) + { + timingPoint = controlPoint; + overridePoint = null; + } + else overridePoint = controlPoint; } + else break; + } - double mult = 1; - - if (applyMultipliers && samplePoint > point) - mult = ControlPoints[samplePoint].VelocityAdjustment; - - return ControlPoints[point].BeatLength * mult; + return timingPoint ?? ControlPoint.Default; } } } diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs new file mode 100644 index 0000000000..14b6ce3e96 --- /dev/null +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -0,0 +1,50 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Modes; +using osu.Game.Modes.Objects; +using System; +using System.Collections.Generic; + +namespace osu.Game.Beatmaps +{ + public abstract class DifficultyCalculator + { + protected abstract PlayMode PlayMode { get; } + + protected double TimeRate = 1; + + protected abstract double ComputeDifficulty(Dictionary categoryDifficulty); + + private void loadTiming() + { + // TODO: Handle mods + int audioRate = 100; + TimeRate = audioRate / 100.0; + } + + public double GetDifficulty(Dictionary categoryDifficulty = null) + { + loadTiming(); + double difficulty = ComputeDifficulty(categoryDifficulty); + return difficulty; + } + } + + public abstract class DifficultyCalculator : DifficultyCalculator where T : HitObject + { + protected List Objects; + + protected abstract HitObjectConverter Converter { get; } + + public DifficultyCalculator(Beatmap beatmap) + { + Objects = Converter.Convert(beatmap); + PreprocessHitObjects(); + } + + protected virtual void PreprocessHitObjects() + { + } + } +} diff --git a/osu.Game/Beatmaps/Drawables/BeatmapGroup.cs b/osu.Game/Beatmaps/Drawables/BeatmapGroup.cs index 9729ddf257..14aff0e7ba 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapGroup.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapGroup.cs @@ -60,7 +60,7 @@ namespace osu.Game.Beatmaps.Drawables } } - public BeatmapGroup(WorkingBeatmap beatmap, BeatmapSetInfo set = null) + public BeatmapGroup(WorkingBeatmap beatmap) { Header = new BeatmapSetHeader(beatmap) { @@ -68,6 +68,7 @@ namespace osu.Game.Beatmaps.Drawables RelativeSizeAxes = Axes.X, }; + BeatmapSet = beatmap.BeatmapSetInfo; BeatmapPanels = beatmap.BeatmapSetInfo.Beatmaps.Select(b => new BeatmapPanel(b) { Alpha = 0, @@ -76,7 +77,6 @@ namespace osu.Game.Beatmaps.Drawables RelativeSizeAxes = Axes.X, }).ToList(); - BeatmapSet = set; Header.AddDifficultyIcons(BeatmapPanels); } diff --git a/osu.Game/Beatmaps/Timing/ControlPoint.cs b/osu.Game/Beatmaps/Timing/ControlPoint.cs index 27cc7244fb..88e2c2d0f4 100644 --- a/osu.Game/Beatmaps/Timing/ControlPoint.cs +++ b/osu.Game/Beatmaps/Timing/ControlPoint.cs @@ -1,20 +1,21 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace osu.Game.Beatmaps.Timing { public class ControlPoint { + public static ControlPoint Default = new ControlPoint + { + BeatLength = 500, + TimingChange = true, + }; + public double Time; public double BeatLength; public double VelocityAdjustment; public bool TimingChange; + } internal enum TimeSignatures diff --git a/osu.Game/Beatmaps/Timing/TimingChange.cs b/osu.Game/Beatmaps/Timing/TimingChange.cs index e86373f157..10a68bb540 100644 --- a/osu.Game/Beatmaps/Timing/TimingChange.cs +++ b/osu.Game/Beatmaps/Timing/TimingChange.cs @@ -1,12 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace osu.Game.Beatmaps.Timing { class TimingChange : ControlPoint diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 62223ec879..28c2c5f0e2 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -68,7 +68,6 @@ namespace osu.Game.Beatmaps beatmap = decoder?.Decode(stream); } - if (WithStoryboard && beatmap != null && BeatmapSetInfo.StoryboardFile != null) using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile))) decoder?.Decode(stream, beatmap); @@ -83,9 +82,9 @@ namespace osu.Game.Beatmaps } private ArchiveReader trackReader; - private AudioTrack track; + private Track track; private object trackLock = new object(); - public AudioTrack Track + public Track Track { get { @@ -99,7 +98,7 @@ namespace osu.Game.Beatmaps trackReader = getReader(); var trackData = trackReader?.GetStream(BeatmapInfo.Metadata.AudioFile); if (trackData != null) - track = new AudioTrackBass(trackData); + track = new TrackBass(trackData); } catch { } diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 381bca2a71..1562571efc 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -31,6 +31,7 @@ namespace osu.Game.Configuration Set(OsuConfig.SnakingInSliders, true); Set(OsuConfig.SnakingOutSliders, false); + Set(OsuConfig.MenuParallax, true); //todo: implement all settings below this line (remove the Disabled set when doing so). Set(OsuConfig.MouseSpeed, 1.0).Disabled = true; @@ -143,7 +144,6 @@ namespace osu.Game.Configuration Set(OsuConfig.DetectPerformanceIssues, true).Disabled = true; Set(OsuConfig.MenuMusic, true).Disabled = true; Set(OsuConfig.MenuVoice, true).Disabled = true; - Set(OsuConfig.MenuParallax, true).Disabled = true; Set(OsuConfig.RawInput, false).Disabled = true; Set(OsuConfig.AbsoluteToOsuWindow, Get(OsuConfig.RawInput)).Disabled = true; Set(OsuConfig.ShowMenuTips, true).Disabled = true; diff --git a/osu.Game/Database/BeatmapInfo.cs b/osu.Game/Database/BeatmapInfo.cs index b2787dcae3..ec797d518e 100644 --- a/osu.Game/Database/BeatmapInfo.cs +++ b/osu.Game/Database/BeatmapInfo.cs @@ -8,6 +8,7 @@ using osu.Game.Modes; using osu.Game.Screens.Play; using SQLite.Net.Attributes; using SQLiteNetExtensions.Attributes; +using osu.Game.Beatmaps; namespace osu.Game.Database { @@ -73,7 +74,23 @@ namespace osu.Game.Database // Metadata public string Version { get; set; } - public float StarDifficulty => BaseDifficulty?.OverallDifficulty ?? 5; //todo: implement properly + //todo: background threaded computation of this + private float starDifficulty = -1; + public float StarDifficulty + { + get + { + return (starDifficulty < 0) ? (BaseDifficulty?.OverallDifficulty ?? 5) : starDifficulty; + } + + set { starDifficulty = value; } + } + + internal void ComputeDifficulty(BeatmapDatabase database) + { + WorkingBeatmap wb = new WorkingBeatmap(this, BeatmapSet, database); + StarDifficulty = (float)Ruleset.GetRuleset(Mode).CreateDifficultyCalculator(wb.Beatmap).GetDifficulty(); + } public bool Equals(BeatmapInfo other) { diff --git a/osu.Game/Graphics/Containers/ParallaxContainer.cs b/osu.Game/Graphics/Containers/ParallaxContainer.cs index fe3601a5f2..bc54fd8fdc 100644 --- a/osu.Game/Graphics/Containers/ParallaxContainer.cs +++ b/osu.Game/Graphics/Containers/ParallaxContainer.cs @@ -8,6 +8,8 @@ using OpenTK; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics.Transformations; +using osu.Game.Configuration; +using osu.Framework.Configuration; namespace osu.Game.Graphics.Containers { @@ -15,6 +17,8 @@ namespace osu.Game.Graphics.Containers { public float ParallaxAmount = 0.02f; + private Bindable parallaxEnabled; + public override bool Contains(Vector2 screenSpacePos) => true; public ParallaxContainer() @@ -34,9 +38,18 @@ namespace osu.Game.Graphics.Containers protected override Container Content => content; [BackgroundDependencyLoader] - private void load(UserInputManager input) + private void load(UserInputManager input, OsuConfigManager config) { this.input = input; + parallaxEnabled = config.GetBindable(OsuConfig.MenuParallax); + parallaxEnabled.ValueChanged += delegate + { + if (!parallaxEnabled) + { + content.MoveTo(Vector2.Zero, firstUpdate ? 0 : 1000, EasingTypes.OutQuint); + content.Scale = new Vector2(1 + ParallaxAmount); + } + }; } bool firstUpdate = true; @@ -45,9 +58,12 @@ namespace osu.Game.Graphics.Containers { base.Update(); - Vector2 offset = input.CurrentState.Mouse == null ? Vector2.Zero : ToLocalSpace(input.CurrentState.Mouse.NativeState.Position) - DrawSize / 2; - content.MoveTo(offset * ParallaxAmount, firstUpdate ? 0 : 1000, EasingTypes.OutQuint); - content.Scale = new Vector2(1 + ParallaxAmount); + if (parallaxEnabled) + { + Vector2 offset = input.CurrentState.Mouse == null ? Vector2.Zero : ToLocalSpace(input.CurrentState.Mouse.NativeState.Position) - DrawSize / 2; + content.MoveTo(offset * ParallaxAmount, firstUpdate ? 0 : 1000, EasingTypes.OutQuint); + content.Scale = new Vector2(1 + ParallaxAmount); + } firstUpdate = false; } diff --git a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs new file mode 100644 index 0000000000..f657ffe330 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs @@ -0,0 +1,49 @@ +using OpenTK.Graphics; +using OpenTK.Input; +using osu.Framework.Input; +using System; +using System.Linq; + +namespace osu.Game.Graphics.UserInterface +{ + public class FocusedTextBox : OsuTextBox + { + protected override Color4 BackgroundUnfocused => new Color4(10, 10, 10, 255); + protected override Color4 BackgroundFocused => new Color4(10, 10, 10, 255); + + public Action Exit; + + private bool focus; + public bool HoldFocus + { + get { return focus; } + set + { + focus = value; + if (!focus) + TriggerFocusLost(); + } + } + + protected override bool OnFocus(InputState state) + { + var result = base.OnFocus(state); + BorderThickness = 0; + return result; + } + + protected override void OnFocusLost(InputState state) + { + if (state.Keyboard.Keys.Any(key => key == Key.Escape)) + { + if (Text.Length > 0) + Text = string.Empty; + else + Exit?.Invoke(); + } + base.OnFocusLost(state); + } + + public override bool RequestingFocus => HoldFocus; + } +} diff --git a/osu.Game/Graphics/UserInterface/OsuCheckbox.cs b/osu.Game/Graphics/UserInterface/OsuCheckbox.cs index 206b0dc09d..b05d005a1b 100644 --- a/osu.Game/Graphics/UserInterface/OsuCheckbox.cs +++ b/osu.Game/Graphics/UserInterface/OsuCheckbox.cs @@ -71,8 +71,8 @@ namespace osu.Game.Graphics.UserInterface private Nub nub; private SpriteText labelSpriteText; - private AudioSample sampleChecked; - private AudioSample sampleUnchecked; + private SampleChannel sampleChecked; + private SampleChannel sampleUnchecked; public OsuCheckbox() { diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 229d510688..63c8749f00 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics.UserInterface { public class OsuSliderBar : SliderBar where U : struct { - private AudioSample sample; + private SampleChannel sample; private double lastSampleTime; private Nub nub; diff --git a/osu.Game/Graphics/UserInterface/OsuTextBox.cs b/osu.Game/Graphics/UserInterface/OsuTextBox.cs index 0e551380ed..d7bc245027 100644 --- a/osu.Game/Graphics/UserInterface/OsuTextBox.cs +++ b/osu.Game/Graphics/UserInterface/OsuTextBox.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; using osu.Game.Graphics.Sprites; -using osu.Game.Overlays; using OpenTK.Graphics; namespace osu.Game.Graphics.UserInterface diff --git a/osu.Game/Graphics/UserInterface/PercentageCounter.cs b/osu.Game/Graphics/UserInterface/PercentageCounter.cs index 399082a9bd..6b48dff26e 100644 --- a/osu.Game/Graphics/UserInterface/PercentageCounter.cs +++ b/osu.Game/Graphics/UserInterface/PercentageCounter.cs @@ -20,8 +20,7 @@ namespace osu.Game.Graphics.UserInterface { protected override Type TransformType => typeof(TransformAccuracy); - protected override double RollingDuration => 150; - protected override bool IsRollingProportional => true; + protected override double RollingDuration => 750; private float epsilon => 1e-10f; @@ -32,6 +31,7 @@ namespace osu.Game.Graphics.UserInterface public PercentageCounter() { + DisplayedCountSpriteText.FixedWidth = true; Count = 1.0f; } diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index fd1022e546..3d7a4ad8d7 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -38,7 +38,7 @@ namespace osu.Game.Graphics.UserInterface /// /// Easing for the counter rollover animation. /// - protected virtual EasingTypes RollingEasing => EasingTypes.Out; + protected virtual EasingTypes RollingEasing => EasingTypes.OutQuint; private T displayedCount; @@ -107,17 +107,16 @@ namespace osu.Game.Graphics.UserInterface { Children = new Drawable[] { - DisplayedCountSpriteText = new OsuSpriteText(), + DisplayedCountSpriteText = new OsuSpriteText() + { + Font = @"Venera" + }, }; TextSize = 40; AutoSizeAxes = Axes.Both; DisplayedCount = Count; - - DisplayedCountSpriteText.Text = FormatCount(count); - DisplayedCountSpriteText.Anchor = Anchor; - DisplayedCountSpriteText.Origin = Origin; } protected override void LoadComplete() @@ -125,6 +124,10 @@ namespace osu.Game.Graphics.UserInterface base.LoadComplete(); Flush(false, TransformType); + + DisplayedCountSpriteText.Text = FormatCount(count); + DisplayedCountSpriteText.Anchor = Anchor; + DisplayedCountSpriteText.Origin = Origin; } /// diff --git a/osu.Game/Graphics/UserInterface/TwoLayerButton.cs b/osu.Game/Graphics/UserInterface/TwoLayerButton.cs index 54277bd7ff..294d8533e4 100644 --- a/osu.Game/Graphics/UserInterface/TwoLayerButton.cs +++ b/osu.Game/Graphics/UserInterface/TwoLayerButton.cs @@ -28,7 +28,7 @@ namespace osu.Game.Graphics.UserInterface public static readonly Vector2 SIZE_EXTENDED = new Vector2(140, 50); public static readonly Vector2 SIZE_RETRACTED = new Vector2(100, 50); - public AudioSample ActivationSound; + public SampleChannel ActivationSound; private SpriteText text; public Color4 HoverColour; diff --git a/osu.Game/Input/GlobalHotkeys.cs b/osu.Game/Input/GlobalHotkeys.cs index 96f8036aed..b1b22f7069 100644 --- a/osu.Game/Input/GlobalHotkeys.cs +++ b/osu.Game/Input/GlobalHotkeys.cs @@ -13,6 +13,11 @@ namespace osu.Game.Input public override bool HandleInput => true; + public GlobalHotkeys() + { + RelativeSizeAxes = Axes.Both; + } + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { return Handler(state, args); diff --git a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs index 4df49ca01f..173176d8b4 100644 --- a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using osu.Framework; @@ -23,8 +24,6 @@ namespace osu.Game.Modes.Objects.Drawables public bool Interactive = true; - public Container ChildObjects; - public JudgementInfo Judgement; public abstract JudgementInfo CreateJudgementInfo(); @@ -55,7 +54,7 @@ namespace osu.Game.Modes.Objects.Drawables } } - AudioSample sample; + SampleChannel sample; [BackgroundDependencyLoader] private void load(AudioManager audio) @@ -66,7 +65,7 @@ namespace osu.Game.Modes.Objects.Drawables sample = audio.Sample.Get($@"Gameplay/{sampleSet}-hit{hitType}"); } - protected void PlaySample() + protected virtual void PlaySample() { sample?.Play(); } @@ -85,6 +84,19 @@ namespace osu.Game.Modes.Objects.Drawables Expire(true); } + private List nestedHitObjects; + + protected IEnumerable NestedHitObjects => nestedHitObjects; + + protected void AddNested(DrawableHitObject h) + { + if (nestedHitObjects == null) + nestedHitObjects = new List(); + + h.OnJudgement += (d, j) => { OnJudgement?.Invoke(d, j); } ; + nestedHitObjects.Add(h); + } + /// /// Process a hit of this hitobject. Carries out judgement. /// @@ -119,7 +131,11 @@ namespace osu.Game.Modes.Objects.Drawables protected virtual void CheckJudgement(bool userTriggered) { - //todo: consider making abstract. + if (NestedHitObjects != null) + { + foreach (var d in NestedHitObjects) + d.CheckJudgement(userTriggered); + } } protected override void UpdateAfterChildren() diff --git a/osu.Game/Modes/Ruleset.cs b/osu.Game/Modes/Ruleset.cs index 5b9373c10b..851e144408 100644 --- a/osu.Game/Modes/Ruleset.cs +++ b/osu.Game/Modes/Ruleset.cs @@ -32,6 +32,8 @@ namespace osu.Game.Modes public abstract HitObjectParser CreateHitObjectParser(); + public abstract DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap); + public static void Register(Ruleset ruleset) => availableRulesets.TryAdd(ruleset.PlayMode, ruleset.GetType()); protected abstract PlayMode PlayMode { get; } diff --git a/osu.Game/Modes/UI/HealthDisplay.cs b/osu.Game/Modes/UI/HealthDisplay.cs index 1771edb1d8..27734cea15 100644 --- a/osu.Game/Modes/UI/HealthDisplay.cs +++ b/osu.Game/Modes/UI/HealthDisplay.cs @@ -1,23 +1,29 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE -using OpenTK; -using OpenTK.Graphics; +using System; +using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Transformations; -using System; +using osu.Game.Graphics; +using OpenTK; +using OpenTK.Graphics; namespace osu.Game.Modes.UI { public class HealthDisplay : Container { private Box background; - private Box fill; + private Container fill; - public BindableDouble Current = new BindableDouble() { MinValue = 0, MaxValue = 1 }; + public BindableDouble Current = new BindableDouble() + { + MinValue = 0, + MaxValue = 1 + }; public HealthDisplay() { @@ -26,19 +32,38 @@ namespace osu.Game.Modes.UI background = new Box { RelativeSizeAxes = Axes.Both, - Colour = Color4.Gray, + Colour = Color4.Black, }, - fill = new Box + fill = new Container { RelativeSizeAxes = Axes.Both, - Colour = Color4.White, Scale = new Vector2(0, 1), - }, + Masking = true, + Children = new[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + } + } + }, }; Current.ValueChanged += current_ValueChanged; } + [BackgroundDependencyLoader] + private void laod(OsuColour colours) + { + fill.Colour = colours.BlueLighter; + fill.EdgeEffect = new EdgeEffect + { + Colour = colours.BlueDarker.Opacity(0.6f), + Radius = 8, + Type= EdgeEffectType.Glow + }; + } + private void current_ValueChanged(object sender, EventArgs e) { fill.ScaleTo(new Vector2((float)Current, 1), 200, EasingTypes.OutQuint); diff --git a/osu.Game/Modes/UI/ScoreOverlay.cs b/osu.Game/Modes/UI/ScoreOverlay.cs index 7268b5a3b5..7be6af5c6a 100644 --- a/osu.Game/Modes/UI/ScoreOverlay.cs +++ b/osu.Game/Modes/UI/ScoreOverlay.cs @@ -27,9 +27,9 @@ namespace osu.Game.Modes.UI protected abstract ScoreCounter CreateScoreCounter(); protected virtual HealthDisplay CreateHealthDisplay() => new HealthDisplay { - Size = new Vector2(0.5f, 20), + Size = new Vector2(1, 5), RelativeSizeAxes = Axes.X, - Padding = new MarginPadding(5) + Margin = new MarginPadding { Top = 20 } }; public virtual void OnHit(HitObject h) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index 71671d09fb..a9e0b2163b 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -196,7 +196,10 @@ namespace osu.Game.Online.API Logger.Log($@"Performing request {req}", LoggingTarget.Network); req.Perform(this); - State = APIState.Online; + //we could still be in initialisation, at which point we don't want to say we're Online yet. + if (LocalUser.Value != null) + State = APIState.Online; + failureCount = 0; return true; } diff --git a/osu.Game/Online/Chat/Channel.cs b/osu.Game/Online/Chat/Channel.cs index e67bfabc2e..d895b93336 100644 --- a/osu.Game/Online/Chat/Channel.cs +++ b/osu.Game/Online/Chat/Channel.cs @@ -3,12 +3,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; using Newtonsoft.Json; -using osu.Framework.Configuration; -using osu.Game.Online.API; -using osu.Game.Online.API.Requests; namespace osu.Game.Online.Chat { @@ -30,16 +25,16 @@ namespace osu.Game.Online.Chat //internal bool Joined; - public const int MAX_HISTORY = 100; + public const int MAX_HISTORY = 300; [JsonConstructor] public Channel() { } - public event Action NewMessagesArrived; + public event Action> NewMessagesArrived; - public void AddNewMessages(params Message[] messages) + public void AddNewMessages(IEnumerable messages) { Messages.AddRange(messages); purgeOldMessages(); diff --git a/osu.Game/Online/Chat/Drawables/ChatLine.cs b/osu.Game/Online/Chat/Drawables/ChatLine.cs index 21c6659e78..7c6b079eb0 100644 --- a/osu.Game/Online/Chat/Drawables/ChatLine.cs +++ b/osu.Game/Online/Chat/Drawables/ChatLine.cs @@ -1,10 +1,12 @@ // Copyright (c) 2007-2017 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.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using OpenTK; using OpenTK.Graphics; @@ -15,6 +17,50 @@ namespace osu.Game.Online.Chat.Drawables { public readonly Message Message; + private static readonly Color4[] username_colours = { + OsuColour.FromHex("588c7e"), + OsuColour.FromHex("b2a367"), + OsuColour.FromHex("c98f65"), + OsuColour.FromHex("bc5151"), + OsuColour.FromHex("5c8bd6"), + OsuColour.FromHex("7f6ab7"), + OsuColour.FromHex("a368ad"), + OsuColour.FromHex("aa6880"), + + OsuColour.FromHex("6fad9b"), + OsuColour.FromHex("f2e394"), + OsuColour.FromHex("f2ae72"), + OsuColour.FromHex("f98f8a"), + OsuColour.FromHex("7daef4"), + OsuColour.FromHex("a691f2"), + OsuColour.FromHex("c894d3"), + OsuColour.FromHex("d895b0"), + + OsuColour.FromHex("53c4a1"), + OsuColour.FromHex("eace5c"), + OsuColour.FromHex("ea8c47"), + OsuColour.FromHex("fc4f4f"), + OsuColour.FromHex("3d94ea"), + OsuColour.FromHex("7760ea"), + OsuColour.FromHex("af52c6"), + OsuColour.FromHex("e25696"), + + OsuColour.FromHex("677c66"), + OsuColour.FromHex("9b8732"), + OsuColour.FromHex("8c5129"), + OsuColour.FromHex("8c3030"), + OsuColour.FromHex("1f5d91"), + OsuColour.FromHex("4335a5"), + OsuColour.FromHex("812a96"), + OsuColour.FromHex("992861"), + }; + + private Color4 getUsernameColour(Message message) + { + //todo: use User instead of Message when user_id is correctly populated. + return username_colours[message.UserId % username_colours.Length]; + } + const float padding = 200; const float text_size = 20; @@ -25,6 +71,8 @@ namespace osu.Game.Online.Chat.Drawables RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; + Padding = new MarginPadding { Left = 15, Right = 15 }; + Children = new Drawable[] { new Container @@ -34,13 +82,19 @@ namespace osu.Game.Online.Chat.Drawables { new OsuSpriteText { - Text = Message.Timestamp.LocalDateTime.ToLongTimeString(), - TextSize = text_size, - Colour = Color4.Gray + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Font = @"Exo2.0-SemiBold", + Text = $@"{Message.Timestamp.LocalDateTime:hh:mm:ss}", + FixedWidth = true, + TextSize = text_size * 0.75f, + Alpha = 0.4f, }, new OsuSpriteText { - Text = Message.User.Name, + Font = @"Exo2.0-BoldItalic", + Text = $@"{Message.User.Name}:", + Colour = getUsernameColour(Message), TextSize = text_size, Origin = Anchor.TopRight, Anchor = Anchor.TopRight, @@ -51,7 +105,7 @@ namespace osu.Game.Online.Chat.Drawables { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - Padding = new MarginPadding { Left = padding + 10 }, + Padding = new MarginPadding { Left = padding + 15 }, Children = new Drawable[] { new OsuSpriteText diff --git a/osu.Game/Online/Chat/Drawables/ChannelDisplay.cs b/osu.Game/Online/Chat/Drawables/DrawableChannel.cs similarity index 53% rename from osu.Game/Online/Chat/Drawables/ChannelDisplay.cs rename to osu.Game/Online/Chat/Drawables/DrawableChannel.cs index 08630a25aa..5b8d034e9d 100644 --- a/osu.Game/Online/Chat/Drawables/ChannelDisplay.cs +++ b/osu.Game/Online/Chat/Drawables/DrawableChannel.cs @@ -4,25 +4,25 @@ using System; using System.Collections.Generic; using System.Linq; -using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Primitives; +using osu.Framework.MathUtils; +using osu.Framework.Threading; using osu.Game.Graphics.Sprites; using OpenTK; namespace osu.Game.Online.Chat.Drawables { - public class ChannelDisplay : Container + public class DrawableChannel : Container { private readonly Channel channel; private FlowContainer flow; + private ScrollContainer scroll; - public ChannelDisplay(Channel channel) + public DrawableChannel(Channel channel) { this.channel = channel; - newMessages(channel.Messages); - channel.NewMessagesArrived += newMessages; RelativeSizeAxes = Axes.Both; @@ -36,8 +36,9 @@ namespace osu.Game.Online.Chat.Drawables Anchor = Anchor.Centre, Origin = Anchor.Centre }, - new ScrollContainer + scroll = new ScrollContainer { + RelativeSizeAxes = Axes.Both, Children = new Drawable[] { flow = new FlowContainer @@ -45,37 +46,54 @@ namespace osu.Game.Online.Chat.Drawables Direction = FlowDirections.Vertical, RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - Spacing = new Vector2(1, 1) + Padding = new MarginPadding { Left = 20, Right = 20 } } } } }; + + channel.NewMessagesArrived += newMessagesArrived; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + newMessagesArrived(channel.Messages); + scrollToEnd(); } protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); - channel.NewMessagesArrived -= newMessages; + channel.NewMessagesArrived -= newMessagesArrived; } - [BackgroundDependencyLoader] - private void load() - { - newMessages(channel.Messages); - } - - private void newMessages(IEnumerable newMessages) + private void newMessagesArrived(IEnumerable newMessages) { if (!IsLoaded) return; var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY)); + if (scroll.IsScrolledToEnd(10) || !flow.Children.Any()) + scrollToEnd(); + //up to last Channel.MAX_HISTORY messages foreach (Message m in displayMessages) - flow.Add(new ChatLine(m)); + { + var d = new ChatLine(m); + flow.Add(d); + } - while (flow.Children.Count() > Channel.MAX_HISTORY) - flow.Remove(flow.Children.First()); + while (flow.Children.Count(c => c.LifetimeEnd == double.MaxValue) > Channel.MAX_HISTORY) + { + var d = flow.Children.First(c => c.LifetimeEnd == double.MaxValue); + if (!scroll.IsScrolledToEnd(10)) + scroll.OffsetScrollPosition(-d.DrawHeight); + d.Expire(); + } } + + private void scrollToEnd() => Scheduler.AddDelayed(() => scroll.ScrollToEnd(), 50); } } \ No newline at end of file diff --git a/osu.Game/Online/Chat/Message.cs b/osu.Game/Online/Chat/Message.cs index d412650176..3081653c34 100644 --- a/osu.Game/Online/Chat/Message.cs +++ b/osu.Game/Online/Chat/Message.cs @@ -11,6 +11,7 @@ namespace osu.Game.Online.Chat [JsonProperty(@"message_id")] public long Id; + //todo: this should be inside sender. [JsonProperty(@"user_id")] public int UserId; diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 2cce0aa0ce..1a0f08ffb8 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -3,7 +3,7 @@ using System; using osu.Framework.Configuration; -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Game.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -31,6 +31,8 @@ namespace osu.Game { public class OsuGame : OsuGameBase { + public virtual bool IsDeployedBuild => false; + public Toolbar Toolbar; private ChatOverlay chat; @@ -39,10 +41,18 @@ namespace osu.Game private NotificationManager notificationManager; - private MainMenu mainMenu => modeStack?.ChildGameMode as MainMenu; - private Intro intro => modeStack as Intro; + private Intro intro + { + get + { + Screen s = screenStack; + while (s != null && !(s is Intro)) + s = s.ChildScreen; + return s as Intro; + } + } - private OsuGameMode modeStack; + private OsuScreen screenStack; private VolumeControl volume; @@ -106,11 +116,11 @@ namespace osu.Game } }); - (modeStack = new Intro()).Preload(this, d => + (screenStack = new Loader()).Preload(this, d => { - modeStack.ModePushed += modeAdded; - modeStack.Exited += modeRemoved; - mainContent.Add(modeStack); + screenStack.ModePushed += screenAdded; + screenStack.Exited += screenRemoved; + mainContent.Add(screenStack); }); //overlay elements @@ -148,7 +158,7 @@ namespace osu.Game (Toolbar = new Toolbar { Depth = -3, - OnHome = delegate { mainMenu?.MakeCurrent(); }, + OnHome = delegate { intro?.ChildScreen?.MakeCurrent(); }, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, }).Preload(this, t => { @@ -206,20 +216,16 @@ namespace osu.Game return base.OnKeyDown(state, args); } - public Action ModeChanged; + public event Action ModeChanged; private Container mainContent; private Container overlayContent; - private void modeChanged(GameMode newMode) + private void modeChanged(Screen newScreen) { - // - Ability to change window size - // - Ability to adjust music playback - // - Frame limiter changes - //central game mode change logic. - if ((newMode as OsuGameMode)?.ShowOverlays != true) + if ((newScreen as OsuScreen)?.ShowOverlays != true) { Toolbar.State = Visibility.Hidden; musicController.State = Visibility.Hidden; @@ -230,22 +236,24 @@ namespace osu.Game Toolbar.State = Visibility.Visible; } - Cursor.FadeIn(100); + if (newScreen is MainMenu) + Cursor.FadeIn(100); - ModeChanged?.Invoke(newMode); + ModeChanged?.Invoke(newScreen); - if (newMode == null) - Host.Exit(); + if (newScreen == null) + Exit(); } protected override bool OnExiting() { - if (!intro.DidLoadMenu || intro.ChildGameMode != null) + if (screenStack.ChildScreen == null) return false; + + if (intro == null) return true; + + if (!intro.DidLoadMenu || intro.ChildScreen != null) { - Scheduler.Add(delegate - { - intro.MakeCurrent(); - }); + Scheduler.Add(intro.MakeCurrent); return true; } @@ -256,21 +264,21 @@ namespace osu.Game { base.UpdateAfterChildren(); - if (modeStack.ChildGameMode != null) - modeStack.ChildGameMode.Padding = new MarginPadding { Top = Toolbar.Position.Y + Toolbar.DrawHeight }; + if (intro?.ChildScreen != null) + intro.ChildScreen.Padding = new MarginPadding { Top = Toolbar.Position.Y + Toolbar.DrawHeight }; } - private void modeAdded(GameMode newMode) + private void screenAdded(Screen newScreen) { - newMode.ModePushed += modeAdded; - newMode.Exited += modeRemoved; + newScreen.ModePushed += screenAdded; + newScreen.Exited += screenRemoved; - modeChanged(newMode); + modeChanged(newScreen); } - private void modeRemoved(GameMode newMode) + private void screenRemoved(Screen newScreen) { - modeChanged(newMode); + modeChanged(newScreen); } } } diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index f99936763f..e0e43fbe64 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using OpenTK; -using OpenTK.Graphics; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -19,12 +18,19 @@ using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.Chat; using osu.Game.Online.Chat.Drawables; +using osu.Game.Graphics.UserInterface; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.UserInterface; +using OpenTK.Graphics; +using osu.Framework.Input; namespace osu.Game.Overlays { - public class ChatOverlay : OverlayContainer, IOnlineComponent + public class ChatOverlay : FocusedOverlayContainer, IOnlineComponent { - private ChannelDisplay channelDisplay; + const float textbox_height = 40; + + private DrawableChannel channelDisplay; private ScheduledDelegate messageRequest; @@ -32,6 +38,8 @@ namespace osu.Game.Overlays protected override Container Content => content; + private FocusedTextBox inputTextBox; + private APIAccess api; public ChatOverlay() @@ -47,15 +55,65 @@ namespace osu.Game.Overlays { Depth = float.MaxValue, RelativeSizeAxes = Axes.Both, - Colour = OsuColour.Gray(0.1f).Opacity(0.4f), + Colour = Color4.Black, + Alpha = 0.9f, }, content = new Container { RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding { Top = 5, Bottom = textbox_height + 5 }, + }, + new Container + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + RelativeSizeAxes = Axes.X, + Height = textbox_height, + Padding = new MarginPadding(5), + Children = new Drawable[] + { + inputTextBox = new FocusedTextBox + { + RelativeSizeAxes = Axes.Both, + Height = 1, + PlaceholderText = "type your message", + Exit = () => State = Visibility.Hidden, + OnCommit = postMessage, + HoldFocus = true, + } + } } }); } + protected override bool OnFocus(InputState state) + { + //this is necessary as inputTextBox is masked away and therefore can't get focus :( + inputTextBox.TriggerFocus(); + return false; + } + + private void postMessage(TextBox sender, bool newText) + { + var postText = sender.Text; + + if (!string.IsNullOrEmpty(postText)) + { + //todo: actually send to server + careChannels.FirstOrDefault()?.AddNewMessages(new[] + { + new Message + { + User = api.LocalUser.Value, + Timestamp = DateTimeOffset.Now, + Content = postText + } + }); + } + + sender.Text = string.Empty; + } + [BackgroundDependencyLoader] private void load(APIAccess api) { @@ -69,7 +127,7 @@ namespace osu.Game.Overlays private void addChannel(Channel channel) { - Add(channelDisplay = new ChannelDisplay(channel)); + Add(channelDisplay = new DrawableChannel(channel)); careChannels.Add(channel); } @@ -82,10 +140,11 @@ namespace osu.Game.Overlays fetchReq = new GetMessagesRequest(careChannels, lastMessageId); fetchReq.Success += delegate (List messages) { - foreach (Message m in messages) - { - careChannels.Find(c => c.Id == m.ChannelId).AddNewMessages(m); - } + var ids = messages.Select(m => m.ChannelId).Distinct(); + + //batch messages per channel. + foreach (var id in ids) + careChannels.Find(c => c.Id == id)?.AddNewMessages(messages.Where(m => m.ChannelId == id)); lastMessageId = messages.LastOrDefault()?.Id ?? lastMessageId; @@ -151,6 +210,8 @@ namespace osu.Game.Overlays ListChannelsRequest req = new ListChannelsRequest(); req.Success += delegate (List channels) { + Debug.Assert(careChannels.Count == 0); + Scheduler.Add(delegate { loading.FadeOut(100); diff --git a/osu.Game/Overlays/NotificationManager.cs b/osu.Game/Overlays/NotificationManager.cs index cb2025c576..5e37ede783 100644 --- a/osu.Game/Overlays/NotificationManager.cs +++ b/osu.Game/Overlays/NotificationManager.cs @@ -38,8 +38,9 @@ namespace osu.Game.Overlays Colour = Color4.Black, Alpha = 0.6f, }, - scrollContainer = new ScrollContainer() + scrollContainer = new ScrollContainer { + RelativeSizeAxes = Axes.Both, Margin = new MarginPadding { Top = Toolbar.Toolbar.HEIGHT }, Children = new[] { diff --git a/osu.Game/Overlays/Notifications/Notification.cs b/osu.Game/Overlays/Notifications/Notification.cs index 6faa79433e..6ad0fde419 100644 --- a/osu.Game/Overlays/Notifications/Notification.cs +++ b/osu.Game/Overlays/Notifications/Notification.cs @@ -89,7 +89,6 @@ namespace osu.Game.Overlays.Notifications IconContent = new Container { Size = new Vector2(40), - Colour = Color4.DarkGray, Masking = true, CornerRadius = 5, }, diff --git a/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs b/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs index a5ec9a3545..61525ed019 100644 --- a/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs +++ b/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs @@ -1,7 +1,11 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Allocation; using osu.Game.Graphics; +using osu.Framework.Graphics.Colour; +using OpenTK.Graphics; + namespace osu.Game.Overlays.Notifications { @@ -14,5 +18,11 @@ namespace osu.Game.Overlays.Notifications this.progressNotification = progressNotification; Icon = FontAwesome.fa_check; } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + IconBackgound.ColourInfo = ColourInfo.GradientVertical(colours.GreenDark, colours.GreenLight); + } } } \ No newline at end of file diff --git a/osu.Game/Overlays/Notifications/SimpleNotification.cs b/osu.Game/Overlays/Notifications/SimpleNotification.cs index 24f347eee3..c9c56e8d4a 100644 --- a/osu.Game/Overlays/Notifications/SimpleNotification.cs +++ b/osu.Game/Overlays/Notifications/SimpleNotification.cs @@ -37,19 +37,21 @@ namespace osu.Game.Overlays.Notifications private SpriteText textDrawable; private TextAwesome iconDrawable; + protected Box IconBackgound; + public SimpleNotification() { IconContent.Add(new Drawable[] { - new Box + IconBackgound = new Box { RelativeSizeAxes = Axes.Both, - ColourInfo = ColourInfo.GradientVertical(OsuColour.Gray(0.2f), OsuColour.Gray(0.5f)) + ColourInfo = ColourInfo.GradientVertical(OsuColour.Gray(0.2f), OsuColour.Gray(0.6f)) }, iconDrawable = new TextAwesome { Anchor = Anchor.Centre, - Icon = icon , + Icon = icon, } }); diff --git a/osu.Game/Overlays/Options/Sidebar.cs b/osu.Game/Overlays/Options/Sidebar.cs index f3fe3e1683..ffc3d04756 100644 --- a/osu.Game/Overlays/Options/Sidebar.cs +++ b/osu.Game/Overlays/Options/Sidebar.cs @@ -74,6 +74,7 @@ namespace osu.Game.Overlays.Options { Content.Anchor = Anchor.CentreLeft; Content.Origin = Anchor.CentreLeft; + RelativeSizeAxes = Axes.Both; } } } diff --git a/osu.Game/Overlays/Pause/PauseButton.cs b/osu.Game/Overlays/Pause/PauseButton.cs index 1a1ba4f527..08ded6fbd1 100644 --- a/osu.Game/Overlays/Pause/PauseButton.cs +++ b/osu.Game/Overlays/Pause/PauseButton.cs @@ -55,7 +55,7 @@ namespace osu.Game.Overlays.Pause } } - public AudioSample SampleClick, SampleHover; + public SampleChannel SampleClick, SampleHover; private Container backgroundContainer, colourContainer, glowContainer; private Box leftGlow, centerGlow, rightGlow; diff --git a/osu.Game/Overlays/Toolbar/ToolbarButton.cs b/osu.Game/Overlays/Toolbar/ToolbarButton.cs index 1b8e68151c..8b8010821d 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarButton.cs @@ -66,7 +66,7 @@ namespace osu.Game.Overlays.Toolbar private SpriteText tooltip1; private SpriteText tooltip2; protected FlowContainer Flow; - private AudioSample sampleClick; + private SampleChannel sampleClick; public ToolbarButton() { diff --git a/osu.Game/Screens/BackgroundMode.cs b/osu.Game/Screens/BackgroundScreen.cs similarity index 74% rename from osu.Game/Screens/BackgroundMode.cs rename to osu.Game/Screens/BackgroundScreen.cs index 45931b7e18..0bce73b92f 100644 --- a/osu.Game/Screens/BackgroundMode.cs +++ b/osu.Game/Screens/BackgroundScreen.cs @@ -5,7 +5,7 @@ using System; using System.Threading; using osu.Framework; using osu.Framework.Allocation; -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Framework.Graphics; using osu.Framework.Graphics.Transformations; using osu.Framework.Input; @@ -13,9 +13,9 @@ using OpenTK; namespace osu.Game.Screens { - public abstract class BackgroundMode : GameMode, IEquatable + public abstract class BackgroundScreen : Screen, IEquatable { - public virtual bool Equals(BackgroundMode other) + public virtual bool Equals(BackgroundScreen other) { return other?.GetType() == GetType(); } @@ -37,21 +37,21 @@ namespace osu.Game.Screens this.game = game; } - public override bool Push(GameMode mode) + public override bool Push(Screen screen) { // When trying to push a non-loaded GameMode, load it asynchronously and re-invoke Push // once it's done. - if (mode.LoadState == LoadState.NotLoaded) + if (screen.LoadState == LoadState.NotLoaded) { - mode.Preload(game, d => Push((BackgroundMode)d)); + screen.Preload(game, d => Push((BackgroundScreen)d)); return true; } // Make sure the in-progress loading is complete before pushing the GameMode. - while (mode.LoadState < LoadState.Loaded) + while (screen.LoadState < LoadState.Loaded) Thread.Sleep(1); - base.Push(mode); + base.Push(screen); return true; } @@ -62,7 +62,7 @@ namespace osu.Game.Screens Content.Scale = new Vector2(1 + (x_movement_amount / DrawSize.X) * 2); } - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { Content.FadeOut(); Content.MoveToX(x_movement_amount); @@ -73,13 +73,13 @@ namespace osu.Game.Screens base.OnEntering(last); } - protected override void OnSuspending(GameMode next) + protected override void OnSuspending(Screen next) { Content.MoveToX(-x_movement_amount, transition_length, EasingTypes.InOutQuart); base.OnSuspending(next); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { Content.FadeOut(transition_length, EasingTypes.OutExpo); Content.MoveToX(x_movement_amount, transition_length, EasingTypes.OutExpo); @@ -87,7 +87,7 @@ namespace osu.Game.Screens return base.OnExiting(next); } - protected override void OnResuming(GameMode last) + protected override void OnResuming(Screen last) { Content.MoveToX(0, transition_length, EasingTypes.OutExpo); base.OnResuming(last); diff --git a/osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs similarity index 89% rename from osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs rename to osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs index e7b0ba1566..a003fa2d57 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs @@ -9,7 +9,7 @@ using osu.Game.Graphics.Backgrounds; namespace osu.Game.Screens.Backgrounds { - public class BackgroundModeBeatmap : BackgroundMode + public class BackgroundScreenBeatmap : BackgroundScreen { private Background background; @@ -55,7 +55,7 @@ namespace osu.Game.Screens.Backgrounds } } - public BackgroundModeBeatmap(WorkingBeatmap beatmap) + public BackgroundScreenBeatmap(WorkingBeatmap beatmap) { Beatmap = beatmap; } @@ -66,9 +66,9 @@ namespace osu.Game.Screens.Backgrounds blurTarget = sigma; } - public override bool Equals(BackgroundMode other) + public override bool Equals(BackgroundScreen other) { - return base.Equals(other) && beatmap == ((BackgroundModeBeatmap)other).Beatmap; + return base.Equals(other) && beatmap == ((BackgroundScreenBeatmap)other).Beatmap; } class BeatmapBackground : Background diff --git a/osu.Game/Screens/Backgrounds/BackgroundModeCustom.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs similarity index 67% rename from osu.Game/Screens/Backgrounds/BackgroundModeCustom.cs rename to osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs index 14c6a520ea..9ec8628c5f 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundModeCustom.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenCustom.cs @@ -5,19 +5,19 @@ using osu.Game.Graphics.Backgrounds; namespace osu.Game.Screens.Backgrounds { - public class BackgroundModeCustom : BackgroundMode + public class BackgroundScreenCustom : BackgroundScreen { private readonly string textureName; - public BackgroundModeCustom(string textureName) + public BackgroundScreenCustom(string textureName) { this.textureName = textureName; Add(new Background(textureName)); } - public override bool Equals(BackgroundMode other) + public override bool Equals(BackgroundScreen other) { - return base.Equals(other) && textureName == ((BackgroundModeCustom)other).textureName; + return base.Equals(other) && textureName == ((BackgroundScreenCustom)other).textureName; } } } \ No newline at end of file diff --git a/osu.Game/Screens/Backgrounds/BackgroundModeDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs similarity index 85% rename from osu.Game/Screens/Backgrounds/BackgroundModeDefault.cs rename to osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index 765afb905f..6807085061 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundModeDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -7,7 +7,7 @@ using osu.Game.Graphics.Backgrounds; namespace osu.Game.Screens.Backgrounds { - public class BackgroundModeDefault : BackgroundMode + public class BackgroundScreenDefault : BackgroundScreen { [BackgroundDependencyLoader] private void load(BaseGame game) diff --git a/osu.Game/Screens/Backgrounds/BackgroundModeEmpty.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenEmpty.cs similarity index 75% rename from osu.Game/Screens/Backgrounds/BackgroundModeEmpty.cs rename to osu.Game/Screens/Backgrounds/BackgroundScreenEmpty.cs index 7bc7c2226c..15aa8d10fe 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundModeEmpty.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenEmpty.cs @@ -3,7 +3,7 @@ namespace osu.Game.Screens.Backgrounds { - public class BackgroundModeEmpty : BackgroundMode + public class BackgroundScreenEmpty : BackgroundScreen { } diff --git a/osu.Game/Screens/Charts/ChartInfo.cs b/osu.Game/Screens/Charts/ChartInfo.cs index 036f0fb441..f85d3acb69 100644 --- a/osu.Game/Screens/Charts/ChartInfo.cs +++ b/osu.Game/Screens/Charts/ChartInfo.cs @@ -3,7 +3,7 @@ namespace osu.Game.Screens.Charts { - class ChartInfo : GameModeWhiteBox + class ChartInfo : ScreenWhiteBox { } } diff --git a/osu.Game/Screens/Charts/ChartListing.cs b/osu.Game/Screens/Charts/ChartListing.cs index 20972550ec..b570b63c06 100644 --- a/osu.Game/Screens/Charts/ChartListing.cs +++ b/osu.Game/Screens/Charts/ChartListing.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace osu.Game.Screens.Charts { - class ChartListing : GameModeWhiteBox + class ChartListing : ScreenWhiteBox { protected override IEnumerable PossibleChildren => new[] { typeof(ChartInfo) diff --git a/osu.Game/Screens/Direct/OnlineListing.cs b/osu.Game/Screens/Direct/OnlineListing.cs index f7358a1a69..28de1c58d9 100644 --- a/osu.Game/Screens/Direct/OnlineListing.cs +++ b/osu.Game/Screens/Direct/OnlineListing.cs @@ -3,7 +3,7 @@ namespace osu.Game.Screens.Direct { - class OnlineListing : GameModeWhiteBox + class OnlineListing : ScreenWhiteBox { } } diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 7050a50bee..284a7f6f94 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -1,23 +1,23 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Game.Screens.Backgrounds; using OpenTK.Graphics; namespace osu.Game.Screens.Edit { - class Editor : GameModeWhiteBox + class Editor : ScreenWhiteBox { - protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4"); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4"); - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); Background.Schedule(() => Background.FadeColour(Color4.DarkGray, 500)); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { Background.Schedule(() => Background.FadeColour(Color4.White, 500)); return base.OnExiting(next); diff --git a/osu.Game/Screens/GameModeWhiteBox.cs b/osu.Game/Screens/GameScreenWhiteBox.cs similarity index 89% rename from osu.Game/Screens/GameModeWhiteBox.cs rename to osu.Game/Screens/GameScreenWhiteBox.cs index dce33eefb0..360dec504c 100644 --- a/osu.Game/Screens/GameModeWhiteBox.cs +++ b/osu.Game/Screens/GameScreenWhiteBox.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -17,7 +17,7 @@ using OpenTK.Graphics; namespace osu.Game.Screens { - public class GameModeWhiteBox : OsuGameMode + public class ScreenWhiteBox : OsuScreen { private BackButton popButton; @@ -29,9 +29,9 @@ namespace osu.Game.Screens private Container textContainer; private Box box; - protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg2"); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg2"); - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); @@ -54,7 +54,7 @@ namespace osu.Game.Screens Content.FadeIn(transition_time, EasingTypes.OutExpo); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { textContainer.MoveTo(new Vector2((DrawSize.X / 16), 0), transition_time, EasingTypes.OutExpo); Content.FadeOut(transition_time, EasingTypes.OutExpo); @@ -62,7 +62,7 @@ namespace osu.Game.Screens return base.OnExiting(next); } - protected override void OnSuspending(GameMode next) + protected override void OnSuspending(Screen next) { base.OnSuspending(next); @@ -70,7 +70,7 @@ namespace osu.Game.Screens Content.FadeOut(transition_time, EasingTypes.OutExpo); } - protected override void OnResuming(GameMode last) + protected override void OnResuming(Screen last) { base.OnResuming(last); @@ -78,7 +78,7 @@ namespace osu.Game.Screens Content.FadeIn(transition_time, EasingTypes.OutExpo); } - public GameModeWhiteBox() + public ScreenWhiteBox() { Children = new Drawable[] { @@ -148,7 +148,7 @@ namespace osu.Game.Screens BackgroundColour = getColourFor(t), Action = delegate { - Push(Activator.CreateInstance(t) as GameMode); + Push(Activator.CreateInstance(t) as Screen); } }); } diff --git a/osu.Game/Screens/Loader.cs b/osu.Game/Screens/Loader.cs new file mode 100644 index 0000000000..33094b7098 --- /dev/null +++ b/osu.Game/Screens/Loader.cs @@ -0,0 +1,28 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Screens; +using osu.Game.Screens.Menu; + +namespace osu.Game.Screens +{ + class Loader : OsuScreen + { + internal override bool ShowOverlays => false; + + public Loader() + { + ValidForResume = false; + } + + [BackgroundDependencyLoader] + private void load(OsuGame game) + { + if (game.IsDeployedBuild) + new Disclaimer().Preload(game, d => Push((Screen)d)); + else + new Intro().Preload(game, d => Push((Screen)d)); + } + } +} diff --git a/osu.Game/Screens/Menu/Button.cs b/osu.Game/Screens/Menu/Button.cs index 14d957733a..0c4c6fc1e8 100644 --- a/osu.Game/Screens/Menu/Button.cs +++ b/osu.Game/Screens/Menu/Button.cs @@ -37,7 +37,7 @@ namespace osu.Game.Screens.Menu private readonly float extraWidth; private Key triggerKey; private string text; - private AudioSample sampleClick; + private SampleChannel sampleClick; public override bool Contains(Vector2 screenSpacePos) { diff --git a/osu.Game/Screens/Menu/ButtonSystem.cs b/osu.Game/Screens/Menu/ButtonSystem.cs index 9a84a79333..a203638478 100644 --- a/osu.Game/Screens/Menu/ButtonSystem.cs +++ b/osu.Game/Screens/Menu/ButtonSystem.cs @@ -32,8 +32,6 @@ namespace osu.Game.Screens.Menu public Action OnChart; public Action OnTest; - private AudioSample sampleOsuClick; - private Toolbar toolbar; private FlowContainerWithOrigin buttonFlow; @@ -122,7 +120,6 @@ namespace osu.Game.Screens.Menu [BackgroundDependencyLoader(true)] private void load(AudioManager audio, OsuGame game = null) { - sampleOsuClick = audio.Sample.Get(@"Menu/menuhit"); toolbar = game?.Toolbar; } @@ -181,7 +178,6 @@ namespace osu.Game.Screens.Menu switch (state) { case MenuState.Initial: - sampleOsuClick.Play(); State = MenuState.TopLevel; return; case MenuState.TopLevel: @@ -218,6 +214,7 @@ namespace osu.Game.Screens.Menu switch (state) { + case MenuState.Exit: case MenuState.Initial: toolbar?.Hide(); @@ -233,6 +230,12 @@ namespace osu.Game.Screens.Menu foreach (Button b in buttonsPlay) b.State = ButtonState.Contracted; + + if (state == MenuState.Exit) + { + osuLogo.RotateTo(20, EXIT_DELAY * 1.5f); + osuLogo.FadeOut(EXIT_DELAY); + } break; case MenuState.TopLevel: buttonArea.Flush(true); @@ -276,21 +279,6 @@ namespace osu.Game.Screens.Menu foreach (Button b in buttonsPlay) b.State = ButtonState.Contracted; break; - case MenuState.Exit: - buttonArea.FadeOut(200); - - foreach (Button b in buttonsTopLevel) - b.State = ButtonState.Contracted; - - foreach (Button b in buttonsPlay) - b.State = ButtonState.Contracted; - - osuLogo.Delay(150); - - osuLogo.ScaleTo(1f, EXIT_DELAY * 1.5f); - osuLogo.RotateTo(20, EXIT_DELAY * 1.5f); - osuLogo.FadeOut(EXIT_DELAY); - break; } backButton.State = state == MenuState.Play ? ButtonState.Expanded : ButtonState.Contracted; diff --git a/osu.Game/Screens/Menu/Disclaimer.cs b/osu.Game/Screens/Menu/Disclaimer.cs new file mode 100644 index 0000000000..c5c00d5037 --- /dev/null +++ b/osu.Game/Screens/Menu/Disclaimer.cs @@ -0,0 +1,119 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Screens; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Screens.Menu +{ + class Disclaimer : OsuScreen + { + private Intro intro; + private TextAwesome icon; + private Color4 iconColour; + + internal override bool ShowOverlays => false; + + public Disclaimer() + { + ValidForResume = false; + + Children = new Drawable[] + { + new FlowContainer + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Direction = FlowDirections.Vertical, + Spacing = new Vector2(0, 2), + Children = new Drawable[] + { + icon = new TextAwesome + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Icon = FontAwesome.fa_warning, + TextSize = 30, + }, + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + TextSize = 30, + Text = "This is a development build", + Margin = new MarginPadding + { + Bottom = 20 + }, + }, + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = "Don't expect shit to work perfectly as this is very much a work in progress." + }, + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = "Don't report bugs because we are aware. Don't complain about missing features because we are adding them." + }, + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = "Sit back and enjoy. Visit discord.gg/ppy if you want to help out!", + Margin = new MarginPadding { Bottom = 20 }, + }, + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + TextSize = 12, + Text = "oh and yes, you will get seizures.", + }, + } + } + }; + } + + [BackgroundDependencyLoader] + private void load(OsuGame game, OsuColour colours) + { + (intro = new Intro()).Preload(game); + + iconColour = colours.Yellow; + } + + protected override void OnEntering(Screen last) + { + base.OnEntering(last); + + Content.FadeInFromZero(500); + + icon.Delay(1500); + icon.FadeColour(iconColour, 200); + + Delay(6000, true); + + Content.FadeOut(250); + + Delay(250); + + Schedule(() => Push(intro)); + } + } +} diff --git a/osu.Game/Screens/Menu/Intro.cs b/osu.Game/Screens/Menu/Intro.cs index cb3cfe0208..c69dfff7db 100644 --- a/osu.Game/Screens/Menu/Intro.cs +++ b/osu.Game/Screens/Menu/Intro.cs @@ -5,7 +5,7 @@ using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Audio.Track; -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Framework.Graphics; using osu.Framework.Graphics.Transformations; using osu.Game.Graphics.Containers; @@ -14,7 +14,7 @@ using OpenTK.Graphics; namespace osu.Game.Screens.Menu { - class Intro : OsuGameMode + public class Intro : OsuScreen { private OsuLogo logo; @@ -24,13 +24,13 @@ namespace osu.Game.Screens.Menu internal bool DidLoadMenu; MainMenu mainMenu; - private AudioSample welcome; - private AudioSample seeya; - private AudioTrack bgm; + private SampleChannel welcome; + private SampleChannel seeya; + private Track bgm; - internal override bool ShowOverlays => (ParentGameMode as OsuGameMode)?.ShowOverlays ?? false; + internal override bool ShowOverlays => false; - protected override BackgroundMode CreateBackground() => new BackgroundModeEmpty(); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenEmpty(); public Intro() { @@ -65,7 +65,7 @@ namespace osu.Game.Screens.Menu bgm.Looping = true; } - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); @@ -77,8 +77,7 @@ namespace osu.Game.Screens.Menu { bgm.Start(); - mainMenu = new MainMenu(); - mainMenu.Preload(Game); + (mainMenu = new MainMenu()).Preload(Game); Scheduler.AddDelayed(delegate { @@ -95,24 +94,27 @@ namespace osu.Game.Screens.Menu logo.FadeIn(20000, EasingTypes.OutQuint); } - protected override void OnSuspending(GameMode next) + protected override void OnSuspending(Screen next) { Content.FadeOut(300); base.OnSuspending(next); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { //cancel exiting if we haven't loaded the menu yet. return !DidLoadMenu; } - protected override void OnResuming(GameMode last) + protected override void OnResuming(Screen last) { + if (!(last is MainMenu)) + Content.FadeIn(300); + //we also handle the exit transition. seeya.Play(); - double fadeOutTime = (last.LifetimeEnd - Time.Current) + 100; + double fadeOutTime = 2000; Scheduler.AddDelayed(Exit, fadeOutTime); diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index f672a3998b..1a6310ea4e 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -2,8 +2,8 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; -using osu.Framework.GameModes; -using osu.Framework.GameModes.Testing; +using osu.Framework.Screens; +using osu.Framework.Screens.Testing; using osu.Framework.Graphics; using osu.Framework.Graphics.Transformations; using osu.Game.Graphics.Containers; @@ -16,20 +16,20 @@ using osu.Game.Screens.Select; namespace osu.Game.Screens.Menu { - public class MainMenu : OsuGameMode + public class MainMenu : OsuScreen { private ButtonSystem buttons; public override string Name => @"Main Menu"; internal override bool ShowOverlays => buttons.State != MenuState.Initial; - private BackgroundMode background; + private BackgroundScreen background; - protected override BackgroundMode CreateBackground() => background; + protected override BackgroundScreen CreateBackground() => background; public MainMenu() { - background = new BackgroundModeDefault(); + background = new BackgroundScreenDefault(); Children = new Drawable[] { @@ -59,16 +59,15 @@ namespace osu.Game.Screens.Menu background.Preload(game); buttons.OnSettings = game.ToggleOptions; - } - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); buttons.FadeInFromZero(500); } - protected override void OnSuspending(GameMode next) + protected override void OnSuspending(Screen next) { base.OnSuspending(next); @@ -80,7 +79,7 @@ namespace osu.Game.Screens.Menu Content.MoveTo(new Vector2(-800, 0), length, EasingTypes.InSine); } - protected override void OnResuming(GameMode last) + protected override void OnResuming(Screen last) { base.OnResuming(last); @@ -92,10 +91,10 @@ namespace osu.Game.Screens.Menu Content.MoveTo(new Vector2(0, 0), length, EasingTypes.OutQuint); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { buttons.State = MenuState.Exit; - Content.FadeOut(ButtonSystem.EXIT_DELAY); + Content.FadeOut(3000); return base.OnExiting(next); } } diff --git a/osu.Game/Screens/Menu/OsuLogo.cs b/osu.Game/Screens/Menu/OsuLogo.cs index 225b15c57e..2035ec17ce 100644 --- a/osu.Game/Screens/Menu/OsuLogo.cs +++ b/osu.Game/Screens/Menu/OsuLogo.cs @@ -33,7 +33,7 @@ namespace osu.Game.Screens.Menu private Container logoBounceContainer; private Container logoHoverContainer; - private AudioSample sampleClick; + private SampleChannel sampleClick; private Container colourAndTriangles; @@ -195,11 +195,12 @@ namespace osu.Game.Screens.Menu protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) { - logoBounceContainer.ScaleTo(1f, 500, EasingTypes.OutElastic); return true; } + protected override bool OnDragStart(InputState state) => true; + protected override bool OnClick(InputState state) { if (!Interactive) return false; diff --git a/osu.Game/Screens/Multiplayer/Lobby.cs b/osu.Game/Screens/Multiplayer/Lobby.cs index c3b4938232..c6d59000d3 100644 --- a/osu.Game/Screens/Multiplayer/Lobby.cs +++ b/osu.Game/Screens/Multiplayer/Lobby.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace osu.Game.Screens.Multiplayer { - class Lobby : GameModeWhiteBox + class Lobby : ScreenWhiteBox { protected override IEnumerable PossibleChildren => new[] { typeof(MatchCreate), diff --git a/osu.Game/Screens/Multiplayer/Match.cs b/osu.Game/Screens/Multiplayer/Match.cs index 10de1655f3..e4edcb5d7d 100644 --- a/osu.Game/Screens/Multiplayer/Match.cs +++ b/osu.Game/Screens/Multiplayer/Match.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Play; using OpenTK.Graphics; @@ -11,23 +11,23 @@ using osu.Game.Screens.Select; namespace osu.Game.Screens.Multiplayer { - class Match : GameModeWhiteBox + class Match : ScreenWhiteBox { protected override IEnumerable PossibleChildren => new[] { typeof(MatchSongSelect), typeof(Player), }; - protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4"); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4"); - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); Background.Schedule(() => Background.FadeColour(Color4.DarkGray, 500)); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { Background.Schedule(() => Background.FadeColour(Color4.White, 500)); return base.OnExiting(next); diff --git a/osu.Game/Screens/Multiplayer/MatchCreate.cs b/osu.Game/Screens/Multiplayer/MatchCreate.cs index b0c0456635..57dc0bcf4b 100644 --- a/osu.Game/Screens/Multiplayer/MatchCreate.cs +++ b/osu.Game/Screens/Multiplayer/MatchCreate.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace osu.Game.Screens.Multiplayer { - class MatchCreate : GameModeWhiteBox + class MatchCreate : ScreenWhiteBox { protected override IEnumerable PossibleChildren => new[] { typeof(Match) diff --git a/osu.Game/Screens/OsuGameMode.cs b/osu.Game/Screens/OsuGameScreen.cs similarity index 81% rename from osu.Game/Screens/OsuGameMode.cs rename to osu.Game/Screens/OsuGameScreen.cs index 3134640a60..7aa3d5a5d0 100644 --- a/osu.Game/Screens/OsuGameMode.cs +++ b/osu.Game/Screens/OsuGameScreen.cs @@ -4,21 +4,21 @@ using System; using osu.Framework.Allocation; using osu.Framework.Configuration; -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Graphics.Containers; namespace osu.Game.Screens { - public abstract class OsuGameMode : GameMode + public abstract class OsuScreen : Screen { - internal BackgroundMode Background { get; private set; } + internal BackgroundScreen Background { get; private set; } /// /// Override to create a BackgroundMode for the current GameMode. /// Note that the instance created may not be the used instance if it matches the BackgroundMode equality clause. /// - protected virtual BackgroundMode CreateBackground() => null; + protected virtual BackgroundScreen CreateBackground() => null; internal virtual bool ShowOverlays => true; @@ -73,15 +73,15 @@ namespace osu.Game.Screens beatmap = game?.Beatmap; } - public override bool Push(GameMode mode) + public override bool Push(Screen screen) { - OsuGameMode nextOsu = mode as OsuGameMode; + OsuScreen nextOsu = screen as OsuScreen; if (nextOsu != null) { nextOsu.beatmap = beatmap; } - return base.Push(mode); + return base.Push(screen); } protected virtual void OnBeatmapChanged(WorkingBeatmap beatmap) @@ -89,11 +89,11 @@ namespace osu.Game.Screens } - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { - OsuGameMode lastOsu = last as OsuGameMode; + OsuScreen lastOsu = last as OsuScreen; - BackgroundMode bg = CreateBackground(); + BackgroundScreen bg = CreateBackground(); if (lastOsu?.Background != null) { @@ -120,9 +120,9 @@ namespace osu.Game.Screens base.OnEntering(last); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { - OsuGameMode nextOsu = next as OsuGameMode; + OsuScreen nextOsu = next as OsuScreen; if (Background != null && !Background.Equals(nextOsu?.Background)) { diff --git a/osu.Game/Screens/Play/FailDialog.cs b/osu.Game/Screens/Play/FailDialog.cs index a275a87626..622dd0a44a 100644 --- a/osu.Game/Screens/Play/FailDialog.cs +++ b/osu.Game/Screens/Play/FailDialog.cs @@ -1,7 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -14,9 +14,9 @@ using OpenTK.Graphics; namespace osu.Game.Screens.Play { - class FailDialog : OsuGameMode + class FailDialog : OsuScreen { - protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap); private static readonly Vector2 background_blur = new Vector2(20); @@ -31,13 +31,13 @@ namespace osu.Game.Screens.Play }); } - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); - Background.Schedule(() => (Background as BackgroundModeBeatmap)?.BlurTo(background_blur, 1000)); + Background.Schedule(() => (Background as BackgroundScreenBeatmap)?.BlurTo(background_blur, 1000)); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { Background.Schedule(() => Background.FadeColour(Color4.White, 500)); return base.OnExiting(next); diff --git a/osu.Game/Screens/Play/KeyCounter.cs b/osu.Game/Screens/Play/KeyCounter.cs index cadc06f561..00dd2393d1 100644 --- a/osu.Game/Screens/Play/KeyCounter.cs +++ b/osu.Game/Screens/Play/KeyCounter.cs @@ -89,6 +89,8 @@ namespace osu.Game.Screens.Play new OsuSpriteText { Text = Name, + Font = @"Venera", + TextSize = 12, Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativePositionAxes = Axes.Both, diff --git a/osu.Game/Screens/Play/ModSelect.cs b/osu.Game/Screens/Play/ModSelect.cs index 917fc1ad23..9d3db0221d 100644 --- a/osu.Game/Screens/Play/ModSelect.cs +++ b/osu.Game/Screens/Play/ModSelect.cs @@ -1,23 +1,23 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Game.Screens.Backgrounds; using OpenTK.Graphics; namespace osu.Game.Screens.Play { - class ModSelect : GameModeWhiteBox + class ModSelect : ScreenWhiteBox { - protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4"); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4"); - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); Background.Schedule(() => Background.FadeColour(Color4.DarkGray, 500)); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { Background.Schedule(() => Background.FadeColour(Color4.White, 500)); return base.OnExiting(next); diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 650568f60b..3d21e9cd40 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -12,7 +12,7 @@ using osu.Game.Modes; using osu.Game.Modes.Objects.Drawables; using osu.Game.Screens.Backgrounds; using OpenTK; -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Game.Modes.UI; using osu.Game.Screens.Ranking; using osu.Game.Configuration; @@ -27,11 +27,11 @@ using osu.Framework.Logging; namespace osu.Game.Screens.Play { - public class Player : OsuGameMode + public class Player : OsuScreen { public bool Autoplay; - protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap); internal override bool ShowOverlays => false; @@ -89,7 +89,7 @@ namespace osu.Game.Screens.Play return; } - AudioTrack track = Beatmap.Track; + Track track = Beatmap.Track; if (track != null) { @@ -240,21 +240,6 @@ namespace osu.Game.Screens.Play }); } - protected override void LoadComplete() - { - base.LoadComplete(); - - Content.Delay(250); - Content.FadeIn(250); - - Delay(750); - Schedule(() => - { - sourceClock.Start(); - initializeSkipButton(); - }); - } - private void onPass() { Delay(1000); @@ -281,18 +266,34 @@ namespace osu.Game.Screens.Play }); } - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); - (Background as BackgroundModeBeatmap)?.BlurTo(Vector2.Zero, 1000); + (Background as BackgroundScreenBeatmap)?.BlurTo(Vector2.Zero, 1000); Background?.FadeTo((100f - dimLevel) / 100, 1000); Content.Alpha = 0; dimLevel.ValueChanged += dimChanged; + + Content.Delay(250); + Content.FadeIn(250); + + Delay(750); + Schedule(() => + { + sourceClock.Start(); + initializeSkipButton(); + }); } - protected override bool OnExiting(GameMode next) + protected override void OnSuspending(Screen next) + { + Content.FadeOut(350); + base.OnSuspending(next); + } + + protected override bool OnExiting(Screen next) { if (pauseOverlay == null) return false; diff --git a/osu.Game/Screens/Ranking/Results.cs b/osu.Game/Screens/Ranking/Results.cs index 5e61f381e9..119bc49e1a 100644 --- a/osu.Game/Screens/Ranking/Results.cs +++ b/osu.Game/Screens/Ranking/Results.cs @@ -1,7 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -14,21 +14,21 @@ using OpenTK.Graphics; namespace osu.Game.Screens.Ranking { - class Results : OsuGameMode + class Results : OsuScreen { - protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap); private static readonly Vector2 background_blur = new Vector2(20); ScoreDisplay scoreDisplay; - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); - Background.Schedule(() => (Background as BackgroundModeBeatmap)?.BlurTo(background_blur, 1000)); + Background.Schedule(() => (Background as BackgroundScreenBeatmap)?.BlurTo(background_blur, 1000)); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { Background.Schedule(() => Background.FadeColour(Color4.White, 500)); return base.OnExiting(next); diff --git a/osu.Game/Screens/Select/EditSongSelect.cs b/osu.Game/Screens/Select/EditSongSelect.cs index 35c212bece..5eaaf1be64 100644 --- a/osu.Game/Screens/Select/EditSongSelect.cs +++ b/osu.Game/Screens/Select/EditSongSelect.cs @@ -8,12 +8,12 @@ using osu.Game.Screens.Edit; namespace osu.Game.Screens.Select { - class EditSongSelect : GameModeWhiteBox + class EditSongSelect : ScreenWhiteBox { protected override IEnumerable PossibleChildren => new[] { typeof(Editor) }; - protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4"); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4"); } } diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index 975a3f9ca3..23a61459ea 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -47,18 +47,19 @@ namespace osu.Game.Screens.Select Direction = FlowDirections.Vertical, Children = new Drawable[] { - searchTextBox = new SearchTextBox { RelativeSizeAxes = Axes.X }, + searchTextBox = new SearchTextBox { + RelativeSizeAxes = Axes.X, + OnChange = (TextBox sender, bool newText) => + { + if (newText) + FilterChanged?.Invoke(); + }, + Exit = () => Exit?.Invoke(), + }, new GroupSortTabs() } } }; - - searchTextBox.OnChange += (TextBox sender, bool newText) => - { - if (newText) - FilterChanged?.Invoke(); - }; - searchTextBox.Exit = () => Exit?.Invoke(); } public void Deactivate() diff --git a/osu.Game/Screens/Select/Footer.cs b/osu.Game/Screens/Select/Footer.cs index 55fb36f144..df926c0778 100644 --- a/osu.Game/Screens/Select/Footer.cs +++ b/osu.Game/Screens/Select/Footer.cs @@ -25,6 +25,8 @@ namespace osu.Game.Screens.Select private const float padding = 80; + public override bool Contains(Vector2 screenSpacePos) => true; + public Action OnBack; public Action OnStart; diff --git a/osu.Game/Screens/Select/MatchSongSelect.cs b/osu.Game/Screens/Select/MatchSongSelect.cs index de250197e7..4c9e7c9d37 100644 --- a/osu.Game/Screens/Select/MatchSongSelect.cs +++ b/osu.Game/Screens/Select/MatchSongSelect.cs @@ -5,8 +5,8 @@ using osu.Game.Screens.Backgrounds; namespace osu.Game.Screens.Select { - class MatchSongSelect : GameModeWhiteBox + class MatchSongSelect : ScreenWhiteBox { - protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4"); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4"); } } diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 1145c7b18a..fcb2bd4387 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -9,7 +9,7 @@ using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Track; using osu.Framework.Configuration; -using osu.Framework.GameModes; +using osu.Framework.Screens; using osu.Framework.Graphics; using osu.Framework.Graphics.Primitives; using osu.Game.Beatmaps; @@ -33,11 +33,11 @@ using osu.Game.Overlays.Mods; namespace osu.Game.Screens.Select { - public class PlaySongSelect : OsuGameMode + public class PlaySongSelect : OsuScreen { private Bindable playMode; private BeatmapDatabase database; - protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap); + protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap); private CarouselContainer carousel; private TrackManager trackManager; @@ -50,8 +50,8 @@ namespace osu.Game.Screens.Select private static readonly Vector2 background_blur = new Vector2(20); private CancellationTokenSource initialAddSetsTask; - private AudioSample sampleChangeDifficulty; - private AudioSample sampleChangeBeatmap; + private SampleChannel sampleChangeDifficulty; + private SampleChannel sampleChangeBeatmap; private List beatmapGroups; @@ -221,7 +221,7 @@ namespace osu.Game.Screens.Select Schedule(() => addBeatmapSet(s, Game, true)); } - protected override void OnEntering(GameMode last) + protected override void OnEntering(Screen last) { base.OnEntering(last); ensurePlayingSelected(); @@ -236,7 +236,7 @@ namespace osu.Game.Screens.Select filter.Activate(); } - protected override void OnResuming(GameMode last) + protected override void OnResuming(Screen last) { player = null; @@ -251,7 +251,7 @@ namespace osu.Game.Screens.Select filter.Activate(); } - protected override void OnSuspending(GameMode next) + protected override void OnSuspending(Screen next) { Content.ScaleTo(1.1f, 250, EasingTypes.InSine); @@ -261,7 +261,7 @@ namespace osu.Game.Screens.Select base.OnSuspending(next); } - protected override bool OnExiting(GameMode next) + protected override bool OnExiting(Screen next) { beatmapInfoWedge.MoveToX(-100, 800, EasingTypes.InQuint); beatmapInfoWedge.RotateTo(10, 800, EasingTypes.InQuint); @@ -290,7 +290,7 @@ namespace osu.Game.Screens.Select private void changeBackground(WorkingBeatmap beatmap) { - var backgroundModeBeatmap = Background as BackgroundModeBeatmap; + var backgroundModeBeatmap = Background as BackgroundScreenBeatmap; if (backgroundModeBeatmap != null) { backgroundModeBeatmap.Beatmap = beatmap; @@ -336,7 +336,7 @@ namespace osu.Game.Screens.Select private void ensurePlayingSelected(bool preview = false) { - AudioTrack track = Beatmap?.Track; + Track track = Beatmap?.Track; if (track != null) { @@ -356,11 +356,13 @@ namespace osu.Game.Screens.Select if (b.Metadata == null) b.Metadata = beatmapSet.Metadata; }); + foreach (var b in beatmapSet.Beatmaps) + b.ComputeDifficulty(database); beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.StarDifficulty).ToList(); var beatmap = new WorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault(), beatmapSet, database); - var group = new BeatmapGroup(beatmap, beatmapSet) + var group = new BeatmapGroup(beatmap) { SelectionChanged = selectionChanged, StartRequested = b => start() diff --git a/osu.Game/Screens/Select/SearchTextBox.cs b/osu.Game/Screens/Select/SearchTextBox.cs index 4cd5353712..aeb9db75db 100644 --- a/osu.Game/Screens/Select/SearchTextBox.cs +++ b/osu.Game/Screens/Select/SearchTextBox.cs @@ -16,26 +16,8 @@ namespace osu.Game.Screens.Select /// /// A textbox which holds focus eagerly. /// - public class SearchTextBox : OsuTextBox + public class SearchTextBox : FocusedTextBox { - protected override Color4 BackgroundUnfocused => new Color4(10, 10, 10, 255); - protected override Color4 BackgroundFocused => new Color4(10, 10, 10, 255); - public Action Exit; - - private bool focus; - public bool HoldFocus - { - get { return focus; } - set - { - focus = value; - if (!focus) - TriggerFocusLost(); - } - } - - public override bool RequestingFocus => HoldFocus; - public SearchTextBox() { Height = 35; @@ -53,25 +35,6 @@ namespace osu.Game.Screens.Select PlaceholderText = "type to search"; } - protected override bool OnFocus(InputState state) - { - var result = base.OnFocus(state); - BorderThickness = 0; - return result; - } - - protected override void OnFocusLost(InputState state) - { - if (state.Keyboard.Keys.Any(key => key == Key.Escape)) - { - if (Text.Length > 0) - Text = string.Empty; - else - Exit?.Invoke(); - } - base.OnFocusLost(state); - } - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { if (HandlePendingText(state)) return true; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 2c0a7fa6cb..cd68d6989d 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -66,10 +66,12 @@ + + @@ -123,15 +125,17 @@ - - - - - + + + + + - + + + @@ -146,7 +150,7 @@ - + @@ -187,7 +191,7 @@ - +