diff --git a/osu.Game.Rulesets.Osu/UI/Cursor/GameplayCursor.cs b/osu.Game.Rulesets.Osu/UI/Cursor/GameplayCursor.cs index 35146dfe29..4d6722b61b 100644 --- a/osu.Game.Rulesets.Osu/UI/Cursor/GameplayCursor.cs +++ b/osu.Game.Rulesets.Osu/UI/Cursor/GameplayCursor.cs @@ -39,6 +39,11 @@ public GameplayCursor() private int downCount; + private const float pressed_scale = 1.2f; + private const float released_scale = 1f; + + private float targetScale => downCount > 0 ? pressed_scale : released_scale; + public bool OnPressed(OsuAction action) { switch (action) @@ -46,7 +51,7 @@ public bool OnPressed(OsuAction action) case OsuAction.LeftButton: case OsuAction.RightButton: downCount++; - ActiveCursor.ScaleTo(1).ScaleTo(1.2f, 100, Easing.OutQuad); + ActiveCursor.ScaleTo(released_scale).ScaleTo(targetScale, 100, Easing.OutQuad); break; } @@ -60,7 +65,7 @@ public bool OnReleased(OsuAction action) case OsuAction.LeftButton: case OsuAction.RightButton: if (--downCount == 0) - ActiveCursor.ScaleTo(1, 200, Easing.OutQuad); + ActiveCursor.ScaleTo(targetScale, 200, Easing.OutQuad); break; } @@ -72,13 +77,13 @@ public bool OnReleased(OsuAction action) protected override void PopIn() { fadeContainer.FadeTo(1, 300, Easing.OutQuint); - ActiveCursor.ScaleTo(1, 400, Easing.OutQuint); + ActiveCursor.ScaleTo(targetScale, 400, Easing.OutQuint); } protected override void PopOut() { fadeContainer.FadeTo(0.05f, 450, Easing.OutQuint); - ActiveCursor.ScaleTo(0.8f, 450, Easing.OutQuint); + ActiveCursor.ScaleTo(targetScale * 0.8f, 450, Easing.OutQuint); } public class OsuCursor : Container diff --git a/osu.Game.Tests/Visual/TestCaseKeyCounter.cs b/osu.Game.Tests/Visual/TestCaseKeyCounter.cs index a20f67e336..b98875cd6a 100644 --- a/osu.Game.Tests/Visual/TestCaseKeyCounter.cs +++ b/osu.Game.Tests/Visual/TestCaseKeyCounter.cs @@ -18,7 +18,6 @@ public TestCaseKeyCounter() { Origin = Anchor.Centre, Anchor = Anchor.Centre, - IsCounting = true, Children = new KeyCounter[] { new KeyCounterKeyboard(Key.Z), diff --git a/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs b/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs index 0ec7dd059d..3fbf5417a8 100644 --- a/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs +++ b/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs @@ -16,7 +16,6 @@ using osu.Game.Screens.Select; using osu.Game.Screens.Select.Carousel; using osu.Game.Screens.Select.Filter; -using osu.Game.Tests.Platform; namespace osu.Game.Tests.Visual { @@ -28,6 +27,7 @@ public class TestCasePlaySongSelect : OsuTestCase private RulesetStore rulesets; private WorkingBeatmap defaultBeatmap; + private DatabaseContextFactory factory; public override IReadOnlyList RequiredTypes => new[] { @@ -59,10 +59,11 @@ private class TestSongSelect : PlaySongSelect [BackgroundDependencyLoader] private void load() { - var storage = new TestStorage(@"TestCasePlaySongSelect"); + factory = new DatabaseContextFactory(LocalStorage); + factory.ResetDatabase(); - // this is by no means clean. should be replacing inside of OsuGameBase somehow. - DatabaseContextFactory factory = new DatabaseContextFactory(storage); + using (var usage = factory.Get()) + usage.Migrate(); factory.ResetDatabase(); @@ -70,7 +71,7 @@ private void load() usage.Migrate(); Dependencies.Cache(rulesets = new RulesetStore(factory)); - Dependencies.Cache(manager = new BeatmapManager(storage, factory, rulesets, null, null) + Dependencies.Cache(manager = new BeatmapManager(LocalStorage, factory, rulesets, null, null) { DefaultBeatmap = defaultBeatmap = Beatmap.Default }); diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 3bd5c440c1..67f02c8ac4 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -123,7 +123,7 @@ protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader archiv private void validateOnlineIds(List beatmaps) { - var beatmapIds = beatmaps.Where(b => b.OnlineBeatmapID.HasValue).Select(b => b.OnlineBeatmapID); + var beatmapIds = beatmaps.Where(b => b.OnlineBeatmapID.HasValue).Select(b => b.OnlineBeatmapID).ToList(); // ensure all IDs are unique in this set and none match existing IDs in the local beatmap store. if (beatmapIds.GroupBy(b => b).Any(g => g.Count() > 1) || QueryBeatmaps(b => beatmapIds.Contains(b.OnlineBeatmapID)).Any()) diff --git a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs index 48512a71c2..dc1cd5ed3b 100644 --- a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs +++ b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs @@ -30,6 +30,8 @@ public HitObject Parse(string text, double offset) { string[] split = text.Split(','); + Vector2 pos = new Vector2((int)Convert.ToSingle(split[0], CultureInfo.InvariantCulture), (int)Convert.ToSingle(split[1], CultureInfo.InvariantCulture)); + ConvertHitObjectType type = (ConvertHitObjectType)int.Parse(split[3]) & ~ConvertHitObjectType.ColourHax; bool combo = type.HasFlag(ConvertHitObjectType.NewCombo); type &= ~ConvertHitObjectType.NewCombo; @@ -41,15 +43,13 @@ public HitObject Parse(string text, double offset) if (type.HasFlag(ConvertHitObjectType.Circle)) { - result = CreateHit(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo); + result = CreateHit(pos, combo); if (split.Length > 5) readCustomSampleBanks(split[5], bankInfo); } else if (type.HasFlag(ConvertHitObjectType.Slider)) { - var pos = new Vector2(int.Parse(split[0]), int.Parse(split[1])); - CurveType curveType = CurveType.Catmull; double length = 0; var points = new List { Vector2.Zero }; @@ -170,7 +170,7 @@ public HitObject Parse(string text, double offset) readCustomSampleBanks(string.Join(":", ss.Skip(1)), bankInfo); } - result = CreateHold(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo, endTime + offset); + result = CreateHold(pos, combo, endTime + offset); } if (result == null) diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index d68afdfedc..ee34e2df04 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -89,6 +89,14 @@ protected RulesetContainer(Ruleset ruleset) Ruleset = ruleset; playfield = new Lazy(CreatePlayfield); + IsPaused.ValueChanged += paused => + { + if (HasReplayLoaded) + return; + + KeyBindingInputManager.UseParentInput = !paused; + }; + Cursor = CreateCursor(); } @@ -120,6 +128,11 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl public Replay Replay { get; private set; } + /// + /// Whether the game is paused. Used to block user input. + /// + public readonly BindableBool IsPaused = new BindableBool(); + /// /// Sets a replay to be used, overriding local input. /// diff --git a/osu.Game/Screens/Play/HUDOverlay.cs b/osu.Game/Screens/Play/HUDOverlay.cs index f920b20649..4f3fe15211 100644 --- a/osu.Game/Screens/Play/HUDOverlay.cs +++ b/osu.Game/Screens/Play/HUDOverlay.cs @@ -195,7 +195,6 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) protected virtual KeyCounterCollection CreateKeyCounter() => new KeyCounterCollection { - IsCounting = true, FadeTime = 50, Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, diff --git a/osu.Game/Screens/Play/KeyCounter.cs b/osu.Game/Screens/Play/KeyCounter.cs index 2a0587133b..2c31e61114 100644 --- a/osu.Game/Screens/Play/KeyCounter.cs +++ b/osu.Game/Screens/Play/KeyCounter.cs @@ -19,7 +19,7 @@ public abstract class KeyCounter : Container private Container textLayer; private SpriteText countSpriteText; - public bool IsCounting { get; set; } + public bool IsCounting { get; set; } = true; private int countPresses; public int CountPresses { diff --git a/osu.Game/Screens/Play/KeyCounterCollection.cs b/osu.Game/Screens/Play/KeyCounterCollection.cs index 114ea83ba6..721d925d63 100644 --- a/osu.Game/Screens/Play/KeyCounterCollection.cs +++ b/osu.Game/Screens/Play/KeyCounterCollection.cs @@ -53,8 +53,7 @@ private void load(OsuConfigManager config) configVisibility.BindValueChanged(_ => updateVisibility(), true); } - //further: change default values here and in KeyCounter if needed, instead of passing them in every constructor - private bool isCounting; + private bool isCounting = true; public bool IsCounting { get { return isCounting; } diff --git a/osu.Game/Screens/Play/PauseContainer.cs b/osu.Game/Screens/Play/PauseContainer.cs index e2f133dde3..d9677e5daf 100644 --- a/osu.Game/Screens/Play/PauseContainer.cs +++ b/osu.Game/Screens/Play/PauseContainer.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Timing; @@ -18,7 +19,7 @@ namespace osu.Game.Screens.Play /// public class PauseContainer : Container { - public bool IsPaused { get; private set; } + public readonly BindableBool IsPaused = new BindableBool(); public Func CheckCanPause; @@ -39,9 +40,6 @@ public class PauseContainer : Container public Action OnRetry; public Action OnQuit; - public Action OnResume; - public Action OnPause; - private readonly FramedClock framedClock; private readonly DecoupleableInterpolatingFramedClock decoupledClock; @@ -84,9 +82,8 @@ public void Pause(bool force = false) => Schedule(() => // Scheduled to ensure a // stop the seekable clock (stops the audio eventually) decoupledClock.Stop(); - IsPaused = true; + IsPaused.Value = true; - OnPause?.Invoke(); pauseOverlay.Show(); lastPauseActionTime = Time.Current; @@ -96,7 +93,7 @@ public void Resume() { if (!IsPaused) return; - IsPaused = false; + IsPaused.Value = false; IsResuming = false; lastPauseActionTime = Time.Current; @@ -105,7 +102,6 @@ public void Resume() decoupledClock.Seek(decoupledClock.CurrentTime); decoupledClock.Start(); - OnResume?.Invoke(); pauseOverlay.Hide(); } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index fc439a48c5..f28ddb09a2 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -162,15 +162,10 @@ private void load(AudioManager audio, APIAccess api, OsuConfigManager config) { pauseContainer = new PauseContainer(offsetClock, adjustableClock) { + Retries = RestartCount, OnRetry = Restart, OnQuit = Exit, CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded, - OnPause = () => - { - pauseContainer.Retries = RestartCount; - hudOverlay.KeyCounter.IsCounting = !pauseContainer.IsPaused; - }, - OnResume = () => hudOverlay.KeyCounter.IsCounting = true, Children = new[] { storyboardContainer = new Container @@ -227,6 +222,8 @@ private void load(AudioManager audio, APIAccess api, OsuConfigManager config) hudOverlay.HoldToQuit.Action = Exit; hudOverlay.KeyCounter.Visible.BindTo(RulesetContainer.HasReplayLoaded); + RulesetContainer.IsPaused.BindTo(pauseContainer.IsPaused); + if (ShowStoryboard) initializeStoryboard(false); diff --git a/osu.Game/Tests/Platform/TestStorage.cs b/osu.Game/Tests/Platform/TestStorage.cs deleted file mode 100644 index a6b6b5530d..0000000000 --- a/osu.Game/Tests/Platform/TestStorage.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Platform; - -namespace osu.Game.Tests.Platform -{ - public class TestStorage : DesktopStorage - { - public TestStorage(string baseName) - : base(baseName, null) - { - } - - public override string GetDatabaseConnectionString(string name) => "Data Source=" + GetUsablePathFor($"{(object)name}.db", true); - } -} diff --git a/osu.Game/Tests/Visual/OsuTestCase.cs b/osu.Game/Tests/Visual/OsuTestCase.cs index fcbab5b8f5..8e09ec849c 100644 --- a/osu.Game/Tests/Visual/OsuTestCase.cs +++ b/osu.Game/Tests/Visual/OsuTestCase.cs @@ -1,10 +1,12 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Configuration; +using osu.Framework.Platform; using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Rulesets; @@ -20,6 +22,9 @@ public abstract class OsuTestCase : TestCase protected DependencyContainer Dependencies { get; private set; } + private readonly Lazy localStorage; + protected Storage LocalStorage => localStorage.Value; + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { Dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); @@ -33,6 +38,11 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl return Dependencies; } + protected OsuTestCase() + { + localStorage = new Lazy(() => new DesktopStorage($"{GetType().Name}-{Guid.NewGuid()}", null)); + } + [BackgroundDependencyLoader] private void load(AudioManager audioManager, RulesetStore rulesets) { @@ -50,6 +60,9 @@ protected override void Dispose(bool isDisposing) beatmap.Disabled = true; beatmap.Value.Track.Stop(); } + + if (localStorage.IsValueCreated) + localStorage.Value.DeleteDirectory("."); } protected override ITestCaseTestRunner CreateRunner() => new OsuTestCaseTestRunner();