2020-07-01 23:15:41 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
using osu.Game.Configuration;
|
2021-08-17 15:13:45 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2020-07-01 23:15:41 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Desktop.Windows
|
|
|
|
|
{
|
2020-07-24 15:38:48 +08:00
|
|
|
|
public partial class GameplayWinKeyBlocker : Component
|
2020-07-01 23:15:41 +08:00
|
|
|
|
{
|
2022-08-02 22:23:54 +08:00
|
|
|
|
private Bindable<bool> disableWinKey = null!;
|
2024-10-01 18:55:46 +08:00
|
|
|
|
private IBindable<LocalUserPlayingState> localUserPlaying = null!;
|
2022-08-02 22:23:54 +08:00
|
|
|
|
private IBindable<bool> isActive = null!;
|
2020-07-01 23:15:41 +08:00
|
|
|
|
|
2020-10-10 12:11:36 +08:00
|
|
|
|
[Resolved]
|
2022-08-02 22:23:54 +08:00
|
|
|
|
private GameHost host { get; set; } = null!;
|
2020-07-01 23:15:41 +08:00
|
|
|
|
|
2020-10-10 12:28:24 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2021-08-17 15:13:45 +08:00
|
|
|
|
private void load(ILocalUserPlayInfo localUserInfo, OsuConfigManager config)
|
2020-07-01 23:15:41 +08:00
|
|
|
|
{
|
2024-10-01 16:00:32 +08:00
|
|
|
|
localUserPlaying = localUserInfo.PlayingState.GetBoundCopy();
|
2020-10-10 12:11:36 +08:00
|
|
|
|
localUserPlaying.BindValueChanged(_ => updateBlocking());
|
2020-07-01 23:15:41 +08:00
|
|
|
|
|
2021-12-20 16:38:14 +08:00
|
|
|
|
isActive = host.IsActive.GetBoundCopy();
|
|
|
|
|
isActive.BindValueChanged(_ => updateBlocking());
|
|
|
|
|
|
2020-07-23 03:45:27 +08:00
|
|
|
|
disableWinKey = config.GetBindable<bool>(OsuSetting.GameplayDisableWinKey);
|
2020-07-24 15:38:48 +08:00
|
|
|
|
disableWinKey.BindValueChanged(_ => updateBlocking(), true);
|
2020-07-01 23:15:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 15:38:48 +08:00
|
|
|
|
private void updateBlocking()
|
2020-07-01 23:15:41 +08:00
|
|
|
|
{
|
2024-10-01 18:55:46 +08:00
|
|
|
|
bool shouldDisable = isActive.Value && disableWinKey.Value && localUserPlaying.Value == LocalUserPlayingState.Playing;
|
2020-07-23 18:45:14 +08:00
|
|
|
|
|
2020-07-24 15:38:48 +08:00
|
|
|
|
if (shouldDisable)
|
2020-07-01 23:15:41 +08:00
|
|
|
|
host.InputThread.Scheduler.Add(WindowsKey.Disable);
|
|
|
|
|
else
|
|
|
|
|
host.InputThread.Scheduler.Add(WindowsKey.Enable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|