diff --git a/osu-resources b/osu-resources index ffccbeb98d..9f46a456dc 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit ffccbeb98dc9e8f0965520270b5885e63f244c83 +Subproject commit 9f46a456dc3a56dcbff09671a3f588b16a464106 diff --git a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs index ec50f19f98..9dcba02849 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs @@ -41,7 +41,7 @@ namespace osu.Desktop.VisualTests.Tests Clear(); ManiaPlayfield playField; - Add(playField = new ManiaPlayfield(cols, new List()) + Add(playField = new ManiaPlayfield(cols, new List { new TimingChange { BeatLength = 200 } }) { Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs index 8c896646bf..8772fc9f28 100644 --- a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -37,5 +37,7 @@ namespace osu.Desktop.Beatmaps.IO { // no-op } + + public override Stream GetUnderlyingStream() => null; } } diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs index d0519c61a8..42bb371975 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs @@ -1,10 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using OpenTK.Graphics; using OpenTK.Input; using osu.Framework.Configuration; using osu.Framework.Graphics; +using osu.Framework.Input; +using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; using osu.Game.Rulesets.Objects.Drawables; @@ -40,14 +43,53 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables } } - protected override void Update() + protected override void CheckJudgement(bool userTriggered) { - if (Time.Current > HitObject.StartTime) - Colour = Color4.Green; + if (!userTriggered) + { + if (Judgement.TimeOffset > HitObject.HitWindows.Bad / 2) + Judgement.Result = HitResult.Miss; + return; + } + + double offset = Math.Abs(Judgement.TimeOffset); + + if (offset > HitObject.HitWindows.Miss / 2) + return; + + ManiaHitResult? tmpResult = HitObject.HitWindows.ResultFor(offset); + + if (tmpResult.HasValue) + { + Judgement.Result = HitResult.Hit; + Judgement.ManiaResult = tmpResult.Value; + } + else + Judgement.Result = HitResult.Miss; } protected override void UpdateState(ArmedState state) { + switch (State) + { + case ArmedState.Hit: + Colour = Color4.Green; + break; + } + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (Judgement.Result != HitResult.None) + return false; + + if (args.Key != Key) + return false; + + if (args.Repeat) + return false; + + return UpdateJudgement(true); } } } diff --git a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs index 6d390464fe..cc8897840e 100644 --- a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs @@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Mania.Timing /// public double TimeSpan { get; set; } - private readonly List drawableControlPoints = new List(); + private readonly List drawableControlPoints; public ControlPointContainer(IEnumerable timingChanges) { diff --git a/osu.Game.Rulesets.Mania/Timing/TimingChange.cs b/osu.Game.Rulesets.Mania/Timing/TimingChange.cs index fb6f1d2db1..9153ba6991 100644 --- a/osu.Game.Rulesets.Mania/Timing/TimingChange.cs +++ b/osu.Game.Rulesets.Mania/Timing/TimingChange.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 - -namespace osu.Game.Rulesets.Mania.Timing -{ - public class TimingChange - { - /// - /// The time at which this timing change happened. - /// - public double Time; - - /// - /// The beat length. - /// - public double BeatLength = 500; - - /// - /// The speed multiplier. - /// - public double SpeedMultiplier = 1; - } +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Rulesets.Mania.Timing +{ + public class TimingChange + { + /// + /// The time at which this timing change happened. + /// + public double Time; + + /// + /// The beat length. + /// + public double BeatLength = 500; + + /// + /// The speed multiplier. + /// + public double SpeedMultiplier = 1; + } } \ No newline at end of file diff --git a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs index 4f87467706..82ceaeed1a 100644 --- a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs +++ b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs @@ -31,12 +31,12 @@ namespace osu.Game.Rulesets.Taiko.Objects public const float DEFAULT_STRONG_CIRCLE_DIAMETER = DEFAULT_CIRCLE_DIAMETER * STRONG_CIRCLE_DIAMETER_SCALE; /// - /// The time taken from the initial (off-screen) spawn position to the centre of the hit target for a of 1000ms. + /// The time taken from the initial (off-screen) spawn position to the centre of the hit target for a of 1000ms. /// private const double scroll_time = 6000; /// - /// Our adjusted taking into consideration local and other speed multipliers. + /// Our adjusted taking into consideration local and other speed multipliers. /// public double ScrollTime; diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/Beatmaps/IO/ArchiveReader.cs index 9d7d67007e..7ff5668b6f 100644 --- a/osu.Game/Beatmaps/IO/ArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/ArchiveReader.cs @@ -63,5 +63,7 @@ namespace osu.Game.Beatmaps.IO return buffer; } } + + public abstract Stream GetUnderlyingStream(); } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index 6c550def8d..eb9e740779 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -49,5 +49,7 @@ namespace osu.Game.Beatmaps.IO archive.Dispose(); archiveStream.Dispose(); } + + public override Stream GetUnderlyingStream() => archiveStream; } } \ No newline at end of file diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index bd25ebe8a9..efd5631077 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -12,6 +12,7 @@ using osu.Game.Beatmaps; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.IO; using osu.Game.IPC; +using osu.Game.Screens.Menu; using SQLite.Net; using SQLiteNetExtensions.Extensions; @@ -38,6 +39,10 @@ namespace osu.Game.Database { foreach (var b in GetAllWithChildren(b => b.DeletePending)) { + if (b.Hash == Intro.MENU_MUSIC_BEATMAP_HASH) + // this is a bit hacky, but will do for now. + continue; + try { Storage.Delete(b.Path); @@ -97,50 +102,49 @@ namespace osu.Game.Database typeof(BeatmapDifficulty), }; + public void Import(string path) + { + try + { + Import(ArchiveReader.GetReader(Storage, path)); + + // We may or may not want to delete the file depending on where it is stored. + // e.g. reconstructing/repairing database with beatmaps from default storage. + // Also, not always a single file, i.e. for LegacyFilesystemReader + // TODO: Add a check to prevent files from storage to be deleted. + try + { + File.Delete(path); + } + catch (Exception e) + { + Logger.Error(e, $@"Could not delete file at {path}"); + } + } + catch (Exception e) + { + e = e.InnerException ?? e; + Logger.Error(e, @"Could not import beatmap set"); + } + } + + public void Import(ArchiveReader archiveReader) + { + BeatmapSetInfo set = getBeatmapSet(archiveReader); + + //If we have an ID then we already exist in the database. + if (set.ID == 0) + Import(new[] { set }); + } + /// /// Import multiple from . /// /// Multiple locations on disk - public void Import(IEnumerable paths) + public void Import(params string[] paths) { foreach (string p in paths) - { - try - { - BeatmapSetInfo set = getBeatmapSet(p); - - //If we have an ID then we already exist in the database. - if (set.ID == 0) - Import(new[] { set }); - - // We may or may not want to delete the file depending on where it is stored. - // e.g. reconstructing/repairing database with beatmaps from default storage. - // Also, not always a single file, i.e. for LegacyFilesystemReader - // TODO: Add a check to prevent files from storage to be deleted. - try - { - File.Delete(p); - } - catch (Exception e) - { - Logger.Error(e, $@"Could not delete file at {p}"); - } - } - catch (Exception e) - { - e = e.InnerException ?? e; - Logger.Error(e, @"Could not import beatmap set"); - } - } - } - - /// - /// Import from . - /// - /// Location on disk - public void Import(string path) - { - Import(new[] { path }); + Import(p); } /// @@ -148,29 +152,26 @@ namespace osu.Game.Database /// /// Content location /// - private BeatmapSetInfo getBeatmapSet(string path) - { - string hash = null; + private BeatmapSetInfo getBeatmapSet(string path) => getBeatmapSet(ArchiveReader.GetReader(Storage, path)); + private BeatmapSetInfo getBeatmapSet(ArchiveReader archiveReader) + { BeatmapMetadata metadata; - using (var reader = ArchiveReader.GetReader(Storage, path)) - { - using (var stream = new StreamReader(reader.GetStream(reader.BeatmapFilenames[0]))) - metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata; - } + using (var stream = new StreamReader(archiveReader.GetStream(archiveReader.BeatmapFilenames[0]))) + metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata; - if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader + string hash; + string path; + + using (var input = archiveReader.GetUnderlyingStream()) { - using (var input = Storage.GetStream(path)) - { - hash = input.GetMd5Hash(); - input.Seek(0, SeekOrigin.Begin); - path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); - if (!Storage.Exists(path)) - using (var output = Storage.GetStream(path, FileAccess.Write)) - input.CopyTo(output); - } + hash = input.GetMd5Hash(); + input.Seek(0, SeekOrigin.Begin); + path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); + if (!Storage.Exists(path)) + using (var output = Storage.GetStream(path, FileAccess.Write)) + input.CopyTo(output); } var existing = Connection.Table().FirstOrDefault(b => b.Hash == hash); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 4cf436a8e4..f13043a745 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -82,7 +82,7 @@ namespace osu.Game if (args?.Length > 0) { var paths = args.Where(a => !a.StartsWith(@"-")); - Task.Run(() => BeatmapDatabase.Import(paths)); + Task.Run(() => BeatmapDatabase.Import(paths.ToArray())); } Dependencies.Cache(this); diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs index 9a5fd769cd..ea9ccd3492 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs @@ -4,6 +4,7 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; namespace osu.Game.Overlays.Settings.Sections.Graphics { @@ -11,11 +12,12 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics { protected override string Header => "Layout"; - private SettingsSlider letterboxPositionX; - private SettingsSlider letterboxPositionY; + private FillFlowContainer letterboxSettings; private Bindable letterboxing; + private const int transition_duration = 400; + [BackgroundDependencyLoader] private void load(FrameworkConfigManager config) { @@ -33,34 +35,40 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics LabelText = "Letterboxing", Bindable = letterboxing, }, - letterboxPositionX = new SettingsSlider + letterboxSettings = new FillFlowContainer { - LabelText = "Horizontal position", - Bindable = config.GetBindable(FrameworkSetting.LetterboxPositionX) - }, - letterboxPositionY = new SettingsSlider - { - LabelText = "Vertical position", - Bindable = config.GetBindable(FrameworkSetting.LetterboxPositionY) + Direction = FillDirection.Vertical, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + AutoSizeDuration = transition_duration, + AutoSizeEasing = EasingTypes.OutQuint, + Masking = true, + + Children = new Drawable[] + { + new SettingsSlider + { + LabelText = "Horizontal position", + Bindable = config.GetBindable(FrameworkSetting.LetterboxPositionX) + }, + new SettingsSlider + { + LabelText = "Vertical position", + Bindable = config.GetBindable(FrameworkSetting.LetterboxPositionY) + }, + } }, }; - letterboxing.ValueChanged += visibilityChanged; - letterboxing.TriggerChange(); - } + letterboxing.ValueChanged += isVisible => + { + letterboxSettings.ClearTransforms(); + letterboxSettings.AutoSizeAxes = isVisible ? Axes.Y : Axes.None; - private void visibilityChanged(bool newVisibility) - { - if (newVisibility) - { - letterboxPositionX.Show(); - letterboxPositionY.Show(); - } - else - { - letterboxPositionX.Hide(); - letterboxPositionY.Hide(); - } + if(!isVisible) + letterboxSettings.ResizeHeightTo(0, transition_duration, EasingTypes.OutQuint); + }; + letterboxing.TriggerChange(); } } } diff --git a/osu.Game/Screens/Menu/Intro.cs b/osu.Game/Screens/Menu/Intro.cs index 01659edd72..5791b7f196 100644 --- a/osu.Game/Screens/Menu/Intro.cs +++ b/osu.Game/Screens/Menu/Intro.cs @@ -8,7 +8,10 @@ using osu.Framework.Audio.Track; using osu.Framework.Configuration; using osu.Framework.Screens; using osu.Framework.Graphics; +using osu.Framework.MathUtils; +using osu.Game.Beatmaps.IO; using osu.Game.Configuration; +using osu.Game.Database; using osu.Game.Graphics.Containers; using osu.Game.Screens.Backgrounds; using OpenTK.Graphics; @@ -19,6 +22,8 @@ namespace osu.Game.Screens.Menu { private readonly OsuLogo logo; + public const string MENU_MUSIC_BEATMAP_HASH = "21c1271b91234385978b5418881fdd88"; + /// /// Whether we have loaded the menu previously. /// @@ -27,7 +32,6 @@ namespace osu.Game.Screens.Menu private MainMenu mainMenu; private SampleChannel welcome; private SampleChannel seeya; - private Track bgm; internal override bool HasLocalCursorDisplayed => true; @@ -60,15 +64,49 @@ namespace osu.Game.Screens.Menu private Bindable menuVoice; private Bindable menuMusic; + private Track track; [BackgroundDependencyLoader] - private void load(AudioManager audio, OsuConfigManager config) + private void load(AudioManager audio, OsuConfigManager config, BeatmapDatabase beatmaps, Framework.Game game) { menuVoice = config.GetBindable(OsuSetting.MenuVoice); menuMusic = config.GetBindable(OsuSetting.MenuMusic); - bgm = audio.Track.Get(@"circles"); - bgm.Looping = true; + var trackManager = audio.Track; + + BeatmapSetInfo setInfo = null; + + if (!menuMusic) + { + var query = beatmaps.Query().Where(b => !b.DeletePending); + int count = query.Count(); + if (count > 0) + setInfo = query.ElementAt(RNG.Next(0, count - 1)); + } + + if (setInfo == null) + { + var query = beatmaps.Query().Where(b => b.Hash == MENU_MUSIC_BEATMAP_HASH); + + setInfo = query.FirstOrDefault(); + + if (setInfo == null) + { + // we need to import the default menu background beatmap + beatmaps.Import(new OszArchiveReader(game.Resources.GetStream(@"Tracks/circles.osz"))); + + setInfo = query.First(); + + setInfo.DeletePending = true; + beatmaps.Update(setInfo, false); + } + } + + beatmaps.GetChildren(setInfo); + Beatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]); + + track = Beatmap.Track; + trackManager.SetExclusive(track); welcome = audio.Sample.Get(@"welcome"); seeya = audio.Sample.Get(@"seeya"); @@ -83,8 +121,7 @@ namespace osu.Game.Screens.Menu Scheduler.AddDelayed(delegate { - if (menuMusic) - bgm.Start(); + track.Start(); LoadComponentAsync(mainMenu = new MainMenu()); diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 71d020b0f2..b74ee52f9c 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -1,18 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Threading.Tasks; using OpenTK; using OpenTK.Input; using osu.Framework.Allocation; -using osu.Framework.Audio.Track; -using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Input; -using osu.Framework.MathUtils; using osu.Framework.Screens; -using osu.Game.Configuration; -using osu.Game.Database; using osu.Game.Graphics.Containers; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Charts; @@ -60,30 +54,11 @@ namespace osu.Game.Screens.Menu }; } - private Bindable menuMusic; - private TrackManager trackManager; - [BackgroundDependencyLoader] - private void load(OsuGame game, OsuConfigManager config, BeatmapDatabase beatmaps) + private void load(OsuGame game) { - menuMusic = config.GetBindable(OsuSetting.MenuMusic); LoadComponentAsync(background); - if (!menuMusic) - { - trackManager = game.Audio.Track; - - var query = beatmaps.Query().Where(b => !b.DeletePending); - int count = query.Count(); - - if (count > 0) - { - var beatmap = query.ElementAt(RNG.Next(0, count - 1)); - beatmaps.GetChildren(beatmap); - Beatmap = beatmaps.GetWorkingBeatmap(beatmap.Beatmaps[0]); - } - } - buttons.OnSettings = game.ToggleSettings; preloadSongSelect(); @@ -108,14 +83,13 @@ namespace osu.Game.Screens.Menu buttons.FadeInFromZero(500); if (last is Intro && Beatmap != null) { - Task.Run(() => + if (!Beatmap.Track.IsRunning) { - trackManager.SetExclusive(Beatmap.Track); Beatmap.Track.Seek(Beatmap.Metadata.PreviewTime); if (Beatmap.Metadata.PreviewTime == -1) Beatmap.Track.Seek(Beatmap.Track.Length * 0.4f); Beatmap.Track.Start(); - }); + } } } diff --git a/osu.Game/Screens/Play/HUDOverlay.cs b/osu.Game/Screens/Play/HUDOverlay.cs index 1e57c2ba2a..115611c244 100644 --- a/osu.Game/Screens/Play/HUDOverlay.cs +++ b/osu.Game/Screens/Play/HUDOverlay.cs @@ -30,7 +30,6 @@ namespace osu.Game.Screens.Play public readonly SongProgress Progress; public readonly ModDisplay ModDisplay; - private Bindable showKeyCounter; private Bindable showHud; private static bool hasShownNotificationOnce; @@ -67,24 +66,8 @@ namespace osu.Game.Screens.Play [BackgroundDependencyLoader(true)] private void load(OsuConfigManager config, NotificationManager notificationManager) { - showKeyCounter = config.GetBindable(OsuSetting.KeyOverlay); - showKeyCounter.ValueChanged += keyCounterVisibility => - { - if (keyCounterVisibility) - KeyCounter.FadeIn(duration); - else - KeyCounter.FadeOut(duration); - }; - showKeyCounter.TriggerChange(); - showHud = config.GetBindable(OsuSetting.ShowInterface); - showHud.ValueChanged += hudVisibility => - { - if (hudVisibility) - content.FadeIn(duration); - else - content.FadeOut(duration); - }; + showHud.ValueChanged += hudVisibility => content.FadeTo(hudVisibility ? 1 : 0, duration); showHud.TriggerChange(); if (!showHud && !hasShownNotificationOnce) diff --git a/osu.Game/Screens/Play/KeyCounterCollection.cs b/osu.Game/Screens/Play/KeyCounterCollection.cs index 4a561e6036..6e1c8a34e5 100644 --- a/osu.Game/Screens/Play/KeyCounterCollection.cs +++ b/osu.Game/Screens/Play/KeyCounterCollection.cs @@ -6,11 +6,18 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using OpenTK.Graphics; using osu.Framework.Input; +using osu.Framework.Configuration; +using osu.Framework.Allocation; +using osu.Game.Configuration; namespace osu.Game.Screens.Play { public class KeyCounterCollection : FillFlowContainer { + private const int duration = 100; + + private Bindable showKeyCounter; + public KeyCounterCollection() { AlwaysReceiveInput = true; @@ -34,6 +41,14 @@ namespace osu.Game.Screens.Play counter.ResetCount(); } + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + showKeyCounter = config.GetBindable(OsuSetting.KeyOverlay); + showKeyCounter.ValueChanged += keyCounterVisibility => FadeTo(keyCounterVisibility ? 1 : 0, duration); + showKeyCounter.TriggerChange(); + } + //further: change default values here and in KeyCounter if needed, instead of passing them in every constructor private bool isCounting; public bool IsCounting