Add prop FormBase.BlocksInputWhenFocused to simplify some logic

This commit is contained in:
YoshiRulz 2020-11-21 22:42:42 +10:00
parent e7f83cb492
commit 7596b97218
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 20 additions and 33 deletions

View File

@ -12,6 +12,8 @@ namespace BizHawk.Client.EmuHawk
{
private string? _windowTitleStatic;
public virtual bool BlocksInputWhenFocused { get; } = true;
public Config? Config { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

View File

@ -392,39 +392,18 @@ namespace BizHawk.Client.EmuHawk
Sound?.StartSound();
};
Input.Instance.MainFormInputAllowedCallback = yieldAlt => {
// the main form gets input
if (ActiveForm == this)
{
return Input.AllowInput.All;
}
// even more special logic for TAStudio:
// TODO - implement by event filter in TAStudio
if (ActiveForm is TAStudio maybeTAStudio)
{
if (yieldAlt || maybeTAStudio.IsInMenuLoop)
{
return Input.AllowInput.None;
}
}
// modals that need to capture input for binding purposes get input, of course
if (ActiveForm is HotkeyConfig
|| ActiveForm is ControllerConfig
|| ActiveForm is TAStudio
|| ActiveForm is VirtualpadTool)
{
return Input.AllowInput.All;
}
// if no form is active on this process, then the background input setting applies
if (ActiveForm == null && Config.AcceptBackgroundInput)
{
return Config.AcceptBackgroundInputControllerOnly ? Input.AllowInput.OnlyController : Input.AllowInput.All;
}
return Input.AllowInput.None;
Input.Instance.MainFormInputAllowedCallback = yieldAlt => ActiveForm switch
{
null => Config.AcceptBackgroundInput // none of our forms are focused, check the background input config
? Config.AcceptBackgroundInputControllerOnly
? Input.AllowInput.OnlyController
: Input.AllowInput.All
: Input.AllowInput.None,
TAStudio _ when yieldAlt => Input.AllowInput.None,
FormBase f when !f.BlocksInputWhenFocused => Input.AllowInput.All,
ControllerConfig _ => Input.AllowInput.All,
HotkeyConfig _ => Input.AllowInput.All,
_ => Input.AllowInput.None
};
Input.Instance.Adapter.FirstInitAll(Handle);
InitControls();
@ -627,6 +606,8 @@ namespace BizHawk.Client.EmuHawk
private readonly bool _suppressSyncSettingsWarning;
public override bool BlocksInputWhenFocused { get; } = false;
public int ProgramRunLoop()
{
CheckMessages(); // can someone leave a note about why this is needed?

View File

@ -15,6 +15,8 @@ namespace BizHawk.Client.EmuHawk
{
public partial class TAStudio : ToolFormBase, IToolFormAutoConfig, IControlMainform
{
public override bool BlocksInputWhenFocused => IsInMenuLoop;
// TODO: UI flow that conveniently allows to start from savestate
public ITasMovie CurrentTasMovie => MovieSession.Movie as ITasMovie;

View File

@ -22,6 +22,8 @@ namespace BizHawk.Client.EmuHawk
private bool _readOnly;
public override bool BlocksInputWhenFocused { get; } = false;
private List<VirtualPad> Pads =>
ControllerPanel.Controls
.OfType<VirtualPad>()