Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

iOS shell: the mapping card keeps its drawing, for touch only

v0lumehic4428a434a6f
diff --git a/frontend-ios/README.md b/frontend-ios/README.md
index e8a97667..f2ba5a65 100644
--- a/frontend-ios/README.md
+++ b/frontend-ios/README.md
@@ -33,7 +33,7 @@ All boundary types are in `Sources/ShellUI/ShellInputs.swift` and `ShellArtwork.
- `ShellActions`: selection, Play, setting changes, game-data and cloud-folder requests, reset, log, app update and Back. The game ID is always passed.
- `ShellInput`: an optional semantic controller event with an increasing sequence and the device that sent it (`InputDevice`: a controller family or the keyboard), so the hints draw that device's glyphs.
-`ShellControllers` is a separate library target, not part of the views: `GamepadAdapter` reads every GameController controller (D-pad and left stick with a deadzone and the Mac's repeat on hold, A activates, B goes back, X and Menu open game settings, Y opens Controllers, by label so each family confirms with its own button) and reports `ShellInput` actions and the connected controllers with their battery. Its pure mapping (`PadMapper`, `RepeatTiming`) is unit tested. The Controllers page also opens a Button mapping card for all games: Swap A and B as a segmented choice, then the 16 buttons in four groups (face buttons, shoulders and triggers, D-pad, more), each row the button's glyph, where it sits and what it sends, with a cream dot on a row that differs and Reset in a footer that does not scroll. The buttons are named as on a Switch controller, by position, as the engine maps every controller. A row picked shows the buttons it can send as a grid of glyphs, and None. These affect games only. Its Button test card draws an Xbox-style controller and lights up each button, trigger and stick of the controller that moved as it is pressed (hold B to close), and forgets a controller that disconnects. Shell menus keep A to confirm and B to go back. Each game's settings have one Button mapping row that opens the same card for that game, which can follow all games, override single buttons, turn a button off, or explicitly keep A and B unswapped. `PadMappingCaptureTests` renders these views on the Mac (`NX_SHELL_CAPTURE_DIR`, `NX_SHELL_CAPTURE_LANG`). The demo uses it, the real shell can too.
+`ShellControllers` is a separate library target, not part of the views: `GamepadAdapter` reads every GameController controller (D-pad and left stick with a deadzone and the Mac's repeat on hold, A activates, B goes back, X and Menu open game settings, Y opens Controllers, by label so each family confirms with its own button) and reports `ShellInput` actions and the connected controllers with their battery. Its pure mapping (`PadMapper`, `RepeatTiming`) is unit tested. The Controllers page also opens a Button mapping card for all games: on top the button test's controller drawing with the Switch names of its places, for touch and VoiceOver, where a tap on a button opens its choices and a cream ring marks a changed button (it shows no controller input and is no focus target, so a controller moves through the rows, A picks and B closes), then Swap A and B as a segmented choice, then the 16 buttons in four groups (face buttons, shoulders and triggers, D-pad, more), each row the button's glyph, where it sits and what it sends, with a cream dot on a row that differs and Reset in a footer that does not scroll. The buttons are named as on a Switch controller, by position, as the engine maps every controller. A row picked shows the buttons it can send as a grid of glyphs, and None. These affect games only. Its Button test card draws an Xbox-style controller and lights up each button, trigger and stick of the controller that moved as it is pressed (hold B to close), and forgets a controller that disconnects. Shell menus keep A to confirm and B to go back. Each game's settings have one Button mapping row that opens the same card for that game, which can follow all games, override single buttons, turn a button off, or explicitly keep A and B unswapped. `PadMappingCaptureTests` renders these views on the Mac (`NX_SHELL_CAPTURE_DIR`, `NX_SHELL_CAPTURE_LANG`). The demo uses it, the real shell can too.
```swift
LibraryView(
diff --git a/frontend-ios/Sources/ShellUI/PadMappingView.swift b/frontend-ios/Sources/ShellUI/PadMappingView.swift
index 68c397f2..47f24060 100644
--- a/frontend-ios/Sources/ShellUI/PadMappingView.swift
+++ b/frontend-ios/Sources/ShellUI/PadMappingView.swift
@@ -86,7 +86,8 @@ struct PadMappingEntryRow: View {
}
}
-/// The button mapping in a card of its own. The list: Swap A and B as a segmented choice, then the 16 buttons in four
+/// The button mapping in a card of its own. The list: the controller drawing for touch and VoiceOver (no live input, no
+/// focus target), Swap A and B as a segmented choice, then the 16 buttons in four
/// grouped cards (face buttons, shoulders and triggers, D-pad, more), each row the button's glyph, where it sits and what it
/// sends, a cream dot on a row that differs. Reset stays in a footer under the scrolling list. A row picked shows the
/// buttons it can send as a grid of glyphs, in the same groups. D-pad and keys move through `map.` targets, A picks, B goes
@@ -213,6 +214,7 @@ struct PadMappingCard: View {
Text(ShellStrings.text(isGame ? "For this game only. A button left alone does what it does in all games."
: "For controllers in games only. This app’s menus keep A to confirm and B to go back."))
.shellType(ShellType.note).foregroundStyle(.white.opacity(0.5)).fixedSize(horizontal: false, vertical: true)
+ drawing
if let swapRow { swap(swapRow) }
ForEach(PadMap.groups, id: \.title) { group in
VStack(alignment: .leading, spacing: 10) {
@@ -236,6 +238,35 @@ struct PadMappingCard: View {
.padding(.horizontal, 20).padding(.vertical, 18)
}
+ /// The controller as the button test draws it, with the Switch names of its places, for touch and VoiceOver: a tap on a
+ /// button opens its choices, as its row does, and a cream ring marks a changed button. It never shows what a controller
+ /// presses and is no focus target. The card is a menu, so a controller moves through the rows below, A picks and B
+ /// closes. Trying buttons is the button test's job, which takes the controller's input for itself (#495).
+ private var drawing: some View {
+ func row(_ e: PadElement) -> SettingRow? {
+ PadMap.button(at: e).flatMap { button in rows.first { PadMappingRows.button(of: $0) == button } }
+ }
+ let marked = Set(rows.filter { !$0.fromShell }.compactMap { PadMap.element(of: PadMappingRows.button(of: $0)) })
+ return VStack(spacing: 10) {
+ XboxControllerDiagram(snapshot: PadSnapshot(), switchNames: true, marked: marked,
+ tap: { e in if let row = row(e) { open(row.id) } },
+ value: { e in
+ guard let row = row(e) else { return "" }
+ let sends = PadMap.label(PadMappingRows.output(of: row, inherited: inherited))
+ return row.fromShell ? sends : sends + ", " + ShellStrings.text("Changed")
+ })
+ .aspectRatio(XboxControllerDiagram.design.width / XboxControllerDiagram.design.height, contentMode: .fit)
+ .frame(maxWidth: 420)
+ .accessibilityElement(children: .contain)
+ .accessibilityLabel(ShellStrings.text("Controller"))
+ .accessibilityIdentifier("padMapping.drawing")
+ Text(ShellStrings.text("Tap a button to change what it sends."))
+ .shellType(ShellType.note).foregroundStyle(.white.opacity(0.45)).multilineTextAlignment(.center)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ .frame(maxWidth: .infinity)
+ }
+
/// Swap A and B: Off and On, and for a game first the shell's choice. Equal segments, stacked when they do not fit.
private func swap(_ row: SettingRow) -> some View {
// The shell's choice reads All games in a segment, short enough for three segments on a phone.
diff --git a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
index cd80ebce..ebecb56c 100644
--- a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
+++ b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
@@ -5105,6 +5105,46 @@
}
}
},
+ "Tap a button to change what it sends.": {
+ "localizations": {
+ "de": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tippe auf eine Taste, um zu ändern, was sie auslöst."
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tap a button to change what it sends."
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Touchez un bouton pour changer ce qu’il envoie."
+ }
+ },
+ "it": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tocca un tasto per cambiare cosa invia."
+ }
+ },
+ "sv": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tryck på en knapp för att ändra vad den skickar."
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "点按某个按键即可更改它对应的键。"
+ }
+ }
+ }
+ },
"The first start waits a few minutes for it, once.": {
"localizations": {
"de": {
diff --git a/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift b/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift
index b2c1b5b2..9f65af4a 100644
--- a/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift
+++ b/frontend-ios/Tests/ShellUITests/PadMappingCaptureTests.swift
@@ -88,10 +88,10 @@ final class PadMappingCaptureTests: XCTestCase {
try capture("pad-settings-row", width: 402, GameDetailView(detail: detail, showsPrimaryAction: false, showsHeader: false).padding(24))
}
- /// The drawing alone and large, to look at the shoulders: the card's (Switch names, rings on changed buttons, the left
- /// bumper held) and the test's (Xbox names, the right trigger half pulled).
+ /// The drawing alone and large, to look at the shoulders: the card's (Switch names, rings on changed buttons, nothing
+ /// held, as the card never shows a controller's input) and the test's (Xbox names, the triggers pulled).
func testCaptureTheDrawingUpClose() throws {
- let card = XboxControllerDiagram(snapshot: PadSnapshot(pressed: [.leftBumper]), switchNames: true, marked: [.rightBumper, .leftTrigger, .b])
+ let card = XboxControllerDiagram(snapshot: PadSnapshot(), switchNames: true, marked: [.rightBumper, .leftTrigger, .b])
try capture("pad-drawing-card", width: 960, card.aspectRatio(320 / 220, contentMode: .fit).padding(24))
// The triggers at 25, 50, 75 and 100 percent, LT and RT side by side in each, a face button held.
for (name, left, right) in [("25-50", 0.25, 0.5), ("75-100", 0.75, 1.0)] {
diff --git a/frontend-ios/Tests/ShellUITests/PadMappingCardControllerTests.swift b/frontend-ios/Tests/ShellUITests/PadMappingCardControllerTests.swift
new file mode 100644
index 00000000..3e0bcb02
--- /dev/null
+++ b/frontend-ios/Tests/ShellUITests/PadMappingCardControllerTests.swift
@@ -0,0 +1,61 @@
+#if os(macOS)
+import AppKit
+import SwiftUI
+import XCTest
+@testable import ShellUI
+
+/// On a device with a controller the mapping card is a menu: the D-pad moves its focus, A picks, B closes (#495). Its drawing
+/// is for touch and VoiceOver. It must not take a controller's state, and it must not be a focus target that takes or traps
+/// the controller's focus.
+@MainActor
+final class PadMappingCardControllerTests: XCTestCase {
+ private var rows: [SettingRow] {
+ let swap = SettingRow(id: "pad.swapAB", label: "Swap A and B",
+ kind: .choice([SettingOption("on", "On"), SettingOption("off", "Off")]), value: "on", fromShell: false)
+ return [swap] + PadMap.buttons.map { button in
+ SettingRow(id: "pad.\(button)", label: PadMap.label(button), kind: .choice(PadMap.options),
+ value: button == "ZR" ? "ZL" : button, fromShell: button != "ZR")
+ }
+ }
+
+ private func card(open: @escaping (String) -> Void = { _ in }) -> PadMappingCard {
+ PadMappingCard(title: "All games", rows: rows, inherited: nil, openRow: nil, open: open, pick: { _, _ in },
+ backToList: {}, reset: {}, close: {})
+ }
+
+ /// The card has no input for a controller's state: nothing held, no snapshot. The host sends `PadSnapshot`s only to the
+ /// button test (`onButtonTest`).
+ func testTheCardTakesNoControllerState() {
+ for child in Mirror(reflecting: card()).children {
+ // By the type's name, so an optional snapshot counts too (a nil of any optional is `is PadSnapshot?`).
+ let type = String(describing: Swift.type(of: child.value))
+ XCTAssertFalse(type.contains("PadSnapshot"), "\(child.label ?? "?") is a controller snapshot: \(type)")
+ XCTAssertFalse(type.contains("PadElement"), "\(child.label ?? "?") holds controller buttons: \(type)")
+ }
+ }
+
+ /// The card's focus targets are its close button, the swap, the 16 rows and Reset. The drawing adds none, and the D-pad
+ /// goes from the close button straight to the swap and from there down the rows.
+ func testTheDrawingIsNoFocusTarget() throws {
+ var targets: [FocusTarget] = []
+ let view = card()
+ .frame(width: 480, height: 3000)
+ .coordinateSpace(name: "shell")
+ .onPreferenceChange(FocusTargets.self) { targets = $0.filter { $0.frame.width > 1 } }
+ .environment(\.colorScheme, .dark)
+ let host = NSHostingView(rootView: view)
+ host.frame = NSRect(x: 0, y: 0, width: 480, height: 3000)
+ let window = NSWindow(contentRect: host.frame, styleMask: [.borderless], backing: .buffered, defer: false)
+ window.isReleasedWhenClosed = false
+ window.contentView = host
+ defer { window.contentView = nil }
+ host.layoutSubtreeIfNeeded()
+ RunLoop.main.run(until: Date().addingTimeInterval(0.3))
+
+ let expected = Set(["map.close", "map.swap.on", "map.swap.off", "map.reset"] + PadMap.buttons.map { "map.row.pad.\($0)" })
+ XCTAssertEqual(Set(targets.map(\.id)), expected)
+ XCTAssertEqual(FocusNavigation.next(from: "map.close", action: .down, targets: targets)?.hasPrefix("map.swap."), true)
+ XCTAssertEqual(FocusNavigation.next(from: "map.swap.on", action: .down, targets: targets), "map.row.pad.A")
+ }
+}
+#endif
diff --git a/frontend/l10n/de.json b/frontend/l10n/de.json
index 005d8d11..42b02c39 100644
--- a/frontend/l10n/de.json
+++ b/frontend/l10n/de.json
@@ -657,6 +657,7 @@
"ios.ui.padSwapAB": "A und B tauschen",
"ios.ui.padSwapNote": "Legt A auf die untere Taste, wo Xbox- und PlayStation-Controller bestätigen.",
"ios.ui.padSwapped": "A und B getauscht",
+ "ios.ui.padTapDrawing": "Tippe auf eine Taste, um zu ändern, was sie auslöst.",
"ios.ui.padTestNote": "Jede Taste leuchtet auf, wenn du sie drückst.",
"ios.ui.padTopButton": "Obere Taste",
"ios.ui.padUp": "Oben",
diff --git a/frontend/l10n/en.json b/frontend/l10n/en.json
index 8928a285..32e52638 100644
--- a/frontend/l10n/en.json
+++ b/frontend/l10n/en.json
@@ -758,6 +758,7 @@
"ios.ui.padSwapAB": "Swap A and B",
"ios.ui.padSwapNote": "Puts A on the bottom button, where Xbox and PlayStation controllers confirm.",
"ios.ui.padSwapped": "A and B swapped",
+ "ios.ui.padTapDrawing": "Tap a button to change what it sends.",
"ios.ui.padTestNote": "See each button light up as you press it.",
"ios.ui.padTopButton": "Top button",
"ios.ui.padUp": "Up",
diff --git a/frontend/l10n/fr.json b/frontend/l10n/fr.json
index 41c3be2e..7509a532 100644
--- a/frontend/l10n/fr.json
+++ b/frontend/l10n/fr.json
@@ -659,6 +659,7 @@
"ios.ui.padSwapAB": "Inverser A et B",
"ios.ui.padSwapNote": "Place A sur le bouton du bas, là où les manettes Xbox et PlayStation valident.",
"ios.ui.padSwapped": "A et B inversés",
+ "ios.ui.padTapDrawing": "Touchez un bouton pour changer ce qu’il envoie.",
"ios.ui.padTestNote": "Chaque bouton s’allume quand vous appuyez dessus.",
"ios.ui.padTopButton": "Bouton du haut",
"ios.ui.padUp": "Haut",
diff --git a/frontend/l10n/it.json b/frontend/l10n/it.json
index 8fc4abff..b8907b36 100644
--- a/frontend/l10n/it.json
+++ b/frontend/l10n/it.json
@@ -660,6 +660,7 @@
"ios.ui.padSwapAB": "Scambia A e B",
"ios.ui.padSwapNote": "Mette A sul tasto in basso, dove confermano i controller Xbox e PlayStation.",
"ios.ui.padSwapped": "A e B scambiati",
+ "ios.ui.padTapDrawing": "Tocca un tasto per cambiare cosa invia.",
"ios.ui.padTestNote": "Ogni tasto si illumina quando lo premi.",
"ios.ui.padTopButton": "Tasto in alto",
"ios.ui.padUp": "Su",
diff --git a/frontend/l10n/sv.json b/frontend/l10n/sv.json
index 90670aaf..1312a647 100644
--- a/frontend/l10n/sv.json
+++ b/frontend/l10n/sv.json
@@ -502,6 +502,7 @@
"ios.ui.padSwapAB": "Byt A och B",
"ios.ui.padSwapNote": "Lägger A på den nedre knappen, där Xbox- och PlayStation-handkontroller bekräftar.",
"ios.ui.padSwapped": "A och B bytta",
+ "ios.ui.padTapDrawing": "Tryck på en knapp för att ändra vad den skickar.",
"ios.ui.padTestNote": "Se varje knapp lysa upp när du trycker på den.",
"ios.ui.padTopButton": "Övre knappen",
"ios.ui.padUp": "Upp",
diff --git a/frontend/l10n/zh.json b/frontend/l10n/zh.json
index 37a5e0cf..4884f1c1 100644
--- a/frontend/l10n/zh.json
+++ b/frontend/l10n/zh.json
@@ -759,6 +759,7 @@
"ios.ui.padSwapAB": "交换 A 和 B",
"ios.ui.padSwapNote": "把 A 放到下方按键,与 Xbox 和 PlayStation 手柄的确认键位置一致。",
"ios.ui.padSwapped": "已交换 A 和 B",
+ "ios.ui.padTapDrawing": "点按某个按键即可更改它对应的键。",
"ios.ui.padTestNote": "按下按键时,对应的位置会亮起。",
"ios.ui.padTopButton": "上方按键",
"ios.ui.padUp": "上",