From 4ffe715c6f9cbe00a552360ba70cc881c766f988 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Fri, 22 Dec 2023 15:39:42 -0600 Subject: [PATCH] remove destroyed gamepad input checkers --- flixel/addons/ui/FlxMultiGamepad.hx | 10 ---- flixel/addons/ui/FlxUICursor.hx | 74 ++++++++++++++++------------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/flixel/addons/ui/FlxMultiGamepad.hx b/flixel/addons/ui/FlxMultiGamepad.hx index 77662786..c8915169 100644 --- a/flixel/addons/ui/FlxMultiGamepad.hx +++ b/flixel/addons/ui/FlxMultiGamepad.hx @@ -28,36 +28,26 @@ class FlxMultiGamepad extends FlxBaseMultiInput private override function checkJustPressed():Bool { - if (gamepad == null) - return false; return gamepad.checkStatus(input, JUST_PRESSED); } private override function checkJustReleased():Bool { - if (gamepad == null) - return false; return gamepad.checkStatus(input, JUST_RELEASED); } private override function checkPressed():Bool { - if (gamepad == null) - return false; return gamepad.checkStatus(input, PRESSED); } private override function checkCombos(value:Bool):Bool { - if (gamepad == null) - return false; return gamepad.anyPressed(combos) == value; } private override function checkForbiddens(value:Bool):Bool { - if (gamepad == null) - return false; return gamepad.anyPressed(forbiddens) == value; } } diff --git a/flixel/addons/ui/FlxUICursor.hx b/flixel/addons/ui/FlxUICursor.hx index afe1413d..8d98a35d 100644 --- a/flixel/addons/ui/FlxUICursor.hx +++ b/flixel/addons/ui/FlxUICursor.hx @@ -606,12 +606,14 @@ class FlxUICursor extends FlxUISprite _defaultCode = code; _clearKeys(); _newKeys(); + if (code.has(KEYS_TAB)) { _addToKeys(keysRight, new FlxMultiKey(TAB, null, [SHIFT])); // Tab, (but NOT Shift+Tab!) _addToKeys(keysLeft, new FlxMultiKey(TAB, [SHIFT])); // Shift+Tab _addToKeys(keysClick, new FlxMultiKey(ENTER)); } + if (code.has(KEYS_ARROWS)) { _addToKeys(keysRight, new FlxMultiKey(RIGHT)); @@ -620,6 +622,7 @@ class FlxUICursor extends FlxUISprite _addToKeys(keysUp, new FlxMultiKey(UP)); _addToKeys(keysClick, new FlxMultiKey(ENTER)); } + if (code.has(KEYS_WASD)) { _addToKeys(keysRight, new FlxMultiKey(D)); @@ -628,6 +631,7 @@ class FlxUICursor extends FlxUISprite _addToKeys(keysUp, new FlxMultiKey(W)); _addToKeys(keysClick, new FlxMultiKey(ENTER)); } + if (code.has(KEYS_NUMPAD)) { _addToKeys(keysRight, new FlxMultiKey(NUMPADSIX)); @@ -636,42 +640,46 @@ class FlxUICursor extends FlxUISprite _addToKeys(keysUp, new FlxMultiKey(NUMPADEIGHT)); _addToKeys(keysClick, new FlxMultiKey(ENTER)); } - + #if FLX_GAMEPAD - if (gamepad == null) - { + if (_gamepad == null || !_gamepad.connected) _gamepad = getGamepad(); // set _gamepad to avoid a stack overflow loop - } - - if (code.has(GAMEPAD_DPAD)) - { - _addToKeys(keysLeft, new FlxMultiGamepad(gamepad, FlxGamepadInputID.DPAD_LEFT)); - _addToKeys(keysRight, new FlxMultiGamepad(gamepad, FlxGamepadInputID.DPAD_RIGHT)); - _addToKeys(keysDown, new FlxMultiGamepad(gamepad, FlxGamepadInputID.DPAD_DOWN)); - _addToKeys(keysUp, new FlxMultiGamepad(gamepad, FlxGamepadInputID.DPAD_UP)); - _addToKeys(keysClick, new FlxMultiGamepad(gamepad, FlxGamepadInputID.A)); - } - if (code.has(GAMEPAD_SHOULDER_BUTTONS)) - { - _addToKeys(keysLeft, new FlxMultiGamepad(gamepad, FlxGamepadInputID.LEFT_SHOULDER)); - _addToKeys(keysRight, new FlxMultiGamepad(gamepad, FlxGamepadInputID.RIGHT_SHOULDER)); - _addToKeys(keysClick, new FlxMultiGamepad(gamepad, FlxGamepadInputID.A)); - } - if (code.has(GAMEPAD_LEFT_STICK)) - { - _addToKeys(keysLeft, new FlxMultiGamepadAnalogStick(gamepad, {id: LEFT_ANALOG_STICK, axis: X, positive: false})); - _addToKeys(keysRight, new FlxMultiGamepadAnalogStick(gamepad, {id: LEFT_ANALOG_STICK, axis: X, positive: true})); - _addToKeys(keysUp, new FlxMultiGamepadAnalogStick(gamepad, {id: LEFT_ANALOG_STICK, axis: Y, positive: false})); - _addToKeys(keysDown, new FlxMultiGamepadAnalogStick(gamepad, {id: LEFT_ANALOG_STICK, axis: Y, positive: true})); - _addToKeys(keysClick, new FlxMultiGamepad(gamepad, FlxGamepadInputID.A)); - } - if (code.has(GAMEPAD_RIGHT_STICK)) + + if (_gamepad != null && _gamepad.connected) { - _addToKeys(keysLeft, new FlxMultiGamepadAnalogStick(gamepad, {id: RIGHT_ANALOG_STICK, axis: X, positive: false})); - _addToKeys(keysRight, new FlxMultiGamepadAnalogStick(gamepad, {id: RIGHT_ANALOG_STICK, axis: X, positive: true})); - _addToKeys(keysUp, new FlxMultiGamepadAnalogStick(gamepad, {id: RIGHT_ANALOG_STICK, axis: Y, positive: false})); - _addToKeys(keysDown, new FlxMultiGamepadAnalogStick(gamepad, {id: RIGHT_ANALOG_STICK, axis: Y, positive: true})); - _addToKeys(keysClick, new FlxMultiGamepad(gamepad, FlxGamepadInputID.A)); + if (code.has(GAMEPAD_DPAD)) + { + _addToKeys(keysLeft, new FlxMultiGamepad(gamepad, FlxGamepadInputID.DPAD_LEFT)); + _addToKeys(keysRight, new FlxMultiGamepad(gamepad, FlxGamepadInputID.DPAD_RIGHT)); + _addToKeys(keysDown, new FlxMultiGamepad(gamepad, FlxGamepadInputID.DPAD_DOWN)); + _addToKeys(keysUp, new FlxMultiGamepad(gamepad, FlxGamepadInputID.DPAD_UP)); + _addToKeys(keysClick, new FlxMultiGamepad(gamepad, FlxGamepadInputID.A)); + } + + if (code.has(GAMEPAD_SHOULDER_BUTTONS)) + { + _addToKeys(keysLeft, new FlxMultiGamepad(gamepad, FlxGamepadInputID.LEFT_SHOULDER)); + _addToKeys(keysRight, new FlxMultiGamepad(gamepad, FlxGamepadInputID.RIGHT_SHOULDER)); + _addToKeys(keysClick, new FlxMultiGamepad(gamepad, FlxGamepadInputID.A)); + } + + if (code.has(GAMEPAD_LEFT_STICK)) + { + _addToKeys(keysLeft, new FlxMultiGamepadAnalogStick(gamepad, {id: LEFT_ANALOG_STICK, axis: X, positive: false})); + _addToKeys(keysRight, new FlxMultiGamepadAnalogStick(gamepad, {id: LEFT_ANALOG_STICK, axis: X, positive: true})); + _addToKeys(keysUp, new FlxMultiGamepadAnalogStick(gamepad, {id: LEFT_ANALOG_STICK, axis: Y, positive: false})); + _addToKeys(keysDown, new FlxMultiGamepadAnalogStick(gamepad, {id: LEFT_ANALOG_STICK, axis: Y, positive: true})); + _addToKeys(keysClick, new FlxMultiGamepad(gamepad, FlxGamepadInputID.A)); + } + + if (code.has(GAMEPAD_RIGHT_STICK)) + { + _addToKeys(keysLeft, new FlxMultiGamepadAnalogStick(gamepad, {id: RIGHT_ANALOG_STICK, axis: X, positive: false})); + _addToKeys(keysRight, new FlxMultiGamepadAnalogStick(gamepad, {id: RIGHT_ANALOG_STICK, axis: X, positive: true})); + _addToKeys(keysUp, new FlxMultiGamepadAnalogStick(gamepad, {id: RIGHT_ANALOG_STICK, axis: Y, positive: false})); + _addToKeys(keysDown, new FlxMultiGamepadAnalogStick(gamepad, {id: RIGHT_ANALOG_STICK, axis: Y, positive: true})); + _addToKeys(keysClick, new FlxMultiGamepad(gamepad, FlxGamepadInputID.A)); + } } #end }