Implement VisualSettings autohiding

This commit is contained in:
TocoToucan 2018-01-11 23:39:23 +03:00
parent 98851e4a78
commit 3ec93966a0
2 changed files with 48 additions and 20 deletions

View File

@ -1,6 +1,8 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Timing;
@ -17,6 +19,23 @@ public class VisualSettings : ReplayGroup
public IAdjustableClock AudioClock { get; set; }
public FramedClock FramedClock { get; set; }
private bool autohide;
public bool Autohide
{
get => autohide;
set
{
autohide = value;
if (autohide && hideStopWatch == null)
hideStopWatch = Stopwatch.StartNew();
else if (!autohide)
hideStopWatch = null;
}
}
private readonly TimeSpan hideTimeSpan = TimeSpan.FromSeconds(5);
private Stopwatch hideStopWatch;
private readonly ReplaySliderBar<double> dimSliderBar;
private readonly ReplayCheckbox showStoryboardToggle;
private readonly ReplayCheckbox mouseWheelDisabledToggle;
@ -25,19 +44,18 @@ public VisualSettings()
{
Children = new Drawable[]
{
new OsuSpriteText
{
Text = "Background dim:"
},
dimSliderBar = new ReplaySliderBar<double>(),
new OsuSpriteText
{
Text = "Toggles:"
},
showStoryboardToggle = new ReplayCheckbox {LabelText = "Storyboards" },
mouseWheelDisabledToggle = new ReplayCheckbox { LabelText = "Disable mouse wheel" }
new OsuSpriteText
{
Text = "Background dim:"
},
dimSliderBar = new ReplaySliderBar<double>(),
new OsuSpriteText
{
Text = "Toggles:"
},
showStoryboardToggle = new ReplayCheckbox { LabelText = "Storyboards" },
mouseWheelDisabledToggle = new ReplayCheckbox { LabelText = "Disable mouse wheel" }
};
ToggleContentVisibility();
}
[BackgroundDependencyLoader]
@ -46,23 +64,34 @@ private void load(OsuConfigManager config)
dimSliderBar.Bindable = config.GetBindable<double>(OsuSetting.DimLevel);
showStoryboardToggle.Bindable = config.GetBindable<bool>(OsuSetting.ShowStoryboard);
mouseWheelDisabledToggle.Bindable = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
ToggleContentVisibility();
}
protected override void ToggleContentVisibility()
{
base.ToggleContentVisibility();
if (!Autohide)
return;
if (Expanded)
{
AudioClock?.Stop();
if (FramedClock != null)
FramedClock.ProcessSourceClockFrames = false;
AudioClock.Stop();
FramedClock.ProcessSourceClockFrames = false;
hideStopWatch.Stop();
}
else
{
AudioClock?.Start();
if (FramedClock != null)
FramedClock.ProcessSourceClockFrames = true;
AudioClock.Start();
FramedClock.ProcessSourceClockFrames = true;
hideStopWatch.Start();
}
}
protected override void Update()
{
base.Update();
if (Autohide && IsPresent && hideStopWatch.Elapsed > hideTimeSpan) this.FadeOut(100);
}
}
}

View File

@ -103,8 +103,7 @@ public virtual void BindRulesetContainer(RulesetContainer rulesetContainer)
if (!replayLoaded)
{
ReplaySettingsOverlay.PlaybackSettings.Hide();
// TODO Hide VisualSettings correctly. At least, It shouldn't dissapear in expanded state.
//ReplaySettingsOverlay.VisualSettings.Delay(10000).FadeOut(200);
ReplaySettingsOverlay.VisualSettings.Autohide = true;
ModDisplay.Delay(2000).FadeOut(200);
}
}