Revert leasing logic

This commit is contained in:
Bartłomiej Dach 2020-12-05 22:07:39 +01:00
parent 15ce7bacf1
commit 08f23cc424
2 changed files with 12 additions and 35 deletions

View File

@ -28,8 +28,6 @@ namespace osu.Game.Tests.Input
setWindowModeTo(windowMode);
setGameSideModeTo(OsuConfineMouseMode.Never);
gameSideConfineModeDisabled(false);
setLocalUserPlayingTo(false);
frameworkSideModeIs(ConfineMouseMode.Never);
@ -44,8 +42,6 @@ namespace osu.Game.Tests.Input
setWindowModeTo(windowMode);
setGameSideModeTo(OsuConfineMouseMode.DuringGameplay);
gameSideConfineModeDisabled(false);
setLocalUserPlayingTo(false);
frameworkSideModeIs(ConfineMouseMode.Never);
@ -60,8 +56,6 @@ namespace osu.Game.Tests.Input
setWindowModeTo(windowMode);
setGameSideModeTo(OsuConfineMouseMode.Always);
gameSideConfineModeDisabled(false);
setLocalUserPlayingTo(false);
frameworkSideModeIs(ConfineMouseMode.Always);
@ -75,20 +69,18 @@ namespace osu.Game.Tests.Input
setGameSideModeTo(OsuConfineMouseMode.Never);
setWindowModeTo(WindowMode.Fullscreen);
gameSideConfineModeDisabled(true);
setLocalUserPlayingTo(false);
frameworkSideModeIs(ConfineMouseMode.Always);
frameworkSideModeIs(ConfineMouseMode.Fullscreen);
setLocalUserPlayingTo(true);
frameworkSideModeIs(ConfineMouseMode.Always);
frameworkSideModeIs(ConfineMouseMode.Fullscreen);
setWindowModeTo(WindowMode.Windowed);
// old state is restored
gameSideModeIs(OsuConfineMouseMode.Never);
frameworkSideModeIs(ConfineMouseMode.Never);
gameSideConfineModeDisabled(false);
}
private void setWindowModeTo(WindowMode mode)
@ -106,9 +98,5 @@ namespace osu.Game.Tests.Input
private void frameworkSideModeIs(ConfineMouseMode mode)
=> AddAssert($"mode is {mode} framework-side", () => frameworkConfigManager.Get<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode) == mode);
private void gameSideConfineModeDisabled(bool disabled)
=> AddAssert($"game-side confine mode {(disabled ? "disabled" : "enabled")}",
() => Game.LocalConfig.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode).Disabled == disabled);
}
}

View File

@ -28,38 +28,27 @@ namespace osu.Game.Input
{
frameworkConfineMode = frameworkConfigManager.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode);
frameworkWindowMode = frameworkConfigManager.GetBindable<WindowMode>(FrameworkSetting.WindowMode);
frameworkWindowMode.BindValueChanged(_ => updateGameConfineMode());
frameworkWindowMode.BindValueChanged(_ => updateConfineMode());
osuConfineMode = osuConfigManager.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode);
localUserPlaying = game.LocalUserPlaying.GetBoundCopy();
osuConfineMode.ValueChanged += _ => updateFrameworkConfineMode();
localUserPlaying.BindValueChanged(_ => updateFrameworkConfineMode(), true);
osuConfineMode.ValueChanged += _ => updateConfineMode();
localUserPlaying.BindValueChanged(_ => updateConfineMode(), true);
}
private LeasedBindable<OsuConfineMouseMode> leasedOsuConfineMode;
private void updateGameConfineMode()
{
if (frameworkWindowMode.Value == WindowMode.Fullscreen && leasedOsuConfineMode == null)
{
leasedOsuConfineMode = osuConfineMode.BeginLease(true);
leasedOsuConfineMode.Value = OsuConfineMouseMode.Always;
}
if (frameworkWindowMode.Value != WindowMode.Fullscreen && leasedOsuConfineMode != null)
{
leasedOsuConfineMode.Return();
leasedOsuConfineMode = null;
}
}
private void updateFrameworkConfineMode()
private void updateConfineMode()
{
// confine mode is unavailable on some platforms
if (frameworkConfineMode.Disabled)
return;
if (frameworkWindowMode.Value == WindowMode.Fullscreen)
{
frameworkConfineMode.Value = ConfineMouseMode.Fullscreen;
return;
}
switch (osuConfineMode.Value)
{
case OsuConfineMouseMode.Never: