Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable mouse input when the debugger interaction tool is active #2209

Merged
merged 8 commits into from
Mar 10, 2019
5 changes: 5 additions & 0 deletions flixel/input/mouse/FlxMouseEventManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ class FlxMouseEventManager extends FlxBasic
}

#if FLX_MOUSE
// If mouse input is not enabled globally, prevent all tracked objects from responding to
// down/click/doubleclick/up events until mouse input is re-enabled.
if (!FlxG.mouse.enabled)
return;

// MouseMove - Look for objects with mouse over that have mouseMove callbacks
if (FlxG.mouse.justMoved)
{
Expand Down
11 changes: 7 additions & 4 deletions flixel/system/debug/FlxDebugger.hx
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,17 @@ class FlxDebugger extends Sprite
@:allow(flixel.system.debug)
function onMouseFocusLost():Void
{
#if FLX_MOUSE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor complaint, but it looks we just need a single FLX_MOUSE check for this entire function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, no need for two checks.

// Disable mouse input if the interaction tool is in use,
// so users can select interactable elements, e.g. buttons.
FlxG.mouse.enabled = !interaction.isInUse();

if (_usingSystemCursor)
{
#if FLX_MOUSE
FlxG.mouse.enabled = true;
FlxG.mouse.useSystemCursor = _wasUsingSystemCursor;
FlxG.mouse.visible = _wasMouseVisible;
#end
}
}
#end
}

inline function toggleDrawDebug():Void
Expand Down
19 changes: 19 additions & 0 deletions flixel/system/debug/interaction/Interaction.hx
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ class Interaction extends Window
activeTool.button.toggled = true;
}

// If the requested new tool is the same as the already active one,
// we deactive it (toggle behavior).
if (activeTool == value)
value = null;

Expand All @@ -468,6 +470,12 @@ class Interaction extends Window
// so the user can click buttons, drag windows, etc.
setSystemCursorVisibility(true);
}

#if FLX_MOUSE
// Allow mouse input only if the interaction tool is visible
// and no tool is active.
FlxG.mouse.enabled = !isInUse();
#end
}

function setSystemCursorVisibility(status:Bool):Void
Expand Down Expand Up @@ -510,6 +518,17 @@ class Interaction extends Window
var value:Int = _keysUp.get(key) == null ? 0 : _keysUp.get(key);
return (_turn - value) == 1;
}

/**
* Informs whether the interactive debug is in use or not. Usage is defined
* as the interactive debug being visible and one of its tools is selected/active.
*
* @return `true` if the interactive debug is visible and one of its tools is selected/active.
*/
public function isInUse():Bool
{
return FlxG.debugger.visible && visible && activeTool != null;
}

public function findItemsWithinState(items:Array<FlxBasic>, state:FlxState, area:FlxRect):Void
{
Expand Down
12 changes: 12 additions & 0 deletions flixel/system/frontEnds/DebuggerFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ class DebuggerFrontEnd
FlxG.stage.focus = null;
// setting focus to null will trigger a focus lost event, let's undo that
FlxG.game.onFocus(null);

#if FLX_MOUSE
FlxG.mouse.enabled = true;
#end
}
else
{
#if FLX_MOUSE
// Debugger is visible, allow mouse input in the game only if the
// interaction tool is not in use.
FlxG.mouse.enabled = !FlxG.game.debugger.interaction.isInUse();
#end
}

visibilityChanged.dispatch();
Expand Down
9 changes: 9 additions & 0 deletions flixel/ui/FlxButton.hx
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,15 @@ class FlxTypedButton<T:FlxSprite> extends FlxSprite implements IFlxInput
*/
function onOverHandler():Void
{
#if FLX_MOUSE
// If mouse input is not enabled, this button must ignore over actions
// by remaining in the normal state (until mouse input is re-enabled).
if (!FlxG.mouse.enabled)
{
status = FlxButton.NORMAL;
return;
}
#end
status = FlxButton.HIGHLIGHT;
// Order matters here, because onOver.fire() could cause a state change and destroy this object.
onOver.fire();
Expand Down