1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 01:23:24 +08:00

Introduce KeyCounterMemento

This commit is contained in:
Roman Kapustin 2018-07-22 17:16:17 +03:00
parent 1796ffde14
commit 72959691e9
4 changed files with 32 additions and 4 deletions

View File

@ -79,7 +79,7 @@ namespace osu.Game.Screens.Play
BindRulesetContainer(rulesetContainer); BindRulesetContainer(rulesetContainer);
Progress.Objects = rulesetContainer.Objects; Progress.Objects = rulesetContainer.Objects;
Progress.AudioClock = offsetClock; Progress.AudioClock = KeyCounter.AudioClock = offsetClock;
Progress.AllowSeeking = rulesetContainer.HasReplayLoaded; Progress.AllowSeeking = rulesetContainer.HasReplayLoaded;
Progress.OnSeek = pos => adjustableClock.Seek(pos); Progress.OnSeek = pos => adjustableClock.Seek(pos);

View File

@ -6,6 +6,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Timing;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
@ -55,6 +56,8 @@ namespace osu.Game.Screens.Play
public Color4 KeyUpTextColor { get; set; } = Color4.White; public Color4 KeyUpTextColor { get; set; } = Color4.White;
public int FadeTime { get; set; } public int FadeTime { get; set; }
public IClock AudioClock { get; set; }
protected KeyCounter(string name) protected KeyCounter(string name)
{ {
Name = name; Name = name;
@ -129,5 +132,9 @@ namespace osu.Game.Screens.Play
} }
public void ResetCount() => CountPresses = 0; public void ResetCount() => CountPresses = 0;
public KeyCounterMemento SaveState() => new KeyCounterMemento(AudioClock.CurrentTime, CountPresses);
public void RestoreState(KeyCounterMemento memento) => CountPresses = memento.CountPresses;
} }
} }

View File

@ -3,14 +3,15 @@
using System; using System;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using OpenTK.Graphics;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Configuration; using osu.Framework.Timing;
using osu.Framework.Allocation;
using osu.Game.Configuration; using osu.Game.Configuration;
using OpenTK; using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
@ -36,6 +37,7 @@ namespace osu.Game.Screens.Play
key.FadeTime = FadeTime; key.FadeTime = FadeTime;
key.KeyDownTextColor = KeyDownTextColor; key.KeyDownTextColor = KeyDownTextColor;
key.KeyUpTextColor = KeyUpTextColor; key.KeyUpTextColor = KeyUpTextColor;
key.AudioClock = AudioClock;
} }
public void ResetCount() public void ResetCount()
@ -117,6 +119,8 @@ namespace osu.Game.Screens.Play
public override bool HandleKeyboardInput => receptor == null; public override bool HandleKeyboardInput => receptor == null;
public override bool HandleMouseInput => receptor == null; public override bool HandleMouseInput => receptor == null;
public IClock AudioClock { get; set; }
private Receptor receptor; private Receptor receptor;
public Receptor GetReceptor() public Receptor GetReceptor()

View File

@ -0,0 +1,17 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Screens.Play
{
public class KeyCounterMemento
{
public KeyCounterMemento(double currentTime, int countPresses)
{
CurrentTime = currentTime;
CountPresses = countPresses;
}
public double CurrentTime { get; }
public int CountPresses { get; }
}
}