From 5a3644d26e9e8ddc7d8a98eb3e8444ebf292cf01 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 6 Jul 2023 09:47:46 -0600 Subject: [PATCH] SimpleWindow first pass at gamepad support --- simplewindow-test/source/PlayState.kiss | 13 ++++++++++++- src/kiss_flixel/SimpleWindow.hx | 4 ++++ src/kiss_flixel/SimpleWindow.kiss | 22 +++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/simplewindow-test/source/PlayState.kiss b/simplewindow-test/source/PlayState.kiss index ce06a6b..8baddc2 100644 --- a/simplewindow-test/source/PlayState.kiss +++ b/simplewindow-test/source/PlayState.kiss @@ -14,10 +14,21 @@ ("Vertical" null) ("Menu" - null) + (subMenu)) ("Quit" (Sys.exit 0)) (never otherwise)))) +(method subMenu [] + (.enableGamepadInput + (SimpleWindow.promptForChoice "SubMenu" ["A" "B" "C" "{tab} Back"] + ->:Void choice + (case choice + ("{tab} Back" (showMenu)) + (never otherwise))) + true + null + [=>B "tab"])) + (method &override :Void update [:Float elapsed] (super.update elapsed)) \ No newline at end of file diff --git a/src/kiss_flixel/SimpleWindow.hx b/src/kiss_flixel/SimpleWindow.hx index aa98a40..db7d665 100644 --- a/src/kiss_flixel/SimpleWindow.hx +++ b/src/kiss_flixel/SimpleWindow.hx @@ -11,6 +11,10 @@ import flixel.FlxSprite; import flixel.util.FlxColor; import flixel.group.FlxGroup; import kiss_flixel.FlxKeyShortcutHandler; +import flixel.input.actions.FlxAction; +import flixel.input.actions.FlxActionInput; +import flixel.input.FlxInput; +import flixel.input.gamepad.FlxGamepadInputID; typedef ShortcutAction = Void->Void; typedef Action = FlxSprite->Void; diff --git a/src/kiss_flixel/SimpleWindow.kiss b/src/kiss_flixel/SimpleWindow.kiss index f66bb8c..f09b055 100644 --- a/src/kiss_flixel/SimpleWindow.kiss +++ b/src/kiss_flixel/SimpleWindow.kiss @@ -495,4 +495,24 @@ // Irreversibly disable the window's buttons (for when you're going to hide it in the next frame) (method clearActions [] - (_actions.clear)) \ No newline at end of file + (_actions.clear)) + +(method enableGamepadInput [:Bool addDefaultUIInputs &opt :Map uiKeyMappings :Map otherKeyMappings :Int gamepadId] + (unless uiKeyMappings (set uiKeyMappings (new Map))) + (localVar DEFAULT_UI_INPUTS [ + =>xKey [B] + =>leftKey [DPAD_LEFT LEFT_STICK_DIGITAL_LEFT] + =>rightKey [DPAD_RIGHT LEFT_STICK_DIGITAL_RIGHT] + =>upKey [DPAD_UP LEFT_STICK_DIGITAL_UP] + =>downKey [DPAD_DOWN LEFT_STICK_DIGITAL_DOWN] + =>enterKey [A START] + ]) + (when addDefaultUIInputs + (doFor key [xKey leftKey rightKey upKey downKey enterKey] + (whenLet [key key buttons (dictGet DEFAULT_UI_INPUTS key)] + (doFor button buttons + (dictSet uiKeyMappings button key))))) + (xHandler.enableGamepadInput uiKeyMappings gamepadId) + (when otherKeyMappings + (keyHandler.enableGamepadInput otherKeyMappings gamepadId)) + this) \ No newline at end of file