diff --git a/src/core/GamepadMap.lua b/src/core/GamepadMap.lua index 729f51b2..a63f851e 100644 --- a/src/core/GamepadMap.lua +++ b/src/core/GamepadMap.lua @@ -87,6 +87,18 @@ function GamepadMap.mapGamepadButton(button) return GamepadMap.gamepadBindings()[button] end +function GamepadMap.mapLauncherButton(button) + if nxActive() then + if button == "a" then return "b" + elseif button == "b" then return "a" + elseif button == "x" then return "y" + elseif button == "y" then return "x" + elseif button == "back" then return "select" + end + end + return button +end + -- Select+face display chords (docs / Nintendo UX): -- Select+A → "2" (COLORS), Select+B → "3" (TILT), -- Select+Y → "5", Select+X → "6", Select+L (leftshoulder) → "7". diff --git a/src/import/LauncherView.lua b/src/import/LauncherView.lua index 303dc8e3..1667bcfa 100644 --- a/src/import/LauncherView.lua +++ b/src/import/LauncherView.lua @@ -5645,6 +5645,14 @@ local function modalUp(imp) end local function buildModals(imp, m) + if Kit.VirtualKeyboard and Kit.VirtualKeyboard.active then + Kit.VirtualKeyboard.draw(m) + return true + end + if Kit.FileBrowser and Kit.FileBrowser.active then + Kit.FileBrowser.draw(m) + return true + end if imp._profileRenamePrompt then buildPrompt(imp, m, { key = "profren", title = Strings("Rename profile"), @@ -5791,14 +5799,6 @@ local function buildModals(imp, m) if imp._modActions then buildModActionsModal(imp, m) return true end if imp._findEntry then buildFindEntryModal(imp, m) return true end if imp._gameManage then buildGameManageModal(imp, m) return true end - if Kit.FileBrowser and Kit.FileBrowser.active then - Kit.FileBrowser.draw(m) - return true - end - if Kit.VirtualKeyboard and Kit.VirtualKeyboard.active then - Kit.VirtualKeyboard.draw(m) - return true - end return false end diff --git a/src/import/RomImporter.lua b/src/import/RomImporter.lua index c9d4f65c..2d69c696 100644 --- a/src/import/RomImporter.lua +++ b/src/import/RomImporter.lua @@ -3181,18 +3181,17 @@ function RomImporter:_updatePadCursor(dt) end function RomImporter:gamepadpressed(_, button) + local action = (GamepadMap.mapLauncherButton and GamepadMap.mapLauncherButton(button)) or button local okKit, Kit = pcall(require, "src.ui.kit.Kit") if okKit then - if Kit.FileBrowser and Kit.FileBrowser.active then - if Kit.FileBrowser.gamepadpressed(button) then return end - end if Kit.VirtualKeyboard and Kit.VirtualKeyboard.active then - if Kit.VirtualKeyboard.gamepadpressed(button) then return end + if Kit.VirtualKeyboard.gamepadpressed(action) then return end + end + if Kit.FileBrowser and Kit.FileBrowser.active then + if Kit.FileBrowser.gamepadpressed(action) then return end end end self:_activatePadCursor() - -- Map through GamepadMap so NX swaps SDL face labels to Nintendo A/B. - local action = GamepadMap.mapGamepadButton(button) if action == "a" then -- Instant click at the virtual pointer: dispatched straight into the -- view, since the launcher no longer hit-tests presses itself. @@ -3200,6 +3199,29 @@ function RomImporter:gamepadpressed(_, button) require("src.import.LauncherView").clickAt(self, self._padCursor.x, self._padCursor.y) end + elseif action == "b" then + -- Cancel / dismiss active prompts + if self._indexPrompt then + self._indexPrompt = nil + self:_disarmTextInput() + return + elseif self._rename then + self._rename = nil + self:_disarmTextInput() + return + elseif self._profileRenamePrompt then + self._profileRenamePrompt = nil + self:_disarmTextInput() + return + elseif self._profileSavePrompt then + self._profileSavePrompt = nil + self:_disarmTextInput() + return + elseif self._settingsText then + self._settingsText = nil + self:_disarmTextInput() + return + end elseif button == "leftshoulder" then self:_cycleTab(-1) elseif button == "rightshoulder" then diff --git a/src/ui/kit/Kit.lua b/src/ui/kit/Kit.lua index 0a0867e1..0ea18386 100644 --- a/src/ui/kit/Kit.lua +++ b/src/ui/kit/Kit.lua @@ -486,17 +486,19 @@ end -- Gamepad d-pad / stick, routed by the host's pad handling. function Kit.gamepadpressed(button) + local GamepadMap = require("src.core.GamepadMap") + local action = (GamepadMap.mapLauncherButton and GamepadMap.mapLauncherButton(button)) or button if VirtualKeyboard.active then - return VirtualKeyboard.gamepadpressed(button) + return VirtualKeyboard.gamepadpressed(action) end if FileBrowser.active then - return FileBrowser.gamepadpressed(button) + return FileBrowser.gamepadpressed(action) end - if button == "dpup" then Kit.navigate("up") return true - elseif button == "dpdown" then Kit.navigate("down") return true - elseif button == "dpleft" then Kit.navigate("left") return true - elseif button == "dpright" then Kit.navigate("right") return true - elseif button == "a" then Kit.activateFocused() return true end + if action == "dpup" then Kit.navigate("up") return true + elseif action == "dpdown" then Kit.navigate("down") return true + elseif action == "dpleft" then Kit.navigate("left") return true + elseif action == "dpright" then Kit.navigate("right") return true + elseif action == "a" then Kit.activateFocused() return true end return false end