From f40b3a8fe3b59b22b0dc4cac9ce08437d5a34696 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 23 Aug 2021 18:52:07 -0400 Subject: [PATCH] FlxAction/Controls.hx accomodations for Android keys --- source/Controls.hx | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/source/Controls.hx b/source/Controls.hx index 342721780..b79dc6323 100644 --- a/source/Controls.hx +++ b/source/Controls.hx @@ -7,6 +7,9 @@ import flixel.input.actions.FlxActionInputAnalog.FlxActionInputAnalogClickAndDra import flixel.input.actions.FlxActionInputDigital; import flixel.input.actions.FlxActionManager; import flixel.input.actions.FlxActionSet; +import flixel.input.android.FlxAndroidKey; +import flixel.input.android.FlxAndroidKeyList; +import flixel.input.android.FlxAndroidKeys; import flixel.input.gamepad.FlxGamepadButton; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.keyboard.FlxKey; @@ -617,10 +620,12 @@ class Controls extends FlxActionSet case Custom: // nothing } - trace('added virtual controls!?'); - trace(virutalPad); - - if (FlxG.onMobile) {} + #if android + forEachBound(Control.BACK, function(action, pres) + { + action.add(new FlxActionInputDigitalAndroid(FlxAndroidKey.BACK, JUST_PRESSED)); + }); + #end } var virutalPad:FlxVirtualPad; @@ -822,3 +827,33 @@ typedef SaveInputLists = ?keys:Array, ?pad:Array }; + +// Maybe this can be committed to main HaxeFlixel repo? +class FlxActionInputDigitalAndroid extends FlxActionInputDigital +{ + /** + * Android buttons action input + * @param androidKeyID Key identifier (FlxAndroidKey.BACK, FlxAndroidKey.MENU... those are the only 2 lol) + * @param Trigger What state triggers this action (PRESSED, JUST_PRESSED, RELEASED, JUST_RELEASED) + */ + public function new(androidKeyID:FlxAndroidKey, Trigger:FlxInputState) + { + // if this gets PR'd into HF repo, the "OTHER" device should prob be changed to "MOBILE" or somethin + super(FlxInputDevice.OTHER, androidKeyID, Trigger); + } + + override public function check(Action:FlxAction):Bool + { + return switch (trigger) + { + #if android + case PRESSED: FlxG.android.checkStatus(inputID, PRESSED) || FlxG.android.checkStatus(inputID, PRESSED); + case RELEASED: FlxG.android.checkStatus(inputID, RELEASED) || FlxG.android.checkStatus(inputID, JUST_RELEASED); + case JUST_PRESSED: FlxG.android.checkStatus(inputID, JUST_PRESSED); + case JUST_RELEASED: FlxG.android.checkStatus(inputID, JUST_RELEASED); + #end + + default: false; + } + } +}