Improve TestCaseOnScreenDisplay

Now doesn't rely on framesync.
This commit is contained in:
smoogipoo 2018-05-10 15:49:37 +09:00
parent 853680ca51
commit c03ab9014f
2 changed files with 90 additions and 37 deletions

View File

@ -4,6 +4,8 @@
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Configuration.Tracking;
using osu.Framework.Graphics;
using osu.Game.Overlays; using osu.Game.Overlays;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
@ -11,36 +13,82 @@ namespace osu.Game.Tests.Visual
[TestFixture] [TestFixture]
public class TestCaseOnScreenDisplay : OsuTestCase public class TestCaseOnScreenDisplay : OsuTestCase
{ {
private FrameworkConfigManager config;
private Bindable<FrameSync> frameSyncMode;
protected override void LoadComplete()
{
base.LoadComplete();
Add(new OnScreenDisplay());
frameSyncMode = config.GetBindable<FrameSync>(FrameworkSetting.FrameSync);
FrameSync initial = frameSyncMode.Value;
AddRepeatStep(@"Change frame limiter", setNextMode, 3);
AddStep(@"Restore frame limiter", () => frameSyncMode.Value = initial);
}
private void setNextMode()
{
var nextMode = frameSyncMode.Value + 1;
if (nextMode > FrameSync.Unlimited)
nextMode = FrameSync.VSync;
frameSyncMode.Value = nextMode;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(FrameworkConfigManager config) private void load()
{ {
this.config = config; var config = new TestConfigManager();
var osd = new TestOnScreenDisplay();
osd.BeginTracking(this, config);
Add(osd);
AddRepeatStep("Change toggle (no bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingNoKeybind), 2);
AddRepeatStep("Change toggle (with bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingWithKeybind), 2);
AddRepeatStep("Change enum (no bind)", () => config.IncrementEnumSetting(TestConfigSetting.EnumSettingNoKeybind), 3);
AddRepeatStep("Change enum (with bind)", () => config.IncrementEnumSetting(TestConfigSetting.EnumSettingWithKeybind), 3);
}
private class TestConfigManager : ConfigManager<TestConfigSetting>
{
public TestConfigManager()
{
InitialiseDefaults();
}
protected override void InitialiseDefaults()
{
Set(TestConfigSetting.ToggleSettingNoKeybind, false);
Set(TestConfigSetting.EnumSettingNoKeybind, EnumSetting.Setting1);
Set(TestConfigSetting.ToggleSettingWithKeybind, false);
Set(TestConfigSetting.EnumSettingWithKeybind, EnumSetting.Setting1);
base.InitialiseDefaults();
}
public void ToggleSetting(TestConfigSetting setting) => Set(setting, !Get<bool>(setting));
public void IncrementEnumSetting(TestConfigSetting setting)
{
var nextValue = Get<EnumSetting>(setting) + 1;
if (nextValue > EnumSetting.Setting4)
nextValue = EnumSetting.Setting1;
Set(setting, nextValue);
}
public override TrackedSettings CreateTrackedSettings() => new TrackedSettings
{
new TrackedSetting<bool>(TestConfigSetting.ToggleSettingNoKeybind, b => new SettingDescription(b, "toggle setting with no keybind", b ? "enabled" : "disabled")),
new TrackedSetting<EnumSetting>(TestConfigSetting.EnumSettingNoKeybind, v => new SettingDescription(v, "enum setting with no keybind", v.ToString())),
new TrackedSetting<bool>(TestConfigSetting.ToggleSettingWithKeybind, b => new SettingDescription(b, "toggle setting with keybind", b ? "enabled" : "disabled", "fake keybind")),
new TrackedSetting<EnumSetting>(TestConfigSetting.EnumSettingWithKeybind, v => new SettingDescription(v, "enum setting with keybind", v.ToString(), "fake keybind")),
};
protected override void PerformLoad()
{
}
protected override bool PerformSave() => false;
}
private enum TestConfigSetting
{
ToggleSettingNoKeybind,
EnumSettingNoKeybind,
ToggleSettingWithKeybind,
EnumSettingWithKeybind
}
private enum EnumSetting
{
Setting1,
Setting2,
Setting3,
Setting4
}
private class TestOnScreenDisplay : OnScreenDisplay
{
protected override void Display(Drawable toDisplay) => toDisplay.FadeIn().ResizeHeightTo(110);
} }
} }
} }

View File

@ -102,12 +102,12 @@ public OnScreenDisplay()
}, },
textLine3 = new OsuSpriteText textLine3 = new OsuSpriteText
{ {
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Padding = new MarginPadding { Bottom = 15 }, Padding = new MarginPadding { Bottom = 15 },
Font = @"Exo2.0-Bold", Font = @"Exo2.0-Bold",
TextSize = 12, TextSize = 12,
Alpha = 0.3f, Alpha = 0.3f,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
}, },
} }
} }
@ -177,13 +177,7 @@ private void display(SettingDescription description)
textLine2.Text = description.Value; textLine2.Text = description.Value;
textLine3.Text = description.Shortcut.ToUpper(); textLine3.Text = description.Shortcut.ToUpper();
box.Animate( Display(box);
b => b.FadeIn(500, Easing.OutQuint),
b => b.ResizeHeightTo(height, 500, Easing.OutQuint)
).Then(
b => b.FadeOutFromOne(1500, Easing.InQuint),
b => b.ResizeHeightTo(height_contracted, 1500, Easing.InQuint)
);
int optionCount = 0; int optionCount = 0;
int selectedOption = -1; int selectedOption = -1;
@ -215,6 +209,17 @@ private void display(SettingDescription description)
}); });
} }
protected virtual void Display(Drawable toDisplay)
{
toDisplay.Animate(
b => b.FadeIn(500, Easing.OutQuint),
b => b.ResizeHeightTo(height, 500, Easing.OutQuint)
).Then(
b => b.FadeOutFromOne(1500, Easing.InQuint),
b => b.ResizeHeightTo(height_contracted, 1500, Easing.InQuint)
);
}
private class OptionLight : Container private class OptionLight : Container
{ {
private Color4 glowingColour, idleColour; private Color4 glowingColour, idleColour;