Move the inherited `AllowTrackAdjustments` into `OsuScreen`

This commit is contained in:
AbstractQbit 2021-09-15 10:55:16 +03:00
parent bd18c581c1
commit b87af3dd68
3 changed files with 13 additions and 18 deletions

View File

@ -1075,6 +1075,11 @@ protected virtual void ScreenChanged(IScreen current, IScreen newScreen)
OverlayActivationMode.BindTo(newOsuScreen.OverlayActivationMode); OverlayActivationMode.BindTo(newOsuScreen.OverlayActivationMode);
API.Activity.BindTo(newOsuScreen.Activity); API.Activity.BindTo(newOsuScreen.Activity);
if (newOsuScreen.AllowTrackAdjustments.HasValue)
MusicController.AllowTrackAdjustments = newOsuScreen.AllowTrackAdjustments.Value;
else
newOsuScreen.AllowTrackAdjustments = MusicController.AllowTrackAdjustments;
if (newOsuScreen.HideOverlaysOnEnter) if (newOsuScreen.HideOverlaysOnEnter)
CloseAllOverlays(); CloseAllOverlays();
else else
@ -1091,16 +1096,6 @@ private void screenPushed(IScreen lastScreen, IScreen newScreen)
{ {
ScreenChanged(lastScreen, newScreen); ScreenChanged(lastScreen, newScreen);
Logger.Log($"Screen changed → {newScreen}"); Logger.Log($"Screen changed → {newScreen}");
// set AllowTrackAdjustments if new screen defines it, inherit otherwise
if (newScreen is IOsuScreen newOsuScreen && newOsuScreen.AllowTrackAdjustments.HasValue)
allowTrackAdjustmentsDict[newScreen] = newOsuScreen.AllowTrackAdjustments.Value;
else if (allowTrackAdjustmentsDict.ContainsKey(lastScreen))
allowTrackAdjustmentsDict[newScreen] = allowTrackAdjustmentsDict[lastScreen];
else
allowTrackAdjustmentsDict[newScreen] = true;
MusicController.AllowTrackAdjustments = allowTrackAdjustmentsDict[newScreen];
} }
private void screenExited(IScreen lastScreen, IScreen newScreen) private void screenExited(IScreen lastScreen, IScreen newScreen)
@ -1108,16 +1103,10 @@ private void screenExited(IScreen lastScreen, IScreen newScreen)
ScreenChanged(lastScreen, newScreen); ScreenChanged(lastScreen, newScreen);
Logger.Log($"Screen changed ← {newScreen}"); Logger.Log($"Screen changed ← {newScreen}");
allowTrackAdjustmentsDict.Remove(lastScreen);
if (newScreen == null) if (newScreen == null)
Exit(); Exit();
else
MusicController.AllowTrackAdjustments = allowTrackAdjustmentsDict[newScreen];
} }
private readonly Dictionary<IScreen, bool> allowTrackAdjustmentsDict = new Dictionary<IScreen, bool>();
IBindable<bool> ILocalUserPlayInfo.IsPlaying => LocalUserPlaying; IBindable<bool> ILocalUserPlayInfo.IsPlaying => LocalUserPlaying;
} }
} }

View File

@ -62,7 +62,7 @@ public interface IOsuScreen : IScreen
/// Whether mod track adjustments are allowed to be applied. /// Whether mod track adjustments are allowed to be applied.
/// Null means to inherit from the parent screen. /// Null means to inherit from the parent screen.
/// </summary> /// </summary>
bool? AllowTrackAdjustments { get; } bool? AllowTrackAdjustments { set; get; }
/// <summary> /// <summary>
/// Invoked when the back button has been pressed to close any overlays before exiting this <see cref="IOsuScreen"/>. /// Invoked when the back button has been pressed to close any overlays before exiting this <see cref="IOsuScreen"/>.

View File

@ -81,7 +81,13 @@ public abstract class OsuScreen : Screen, IOsuScreen, IHasDescription
public virtual float BackgroundParallaxAmount => 1; public virtual float BackgroundParallaxAmount => 1;
public virtual bool? AllowTrackAdjustments => null; private bool? allowTrackAdjustments = null;
public virtual bool? AllowTrackAdjustments
{
set => allowTrackAdjustments = value;
get => allowTrackAdjustments;
}
public Bindable<WorkingBeatmap> Beatmap { get; private set; } public Bindable<WorkingBeatmap> Beatmap { get; private set; }